Skip to content

Commit e3fac47

Browse files
authored
Merge pull request #15 from All4Gis/test-QWebEngineView
remove cefpython/migrate to QWebEngine/ fix server
2 parents ae58696 + df97e17 commit e3fac47

49 files changed

Lines changed: 811 additions & 750 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.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
5.07 KB
Binary file not shown.

Project_example/images/4.jpg

6.9 MB
Loading
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"type": "FeatureCollection",
3+
"name": "photos_4326",
4+
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
5+
"features": [
6+
{ "type": "Feature", "properties": { "GID": null, "ORDER": 0.0, "PATH": "\/home\/fragalop\/Desktop\/Git\/EquirectangularViewer\/Project_example\/images\/0.jpg", "DIRECTION": 310.0 }, "geometry": { "type": "Point", "coordinates": [ -3.685760342621331, 40.400419291455293 ] } },
7+
{ "type": "Feature", "properties": { "GID": null, "ORDER": 1.0, "PATH": "images\/3.png", "DIRECTION": 310.0 }, "geometry": { "type": "Point", "coordinates": [ -3.685817060712635, 40.400469527479018 ] } },
8+
{ "type": "Feature", "properties": { "GID": null, "ORDER": 2.0, "PATH": "images\/2.jpg", "DIRECTION": 310.0 }, "geometry": { "type": "Point", "coordinates": [ -3.685865676219466, 40.400516522468955 ] } },
9+
{ "type": "Feature", "properties": { "GID": null, "ORDER": 3.0, "PATH": "\/home\/fragalop\/Desktop\/Git\/EquirectangularViewer\/Project_example\/images\/1.jpg", "DIRECTION": 310.0 }, "geometry": { "type": "Point", "coordinates": [ -3.685917532760087, 40.400561896942001 ] } },
10+
{ "type": "Feature", "properties": { "GID": null, "ORDER": 4.0, "PATH": "images\/2.jpg", "DIRECTION": 310.0 }, "geometry": { "type": "Point", "coordinates": [ -3.68597425085139, 40.400615373999514 ] } },
11+
{ "type": "Feature", "properties": { "GID": null, "ORDER": 5.0, "PATH": "images\/1.jpg", "DIRECTION": 310.0 }, "geometry": { "type": "Point", "coordinates": [ -3.68602610739201, 40.400670471573925 ] } },
12+
{ "type": "Feature", "properties": { "GID": null, "ORDER": 6.0, "PATH": "images\/0.jpg", "DIRECTION": 310.0 }, "geometry": { "type": "Point", "coordinates": [ -3.686079584449525, 40.400712605013176 ] } },
13+
{ "type": "Feature", "properties": { "GID": null, "ORDER": 7.0, "PATH": "images\/3.png", "DIRECTION": 310.0 }, "geometry": { "type": "Point", "coordinates": [ -3.686133061507039, 40.400759600003113 ] } },
14+
{ "type": "Feature", "properties": { "GID": null, "ORDER": 8.0, "PATH": "images\/4.jpg", "DIRECTION": 310.0 }, "geometry": { "type": "Point", "coordinates": [ -3.685701428121899, 40.400360181318021 ] } }
15+
]
16+
}

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: 101 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
/***************************************************************************
43
Equirectangular Viewer
@@ -18,32 +17,34 @@
1817
* *
1918
***************************************************************************/
2019
"""
21-
from qgis.gui import QgsMapToolIdentify
2220

23-
from PyQt5.QtCore import QTimer, Qt, QSettings, QThread
24-
from PyQt5.QtGui import QIcon, QCursor, QPixmap
25-
from PyQt5.QtWidgets import QAction
21+
from qgis.gui import QgsMapToolIdentify
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
2625

2726
from EquirectangularViewer.Geo360Dialog import Geo360Dialog
2827
import EquirectangularViewer.config as config
29-
from EquirectangularViewer.server.local_server import openWebApp
3028
from EquirectangularViewer.utils.log import log
3129
from EquirectangularViewer.utils.qgsutils import qgsutils
3230
from qgis.core import QgsApplication
31+
from functools import partial
32+
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
33+
from threading import Thread
34+
import time
3335

3436
try:
3537
from pydevd import *
3638
except ImportError:
3739
None
3840

39-
try:
40-
from cefpython3 import cefpython
41-
except ImportError:
42-
None
41+
42+
class QuietHandler(SimpleHTTPRequestHandler):
43+
def log_message(self, format, *args):
44+
pass
4345

4446

4547
class Geo360:
46-
timer = None
4748

4849
"""QGIS Plugin Implementation."""
4950

@@ -58,100 +59,101 @@ def __init__(self, iface):
5859
# OpenCL acceleration
5960
QSettings().setValue("/core/OpenClEnabled", True)
6061
self.dlg = None
61-
62-
def createTimer(self):
63-
self.timer = QTimer()
64-
self.timer.timeout.connect(self.onTimer)
65-
self.timer.start(10)
66-
67-
def onTimer(self):
68-
try:
69-
cefpython.MessageLoopWork()
70-
except Exception:
71-
None
72-
73-
def stopTimer(self):
74-
self.timer.stop()
75-
76-
def StartCefPython(self):
77-
''' Start CefPython '''
78-
settings = {}
79-
settings["browser_subprocess_path"] = "%s/%s" % (
80-
cefpython.GetModuleDirectory(), "subprocess")
81-
settings["log_severity"] = cefpython.LOGSEVERITY_DISABLE
82-
settings["context_menu"] = {
83-
"enabled": False,
84-
"navigation": False, # Back, Forward, Reload
85-
"print": False,
86-
"view_source": False,
87-
"external_browser": False, # Open in external browser
88-
"devtools": False, # Developer Tools
89-
}
90-
91-
cefpython.Initialize(settings)
62+
self.server = None
63+
self.make_server()
9264

9365
def initGui(self):
94-
''' Add Geo360 tool '''
66+
"""Add Geo360 tool"""
9567
log.initLogging()
96-
self.action = QAction(QIcon(":/EquirectangularViewer/images/icon.png"),
97-
u"Equirectangular Viewer",
98-
self.iface.mainWindow())
68+
self.action = QAction(
69+
QIcon(":/EquirectangularViewer/images/icon.png"),
70+
u"Equirectangular Viewer",
71+
self.iface.mainWindow(),
72+
)
9973
self.action.triggered.connect(self.run)
10074
self.iface.addToolBarIcon(self.action)
10175
self.iface.addPluginToMenu(u"&Equirectangular Viewer", self.action)
10276

10377
def unload(self):
104-
''' Unload Geo360 tool '''
78+
"""Unload Geo360 tool"""
10579
self.iface.removePluginMenu(u"&Equirectangular Viewer", self.action)
10680
self.iface.removeToolBarIcon(self.action)
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")
107121

108122
def run(self):
109-
''' Run click feature '''
110-
self.encontrado = False
123+
"""Run click feature"""
124+
self.found = False
111125

112126
# Check if mapa foto is loaded
113127
lys = self.canvas.layers()
114-
if len(lys) == 0:
115-
qgsutils.showUserAndLogMessage(
116-
u"Information: ", u"You need to upload the photo layer.")
117-
return
118-
119-
# Folder viewer for local server
120-
folder = QgsApplication.qgisSettingsDirPath() + 'python/plugins/EquirectangularViewer/viewer'
121-
# Start local server in plugin folder
122-
openWebApp(folder)
123-
self.StartCefPython()
124-
125-
# Create Timer is necessary for cefpython
126-
self.createTimer()
127-
128128
for layer in lys:
129129
if layer.name() == config.layer_name:
130-
self.encontrado = True
130+
self.found = True
131131
self.mapTool = SelectTool(self.iface, parent=self, layer=layer)
132132
self.iface.mapCanvas().setMapTool(self.mapTool)
133133

134-
if self.encontrado is False:
134+
if self.found is False:
135135
qgsutils.showUserAndLogMessage(
136-
u"Information: ", u"You need to upload the photo layer.")
137-
138-
return
136+
u"Information: ", u"You need to upload the photo layer."
137+
)
138+
return
139139

140140
def ShowDialog(self, featuresId=None, layer=None):
141-
''' Run dialog Geo360 '''
141+
"""Run dialog Geo360"""
142142
self.featuresId = featuresId
143143
self.layer = layer
144144

145145
if self.dlg is None:
146-
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+
)
147149
self.dlg.setWindowFlags(Qt.Window | Qt.WindowCloseButtonHint)
148150
self.dlg.show()
149151
else:
150152
self.dlg.ReloadView(self.featuresId)
151153

152154

153155
class SelectTool(QgsMapToolIdentify):
154-
''' Select Photo on map '''
156+
"""Select Photo on map"""
155157

156158
def __init__(self, iface, parent=None, layer=None):
157159
QgsMapToolIdentify.__init__(self, iface.mapCanvas())
@@ -160,33 +162,40 @@ def __init__(self, iface, parent=None, layer=None):
160162
self.layer = layer
161163
self.parent = parent
162164

163-
self.cursor = QCursor(QPixmap(["16 16 3 1",
164-
" c None",
165-
". c #FF0000",
166-
"+ c #FFFFFF",
167-
" ",
168-
" +.+ ",
169-
" ++.++ ",
170-
" +.....+ ",
171-
" +. .+ ",
172-
" +. . .+ ",
173-
" +. . .+ ",
174-
" ++. . .++",
175-
" ... ...+... ...",
176-
" ++. . .++",
177-
" +. . .+ ",
178-
" +. . .+ ",
179-
" ++. .+ ",
180-
" ++.....+ ",
181-
" ++.++ ",
182-
" +.+ "]))
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+
)
183191

184192
def activate(self):
185193
self.canvas.setCursor(self.cursor)
186194

187195
def canvasReleaseEvent(self, event):
188196
found_features = self.identify(
189-
event.x(), event.y(), [self.layer], self.TopDownAll)
197+
event.x(), event.y(), [self.layer], self.TopDownAll
198+
)
190199

191200
if len(found_features) > 0:
192201

0 commit comments

Comments
 (0)