Skip to content

Commit

Permalink
Save and restore last used directory in file chooser; Issue #29
Browse files Browse the repository at this point in the history
  • Loading branch information
JWCook committed Jun 13, 2020
1 parent 3e88bf7 commit 238d2b9
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 265 deletions.
2 changes: 2 additions & 0 deletions default_settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ metadata:
create_xmp: true
darwin_core: true
hierarchical_keywords: true
photos:
start_dir: '/'
12 changes: 11 additions & 1 deletion kv/context_menus.kv
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@
PhotoContextMenuItem:
id: remove_ctx
text: "Remove from selection"
# Just some ideas for future features
# Just some ideas for future features
# ContextMenuDivider:
# text: "Taxon"
# PhotoContextMenuItem:
# id: view_taxon_ctx
# text: "View taxon"
# disabled: True
# PhotoContextMenuItem:
# text: "View taxon on iNaturalist"
# disabled: True
# Or maybe nested menus:
# ContextMenuDivider:
# text: "More options"
# ContextMenuTextItem:
Expand Down
25 changes: 5 additions & 20 deletions kv/image_selection.kv
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,14 @@
orientation: 'vertical'
md_bg_color: .1, .1, .1, .75
FileChooserListView:
rootpath: 'D:\\NextCloud\\Photos' # TODO: remove, just for debugging
id: file_chooser
dirselect: True
filters: IMAGE_FILETYPES

# List of selected files
MDBoxLayout:
orientation: 'vertical'
md_bg_color: app.theme_cls.primary_color

MDLabel:
text: 'Selected Files:'
size_hint_max_y: dp(20)
TextInput:
id: file_list_text_box
readonly: True
multiline: True
size_hint_y: .3

# Buttons; TODO: Make this less ugly
MDBoxLayout:
size_hint_y: None
height: dp(30)
height: dp(50)
spacing: dp(5)

MDRaisedButton:
Expand All @@ -95,10 +80,10 @@
height: dp(50)
theme_text_color: 'Primary'
md_bg_color: app.theme_cls.accent_color
# MDRaisedButton:
# id: debug_button
# text: 'Debug'
# md_bg_color: app.theme_cls.accent_color
# MDRaisedButton:
# id: debug_button
# text: 'Debug'
# md_bg_color: app.theme_cls.accent_color
MDRaisedButton:
id: load_button
text: 'Load Selected File/Folder'
Expand Down
2 changes: 2 additions & 0 deletions naturtag/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ def init_controllers(self, screens):
self.select_taxon = self.taxon_view_controller.select_taxon
self.select_taxon_from_photo = self.image_selection_controller.select_taxon_from_photo
self.update_history = self.taxon_selection_controller.update_history
self.add_control_widget = self.settings_controller.add_control_widget

# Proxy properties
self.stored_taxa = self.settings_controller.stored_taxa
self.locale = self.settings_controller.locale
self.metadata = self.settings_controller.metadata
self.preferred_place_id = self.settings_controller.preferred_place_id

self.image_selection_controller.post_init()
self.taxon_selection_controller.post_init()

def get_taxon_list_item(self, *args, **kwargs):
Expand Down
236 changes: 0 additions & 236 deletions naturtag/app/testapp.py

This file was deleted.

11 changes: 5 additions & 6 deletions naturtag/controllers/image_selection_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def __init__(self, screen, **kwargs):
self.image_previews = screen.image_previews
self.file_chooser = screen.file_chooser
self.file_list = []
self.file_list_text = ''

# Context menu item events
self.context_menu.ids.view_taxon_ctx.bind(on_release=self.view_taxon)
Expand All @@ -42,6 +41,10 @@ def __init__(self, screen, **kwargs):
self.inputs.run_button.bind(on_release=self.run)
self.file_chooser.bind(on_submit=self.add_file_chooser_images)

def post_init(self):
# Load and save start dir from file chooser with the rest of the app settings
get_app().add_control_widget(self.file_chooser, 'start_dir', 'photos')

def add_file_chooser_images(self, *args):
""" Add one or more files and/or dirs selected via a FileChooser """
self.add_images(self.file_chooser.selection)
Expand Down Expand Up @@ -70,7 +73,6 @@ async def load_image(self, path):
logger.info(f'Main: Adding image {path}')
self.file_list.append(path)
self.file_list.sort()
self.inputs.file_list_text_box.text = '\n'.join(self.file_list)

# Add thumbnail to image preview screen
metadata = MetaMetadata(path)
Expand Down Expand Up @@ -112,15 +114,12 @@ def remove_image(self, image):
""" Remove an image from file list and image previews """
logger.info(f'Main: Removing image {image.metadata.image_path}')
self.file_list.remove(image.metadata.image_path)
self.inputs.file_list_text_box.text = '\n'.join(self.file_list)
image.parent.remove_widget(image)

def clear(self, *args):
""" Clear all image selections (selected files, previews, and inputs) """
logger.info('Main: Clearing image selections')
self.file_list = []
self.file_list_text = ''
self.inputs.file_list_text_box.text = ''
self.inputs.observation_id_input.text = ''
self.inputs.taxon_id_input.text = ''
self.file_chooser.selection = []
Expand All @@ -138,7 +137,7 @@ def get_state(self, *args):
logger.info(
'Main:',
f'IDs: {self.ids}\n'
f'Files:\n{self.file_list_text}\n'
f'Files:\n{self.file_list}\n'
f'Input: {self.input_dict}\n'
)

Expand Down

0 comments on commit 238d2b9

Please sign in to comment.