13
13
for details.
14
14
15
15
@author Linda Karlovska (Kladivova) [email protected]
16
+ @author Anna Petrasova (kratochanna gmail com)
17
+ @author Tomas Zigo
16
18
"""
17
19
18
20
import wx
19
- import re
20
-
21
- from core import globalvar
22
- from core .gcmd import GError , GException
23
- from core .utils import (
24
- parse_mapcalc_cmd ,
25
- replace_module_cmd_special_flags ,
26
- split ,
27
- )
28
- from gui_core .forms import GUI
29
- from gui_core .treeview import CTreeView
21
+
30
22
from gui_core .wrap import SearchCtrl
31
23
from history .tree import HistoryBrowserTree
32
24
33
25
from grass .pydispatch .signal import Signal
34
26
35
27
36
28
class HistoryBrowser (wx .Panel ):
37
- """History browser for executing the commands from history log.
29
+ """History browser panel for executing the commands from history log.
38
30
39
31
Signal:
40
32
showNotification - attribute 'message'
@@ -52,22 +44,24 @@ def __init__(
52
44
self .parent = parent
53
45
self ._giface = giface
54
46
55
- self .showNotification = Signal ("HistoryBrowser.showNotification" )
56
- self .runIgnoredCmdPattern = Signal ("HistoryBrowser.runIgnoredCmdPattern" )
57
47
wx .Panel .__init__ (self , parent = parent , id = id , ** kwargs )
48
+ self .SetName ("HistoryBrowser" )
58
49
59
- self ._createTree ()
60
-
61
- self ._giface .currentMapsetChanged .connect (self .UpdateHistoryModelFromScratch )
62
- self ._giface .updateHistory .connect (
63
- lambda cmd : self .UpdateHistoryModelByCommand (cmd )
64
- )
50
+ self .showNotification = Signal ("HistoryBrowser.showNotification" )
51
+ self .runIgnoredCmdPattern = Signal ("HistoryBrowser.runIgnoredCmdPattern" )
65
52
53
+ # search box
66
54
self .search = SearchCtrl (self )
67
55
self .search .SetDescriptiveText (_ ("Search" ))
68
56
self .search .ShowCancelButton (True )
69
- self .search .Bind (wx .EVT_TEXT , lambda evt : self .Filter (evt .GetString ()))
70
- self .search .Bind (wx .EVT_SEARCHCTRL_CANCEL_BTN , lambda evt : self .Filter ("" ))
57
+ self .search .Bind (wx .EVT_TEXT , lambda evt : self .tree .Filter (evt .GetString ()))
58
+ self .search .Bind (wx .EVT_SEARCHCTRL_CANCEL_BTN , lambda evt : self .tree .Filter ("" ))
59
+
60
+ # tree with layers
61
+ self .tree = HistoryBrowserTree (self , giface = giface )
62
+ self .tree .SetToolTip (_ ("Double-click to run selected tool" ))
63
+ self .tree .showNotification .connect (self .showNotification )
64
+ self .tree .runIgnoredCmdPattern .connect (self .runIgnoredCmdPattern )
71
65
72
66
self ._layout ()
73
67
@@ -81,83 +75,9 @@ def _layout(self):
81
75
border = 5 ,
82
76
)
83
77
sizer .Add (
84
- self ._tree , proportion = 1 , flag = wx .EXPAND | wx .LEFT | wx .RIGHT , border = 5
78
+ self .tree , proportion = 1 , flag = wx .EXPAND | wx .LEFT | wx .RIGHT , border = 5
85
79
)
86
80
87
81
self .SetSizerAndFit (sizer )
88
82
self .SetAutoLayout (True )
89
83
self .Layout ()
90
-
91
- def _createTree (self ):
92
- """Create tree based on the model"""
93
- self ._model = HistoryBrowserTree ()
94
- self ._tree = self ._getTreeInstance ()
95
- self ._tree .SetToolTip (_ ("Double-click to open the tool" ))
96
- self ._tree .selectionChanged .connect (self .OnItemSelected )
97
- self ._tree .itemActivated .connect (lambda node : self .Run (node ))
98
-
99
- def _getTreeInstance (self ):
100
- return CTreeView (model = self ._model .GetModel (), parent = self )
101
-
102
- def _getSelectedNode (self ):
103
- selection = self ._tree .GetSelected ()
104
- if not selection :
105
- return None
106
- return selection [0 ]
107
-
108
- def _refreshTree (self ):
109
- self ._tree .SetModel (self ._model .GetModel ())
110
-
111
- def Filter (self , text ):
112
- """Filter history
113
-
114
- :param str text: text string
115
- """
116
- model = self ._model .GetModel ()
117
- if text :
118
- model = self ._model .model .Filtered (key = ["command" ], value = text )
119
- self ._tree .SetModel (model )
120
- else :
121
- self ._tree .SetModel (model )
122
-
123
- def UpdateHistoryModelFromScratch (self ):
124
- """Update the model from scratch and refresh the tree"""
125
- self ._model .CreateModel ()
126
- self ._refreshTree ()
127
-
128
- def UpdateHistoryModelByCommand (self , cmd ):
129
- """Update the model by the command and refresh the tree"""
130
- self ._model .UpdateModel (cmd )
131
- self ._refreshTree ()
132
-
133
- def OnItemSelected (self , node ):
134
- """Item selected"""
135
- command = node .data ["command" ]
136
- self .showNotification .emit (message = command )
137
-
138
- def Run (self , node = None ):
139
- """Parse selected history command into list and launch module dialog."""
140
- node = node or self ._getSelectedNode ()
141
- if node :
142
- command = node .data ["command" ]
143
- if (
144
- globalvar .ignoredCmdPattern
145
- and re .compile (globalvar .ignoredCmdPattern ).search (command )
146
- and "--help" not in command
147
- and "--ui" not in command
148
- ):
149
- self .runIgnoredCmdPattern .emit (cmd = split (command ))
150
- return
151
- if re .compile (r"^r[3]?\.mapcalc" ).search (command ):
152
- command = parse_mapcalc_cmd (command )
153
- command = replace_module_cmd_special_flags (command )
154
- lst = split (command )
155
- try :
156
- GUI (parent = self , giface = self ._giface ).ParseCommand (lst )
157
- except GException as e :
158
- GError (
159
- parent = self ,
160
- message = str (e ),
161
- caption = _ ("Cannot be parsed into command" ),
162
- showTraceback = False ,
163
- )
0 commit comments