1818 * *
1919 ***************************************************************************/
2020"""
21- import os . path
21+ from qgis . gui import QgsMapToolIdentify
2222
23- from Geo360Dialog import Geo360Dialog
24- from PyQt4 .QtCore import QTimer , Qt
25- from PyQt4 .QtGui import QAction , QIcon , QCursor , QPixmap
26- from qgis .core import *
27- from qgis .gui import QgsMapToolIdentify , QgsMessageBar
28- import qgis .utils
29- from server .local_server import *
30- from utils .log import log
31- from utils .qgsutils import qgsutils
32-
33-
34- from PyQt4 import QtGui
23+ from PyQt5 .QtCore import QTimer , Qt , QSettings , QThread
24+ from PyQt5 .QtGui import QIcon , QCursor , QPixmap
25+ from PyQt5 .QtWidgets import QAction
3526
27+ from EquirectangularViewer .Geo360Dialog import Geo360Dialog
28+ import EquirectangularViewer .config as config
29+ from EquirectangularViewer .server .local_server import openWebApp
30+ from EquirectangularViewer .utils .log import log
31+ from EquirectangularViewer .utils .qgsutils import qgsutils
32+ from qgis .core import QgsApplication
3633
3734try :
3835 from pydevd import *
@@ -54,8 +51,13 @@ def __init__(self, iface):
5451
5552 self .iface = iface
5653 self .canvas = self .iface .mapCanvas ()
57-
58- self .plugin_path = os .path .dirname (os .path .realpath (__file__ ))
54+ threadcount = QThread .idealThreadCount ()
55+ # use all available cores and parallel rendering
56+ QgsApplication .setMaxThreads (threadcount )
57+ QSettings ().setValue ("/qgis/parallel_rendering" , True )
58+ # OpenCL acceleration
59+ QSettings ().setValue ("/core/OpenClEnabled" , True )
60+ self .dlg = None
5961
6062 def createTimer (self ):
6163 self .timer = QTimer ()
@@ -65,17 +67,14 @@ def createTimer(self):
6567 def onTimer (self ):
6668 try :
6769 cefpython .MessageLoopWork ()
68- except :
70+ except Exception :
6971 None
7072
7173 def stopTimer (self ):
7274 self .timer .stop ()
7375
7476 def StartCefPython (self ):
7577 ''' Start CefPython '''
76- qgsutils .showUserAndLogMessage (
77- self , u"Information: " , u"Create Viewer." , QgsMessageBar .INFO ,
78- onlyLog = True )
7978 settings = {}
8079 settings ["browser_subprocess_path" ] = "%s/%s" % (
8180 cefpython .GetModuleDirectory (), "subprocess" )
@@ -114,23 +113,17 @@ def run(self):
114113 lys = self .canvas .layers ()
115114 if len (lys ) == 0 :
116115 qgsutils .showUserAndLogMessage (
117- self , u"Information: " , u"You need to upload the photo layer." ,
118- QgsMessageBar .INFO )
116+ u"Information: " , u"You need to upload the photo layer." )
119117 return
120118
121119 # Folder viewer for local server
122- folder = self .plugin_path + "\\ viewer"
123-
120+ folder = QgsApplication .qgisSettingsDirPath () + 'python/plugins/EquirectangularViewer/viewer'
124121 # Start local server in plugin folder
125122 openWebApp (folder )
126- QtGui .qApp .processEvents ()
127-
128123 self .StartCefPython ()
129- QtGui .qApp .processEvents ()
130124
131125 # Create Timer is necessary for cefpython
132126 self .createTimer ()
133- QtGui .qApp .processEvents ()
134127
135128 for layer in lys :
136129 if layer .name () == config .layer_name :
@@ -140,8 +133,7 @@ def run(self):
140133
141134 if self .encontrado is False :
142135 qgsutils .showUserAndLogMessage (
143- self , u"Information: " , u"You need to upload the photo layer." ,
144- level = QgsMessageBar .INFO )
136+ u"Information: " , u"You need to upload the photo layer." )
145137
146138 return
147139
@@ -150,22 +142,12 @@ def ShowDialog(self, featuresId=None, layer=None):
150142 self .featuresId = featuresId
151143 self .layer = layer
152144
153- Geo360 = qgis .utils .plugins ["EquirectangularViewer" ]
154- try :
155- if (Geo360 .dlg ):
156- qgsutils .removeAllHighlightFeaturesFromCanvasScene (self .canvas )
157- self .dlg .ReloadView (self .featuresId )
158-
159- if (Geo360 .dlg .isVisible () is False ):
160- self .dlg .show ()
161- return
162- except :
163- self .dlg = Geo360Dialog (self .iface , parent = self .iface .mainWindow (
164- ), featuresId = featuresId , layer = self .layer )
165- self .dlg .setWindowFlags (
166- Qt .WindowSystemMenuHint | Qt .WindowTitleHint )
145+ if self .dlg is None :
146+ self .dlg = Geo360Dialog (self .iface , parent = self , featuresId = featuresId , layer = self .layer )
147+ self .dlg .setWindowFlags (Qt .Window | Qt .WindowCloseButtonHint )
167148 self .dlg .show ()
168- None
149+ else :
150+ self .dlg .ReloadView (self .featuresId )
169151
170152
171153class SelectTool (QgsMapToolIdentify ):
0 commit comments