|
1 |
| -from PyQt4.QtCore import * |
2 |
| -from PyQt4.QtGui import * |
3 |
| -from qgis.core import * |
4 |
| -import os, sys |
5 |
| -import inspect |
6 |
| -from sextante.core.Sextante import Sextante |
7 |
| -from sextante.gui.SextanteToolbox import SextanteToolbox |
8 |
| -from sextante.core.QGisLayers import QGisLayers |
9 |
| -from sextante.gui.HistoryDialog import HistoryDialog |
10 |
| -from sextante.core.SextanteUtils import SextanteUtils |
11 |
| -from sextante.gui.ConfigDialog import ConfigDialog |
12 |
| -from sextante.modeler.ModelerDialog import ModelerDialog |
13 |
| -from sextante.gui.ResultsDialog import ResultsDialog |
14 |
| -from sextante.about.AboutDialog import AboutDialog |
15 |
| -import subprocess |
16 |
| - |
17 |
| -cmd_folder = os.path.split(inspect.getfile( inspect.currentframe() ))[0] |
18 |
| -if cmd_folder not in sys.path: |
19 |
| - sys.path.insert(0, cmd_folder) |
20 |
| - |
21 |
| -class SextantePlugin: |
22 |
| - |
23 |
| - def __init__(self, iface): |
24 |
| - self.iface = iface |
25 |
| - QGisLayers.setInterface(iface) |
26 |
| - Sextante.initialize() |
27 |
| - Sextante.setInterface(iface) |
28 |
| - |
29 |
| - def initGui(self): |
30 |
| - self.toolbox = SextanteToolbox(self.iface) |
31 |
| - self.toolbox.setVisible(False) |
32 |
| - Sextante.addAlgListListener(self.toolbox) |
33 |
| - |
34 |
| - self.menu = QMenu(self.iface.mainWindow()) |
35 |
| - self.menu.setTitle("Analysis") |
36 |
| - |
37 |
| - icon = QIcon(os.path.dirname(__file__) + "/images/toolbox.png") |
38 |
| - self.toolboxAction = QAction(icon, \ |
39 |
| - "&SEXTANTE Toolbox", self.iface.mainWindow()) |
40 |
| - QObject.connect(self.toolboxAction, SIGNAL("triggered()"), self.openToolbox) |
41 |
| - self.menu.addAction(self.toolboxAction) |
42 |
| - |
43 |
| - icon = QIcon(os.path.dirname(__file__) + "/images/model.png") |
44 |
| - self.modelerAction = QAction(icon, \ |
45 |
| - "&SEXTANTE Modeler", self.iface.mainWindow()) |
46 |
| - QObject.connect(self.modelerAction, SIGNAL("triggered()"), self.openModeler) |
47 |
| - self.menu.addAction(self.modelerAction) |
48 |
| - |
49 |
| - icon = QIcon(os.path.dirname(__file__) + "/images/history.gif") |
50 |
| - self.historyAction = QAction(icon, \ |
51 |
| - "&SEXTANTE History and log", self.iface.mainWindow()) |
52 |
| - QObject.connect(self.historyAction, SIGNAL("triggered()"), self.openHistory) |
53 |
| - self.menu.addAction(self.historyAction) |
54 |
| - |
55 |
| - icon = QIcon(os.path.dirname(__file__) + "/images/config.png") |
56 |
| - self.configAction = QAction(icon, \ |
57 |
| - "&SEXTANTE options and configuration", self.iface.mainWindow()) |
58 |
| - QObject.connect(self.configAction, SIGNAL("triggered()"), self.openConfig) |
59 |
| - self.menu.addAction(self.configAction) |
60 |
| - |
61 |
| - icon = QIcon(os.path.dirname(__file__) + "/images/results.png") |
62 |
| - self.resultsAction = QAction(icon, \ |
63 |
| - "&SEXTANTE results viewer", self.iface.mainWindow()) |
64 |
| - QObject.connect(self.resultsAction, SIGNAL("triggered()"), self.openResults) |
65 |
| - self.menu.addAction(self.resultsAction) |
66 |
| - |
67 |
| - icon = QIcon(os.path.dirname(__file__) + "/images/help.png") |
68 |
| - self.helpAction = QAction(icon, \ |
69 |
| - "&SEXTANTE help", self.iface.mainWindow()) |
70 |
| - QObject.connect(self.helpAction, SIGNAL("triggered()"), self.openHelp) |
71 |
| - self.menu.addAction(self.helpAction) |
72 |
| - |
73 |
| - icon = QIcon(os.path.dirname(__file__) + "/images/info.png") |
74 |
| - self.aboutAction = QAction(icon, \ |
75 |
| - "&About SEXTANTE", self.iface.mainWindow()) |
76 |
| - QObject.connect(self.aboutAction, SIGNAL("triggered()"), self.openAbout) |
77 |
| - self.menu.addAction(self.aboutAction) |
78 |
| - |
79 |
| - menuBar = self.iface.mainWindow().menuBar() |
80 |
| - menuBar.insertMenu(menuBar.actions()[-1], self.menu) |
81 |
| - |
82 |
| - def unload(self): |
83 |
| - self.toolbox.setVisible(False) |
84 |
| - self.menu.deleteLater() |
85 |
| - #delete temporary output files |
86 |
| - folder = SextanteUtils.tempFolder() |
87 |
| - for f in os.listdir(folder): |
88 |
| - path = os.path.join(folder,f) |
89 |
| - try: |
90 |
| - os.unlink(path) |
91 |
| - except: |
92 |
| - #leave files that could not be deleted |
93 |
| - pass |
94 |
| - |
95 |
| - |
96 |
| - def openToolbox(self): |
97 |
| - self.toolbox.setVisible(True) |
98 |
| - |
99 |
| - def openModeler(self): |
100 |
| - dlg = ModelerDialog() |
101 |
| - dlg.exec_() |
102 |
| - if dlg.update: |
103 |
| - self.toolbox.updateTree() |
104 |
| - |
105 |
| - def openResults(self): |
106 |
| - dlg = ResultsDialog() |
107 |
| - dlg.exec_() |
108 |
| - |
109 |
| - def openHistory(self): |
110 |
| - dlg = HistoryDialog() |
111 |
| - dlg.exec_() |
112 |
| - |
113 |
| - def openConfig(self): |
114 |
| - dlg = ConfigDialog(self.toolbox) |
115 |
| - dlg.exec_() |
116 |
| - |
117 |
| - def openAbout(self): |
118 |
| - dlg = AboutDialog() |
119 |
| - dlg.exec_() |
120 |
| - |
121 |
| - def openHelp(self): |
122 |
| - filename = os.path.dirname(__file__) + "/help/index.html" |
123 |
| - if os.name == "nt": |
124 |
| - os.startfile(filename) |
125 |
| - elif sys.platform == "darwin": |
126 |
| - subprocess.Popen(('open', filename)) |
127 |
| - else: |
128 |
| - subprocess.call(('xdg-open', filename)) |
129 |
| - |
130 |
| -
|
| 1 | +from PyQt4.QtCore import * |
| 2 | +from PyQt4.QtGui import * |
| 3 | +from qgis.core import * |
| 4 | +import os, sys |
| 5 | +import inspect |
| 6 | +from sextante.core.Sextante import Sextante |
| 7 | +from sextante.gui.SextanteToolbox import SextanteToolbox |
| 8 | +from sextante.core.QGisLayers import QGisLayers |
| 9 | +from sextante.gui.HistoryDialog import HistoryDialog |
| 10 | +from sextante.core.SextanteUtils import SextanteUtils |
| 11 | +from sextante.gui.ConfigDialog import ConfigDialog |
| 12 | +from sextante.modeler.ModelerDialog import ModelerDialog |
| 13 | +from sextante.gui.ResultsDialog import ResultsDialog |
| 14 | +from sextante.about.AboutDialog import AboutDialog |
| 15 | +import subprocess |
| 16 | + |
| 17 | +cmd_folder = os.path.split(inspect.getfile( inspect.currentframe() ))[0] |
| 18 | +if cmd_folder not in sys.path: |
| 19 | + sys.path.insert(0, cmd_folder) |
| 20 | + |
| 21 | +class SextantePlugin: |
| 22 | + |
| 23 | + def __init__(self, iface): |
| 24 | + self.iface = iface |
| 25 | + QGisLayers.setInterface(iface) |
| 26 | + Sextante.initialize() |
| 27 | + Sextante.setInterface(iface) |
| 28 | + |
| 29 | + def initGui(self): |
| 30 | + self.toolbox = SextanteToolbox(self.iface) |
| 31 | + self.toolbox.setVisible(False) |
| 32 | + Sextante.addAlgListListener(self.toolbox) |
| 33 | + |
| 34 | + self.menu = QMenu(self.iface.mainWindow()) |
| 35 | + self.menu.setTitle("Analysis") |
| 36 | + |
| 37 | + icon = QIcon(os.path.dirname(__file__) + "/images/toolbox.png") |
| 38 | + self.toolboxAction = QAction(icon, \ |
| 39 | + "&SEXTANTE Toolbox", self.iface.mainWindow()) |
| 40 | + QObject.connect(self.toolboxAction, SIGNAL("triggered()"), self.openToolbox) |
| 41 | + self.menu.addAction(self.toolboxAction) |
| 42 | + |
| 43 | + icon = QIcon(os.path.dirname(__file__) + "/images/model.png") |
| 44 | + self.modelerAction = QAction(icon, \ |
| 45 | + "&SEXTANTE Modeler", self.iface.mainWindow()) |
| 46 | + QObject.connect(self.modelerAction, SIGNAL("triggered()"), self.openModeler) |
| 47 | + self.menu.addAction(self.modelerAction) |
| 48 | + |
| 49 | + icon = QIcon(os.path.dirname(__file__) + "/images/history.gif") |
| 50 | + self.historyAction = QAction(icon, \ |
| 51 | + "&SEXTANTE History and log", self.iface.mainWindow()) |
| 52 | + QObject.connect(self.historyAction, SIGNAL("triggered()"), self.openHistory) |
| 53 | + self.menu.addAction(self.historyAction) |
| 54 | + |
| 55 | + icon = QIcon(os.path.dirname(__file__) + "/images/config.png") |
| 56 | + self.configAction = QAction(icon, \ |
| 57 | + "&SEXTANTE options and configuration", self.iface.mainWindow()) |
| 58 | + QObject.connect(self.configAction, SIGNAL("triggered()"), self.openConfig) |
| 59 | + self.menu.addAction(self.configAction) |
| 60 | + |
| 61 | + icon = QIcon(os.path.dirname(__file__) + "/images/results.png") |
| 62 | + self.resultsAction = QAction(icon, \ |
| 63 | + "&SEXTANTE results viewer", self.iface.mainWindow()) |
| 64 | + QObject.connect(self.resultsAction, SIGNAL("triggered()"), self.openResults) |
| 65 | + self.menu.addAction(self.resultsAction) |
| 66 | + |
| 67 | + icon = QIcon(os.path.dirname(__file__) + "/images/help.png") |
| 68 | + self.helpAction = QAction(icon, \ |
| 69 | + "&SEXTANTE help", self.iface.mainWindow()) |
| 70 | + QObject.connect(self.helpAction, SIGNAL("triggered()"), self.openHelp) |
| 71 | + self.menu.addAction(self.helpAction) |
| 72 | + |
| 73 | + icon = QIcon(os.path.dirname(__file__) + "/images/info.png") |
| 74 | + self.aboutAction = QAction(icon, \ |
| 75 | + "&About SEXTANTE", self.iface.mainWindow()) |
| 76 | + QObject.connect(self.aboutAction, SIGNAL("triggered()"), self.openAbout) |
| 77 | + self.menu.addAction(self.aboutAction) |
| 78 | + |
| 79 | + menuBar = self.iface.mainWindow().menuBar() |
| 80 | + menuBar.insertMenu(menuBar.actions()[-1], self.menu) |
| 81 | + |
| 82 | + def unload(self): |
| 83 | + self.toolbox.setVisible(False) |
| 84 | + self.menu.deleteLater() |
| 85 | + #delete temporary output files |
| 86 | + folder = SextanteUtils.tempFolder() |
| 87 | + for f in os.listdir(folder): |
| 88 | + path = os.path.join(folder,f) |
| 89 | + try: |
| 90 | + os.unlink(path) |
| 91 | + except: |
| 92 | + #leave files that could not be deleted |
| 93 | + pass |
| 94 | + |
| 95 | + |
| 96 | + def openToolbox(self): |
| 97 | + self.toolbox.setVisible(True) |
| 98 | + |
| 99 | + def openModeler(self): |
| 100 | + dlg = ModelerDialog() |
| 101 | + dlg.exec_() |
| 102 | + if dlg.update: |
| 103 | + self.toolbox.updateTree() |
| 104 | + |
| 105 | + def openResults(self): |
| 106 | + dlg = ResultsDialog() |
| 107 | + dlg.exec_() |
| 108 | + |
| 109 | + def openHistory(self): |
| 110 | + dlg = HistoryDialog() |
| 111 | + dlg.exec_() |
| 112 | + |
| 113 | + def openConfig(self): |
| 114 | + dlg = ConfigDialog(self.toolbox) |
| 115 | + dlg.exec_() |
| 116 | + |
| 117 | + def openAbout(self): |
| 118 | + dlg = AboutDialog() |
| 119 | + dlg.exec_() |
| 120 | + |
| 121 | + def openHelp(self): |
| 122 | + filename = os.path.dirname(__file__) + "/help/index.html" |
| 123 | + if os.name == "nt": |
| 124 | + os.startfile(filename) |
| 125 | + elif sys.platform == "darwin": |
| 126 | + subprocess.Popen(('open', filename)) |
| 127 | + else: |
| 128 | + subprocess.call(('xdg-open', filename)) |
| 129 | + |
| 130 | + |
0 commit comments