1- # -*- coding: utf-8 -*-
21"""
32/***************************************************************************
43 Equirectangular Viewer
1817 * *
1918 ***************************************************************************/
2019"""
21- from qgis .gui import QgsMapToolIdentify
2220
21+ import sys
22+ import os
23+ from qgis .gui import QgsMapToolIdentify
2324from PyQt5 .QtCore import QTimer , Qt , QSettings , QThread
2425from PyQt5 .QtGui import QIcon , QCursor , QPixmap
2526from PyQt5 .QtWidgets import QAction
2627
2728from EquirectangularViewer .Geo360Dialog import Geo360Dialog
2829import EquirectangularViewer .config as config
29- from EquirectangularViewer .server .local_server import openWebApp
30+ from EquirectangularViewer .server .local_server import serverInFolder , serverShutdown
3031from EquirectangularViewer .utils .log import log
3132from EquirectangularViewer .utils .qgsutils import qgsutils
3233from qgis .core import QgsApplication
34+ import platform
3335
3436try :
3537 from pydevd import *
3638except ImportError :
3739 None
3840
41+ # libs_path = os.path.join(os.path.dirname(__file__), "libs")
42+ # sys.path.append(libs_path)
43+
3944try :
40- from cefpython3 import cefpython
45+ from cefpython3 import cefpython as cef
46+ import ctypes
4147except ImportError :
4248 None
4349
50+ WINDOWS = (platform .system () == "Windows" )
51+ LINUX = (platform .system () == "Linux" )
52+ MAC = (platform .system () == "Darwin" )
4453
4554class Geo360 :
46- timer = None
4755
4856 """QGIS Plugin Implementation."""
4957
5058 def __init__ (self , iface ):
5159
60+ if not cef .GetAppSetting ("external_message_pump" ):
61+ self .timer = self .createTimer ()
5262 self .iface = iface
5363 self .canvas = self .iface .mapCanvas ()
5464 threadcount = QThread .idealThreadCount ()
@@ -60,13 +70,14 @@ def __init__(self, iface):
6070 self .dlg = None
6171
6272 def createTimer (self ):
63- self .timer = QTimer ()
64- self .timer .timeout .connect (self .onTimer )
65- self .timer .start (10 )
73+ timer = QTimer ()
74+ timer .timeout .connect (self .onTimer )
75+ timer .start (10 )
76+ return timer
6677
6778 def onTimer (self ):
6879 try :
69- cefpython .MessageLoopWork ()
80+ cef .MessageLoopWork ()
7081 except Exception :
7182 None
7283
@@ -77,18 +88,24 @@ def StartCefPython(self):
7788 ''' Start CefPython '''
7889 settings = {}
7990 settings ["browser_subprocess_path" ] = "%s/%s" % (
80- cefpython .GetModuleDirectory (), "subprocess" )
81- settings ["log_severity" ] = cefpython .LOGSEVERITY_DISABLE
91+ cef .GetModuleDirectory (), "subprocess" )
92+ settings ["log_severity" ] = cef .LOGSEVERITY_DISABLE
8293 settings ["context_menu" ] = {
83- "enabled" : False ,
94+ "enabled" : True ,
8495 "navigation" : False , # Back, Forward, Reload
85- "print" : False ,
86- "view_source" : False ,
96+ "print" : True ,
97+ "view_source" : True ,
8798 "external_browser" : False , # Open in external browser
88- "devtools" : False , # Developer Tools
99+ "devtools" : True , # Developer Tools
89100 }
101+
102+ if MAC :
103+ # requires enabling message pump on Mac
104+ # in Qt example. Calling cef.DoMessageLoopWork in a timer
105+ # doesn't work anymore.
106+ settings ["external_message_pump" ] = True
90107
91- cefpython .Initialize (settings )
108+ cef .Initialize (settings )
92109
93110 def initGui (self ):
94111 ''' Add Geo360 tool '''
@@ -104,38 +121,38 @@ def unload(self):
104121 ''' Unload Geo360 tool '''
105122 self .iface .removePluginMenu (u"&Equirectangular Viewer" , self .action )
106123 self .iface .removeToolBarIcon (self .action )
124+ #ShutDown server
125+ serverShutdown ()
126+ #ShutDown Cef
127+ cef .Shutdown ()
107128
108129 def run (self ):
109130 ''' Run click feature '''
110- self .encontrado = False
131+ #Trick fix AttributeError: module 'sys' has no attribute 'argv'
132+ # We need fedback about this
133+ sys .argv = []
134+
135+ self .found = False
111136
112137 # Check if mapa foto is loaded
113138 lys = self .canvas .layers ()
114- if len (lys ) == 0 :
139+ for layer in lys :
140+ if layer .name () == config .layer_name :
141+ self .found = True
142+ self .mapTool = SelectTool (self .iface , parent = self , layer = layer )
143+ self .iface .mapCanvas ().setMapTool (self .mapTool )
144+
145+ if self .found is False :
115146 qgsutils .showUserAndLogMessage (
116147 u"Information: " , u"You need to upload the photo layer." )
117148 return
118149
119150 # Folder viewer for local server
120151 folder = QgsApplication .qgisSettingsDirPath () + 'python/plugins/EquirectangularViewer/viewer'
121152 # Start local server in plugin folder
122- openWebApp (folder )
153+ serverInFolder (folder )
123154 self .StartCefPython ()
124155
125- # Create Timer is necessary for cefpython
126- self .createTimer ()
127-
128- for layer in lys :
129- if layer .name () == config .layer_name :
130- self .encontrado = True
131- self .mapTool = SelectTool (self .iface , parent = self , layer = layer )
132- self .iface .mapCanvas ().setMapTool (self .mapTool )
133-
134- if self .encontrado is False :
135- qgsutils .showUserAndLogMessage (
136- u"Information: " , u"You need to upload the photo layer." )
137-
138- return
139156
140157 def ShowDialog (self , featuresId = None , layer = None ):
141158 ''' Run dialog Geo360 '''
0 commit comments