Skip to content

Commit

Permalink
Add dialog to prompt for username on first startup
Browse files Browse the repository at this point in the history
  • Loading branch information
JWCook committed Dec 6, 2023
1 parent 81726a4 commit 5e0f57b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
5 changes: 3 additions & 2 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
* Add tab for basic observation details
* When an observation is selected, show a summary of basic observation details on main screen
* Display observation count and leaf taxon count on taxon info cards
* In refresh mode, check for taxonomy changes and update tags with the new taxon (1:1 changes only)
* Add support for alternate XMP sidecar path format, if it already exists (`basename.ext.xmp` instead of `basename.xmp`)
* Add support for displaying and searching common names in any language supported by iNaturalist.org
* Uses the `locale` setting from settings menu
* The packaged taxon DB only contains english names, but a full version can be downloaded [here](https://github.com/pyinat/naturtag/releases/download/untagged-e757223556c30fa118ba/taxonomy_full.tar.gz)
* Add dialog to prompt for username on first startup

**CLI:**
* Split CLI into subcommands:
Expand All @@ -25,6 +24,8 @@

**Metadata:**
* Add support for GPS positional accuracy
* Add support for alternate XMP sidecar path format, if it already exists (`basename.ext.xmp` instead of `basename.xmp`)
* In refresh mode, check for taxonomy changes and update tags with the new taxon (1:1 changes only)

**Database:**
* Include data for most commonly observed taxa with PyInstaller packages and platform-specific installers
Expand Down
38 changes: 28 additions & 10 deletions naturtag/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from PySide6.QtGui import QIcon, QKeySequence, QPixmap, QShortcut
from PySide6.QtWidgets import (
QApplication,
QInputDialog,
QLineEdit,
QMainWindow,
QMessageBox,
Expand Down Expand Up @@ -40,19 +41,21 @@


class NaturtagApp(QApplication):
def __init__(self, *args, settings: Settings, **kwargs):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setApplicationName('Naturtag')
self.setOrganizationName('pyinat')
self.setApplicationVersion(pkg_version('naturtag'))
self.setOrganizationName('pyinat')
self.setWindowIcon(QIcon(QPixmap(str(APP_ICON))))
self.settings = Settings.read()

def post_init(self):
# Run any first-time setup steps, if needed
setup(settings)
setup(self.settings)

# Globally available application objects
self.settings = settings
self.client = iNatDbClient(settings.db_path)
self.img_session = ImageSession(settings.image_cache_path)
self.client = iNatDbClient(self.settings.db_path)
self.img_session = ImageSession(self.settings.image_cache_path)
self.log_handler = init_handler(
self.settings.log_level,
root_level=self.settings.log_level_external,
Expand Down Expand Up @@ -174,6 +177,21 @@ def __init__(self, app: NaturtagApp):
self.image_controller.gallery.load_images(demo_images) # type: ignore
self.observation_controller.select_observation(56830941)

def check_username(self):
"""If username isn't saved, show popup dialog to prompt user to enter it"""
if self.app.settings.username:
return

username, ok = QInputDialog.getText(
self,
'iNaturalist username',
'Enter your iNaturalist username to fetch your observations',
)
if ok:
self.app.settings.username = username
self.app.settings.write()
self.observation_controller.load_user_observations()

def closeEvent(self, _):
"""Save settings before closing the app"""
self.app.settings.write()
Expand Down Expand Up @@ -254,16 +272,16 @@ def toggle_log_tab(self, checked: bool = True):


def main():
settings = Settings.read()
app = NaturtagApp(sys.argv, settings=settings)
app = NaturtagApp(sys.argv)
splash = QSplashScreen(QPixmap(str(APP_LOGO)).scaledToHeight(512))
splash.show()
app.setWindowIcon(QIcon(QPixmap(str(APP_ICON))))
app.post_init()

set_theme(dark_mode=settings.dark_mode)
set_theme(dark_mode=app.settings.dark_mode)
window = MainWindow(app)
window.show()
splash.finish(window)
window.check_username()
sys.exit(app.exec())


Expand Down

0 comments on commit 5e0f57b

Please sign in to comment.