Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI : ajoute une toolbar dédiée au plugin #169

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions qtribu/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
from typing import Optional
from urllib.parse import urlparse

# 3rd party
from qgis.PyQt.QtGui import QIcon

# plugin
from qtribu.__about__ import DIR_PLUGIN_ROOT

ICON_ARTICLE = QIcon(str(DIR_PLUGIN_ROOT.joinpath("resources/images/article.svg")))
ICON_GEORDP = QIcon(str(DIR_PLUGIN_ROOT.joinpath("resources/images/geordp.svg")))


# Classes
@dataclass
Expand Down
4 changes: 1 addition & 3 deletions qtribu/gui/dlg_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from qgis.PyQt.QtWidgets import QDialog, QTreeWidgetItem, QWidget

from qtribu.__about__ import DIR_PLUGIN_ROOT
from qtribu.constants import ICON_ARTICLE, ICON_GEORDP
from qtribu.gui.form_article import ArticleForm
from qtribu.gui.form_rdp_news import RdpNewsForm
from qtribu.logic import RssItem
Expand All @@ -21,9 +22,6 @@
from qtribu.toolbelt.commons import open_url_in_browser, open_url_in_webviewer

# -- GLOBALS --

ICON_ARTICLE = QIcon(str(DIR_PLUGIN_ROOT.joinpath("resources/images/article.svg")))
ICON_GEORDP = QIcon(str(DIR_PLUGIN_ROOT.joinpath("resources/images/geordp.svg")))
MARKER_VALUE = "---"

# -- CLASSES --
Expand Down
64 changes: 50 additions & 14 deletions qtribu/plugin_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

# project
from qtribu.__about__ import DIR_PLUGIN_ROOT, __icon_path__, __title__, __uri_homepage__
from qtribu.constants import ICON_ARTICLE, ICON_GEORDP
from qtribu.gui.dlg_contents import GeotribuContentsDialog
from qtribu.gui.dlg_settings import PlgOptionsFactory
from qtribu.gui.form_article import ArticleForm
from qtribu.gui.form_rdp_news import RdpNewsForm
from qtribu.logic import RssMiniReader, SplashChanger
from qtribu.toolbelt import NetworkRequestsManager, PlgLogger, PlgOptionsManager
Expand Down Expand Up @@ -77,9 +79,13 @@ def initGui(self):
self.options_factory = PlgOptionsFactory()
self.iface.registerOptionsWidgetFactory(self.options_factory)

# toolbar
self.toolbar = self.iface.addToolBar("ToolbarGeotribu")

# -- Forms
self.form_rdp_news = None
self.form_article = None
self.form_contents = None
self.form_rdp_news = None

