Skip to content

Commit

Permalink
Add some more status messages
Browse files Browse the repository at this point in the history
  • Loading branch information
JWCook committed Jul 3, 2024
1 parent 2d65777 commit b24d3d1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
7 changes: 5 additions & 2 deletions naturtag/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ def __init__(self, app: NaturtagApp):
self.addToolBar(self.toolbar)
self.statusbar = QStatusBar(self)
self.setStatusBar(self.statusbar)
# self.status_widget = QLabel('This is a status widget')
# self.statusbar.addWidget(self.status_widget)
# self.status_widget.setAttribute(Qt.WA_TransparentForMouseEvents)

# Load any valid image paths provided on command line (or from drag & drop)
self.image_controller.gallery.load_images(
Expand Down Expand Up @@ -218,9 +221,9 @@ def closeEvent(self, _):
self.app.settings.write()
self.app.state.write()

def info(self, message: str):
def info(self, message: str, timeout: int = 3000):
"""Show a message both in the status bar and in the logs"""
self.statusbar.showMessage(message)
self.statusbar.showMessage(message, timeout)
logger.info(message)

def mousePressEvent(self, event):
Expand Down
3 changes: 3 additions & 0 deletions naturtag/controllers/base_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ class BaseController(StylableWidget):
@property
def app(self) -> 'NaturtagApp':
return QApplication.instance()

def info(self, message: str):
self.on_message.emit(message)
5 changes: 1 addition & 4 deletions naturtag/controllers/image_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ def refresh(self):
self.info('Select images to tag')
return

self.info(f'Refreshing tags for {len(images)} images')
for image in images:
future = self.app.threadpool.schedule(
lambda: _refresh_tags(image.metadata, self.app.client, self.app.settings),
)
future.on_result.connect(self.update_metadata)
self.info(f'{len(images)} images updated')

def clear(self):
"""Clear all images and input"""
Expand Down Expand Up @@ -208,6 +208,3 @@ def select_observation(self, observation: Observation):
card = ObservationInfoCard(obs=observation, delayed_load=False)
card.on_click.connect(self.on_view_observation_id)
self.data_source_card.addWidget(card)

def info(self, message: str):
self.on_message.emit(message)
3 changes: 2 additions & 1 deletion naturtag/controllers/observation_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def load_user_observations(self):
logger.info('Unknown user; skipping observation load')
return

logger.info('Fetching user observations')
self.info('Fetching user observations')
future = self.app.threadpool.schedule(
self.get_user_observations, priority=QThread.LowPriority
)
Expand Down Expand Up @@ -139,6 +139,7 @@ def display_user_observations(self, observations: list[Observation]):
self.update_pagination_buttons()
if self.total_results:
self.user_obs_group_box.set_title(f'My Observations ({self.total_results})')
self.info('')

def bind_selection(self, obs_cards: Iterable[ObservationInfoCard]):
"""Connect click signal from each observation card"""
Expand Down
5 changes: 3 additions & 2 deletions naturtag/controllers/taxon_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def display_taxon_by_id(self, taxon_id: int):
return

# Fetch taxon record
logger.info(f'Loading taxon {taxon_id}')
self.info(f'Loading taxon {taxon_id}')
client = self.app.client
if self.tabs._init_complete:
self.app.threadpool.cancel()
Expand All @@ -96,6 +96,7 @@ def display_taxon(self, taxon: Taxon, notify: bool = True):
self.bind_selection(self.taxonomy.ancestors_list.cards)
self.bind_selection(self.taxonomy.children_list.cards)
logger.debug(f'Loaded taxon {taxon.id}')
self.info('')

def set_search_results(self, taxa: list[Taxon]):
"""Load search results into Results tab"""
Expand Down Expand Up @@ -163,7 +164,7 @@ def add_tab(self, taxon_list: TaxonList, icon_str: str, label: str, tooltip: str
return taxon_list

def load_user_taxa(self):
logger.info('Fetching user-observed taxa')
self.info('Fetching user-observed taxa')
app = get_app()
client = app.client
display_ids = self.user_taxa.display_ids
Expand Down
5 changes: 4 additions & 1 deletion naturtag/storage/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ def get_user_observations(
updated_since=updated_since,
refresh=True,
).all()
logger.debug(f'{len(new_observations)} new observations found')
if new_observations:
logger.info(f'{len(new_observations)} new observations found since {updated_since}')
else:
logger.info(f'No new observations found since {updated_since}')

if not limit:
return []
Expand Down

0 comments on commit b24d3d1

Please sign in to comment.