Skip to content

Commit

Permalink
Add option to open native file chooser + keyboard shortcuts; Issue #29
Browse files Browse the repository at this point in the history
  • Loading branch information
JWCook committed Jun 13, 2020
1 parent ce53179 commit ebe547b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,18 @@ See [CLI Usage](#cli-usage) for more details on these settings.
### Keyboard Shortcuts
Some keyboard shortcuts are included for convenience:

Key(s) | Action | Screen
----------------|------------------------|----------
F11 | Toggle fullscreen | All
Ctrl+Enter | Run image tagger | Image selection
Ctrl+Enter | Run taxon search | Taxon search
Shift+Ctrl+X | Clear selected images | Image selection
Shift+Ctrl+X | Clear search filters | Taxon search
Ctrl+S | Open settings screen | All
Ctrl+Backspace | Return to main screen | All
Ctrl+Q | Quit | All
Key(s) | Action | Screen
---- |---- |----------
F11 | Toggle fullscreen | All
Ctrl+O | Open file chooser | Image selection
Shift+Ctrl+O | Open file chooser (dirs) | Image selection
Ctrl+Enter | Run image tagger | Image selection
Ctrl+Enter | Run taxon search | Taxon search
Shift+Ctrl+X | Clear selected images | Image selection
Shift+Ctrl+X | Clear search filters | Taxon search
Ctrl+S | Open settings screen | All
Ctrl+Backspace | Return to main screen | All
Ctrl+Q | Quit | All

# See Also
* For generating keyword _collections_, see the related tool
Expand Down
6 changes: 4 additions & 2 deletions naturtag/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,12 @@ def on_keyboard(self, window, key, scancode, codepoint, modifier):
self.home()
elif (modifier, key) == (['ctrl'], ENTER):
self.current_screen_action()
elif (modifier, codepoint) == (['shift', 'ctrl'], 'x'):
elif (set(modifier), codepoint) == ({'ctrl', 'shift'}, 'x'):
self.current_screen_clear()
elif (modifier, codepoint) == (['ctrl'], 'o'):
pass # TODO: Open kivymd file manager
self.image_selection_controller.open_native_file_chooser()
elif (set(modifier), codepoint) == ({'ctrl', 'shift'}, 'o'):
self.image_selection_controller.open_native_file_chooser(dirs=True)
elif (modifier, codepoint) == (['ctrl'], 'q'):
self.on_request_close()
elif (modifier, codepoint) == (['ctrl'], 's'):
Expand Down
12 changes: 12 additions & 0 deletions naturtag/controllers/image_selection_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ async def load_image(self, path):
await asyncio.sleep(0)
return taxon, observation

def open_native_file_chooser(self, dirs=False):
""" A bit of a hack; uses a hidden tkinter window to open a native file chooser dialog """
from tkinter import Tk
from tkinter.filedialog import askopenfilenames, askdirectory
Tk().withdraw()
# Tkinter does not have a single dialog that combines directory and file selection >:[
if dirs:
paths = askdirectory(title='Choose an image directory')
else:
paths = askopenfilenames(title='Choose images')
self.add_images(paths)

def select_taxon_from_photo(self, taxon_id):
self.inputs.taxon_id_input.text = str(taxon_id)

Expand Down
4 changes: 4 additions & 0 deletions widget_tests/tk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from tkinter.filedialog import askopenfilename
import tkinter
tkinter.Tk().withdraw()
filename = askopenfilename()

0 comments on commit ebe547b

Please sign in to comment.