~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to gui/wxpython/core/giface.py

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
@package core.giface
 
3
 
 
4
@brief GRASS interface for standalone application (without layer manager)
 
5
 
 
6
Classes:
 
7
 - giface::StandaloneGrassInterface
 
8
 
 
9
(C) 2012-2014 by the GRASS Development Team
 
10
 
 
11
This program is free software under the GNU General Public License
 
12
(>=v2). Read the file COPYING that comes with GRASS for details.
 
13
 
 
14
@author Anna Kratochvilova <kratochanna gmail.com>
 
15
@author Vaclav Petras <wenzeslaus gmail.com>
 
16
"""
 
17
 
 
18
import os
 
19
from core.utils import _
 
20
 
 
21
import grass.script as grass
 
22
 
 
23
from grass.pydispatch.signal import Signal
 
24
 
 
25
# to disable Abstract class not referenced
 
26
#pylint: disable=R0921
 
27
 
 
28
 
 
29
class Notification:
 
30
    """Enum class for notifications suggestions.
 
31
 
 
32
    Can be used for log messages, commands, warnings, errors.
 
33
    The value is the suggestion how user should be notified
 
34
    about the new message.
 
35
    """
 
36
    NO_NOTIFICATION = 0
 
37
    HIGHLIGHT = 1
 
38
    MAKE_VISIBLE = 2
 
39
    RAISE_WINDOW = 3
 
40
 
 
41
 
 
42
class Layer(object):
 
43
    """Layer is generaly usable layer object.
 
44
 
 
45
    .. note::
 
46
        Currently without specifying the interface.
 
47
        Current implementations only provides all attributes of existing
 
48
        layer as used in lmgr.
 
49
    """
 
50
    pass
 
51
 
 
52
 
 
53
class LayerList(object):
 
54
    def GetSelectedLayers(self, checkedOnly=True):
 
55
        """Returns list of selected layers.
 
56
 
 
57
        .. note::
 
58
            Usage of checked and selected is still subject to change.
 
59
            Checked layers should be showed. Selected are for analyses.
 
60
            However, this may be the same for some implementations
 
61
            (e.g. it d.mon has all layers checked and selected).
 
62
        """
 
63
        raise NotImplementedError()
 
64
 
 
65
    def GetSelectedLayer(self, checkedOnly=False):
 
66
        """Returns selected layer or None when there is no selected layer.
 
67
 
 
68
        .. note::
 
69
            Parameter checkedOnly is here False by default. This might
 
70
            change if we find the right way of handling unchecked layers.
 
71
        """
 
72
        raise NotImplementedError()
 
73
 
 
74
    def AddLayer(self, ltype, name=None, checked=None,
 
75
                 opacity=1.0, cmd=None):
 
76
        """Adds a new layer to the layer list.
 
77
 
 
78
        Launches property dialog if needed (raster, vector, etc.)
 
79
 
 
80
        :param ltype: layer type (raster, vector, 3d-raster, ...)
 
81
        :param name: layer name
 
82
        :param checked: if True layer is checked
 
83
        :param opacity: layer opacity level
 
84
        :param cmd: command (given as a list)
 
85
        """
 
86
        raise NotImplementedError()
 
87
 
 
88
    def GetLayersByName(self, name):
 
89
        """Returns list of layers with a given name.
 
90
 
 
91
        :param name: fully qualified map name
 
92
 
 
93
        .. todo::
 
94
            if common usage is just to check the presence of layer,
 
95
            intoroduce a new method ContainsLayerByName(name)
 
96
        """
 
97
        raise NotImplementedError()
 
98
 
 
99
    def GetLayerByData(self, key, value):
 
100
        """Returns layer with specified.
 
101
 
 
102
        .. note::
 
103
            Returns only one layer. This might change.
 
104
 
 
105
        .. warning::
 
106
            Avoid using this method, it might be removed in the future.
 
107
        """
 
108
        raise NotImplementedError()
 
109
 
 
110
 
 
111
class GrassInterface:
 
112
    """GrassInterface provides the functionality which should be available
 
113
    to every GUI component.
 
114
 
 
115
    .. note::
 
116
 
 
117
        The GrassInterface process is not finished.
 
118
    """
 
119
    def RunCmd(self, *args, **kwargs):
 
120
        """Executes a command.
 
121
        """
 
122
        raise NotImplementedError()
 
123
 
 
124
    def Help(self, entry):
 
125
        """Shows a manual page for a given entry.
 
126
        """
 
127
        raise NotImplementedError()
 
128
 
 
129
    def WriteLog(self, text, wrap=None, notification=Notification.HIGHLIGHT):
 
130
        """Writes log message.
 
131
        """
 
132
        raise NotImplementedError()
 
133
 
 
134
    def WriteCmdLog(self, text, pid=None, notification=Notification.MAKE_VISIBLE):
 
135
        """Writes message related to start or end of the command.
 
136
        """
 
137
        raise NotImplementedError()
 
138
 
 
139
    def WriteWarning(self, text):
 
140
        """Writes warning message for the user.
 
141
        """
 
142
        raise NotImplementedError()
 
143
 
 
144
    def WriteError(self, text):
 
145
        """Writes error message for the user."""
 
146
        raise NotImplementedError()
 
147
 
 
148
    def GetLayerTree(self):
 
149
        """Returns LayerManager's tree GUI object.
 
150
        .. note::
 
151
 
 
152
            Will be removed from the interface.
 
153
        """
 
154
        raise NotImplementedError()
 
155
 
 
156
    def GetLayerList(self):
 
157
        """Returns a layer management object.
 
