-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
124 lines (100 loc) · 4.34 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# -*- coding: utf-8 -*-
# qazp_20
# (c) Milosz Piglas 2014 Wszystkie prawa zastrzezone
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of qazp_20 nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import importlib
import operator
from PyQt4 import QtCore as qcore
from PyQt4 import QtGui as qgui
class AppModule(object):
def initModule(self, application):
pass
class NullException(Exception):
def __init__(self, msg):
Exception.__init__(self, msg)
def _prepareKey(**kwargs):
items = sorted(kwargs.iteritems(), key=operator.itemgetter(0))
key = []
for it in items:
key.extend(it)
return tuple(key)
class BundleContext(object):
def __init__(self):
self.menu = None
self.parent = None
self.dataSources = {}
self.services = {}
def showWidget(self, widget):
window = self.parent.addSubWindow(widget)
window.setAttribute(qcore.Qt.WA_DeleteOnClose)
widget.show()
return window
def dataSourceFactory(self, dataSourceFactory, etype, variant='default'):
self.dataSources[(etype.name,variant)] = dataSourceFactory
def prepareDataSource(self, etype, variant='default'):
return self.dataSources[(etype.name, variant) ](etype)
def registerService(self, iclazz, impl, **props):
self.services[(iclazz, _prepareKey(**props))] = impl
def service(self, iclazz, **props):
return self.services.get((iclazz, _prepareKey(**props) ), None)
class Application(qgui.QMainWindow):
def __init__(self, parent=None, iface=None):
qgui.QMainWindow.__init__(self, parent)
self._appArea = qgui.QMdiArea(self)
self.setCentralWidget(self._appArea)
self._initModules()
def _initModules(self):
context = BundleContext()
context.parent = self._appArea
context.main = self
context.menu = self.menuBar()
with open('modules.txt', 'r') as modList:
for name in modList.readlines():
bundle = importlib.import_module(name.rstrip('\n'))
bundle.start(context)
def start(qgis=None, qgsIface=None, guiApp=None):
app = Application(qgis, qgsIface)
app.show()
if guiApp:
guiApp.exec_()
def main():
from sys import argv
import qgsctx
qgsctx.initProviders('/usr/lib/qgis/plugins/')
suri = qgsctx.liteUri('/home/milosz/Downloads/nowa_test.db', 'stanowiska', 'wspolrzedne')
qgsctx.addVectorLayer(suri, 'spatialite')
turi = qgsctx.liteUri('/home/milosz/Downloads/nowa_test.db', 'trasy', 'wspolrzedne')
qgsctx.addVectorLayer(turi, 'spatialite')
muri = qgsctx.liteUri('/home/milosz/Downloads/nowa_test.db', 'miejsca', 'wspolrzedne')
qgsctx.addVectorLayer(muri, 'spatialite')
zuri = qgsctx.liteUri('/home/milosz/Downloads/nowa_test.db', 'zdjecia_lotnicze', 'wspolrzedne')
qgsctx.addVectorLayer(zuri, 'spatialite')
qif = qgsctx.Iface()
app = qgui.QApplication(argv)
start(qgsIface=qif, guiApp=app)
if __name__ == '__main__':
main()