Skip to content

Commit

Permalink
fix bug: menu cannot reload
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanchengyan committed Aug 26, 2023
1 parent 451146f commit 763979d
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions geo_sam_tool.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import List
from qgis.core import QgsApplication
from qgis.gui import QgsMapToolPan, QgisInterface
from qgis.gui import QgisInterface
from PyQt5.QtCore import pyqtSignal, QObject
from PyQt5.QtWidgets import (
QAction,
Expand Down Expand Up @@ -50,7 +49,7 @@ def initGui(self):

self.actionSamEncoderCopilot = QAction(
QIcon_EncoderCopilot,
"Encoder Copilot",
"Geo-SAM Encoder Copilot",
self.iface.mainWindow()
)

Expand Down Expand Up @@ -81,44 +80,40 @@ def initGui(self):
self.toolbar.addAction(self.actionSamEncoder)
self.toolbar.addAction(self.actionSamEncoderCopilot)
self.toolbar.setVisible(True)
# Not working
# start_time = time.time()
# while True:
# geoSamToolbar: QToolBar = self.iface.mainWindow().findChild(QToolBar,
# 'mGeoSamToolbar')
# current_time = time.time()
# elapsed_time = (current_time - start_time) * 1000
# if geoSamToolbar:
# geoSamToolbar.setVisible(False)
# break
# if elapsed_time > 3000:
# break

def create_widget_selector(self):
'''Create widget for selecting landform by prompts'''
if not hasattr(self, "wdg_sel"):
self.wdg_sel = Selector(self, self.iface, self.cwd)
self.wdg_sel.open_widget()
if not hasattr(self, "wdg_select"):
self.wdg_select = Selector(self, self.iface, self.cwd)
self.wdg_select.open_widget()

def create_widget_encoder_copilot(self):
'''Create widget for co-piloting encoder settings'''
if not hasattr(self, "wdg_sel"):
self.wdg_sel = EncoderCopilot(self, self.iface, self.cwd)
self.wdg_sel.open_widget()
if not hasattr(self, "wdg_copilot"):
self.wdg_copilot = EncoderCopilot(self, self.iface, self.cwd)
self.wdg_copilot.open_widget()

def unload(self):
'''Unload actions when plugin is closed'''
if hasattr(self, "wdg_sel"):
self.wdg_sel.unload()
self.wdg_sel.setParent(None)
# self.wdg_sel.setVisible(False)
if hasattr(self, "wdg_select"):
self.wdg_select.unload()
self.wdg_select.setParent(None)
if hasattr(self, "wdg_copilot"):
self.wdg_copilot.unload()
self.wdg_copilot.setParent(None)

# self.wdg_select.setVisible(False)
self.iface.removeToolBarIcon(self.actionSamTool)
self.iface.removeToolBarIcon(self.actionSamEncoder)
self.iface.removePluginMenu('&Geo-SAM', self.actionSamTool)
self.iface.removePluginMenu('&Geo-SAM', self.actionSamEncoder)
self.iface.removeToolBarIcon(self.actionSamEncoderCopilot)
self.iface.removePluginMenu('&Geo-SAM Tools', self.actionSamTool)
self.iface.removePluginMenu('&Geo-SAM Tools', self.actionSamEncoder)
self.iface.removePluginMenu(
'&Geo-SAM Tools', self.actionSamEncoderCopilot)

del self.actionSamTool
del self.actionSamEncoder
del self.actionSamEncoderCopilot
del self.toolbar
QgsApplication.processingRegistry().removeProvider(self.provider)

Expand Down

0 comments on commit 763979d

Please sign in to comment.