Skip to content

Commit df97e17

Browse files
committed
Remove CefPython and migrate to QwebView/ fix ser win and linux
1 parent ddce6e5 commit df97e17

24 files changed

Lines changed: 408 additions & 588 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
Deploy/
2+
.project
3+
.pydevproject
4+
.settings

.project

Lines changed: 0 additions & 22 deletions
This file was deleted.

.pydevproject

Lines changed: 0 additions & 8 deletions
This file was deleted.

.settings/de.loskutov.FileSync.prefs

Lines changed: 0 additions & 7 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ Click on the image to see the demo video.
88

99
## Prerequisites
1010

11-
The libraries [CefPython](https://github.com/cztomczak/cefpython) is required and Pillow, install the **cefpython3** python package and **Pillow**.
11+
The library Pillow is required, install the **Pillow** python package.
1212
Always from command prompt:
1313

14-
`python3 -m pip install cefpython3`
1514
`python3 -m pip install pillow`
1615

1716
Or using:
@@ -20,15 +19,15 @@ Or using:
2019

2120

2221
Once installed, you can test the correct functioning of the plugin with the example that is provided,a shapefile with some images.
23-
[Test Project](https://github.com/All4Gis/EquirectangularViewer/tree/master/code/Project_example)
22+
[Test Project](https://github.com/All4Gis/EquirectangularViewer/tree/master/Project_example)
2423

2524

2625
## How it works?
2726

2827
It's simple:
2928
- You start a local server in Python in `http://127.0.0.1:1520/viewer.html `
3029
- A copy of the image associated to the selected registry is created in the folder where our viewer and server are.
31-
- With cefpython, we open the browser and return the current yaw to our canvas anytime the image is moved.
30+
- We open the browser and return the current yaw to our canvas anytime the image is moved.
3231

3332

3433
## Donations

code/Geo360.py

Lines changed: 95 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -18,47 +18,38 @@
1818
***************************************************************************/
1919
"""
2020

21-
import sys
22-
import os
2321
from qgis.gui import QgsMapToolIdentify
24-
from PyQt5.QtCore import QTimer, Qt, QSettings, QThread
25-
from PyQt5.QtGui import QIcon, QCursor, QPixmap
26-
from PyQt5.QtWidgets import QAction
22+
from qgis.PyQt.QtCore import Qt, QSettings, QThread
23+
from qgis.PyQt.QtGui import QIcon, QCursor, QPixmap
24+
from qgis.PyQt.QtWidgets import QAction
2725

2826
from EquirectangularViewer.Geo360Dialog import Geo360Dialog
2927
import EquirectangularViewer.config as config
30-
from EquirectangularViewer.server.local_server import serverInFolder, serverShutdown
3128
from EquirectangularViewer.utils.log import log
3229
from EquirectangularViewer.utils.qgsutils import qgsutils
3330
from qgis.core import QgsApplication
34-
import platform
31+
from functools import partial
32+
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
33+
from threading import Thread
34+
import time
3535

3636
try:
3737
from pydevd import *
3838
except ImportError:
3939
None
4040

41-
# libs_path = os.path.join(os.path.dirname(__file__), "libs")
42-
# sys.path.append(libs_path)
4341

44-
try:
45-
from cefpython3 import cefpython as cef
46-
import ctypes
47-
except ImportError:
48-
None
42+
class QuietHandler(SimpleHTTPRequestHandler):
43+
def log_message(self, format, *args):
44+
pass
4945

50-
WINDOWS = (platform.system() == "Windows")
51-
LINUX = (platform.system() == "Linux")
52-
MAC = (platform.system() == "Darwin")
5346

5447
class Geo360:
5548

5649
"""QGIS Plugin Implementation."""
5750

5851
def __init__(self, iface):
5952

60-
if not cef.GetAppSetting("external_message_pump"):
61-
self.timer = self.createTimer()
6253
self.iface = iface
6354
self.canvas = self.iface.mapCanvas()
6455
threadcount = QThread.idealThreadCount()
@@ -68,70 +59,68 @@ def __init__(self, iface):
6859
# OpenCL acceleration
6960
QSettings().setValue("/core/OpenClEnabled", True)
7061
self.dlg = None
71-
72-
def createTimer(self):
73-
timer = QTimer()
74-
timer.timeout.connect(self.onTimer)
75-
timer.start(10)
76-
return timer
77-
78-
def onTimer(self):
79-
try:
80-
cef.MessageLoopWork()
81-
except Exception:
82-
None
83-
84-
def stopTimer(self):
85-
self.timer.stop()
86-
87-
def StartCefPython(self):
88-
''' Start CefPython '''
89-
settings = {}
90-
settings["browser_subprocess_path"] = "%s/%s" % (
91-
cef.GetModuleDirectory(), "subprocess")
92-
settings["log_severity"] = cef.LOGSEVERITY_DISABLE
93-
settings["context_menu"] = {
94-
"enabled": True,
95-
"navigation": False, # Back, Forward, Reload
96-
"print": True,
97-
"view_source": True,
98-
"external_browser": False, # Open in external browser
99-
"devtools": True, # Developer Tools
100-
}
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
107-
108-
cef.Initialize(settings)
62+
self.server = None
63+
self.make_server()
10964

11065
def initGui(self):
111-
''' Add Geo360 tool '''
66+
"""Add Geo360 tool"""
11267
log.initLogging()
113-
self.action = QAction(QIcon(":/EquirectangularViewer/images/icon.png"),
114-
u"Equirectangular Viewer",
115-
self.iface.mainWindow())
68+
self.action = QAction(
69+
QIcon(":/EquirectangularViewer/images/icon.png"),
70+
u"Equirectangular Viewer",
71+
self.iface.mainWindow(),
72+
)
11673
self.action.triggered.connect(self.run)
11774
self.iface.addToolBarIcon(self.action)
11875
self.iface.addPluginToMenu(u"&Equirectangular Viewer", self.action)
11976

12077
def unload(self):
121-
''' Unload Geo360 tool '''
78+
"""Unload Geo360 tool"""
12279
self.iface.removePluginMenu(u"&Equirectangular Viewer", self.action)
12380
self.iface.removeToolBarIcon(self.action)
124-
#ShutDown server
125-
serverShutdown()
126-
#ShutDown Cef
127-
cef.Shutdown()
81+
# Close server
82+
self.close_server()
83+
84+
def is_running(self):
85+
return self.server_thread and self.server_thread.is_alive()
86+
87+
def close_server(self):
88+
# Close server
89+
if self.server is not None:
90+
self.server.shutdown()
91+
time.sleep(1)
92+
self.server.server_close()
93+
while self.server_thread.is_alive():
94+
self.server_thread.join()
95+
self.server = None
96+
97+
def make_server(self):
98+
# Close server
99+
self.close_server()
100+
# Create Server
101+
directory = (
102+
QgsApplication.qgisSettingsDirPath().replace("\\", "/")
103+
+ "python/plugins/EquirectangularViewer/viewer"
104+
)
105+
try:
106+
self.server = ThreadingHTTPServer(
107+
(config.IP, config.PORT),
108+
partial(QuietHandler, directory=directory),
109+
)
110+
self.server_thread = Thread(
111+
target=self.server.serve_forever, name="http_server"
112+
)
113+
self.server_thread.daemon = True
114+
print("Serving at port: %s" % self.server.server_address[1])
115+
time.sleep(1)
116+
self.server_thread.start()
117+
# while self.server_thread.is_alive():
118+
# print ("isRunning")
119+
except Exception:
120+
print("Server Error")
128121

129122
def run(self):
130-
''' Run click feature '''
131-
#Trick fix AttributeError: module 'sys' has no attribute 'argv'
132-
# We need fedback about this
133-
sys.argv = []
134-
123+
"""Run click feature"""
135124
self.found = False
136125

137126
# Check if mapa foto is loaded
@@ -144,31 +133,27 @@ def run(self):
144133

145134
if self.found is False:
146135
qgsutils.showUserAndLogMessage(
147-
u"Information: ", u"You need to upload the photo layer.")
136+
u"Information: ", u"You need to upload the photo layer."
137+
)
148138
return
149139

150-
# Folder viewer for local server
151-
folder = QgsApplication.qgisSettingsDirPath() + 'python/plugins/EquirectangularViewer/viewer'
152-
# Start local server in plugin folder
153-
serverInFolder(folder)
154-
self.StartCefPython()
155-
156-
157140
def ShowDialog(self, featuresId=None, layer=None):
158-
''' Run dialog Geo360 '''
141+
"""Run dialog Geo360"""
159142
self.featuresId = featuresId
160143
self.layer = layer
161144

162145
if self.dlg is None:
163-
self.dlg = Geo360Dialog(self.iface, parent=self, featuresId=featuresId, layer=self.layer)
146+
self.dlg = Geo360Dialog(
147+
self.iface, parent=self, featuresId=featuresId, layer=self.layer
148+
)
164149
self.dlg.setWindowFlags(Qt.Window | Qt.WindowCloseButtonHint)
165150
self.dlg.show()
166151
else:
167152
self.dlg.ReloadView(self.featuresId)
168153

169154

170155
class SelectTool(QgsMapToolIdentify):
171-
''' Select Photo on map '''
156+
"""Select Photo on map"""
172157

173158
def __init__(self, iface, parent=None, layer=None):
174159
QgsMapToolIdentify.__init__(self, iface.mapCanvas())
@@ -177,33 +162,40 @@ def __init__(self, iface, parent=None, layer=None):
177162
self.layer = layer
178163
self.parent = parent
179164

180-
self.cursor = QCursor(QPixmap(["16 16 3 1",
181-
" c None",
182-
". c #FF0000",
183-
"+ c #FFFFFF",
184-
" ",
185-
" +.+ ",
186-
" ++.++ ",
187-
" +.....+ ",
188-
" +. .+ ",
189-
" +. . .+ ",
190-
" +. . .+ ",
191-
" ++. . .++",
192-
" ... ...+... ...",
193-
" ++. . .++",
194-
" +. . .+ ",
195-
" +. . .+ ",
196-
" ++. .+ ",
197-
" ++.....+ ",
198-
" ++.++ ",
199-
" +.+ "]))
165+
self.cursor = QCursor(
166+
QPixmap(
167+
[
168+
"16 16 3 1",
169+
" c None",
170+
". c #FF0000",
171+
"+ c #FFFFFF",
172+
" ",
173+
" +.+ ",
174+
" ++.++ ",
175+
" +.....+ ",
176+
" +. .+ ",
177+
" +. . .+ ",
178+
" +. . .+ ",
179+
" ++. . .++",
180+
" ... ...+... ...",
181+
" ++. . .++",
182+
" +. . .+ ",
183+
" +. . .+ ",
184+
" ++. .+ ",
185+
" ++.....+ ",
186+
" ++.++ ",
187+
" +.+ ",
188+
]
189+
)
190+
)
200191

201192
def activate(self):
202193
self.canvas.setCursor(self.cursor)
203194

204195
def canvasReleaseEvent(self, event):
205196
found_features = self.identify(
206-
event.x(), event.y(), [self.layer], self.TopDownAll)
197+
event.x(), event.y(), [self.layer], self.TopDownAll
198+
)
207199

208200
if len(found_features) > 0:
209201

0 commit comments

Comments
 (0)