2
@package iscatt.dialogs
4
@brief Dialogs widgets.
7
- dialogs::AddScattPlotDialog
8
- dialogs::ExportCategoryRaster
9
- dialogs::SettingsDialog
10
- dialogs::ManageBusyCursorMixin
11
- dialogs::RenameClassDialog
13
(C) 2013 by the GRASS Development Team
15
This program is free software under the GNU General Public License
16
(>=v2). Read the file COPYING that comes with GRASS for details.
18
@author Stepan Turek <stepan.turek seznam.cz> (mentor: Martin Landa)
24
from iscatt.iscatt_core import idBandsToidScatt
25
from gui_core.gselect import Select
26
import wx.lib.colourselect as csel
28
import grass.script as grass
30
from core import globalvar
31
from core.gcmd import GMessage
32
from core.settings import UserSettings
33
from gui_core.dialogs import SimpleDialog
35
class AddScattPlotDialog(wx.Dialog):
37
def __init__(self, parent, bands, check_bands_callback, id = wx.ID_ANY):
38
wx.Dialog.__init__(self, parent, title = _("Add scatter plots"), id = id)
45
self.chb_callback = check_bands_callback
47
self.added_bands_ids = []
48
self.sel_bands_ids = []
51
def _createWidgets(self):
56
self.band_1_label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("x axis:"))
58
self.band_1_ch = wx.ComboBox(parent = self, id = wx.ID_ANY,
60
style = wx.CB_READONLY, size = (350, 30))
62
self.band_2_label = wx.StaticText(parent = self, id = wx.ID_ANY, label = _("y axis:"))
64
self.band_2_ch = wx.ComboBox(parent = self, id = wx.ID_ANY,
66
style = wx.CB_READONLY, size = (350, 30))
68
self.scattsBox = wx.ListBox(parent = self, id = wx.ID_ANY, size = (-1, 150),
69
style = wx.LB_MULTIPLE | wx.LB_NEEDED_SB)
72
self.btn_add = wx.Button(parent=self, id=wx.ID_ADD)
73
self.btn_remove = wx.Button(parent=self, id=wx.ID_REMOVE)
75
self.btn_close = wx.Button(parent=self, id=wx.ID_CANCEL)
76
self.btn_ok = wx.Button(parent=self, id=wx.ID_OK)
82
border = wx.BoxSizer(wx.VERTICAL)
83
dialogSizer = wx.BoxSizer(wx.VERTICAL)
85
regionSizer = wx.BoxSizer(wx.HORIZONTAL)
87
dialogSizer.Add(item = self._addSelectSizer(title = self.band_1_label,
88
sel = self.band_1_ch))
90
dialogSizer.Add(item = self._addSelectSizer(title = self.band_2_label,
91
sel = self.band_2_ch))
94
dialogSizer.Add(item=self.btn_add, proportion=0, flag = wx.TOP | wx.ALIGN_RIGHT, border = 5)
96
box = wx.StaticBox(self, id = wx.ID_ANY,
97
label = " %s " % _("Bands of scatter plots to be added (x y):"))
98
sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
100
sizer.Add(item=self.scattsBox, proportion=1, flag=wx.EXPAND | wx.TOP, border=5)
101
sizer.Add(item=self.btn_remove, proportion=0, flag=wx.TOP | wx.ALIGN_RIGHT, border = 5)
103
dialogSizer.Add(item=sizer, proportion=1, flag = wx.EXPAND | wx.TOP, border = 5)
106
self.btnsizer = wx.BoxSizer(orient = wx.HORIZONTAL)
108
self.btnsizer.Add(item = self.btn_close, proportion = 0,
109
flag = wx.RIGHT | wx.LEFT | wx.ALIGN_CENTER,
112
self.btnsizer.Add(item = self.btn_ok, proportion = 0,
113
flag = wx.RIGHT | wx.LEFT | wx.ALIGN_CENTER,
116
dialogSizer.Add(item = self.btnsizer, proportion = 0,
117
flag = wx.ALIGN_CENTER | wx.TOP, border = 5)
119
border.Add(item = dialogSizer, proportion = 0,
120
flag = wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 10)
122
self.SetSizer(border)
127
self.btn_close.Bind(wx.EVT_BUTTON, self.OnClose)
128
self.btn_ok.Bind(wx.EVT_BUTTON, self.OnOk)
129
self.btn_add.Bind(wx.EVT_BUTTON, self.OnAdd)
130
self.btn_remove.Bind(wx.EVT_BUTTON, self.OnRemoveLayer)
132
def OnOk(self, event):
134
if not self.GetBands():
135
GMessage(parent=self, message=_("No scatter plots selected."))
140
def _addSelectSizer(self, title, sel):
141
"""Helper layout function.
143
selSizer = wx.BoxSizer(orient = wx.VERTICAL)
145
selTitleSizer = wx.BoxSizer(wx.HORIZONTAL)
146
selTitleSizer.Add(item = title, proportion = 1,
147
flag = wx.TOP | wx.EXPAND, border = 5)
149
selSizer.Add(item = selTitleSizer, proportion = 0,
152
selSizer.Add(item = sel, proportion = 1,
153
flag = wx.EXPAND | wx.TOP| wx.ALIGN_CENTER_VERTICAL,
160
return self.sel_bands_ids
162
def OnClose(self, event):
165
if not self.IsModal():
169
def OnRemoveLayer(self, event):
170
"""Remove layer from listbox"""
171
while self.scattsBox.GetSelections():
172
sel = self.scattsBox.GetSelections()[0]
173
self.scattsBox.Delete(sel)
174
self.sel_bands_ids.pop(sel)
176
def OnAdd(self, event):
179
b_x = self.band_1_ch.GetSelection()
180
b_y = self.band_2_ch.GetSelection()
182
if b_x < 0 or b_y < 0:
183
GMessage(parent=self, message=_("Select both x and y bands."))
186
GMessage(parent=self, message=_("Selected bands must be different."))
189
if [b_x, b_y] in self.sel_bands_ids or [b_y, b_x] in self.sel_bands_ids:
190
GMessage(parent=self,
191
message=_("Scatter plot with same bands combination (regardless x y order) "
192
"has been already added into the list."))
195
if not self.chb_callback(b_x, b_y):
198
self.sel_bands_ids.append([b_x, b_y])
200
b_x_str = self.band_1_ch.GetStringSelection()
201
b_y_str = self.band_2_ch.GetStringSelection()
203
text = b_x_str + " " + b_y_str
205
self.scattsBox.Append(text)
208
class ExportCategoryRaster(wx.Dialog):
209
def __init__(self, parent, title, rasterName = None, id = wx.ID_ANY,
210
style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
212
"""Dialog for export of category raster.
214
:param parent: window
215
:param str rasterName name of vector layer for export
216
:param title: window title
218
wx.Dialog.__init__(self, parent, id, title, style = style, **kwargs)
220
self.rasterName = rasterName
221
self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
223
self.btnCancel = wx.Button(parent = self.panel, id = wx.ID_CANCEL)
224
self.btnOK = wx.Button(parent = self.panel, id = wx.ID_OK)
225
self.btnOK.SetDefault()
226
self.btnOK.Enable(False)
227
self.btnOK.Bind(wx.EVT_BUTTON, self.OnOK)
231
self.vectorNameCtrl.Bind(wx.EVT_TEXT, self.OnTextChanged)
232
self.OnTextChanged(None)
233
wx.CallAfter(self.vectorNameCtrl.SetFocus)
235
def OnTextChanged(self, event):
236
"""Name of new vector map given.
238
Enable/diable OK button.
240
file = self.vectorNameCtrl.GetValue()
242
self.btnOK.Enable(True)
244
self.btnOK.Enable(False)
248
sizer = wx.BoxSizer(wx.VERTICAL)
250
dataSizer = wx.BoxSizer(wx.VERTICAL)
252
dataSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
253
label = _("Enter name of new vector map:")),
254
proportion = 0, flag = wx.ALL, border = 3)
255
self.vectorNameCtrl = Select(parent = self.panel, type = 'raster',
256
mapsets = [grass.gisenv()['MAPSET']],
257
size = globalvar.DIALOG_GSELECT_SIZE)
259
self.vectorNameCtrl.SetValue(self.rasterName)
260
dataSizer.Add(item = self.vectorNameCtrl,
261
proportion = 0, flag = wx.ALL | wx.EXPAND, border = 3)
265
btnSizer = wx.StdDialogButtonSizer()
266
btnSizer.AddButton(self.btnCancel)
267
btnSizer.AddButton(self.btnOK)
270
sizer.Add(item = dataSizer, proportion = 1,
271
flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
273
sizer.Add(item = btnSizer, proportion = 0,
274
flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
276
self.panel.SetSizer(sizer)
279
self.SetMinSize(self.GetSize())
281
def GetRasterName(self):
282
"""Returns vector name"""
283
return self.vectorNameCtrl.GetValue()
285
def OnOK(self, event):
286
"""Checks if map exists and can be overwritten."""
287
overwrite = UserSettings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled')
288
rast_name = self.GetRasterName()
289
res = grass.find_file(rast_name, element = 'cell')
290
if res['fullname'] and overwrite is False:
291
qdlg = wx.MessageDialog(parent = self,
292
message = _("Raster map <%s> already exists."
293
" Do you want to overwrite it?" % rast_name) ,
294
caption = _("Raster <%s> exists" % rast_name),
295
style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION | wx.CENTRE)
296
if qdlg.ShowModal() == wx.ID_YES:
302
class SettingsDialog(wx.Dialog):
303
def __init__(self, parent, id, title, scatt_mgr, pos=wx.DefaultPosition, size=wx.DefaultSize,
304
style=wx.DEFAULT_DIALOG_STYLE):
305
"""Settings dialog"""
306
wx.Dialog.__init__(self, parent, id, title, pos, size, style)
308
self.scatt_mgr = scatt_mgr
316
self.settings["show_ellips"] = wx.CheckBox(parent = self, id=wx.ID_ANY,
317
label = _('Show confidence ellipses'))
318
show_ellips = UserSettings.Get(group ='scatt', key = "ellipses", subkey = "show_ellips")
319
self.settings["show_ellips"].SetValue(show_ellips)
323
"sel_pol" : ["selection", _("Selection polygon color:")],
324
"sel_pol_vertex" : ["selection", _("Color of selection polygon vertex:")],
325
"sel_area" : ["selection", _("Selected area color:")]
328
for settKey, sett in self.colorsSetts.iteritems():
329
settsLabels[settKey] = wx.StaticText(parent = self, id = wx.ID_ANY, label = sett[1])
330
col = UserSettings.Get(group ='scatt', key = sett[0], subkey = settKey)
331
self.settings[settKey] = csel.ColourSelect(parent = self, id = wx.ID_ANY,
332
colour = wx.Colour(col[0],
338
"snap_tresh" : ["selection", _("Snapping treshold in pixels:")],
339
"sel_area_opacty" : ["selection", _("Selected area opacity:")]
342
for settKey, sett in self.sizeSetts.iteritems():
343
settsLabels[settKey] = wx.StaticText(parent = self, id = wx.ID_ANY, label = sett[1])
344
self.settings[settKey] = wx.SpinCtrl(parent = self, id = wx.ID_ANY, min=0, max = 100)
345
size = int(UserSettings.Get(group = 'scatt', key = sett[0], subkey = settKey))
346
self.settings[settKey].SetValue(size)
350
self.btnSave = wx.Button(self, wx.ID_SAVE)
351
self.btnApply = wx.Button(self, wx.ID_APPLY)
352
self.btnClose = wx.Button(self, wx.ID_CLOSE)
353
self.btnApply.SetDefault()
356
self.btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
357
self.btnApply.SetToolTipString(_("Apply changes for the current session"))
358
self.btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
359
self.btnSave.SetToolTipString(_("Apply and save changes to user settings file (default for next sessions)"))
360
self.btnClose.Bind(wx.EVT_BUTTON, self.OnClose)
361
self.btnClose.SetToolTipString(_("Close dialog"))
365
# Analysis result style layout
366
self.SetMinSize(self.GetBestSize())
368
sizer = wx.BoxSizer(wx.VERTICAL)
370
sel_pol_box = wx.StaticBox(parent = self, id = wx.ID_ANY,
371
label =" %s " % _("Selection style:"))
372
selPolBoxSizer = wx.StaticBoxSizer(sel_pol_box, wx.VERTICAL)
374
gridSizer = wx.GridBagSizer(vgap = 1, hgap = 1)
377
setts = dict(self.colorsSetts.items() + self.sizeSetts.items())
379
settsOrder = ["sel_pol", "sel_pol_vertex", "sel_area",
380
"sel_area_opacty", "snap_tresh"]
381
for settKey in settsOrder:
382
sett = setts[settKey]
383
gridSizer.Add(item = settsLabels[settKey], flag = wx.ALIGN_CENTER_VERTICAL, pos =(row, 0))
384
gridSizer.Add(item = self.settings[settKey],
385
flag = wx.ALIGN_RIGHT | wx.ALL, border = 5,
389
gridSizer.AddGrowableCol(1)
390
selPolBoxSizer.Add(item = gridSizer, flag = wx.EXPAND)
392
ell_box = wx.StaticBox(parent = self, id = wx.ID_ANY,
393
label =" %s " % _("Ellipses settings:"))
394
ellPolBoxSizer = wx.StaticBoxSizer(ell_box, wx.VERTICAL)
395
gridSizer = wx.GridBagSizer(vgap = 1, hgap = 1)
397
sett = setts[settKey]
400
gridSizer.Add(item=self.settings["show_ellips"],
401
flag=wx.ALIGN_CENTER_VERTICAL,
404
gridSizer.AddGrowableCol(1)
405
ellPolBoxSizer.Add(item=gridSizer, flag=wx.EXPAND)
407
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
408
btnSizer.Add(self.btnApply, flag=wx.LEFT | wx.RIGHT, border=5)
409
btnSizer.Add(self.btnSave, flag=wx.LEFT | wx.RIGHT, border=5)
410
btnSizer.Add(self.btnClose, flag=wx.LEFT | wx.RIGHT, border=5)
412
sizer.Add(item=selPolBoxSizer, flag=wx.EXPAND | wx.ALL, border=5)
413
sizer.Add(item=ellPolBoxSizer, flag=wx.EXPAND | wx.ALL, border=5)
414
sizer.Add(item=btnSizer, flag=wx.EXPAND | wx.ALL, border=5, proportion=0)
419
def OnSave(self, event):
420
"""Button 'Save' pressed"""
421
self.UpdateSettings()
424
UserSettings.ReadSettingsFile(settings=fileSettings)
425
fileSettings['scatt'] = UserSettings.Get(group='scatt')
426
UserSettings.SaveToFile(fileSettings)
430
def UpdateSettings(self):
433
for settKey, sett in self.colorsSetts.iteritems():
434
col = tuple(self.settings[settKey].GetColour())
435
col_s = UserSettings.Get(group='scatt', key=sett[0], subkey=settKey)
437
UserSettings.Set(group='scatt',
441
chanaged_setts.append([settKey, sett[0]])
443
for settKey, sett in self.sizeSetts.iteritems():
444
val = self.settings[settKey].GetValue()
445
val_s = UserSettings.Get(group ='scatt', key = sett[0], subkey = settKey)
448
UserSettings.Set(group = 'scatt', key = sett[0], subkey = settKey,
450
chanaged_setts.append([settKey, sett[0]])
452
val = self.settings['show_ellips'].IsChecked()
453
val_s = UserSettings.Get(group ='scatt', key='ellipses', subkey='show_ellips')
456
UserSettings.Set(group='scatt', key='ellipses', subkey='show_ellips',
458
chanaged_setts.append(['ellipses', 'show_ellips'])
461
self.scatt_mgr.SettingsUpdated(chanaged_setts)
463
def OnApply(self, event):
464
"""Button 'Apply' pressed"""
465
self.UpdateSettings()
468
def OnClose(self, event):
469
"""Button 'Cancel' pressed"""
472
class ManageBusyCursorMixin:
473
def __init__(self, window):
477
self.cur_inside = False
479
self.win.Bind(wx.EVT_ENTER_WINDOW, self.OnEnter)
480
self.win.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
482
def OnLeave(self, event):
483
self.cur_inside = False
486
def OnEnter(self, event):
487
self.cur_inside = True
489
self.busy_cur = wx.BusyCursor()
491
def UpdateCur(self, busy):
493
if self.cur_inside and self.is_busy:
494
self.busy_cur = wx.BusyCursor()
499
class RenameClassDialog(SimpleDialog):
500
def __init__(self, parent, old_name, title=("Change class name")):
501
SimpleDialog.__init__(self, parent, title)
503
self.name = wx.TextCtrl(self.panel, id = wx.ID_ANY)
504
self.name.SetValue(old_name)
506
self.dataSizer.Add(self.name, proportion = 0,
507
flag = wx.EXPAND | wx.ALL, border = 1)
509
self.panel.SetSizer(self.sizer)
510
self.name.SetMinSize((200, -1))
513
def GetNewName(self):
514
return self.name.GetValue()