Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
8 changes: 5 additions & 3 deletions docs/docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ In the `Project` tab:

## Install the module plugin

In the `Plugin` tab, you can install the module plugin (ie. TWW plugin). Direct install using the `Install` button is currently not implemented.
In the `Plugin` tab, you can install the module plugin (ie. TWW plugin). There are two possibilities:

* Click `Copy ZIP to directory`
* In QGIS > Extension > Install and manage extension > Install from ZIP
1. Click `Install` and it will be installed in the current QGIS profile. Note: this is possible only if running oQtopus from QGIS.
2. Click `Copy ZIP to directory`:
* You can copy the plugin zip file to a directory of your choice.
* Then in QGIS > Extension > Install and manage extension > Install from ZIP.


## oQtopus as a standalone python executable
Expand Down
5 changes: 2 additions & 3 deletions oqtopus/gui/main_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@


class MainDialog(QDialog, DIALOG_UI):

def __init__(self, modules_config_path, about_dialog_cls=None, parent=None):
def __init__(self, modules_config_path, about_dialog_cls=None, parent=None, qgis_iface=None):
QDialog.__init__(self, parent)
self.setupUi(self)

Expand All @@ -82,7 +81,7 @@ def __init__(self, modules_config_path, about_dialog_cls=None, parent=None):
self.project_tab.layout().addWidget(self.__projectWidget)

# Init GUI Plugin
self.__pluginWidget = PluginWidget(self)
self.__pluginWidget = PluginWidget(self, qgis_iface=qgis_iface)
self.plugin_tab.layout().addWidget(self.__pluginWidget)

# Init GUI Logs
Expand Down
110 changes: 96 additions & 14 deletions oqtopus/gui/plugin_widget.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import shutil
from zipfile import ZipFile

from qgis.PyQt.QtCore import QUrl
from qgis.PyQt.QtGui import QDesktopServices
Expand All @@ -13,8 +14,7 @@


class PluginWidget(QWidget, DIALOG_UI):

def __init__(self, parent=None):
def __init__(self, parent=None, qgis_iface=None):
QWidget.__init__(self, parent)
self.setupUi(self)

Expand All @@ -23,9 +23,17 @@ def __init__(self, parent=None):
self.copyZipToDirectory_pushButton.clicked.connect(self.__copyZipToDirectoryClicked)

self.__current_module_package = None
self.__plugin_name = None
self.__iface = qgis_iface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another simpler approach is to simply import iface
https://github.com/osgeosuomi/flake8-qgis?tab=readme-ov-file#qgs105

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I'll use that


if self.__iface:
self.qgisProfile_label.setText(self.__iface.userProfileManager().userProfile().name())
else:
self.qgisProfile_label.setText("Unknown")

def setModulePackage(self, module_package: ModulePackage):
self.__current_module_package = module_package
self.__plugin_name = None
self.__packagePrepareGetPluginFilename()

def clearModulePackage(self):
Expand Down Expand Up @@ -58,6 +66,20 @@ def __packagePrepareGetPluginFilename(self):
QtUtils.setFontItalic(self.info_label, True)
return

# Get the plugin name
self.__plugin_name = self.__extractPluginName(asset_plugin.package_zip)
if not self.__plugin_name:
self.info_label.setText(
self.tr(f"Couldn't determinate the plugin name for '{asset_plugin.package_zip}'.")
)
QtUtils.setForegroundColor(self.info_label, PluginUtils.COLOR_WARNING)
QtUtils.setFontItalic(self.info_label, True)
return

# Get the installed plugin current version
version = self.__getInstalledPluginVersion(self.__plugin_name)
self.currentVersion_label.setText(version)

QtUtils.resetForegroundColor(self.info_label)
QtUtils.setFontItalic(self.info_label, False)
self.info_label.setText(
Expand All @@ -76,21 +98,61 @@ def __installClicked(self):
# Check if the package exists
asset_plugin = self.__current_module_package.asset_plugin
if not os.path.exists(asset_plugin.package_zip):
self.info_label.setText(
self.tr(f"Plugin zip file '{asset_plugin.package_zip}' does not exist.")
QMessageBox.critical(
self,
self.tr("Error"),
self.tr(f"Plugin zip file '{asset_plugin.package_zip}' does not exist."),
)
QtUtils.setForegroundColor(self.info_label, PluginUtils.COLOR_WARNING)
QtUtils.setFontItalic(self.info_label, True)
return

QMessageBox.warning(
self,
self.tr("Not implemented"),
self.tr(
'Installation is not implemented yet.\nAt the moment, you can only copy the plugin zip file to a directory and use "Install from ZIP" in QGIS.'
),
)
return
try:
from pyplugin_installer import instance as plugin_installer_instance
from qgis.core import Qgis
except ImportError:
QMessageBox.critical(
self,
self.tr("Error"),
self.tr("Plugin installation is not possible when oQtopus is running standalone."),
)
return

try:
installer = plugin_installer_instance()
success = installer.installFromZipFile(asset_plugin.package_zip)

# installFromZipFile return success from QGIS 3.44.08
if Qgis.QGIS_VERSION_INT < 34408:
version = self.__getInstalledPluginVersion(self.__plugin_name)
QMessageBox.information(
self,
self.tr("Installation finished"),
self.tr(f"Current '{self.__plugin_name}' plugin version is {version}"),
)
self.__packagePrepareGetPluginFilename()
return

if not success:
QMessageBox.critical(
self,
self.tr("Error"),
self.tr(f"Plugin '{self.__plugin_name}' installation failed."),
)
return

QMessageBox.information(
self,
self.tr("Success"),
self.tr(f"Plugin '{self.__plugin_name}' installed successfully."),
)
self.__packagePrepareGetPluginFilename()

except Exception as e:
QMessageBox.critical(
self,
self.tr("Error"),
self.tr("Plugin installation failed with an exception: {0}").format(str(e)),
)
return

def __seeChangelogClicked(self):
if self.__current_module_package is None:
Expand Down Expand Up @@ -168,3 +230,23 @@ def __copyZipToDirectoryClicked(self):
self.tr(f"Failed to copy plugin package: {e}"),
)
return

def __extractPluginName(self, package_zip: str) -> str:
with ZipFile(package_zip, "r") as zip_ref:
for name in zip_ref.namelist():
print(f"name: {name}")
if name.endswith("/metadata.txt"):
return name.split("/")[0]
return ""

def __getInstalledPluginVersion(self, plugin_name: str):
if not self.__iface:
return self.tr("Unknown")

import qgis

version = qgis.utils.pluginMetadata(plugin_name, "version")
if version == "__error__":
return self.tr("Not installed")

return version
4 changes: 3 additions & 1 deletion oqtopus/oqtopus_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ def unload(self):
def show_main_dialog(self):
conf_path = Path(__file__).parent / "default_config.yaml"

main_dialog = MainDialog(modules_config_path=conf_path, parent=self.iface.mainWindow())
main_dialog = MainDialog(
modules_config_path=conf_path, parent=self.iface.mainWindow(), qgis_iface=self.iface
)
main_dialog.exec()

def show_logs_folder(self):
Expand Down
8 changes: 7 additions & 1 deletion oqtopus/ui/plugin_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@
<property name="text">
<string>-</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="currentVersion_label">
<property name="text">
<string>no current version</string>
<string>Unknown</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
Expand Down