158
        """
 
159
        raise NotImplementedError()
 
160
 
 
161
    def GetMapDisplay(self):
 
162
        """Returns current map display.
 
163
 
 
164
        .. note::
 
165
 
 
166
            For layer related tasks use GetLayerList().
 
167
 
 
168
        :return: MapFrame instance
 
169
        :return: None when no mapdisplay open
 
170
        """
 
171
        raise NotImplementedError()
 
172
 
 
173
    def GetAllMapDisplays(self):
 
174
        """Get list of all map displays.
 
175
 
 
176
        .. note::
 
177
 
 
178
            Might be removed from the interface.
 
179
 
 
180
        :return: list of MapFrame instances
 
181
        """
 
182
        raise NotImplementedError()
 
183
 
 
184
    def GetMapWindow(self):
 
185
        """Returns current map window.
 
186
 
 
187
        .. note::
 
188
 
 
189
            For layer related tasks use GetLayerList().
 
190
        """
 
191
        raise NotImplementedError()
 
192
 
 
193
    def GetProgress(self):
 
194
        """Returns object which shows the progress.
 
195
 
 
196
        .. note::
 
197
 
 
198
            Some implementations may not implement this method.
 
199
        """
 
200
        raise NotImplementedError()
 
201
 
 
202
 
 
203
class StandaloneGrassInterface():
 
204
    """@implements GrassInterface"""
 
205
    def __init__(self):
 
206
 
 
207
        # Signal when some map is created or updated by a module.
 
208
        # attributes: name: map name, ltype: map type,
 
209
        # add: if map should be added to layer tree (questionable attribute)
 
210
        self.mapCreated = Signal('StandaloneGrassInterface.mapCreated')
 
211
 
 
212
        # Signal emitted to request updating of map
 
213
        self.updateMap = Signal('StandaloneGrassInterface.updateMap')
 
214
 
 
215
        # workaround, standalone grass interface should be moved to sep. file
 
216
        from core.gconsole import GConsole, \
 
217
            EVT_CMD_OUTPUT, EVT_CMD_PROGRESS
 
218
 
 
219
        self._gconsole = GConsole()
 
220
        self._gconsole.Bind(EVT_CMD_PROGRESS, self._onCmdProgress)
 
221
        self._gconsole.Bind(EVT_CMD_OUTPUT, self._onCmdOutput)
 
222
        self._gconsole.writeLog.connect(self.WriteLog)
 
223
        self._gconsole.writeCmdLog.connect(self.WriteCmdLog)
 
224
        self._gconsole.writeWarning.connect(self.WriteWarning)
 
225
        self._gconsole.writeError.connect(self.WriteError)
 
226
 
 
227
    def _onCmdOutput(self, event):
 
228
        """Print command output"""
 
229
        message = event.text
 
230
        style = event.type
 
231
 
 
232
        if style == 'warning':
 
233
            self.WriteWarning(message)
 
234
        elif style == 'error':
 
235
            self.WriteError(message)
 
236
        else:
 
237
            self.WriteLog(message)
 
238
        event.Skip()
 
239
 
 
240
    def _onCmdProgress(self, event):
 
241
        """Update progress message info"""
 
242
        grass.percent(event.value, 100, 1)
 
243
        event.Skip()
 
244
 
 
245
    def RunCmd(self, command, compReg=True, skipInterface=False,
 
246
               onDone=None, onPrepare=None, userData=None, notification=Notification.MAKE_VISIBLE):
 
247
        self._gconsole.RunCmd(command=command, compReg=compReg,
 
248
                              skipInterface=skipInterface, onDone=onDone,
 
249
                              onPrepare=onPrepare, userData=userData, notification=notification)
 
250
 
 
251
    def Help(self, entry):
 
252
        self._gconsole.RunCmd(['g.manual', 'entry=%s' % entry])
 
253
 
 
254
    def WriteLog(self, text, wrap=None,
 
255
                 notification=Notification.HIGHLIGHT):
 
256
        self._write(grass.message, text)
 
257
 
 
258
    def WriteCmdLog(self, text, pid=None, notification=Notification.MAKE_VISIBLE):
 
259
        if pid:
 
260
            text = '(' + str(pid) + ') ' + text
 
261
        self._write(grass.message, text)
 
262
 
 
263
    def WriteWarning(self, text):
 
264
        self._write(grass.warning, text)
 
265
 
 
266
    def WriteError(self, text):
 
267
        self._write(grass.error, text)
 
268
 
 
269
    def _write(self, function, text):
 
270
        orig = os.getenv("GRASS_MESSAGE_FORMAT")
 
271
        os.environ["GRASS_MESSAGE_FORMAT"] = 'standard'
 
272
        function(text)
 
273
        os.environ["GRASS_MESSAGE_FORMAT"] = orig
 
274
 
 
275
    def GetLayerList(self):
 
276
        raise NotImplementedError()
 
277
 
 
278
    def GetLayerTree(self):
 
279
        return None
 
280
 
 
281
    def GetMapDisplay(self):
 
282
        """Get current map display.
 
283
        """
 
284
        return None
 
285
 
 
286
    def GetAllMapDisplays(self):
 
287
        """Get list of all map displays.
 
288
        """
 
289
        return []
 
290
 
 
291
    def GetMapWindow(self):
 
292
        raise NotImplementedError()
 
293
 
 
294
    def GetProgress(self):
 
295
        # TODO: implement some progress with same inface as gui one
 
296
        # (probably using g.message or similarly to Write... functions)
 
297
        raise NotImplementedError()
 
298
 
 
299
    def UpdateCmdHistory(self, cmd):
 
300
        raise NotImplementedError()