# -- Actions
self.action_run = QAction(
Expand All @@ -93,18 +99,25 @@ def initGui(self):

self.action_contents = QAction(
QgsApplication.getThemeIcon("mActionOpenTableVisible.svg"),
self.tr("Contents"),
self.tr("Browse latest contents"),
self.iface.mainWindow(),
)
self.action_contents.setToolTip(self.tr("Contents"))
self.action_contents.setToolTip(self.tr("Browse latest contents"))
self.action_contents.triggered.connect(self.contents)

self.action_rdp_news = QAction(
QIcon(QgsApplication.iconPath("mActionHighlightFeature.svg")),
self.action_form_rdp_news = QAction(
ICON_GEORDP,
self.tr("Propose a news to the next GeoRDP"),
self.iface.mainWindow(),
)
self.action_rdp_news.triggered.connect(self.open_form_rdp_news)
self.action_form_rdp_news.triggered.connect(self.open_form_rdp_news)

self.action_form_article = QAction(
ICON_ARTICLE,
self.tr("Submit an article"),
self.iface.mainWindow(),
)
self.action_form_article.triggered.connect(self.open_form_article)

self.action_help = QAction(
QIcon(QgsApplication.iconPath("mActionHelpContents.svg")),
Expand All @@ -130,7 +143,8 @@ def initGui(self):
# -- Menu
self.iface.addPluginToWebMenu(__title__, self.action_run)
self.iface.addPluginToWebMenu(__title__, self.action_contents)
self.iface.addPluginToWebMenu(__title__, self.action_rdp_news)
self.iface.addPluginToWebMenu(__title__, self.action_form_rdp_news)
self.iface.addPluginToWebMenu(__title__, self.action_form_article)
self.iface.addPluginToWebMenu(__title__, self.action_splash)
self.iface.addPluginToWebMenu(__title__, self.action_settings)
self.iface.addPluginToWebMenu(__title__, self.action_help)
Expand Down Expand Up @@ -173,9 +187,10 @@ def initGui(self):
self.iface.helpMenu().addAction(self.action_osgeofr)

# -- Toolbar
self.iface.addToolBarIcon(self.action_run)
self.iface.addToolBarIcon(self.action_contents)
self.iface.addToolBarIcon(self.action_rdp_news)
self.toolbar.addAction(self.action_run)
self.toolbar.addAction(self.action_contents)
self.toolbar.addAction(self.action_form_rdp_news)
self.toolbar.addAction(self.action_form_article)

# -- Post UI initialization
self.iface.initializationCompleted.connect(self.post_ui_init)
Expand All @@ -184,7 +199,8 @@ def unload(self):
"""Cleans up when plugin is disabled/uninstalled."""
# -- Clean up menu
self.iface.removePluginWebMenu(__title__, self.action_help)
self.iface.removePluginWebMenu(__title__, self.action_rdp_news)
self.iface.removePluginWebMenu(__title__, self.action_form_article)
self.iface.removePluginWebMenu(__title__, self.action_form_rdp_news)
self.iface.removePluginWebMenu(__title__, self.action_run)
self.iface.removePluginWebMenu(__title__, self.action_contents)
self.iface.removePluginWebMenu(__title__, self.action_settings)
Expand All @@ -195,9 +211,7 @@ def unload(self):
self.iface.pluginHelpMenu().removeAction(self.action_osgeofr)

# -- Clean up toolbar
self.iface.removeToolBarIcon(self.action_run)
self.iface.removeToolBarIcon(self.action_contents)
self.iface.removeToolBarIcon(self.action_rdp_news)
del self.toolbar

# -- Clean up preferences panel in QGIS settings
self.iface.unregisterOptionsWidgetFactory(self.options_factory)
Expand Down Expand Up @@ -319,6 +333,28 @@ def contents(self):
self.form_contents = GeotribuContentsDialog()
self.form_contents.show()

def open_form_article(self) -> None:
"""Open the form to create a GeoRDP news."""
if not self.form_article:
self.form_article = ArticleForm()
self.form_article.setModal(True)
self.form_article.finished.connect(self._post_form_article)
self.form_article.show()

def _post_form_article(self, dialog_result: int) -> None:
"""Perform actions after the GeoRDP news form has been closed.

:param dialog_result: dialog's result code. Accepted (1) or Rejected (0)
:type dialog_result: int
"""
if self.form_article:
# if accept button, save user inputs
if dialog_result == 1:
self.form_article.wdg_author.save_settings()
# clean up
self.form_article.deleteLater()
self.form_article = None

def open_form_rdp_news(self) -> None:
"""Open the form to create a GeoRDP news."""
if not self.form_rdp_news:
Expand Down
37 changes: 21 additions & 16 deletions qtribu/resources/i18n/qtribu_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,83 +134,88 @@
<context>
<name>GeotribuContentsDialog</name>
<message>
<location filename="../../gui/dlg_contents.py" line="82"/>
<location filename="../../gui/dlg_contents.py" line="80"/>
<source>Date</source>
<translation>Date de publication</translation>
</message>
<message>
<location filename="../../gui/dlg_contents.py" line="82"/>
<location filename="../../gui/dlg_contents.py" line="80"/>
<source>Title</source>
<translation>Titre</translation>
</message>
<message>
<location filename="../../gui/dlg_contents.py" line="82"/>
<location filename="../../gui/dlg_contents.py" line="80"/>
<source>Author(s)</source>
<translation>Auteur(ices)</translation>
</message>
<message>
<location filename="../../gui/dlg_contents.py" line="82"/>
<location filename="../../gui/dlg_contents.py" line="80"/>
<source>Tags</source>
<translation>Mots-clés</translation>
</message>
</context>
<context>
<name>GeotribuPlugin</name>
<message>
<location filename="../../plugin_main.py" line="303"/>
<location filename="../../plugin_main.py" line="317"/>
<source>Newest article</source>
<translation>Afficher le dernier article</translation>
</message>
<message>
<location filename="../../plugin_main.py" line="109"/>
<location filename="../../plugin_main.py" line="122"/>
<source>Help</source>
<translation>Aide en ligne</translation>
</message>
<message>
<location filename="../../plugin_main.py" line="118"/>
<location filename="../../plugin_main.py" line="131"/>
<source>Settings</source>
<translation>Réglages</translation>
</message>
<message>
<location filename="../../plugin_main.py" line="244"/>
<location filename="../../plugin_main.py" line="258"/>
<source>New content published:</source>
<translation>Nouveau contenu publié :</translation>
</message>
<message>
<location filename="../../plugin_main.py" line="151"/>
<location filename="../../plugin_main.py" line="165"/>
<source>QGIS forum on GeoRezo</source>
<translation>Forum QGIS sur GeoRezo</translation>
</message>
<message>
<location filename="../../plugin_main.py" line="140"/>
<location filename="../../plugin_main.py" line="154"/>
<source>Geotribu website</source>
<translation>Site Geotribu</translation>
</message>
<message>
<location filename="../../plugin_main.py" line="161"/>
<location filename="../../plugin_main.py" line="175"/>
<source>OSGeo France</source>
<translation>OSGeo FR</translation>
</message>
<message>
<location filename="../../plugin_main.py" line="102"/>
<location filename="../../plugin_main.py" line="108"/>
<source>Propose a news to the next GeoRDP</source>
<translation>Proposer une news pour la GeoRDP</translation>
</message>
<message>
<location filename="../../plugin_main.py" line="309"/>
<location filename="../../plugin_main.py" line="323"/>
<source>Michel, we&apos;ve got a problem: {err}</source>
<translation></translation>
</message>
<message>
<location filename="../../plugin_main.py" line="271"/>
<location filename="../../plugin_main.py" line="285"/>
<source>Unable to insert latest item within QGIS news feed. Trace: {err}</source>
<translation>Impossible d&apos;insérer le dernier contenu publié dans le fil d&apos;actualité de QGIS. Trace : {err}</translation>
</message>
<message>
<location filename="../../plugin_main.py" line="99"/>
<source>Contents</source>
<location filename="../../plugin_main.py" line="105"/>
<source>Browse latest contents</source>
<translation>Rechercher dans les contenus</translation>
</message>
<message>
<location filename="../../plugin_main.py" line="115"/>
<source>Submit an article</source>
<translation>Proposer un article</translation>
</message>
</context>
<context>
<name>RdpNewsForm</name>
Expand Down
Loading