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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
|
"""
@package mapswipe.dialogs
@brief Dialogs used in Map Swipe
Classes:
- dialogs::SwipeMapDialog
(C) 2013 by the GRASS Development Team
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
@author Anna Petrasova <kratochanna gmail.com>
"""
import copy
import wx
import wx.lib.scrolledpanel as SP
import wx.lib.colourselect as csel
from core import globalvar
from gui_core import gselect
from gui_core.widgets import SimpleValidator
from gui_core.preferences import PreferencesBaseDialog
from core.gcmd import GMessage
from core.layerlist import LayerList
from core.settings import UserSettings
from gui_core.wrap import SpinCtrl, Button, StaticText, StaticBox
from gui_core.simplelmgr import (
SimpleLayerManager,
SIMPLE_LMGR_RASTER,
SIMPLE_LMGR_VECTOR,
SIMPLE_LMGR_RGB,
SIMPLE_LMGR_TB_LEFT,
SIMPLE_LMGR_TB_RIGHT,
)
from grass.pydispatch.signal import Signal
class SwipeMapDialog(wx.Dialog):
"""Dialog used to select maps.
There are two modes - simple (only two raster maps),
or two layer lists.
"""
def __init__(
self,
parent,
title=_("Select raster maps"),
first=None,
second=None,
firstLayerList=None,
secondLayerList=None,
):
wx.Dialog.__init__(
self,
parent=parent,
title=title,
style=wx.RESIZE_BORDER | wx.DEFAULT_DIALOG_STYLE,
)
if firstLayerList is None:
self._firstLayerList = LayerList()
else:
self._firstLayerList = copy.deepcopy(firstLayerList)
if secondLayerList is None:
self._secondLayerList = LayerList()
else:
self._secondLayerList = copy.deepcopy(secondLayerList)
self._firstPanel = self._createSimplePanel()
self._secondPanel = self._createAdvancedPanel()
self.btnSwitch = Button(self)
self.btnCancel = Button(self, id=wx.ID_CANCEL)
self.btnApply = Button(self, id=wx.ID_APPLY)
self.btnOK = Button(self, id=wx.ID_OK)
self.btnOK.SetDefault()
self.btnSwitch.Bind(wx.EVT_BUTTON, self.OnSwitchMode)
self.btnApply.Bind(wx.EVT_BUTTON, lambda evt: self._apply())
self.btnOK.Bind(wx.EVT_BUTTON, lambda evt: self._ok())
self.btnCancel.Bind(wx.EVT_BUTTON, lambda evt: self.Close())
self.Bind(wx.EVT_CLOSE, lambda evt: self.Hide())
self.applyChanges = Signal("SwipeMapDialog.applyChanges")
if first:
self._firstRaster.SetValue(first)
if second:
self._secondRaster.SetValue(second)
self._layout()
def UnInit(self):
self._firstLmgr.UnInit()
self._secondLmgr.UnInit()
def _layout(self):
"""Do layout"""
mainSizer = wx.BoxSizer(wx.VERTICAL)
self._switchSizer = wx.BoxSizer()
self._switchSizer.Add(
self._firstPanel, proportion=1, flag=wx.EXPAND | wx.ALL, border=5
)
self._switchSizer.Add(
self._secondPanel, proportion=1, flag=wx.EXPAND | wx.ALL, border=5
)
mainSizer.Add(self._switchSizer, proportion=1, flag=wx.EXPAND | wx.ALL)
self.btnSizer = wx.StdDialogButtonSizer()
self.btnSizer.AddButton(self.btnCancel)
self.btnSizer.AddButton(self.btnOK)
self.btnSizer.AddButton(self.btnApply)
self.btnSizer.Realize()
mainSizer.Add(
self.btnSwitch, proportion=0, flag=wx.ALL | wx.ALIGN_LEFT, border=5
)
mainSizer.Add(self.btnSizer, proportion=0, flag=wx.EXPAND | wx.ALL, border=5)
self.mainSizer = mainSizer
self._switchMode(simple=True)
self.SetSizer(mainSizer)
mainSizer.Fit(self)
def _createSimplePanel(self):
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
self._firstRaster = gselect.Select(
parent=panel,
type="raster",
size=globalvar.DIALOG_GSELECT_SIZE,
validator=SimpleValidator(callback=self.ValidatorCallback),
)
self._secondRaster = gselect.Select(
parent=panel,
type="raster",
size=globalvar.DIALOG_GSELECT_SIZE,
validator=SimpleValidator(callback=self.ValidatorCallback),
)
sizer.Add(
StaticText(panel, label=_("Name of top/left raster map:")),
proportion=0,
flag=wx.EXPAND | wx.ALL,
border=5,
)
sizer.Add(self._firstRaster, proportion=0, flag=wx.EXPAND | wx.ALL, border=1)
sizer.Add(
StaticText(panel, label=_("Name of bottom/right raster map:")),
proportion=0,
flag=wx.EXPAND | wx.ALL,
border=1,
)
sizer.Add(self._secondRaster, proportion=0, flag=wx.EXPAND | wx.ALL, border=1)
self._firstRaster.SetFocus()
panel.SetSizer(sizer)
sizer.Fit(panel)
return panel
def _createAdvancedPanel(self):
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.HORIZONTAL)
self._firstLmgr = SimpleLayerManager(
parent=panel,
layerList=self._firstLayerList,
lmgrStyle=SIMPLE_LMGR_RASTER
| SIMPLE_LMGR_RGB
| SIMPLE_LMGR_VECTOR
| SIMPLE_LMGR_TB_LEFT,
)
self._secondLmgr = SimpleLayerManager(
parent=panel,
layerList=self._secondLayerList,
lmgrStyle=SIMPLE_LMGR_RASTER
| SIMPLE_LMGR_RGB
| SIMPLE_LMGR_VECTOR
| SIMPLE_LMGR_TB_RIGHT,
)
sizer.Add(self._firstLmgr, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
sizer.Add(self._secondLmgr, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
panel.SetSizer(sizer)
sizer.Fit(panel)
return panel
def _switchMode(self, simple):
if simple:
self._switchSizer.Show(self._firstPanel, show=True, recursive=True)
self._switchSizer.Show(self._secondPanel, show=False, recursive=True)
self.btnSwitch.SetLabel(_("Switch to advanced mode"))
self.btnCancel.SetLabel(_("Cancel"))
else:
self._switchSizer.Show(self._firstPanel, show=False, recursive=True)
self._switchSizer.Show(self._secondPanel, show=True, recursive=True)
self.btnSwitch.SetLabel(_("Switch to simple mode"))
self.btnCancel.SetLabel(_("Close"))
self.Freeze() # doesn't do anything (at least on Ubuntu)
self.btnSizer.Show(self.btnApply, simple)
self.btnSizer.Show(self.btnOK, simple)
self.btnSizer.Layout()
self._switchSizer.Layout()
self.Fit()
self.Thaw()
self.applyChanges.emit()
def OnSwitchMode(self, event):
if self._switchSizer.IsShown(self._secondPanel):
self._switchMode(simple=True)
else:
self._switchMode(simple=False)
def ValidatorCallback(self, win):
if self._switchSizer.IsShown(self._secondPanel):
return
if win == self._firstRaster.GetTextCtrl():
GMessage(parent=self, message=_("Name of the first map is missing."))
else:
GMessage(parent=self, message=_("Name of the second map is missing."))
def _ok(self):
self._apply()
self.Close()
def _apply(self):
# TODO check if not empty
self.applyChanges.emit()
def GetValues(self):
"""Get raster maps"""
if self.IsSimpleMode():
return (self._firstRaster.GetValue(), self._secondRaster.GetValue())
else:
return (self._firstLayerList, self._secondLayerList)
def IsSimpleMode(self):
if self._switchSizer.IsShown(self._firstPanel):
return True
return False
def GetFirstSimpleLmgr(self):
return self._firstLmgr
def GetSecondSimpleLmgr(self):
return self._secondLmgr
class PreferencesDialog(PreferencesBaseDialog):
"""Mapswipe preferences dialog"""
def __init__(
self, parent, giface, title=_("Map Swipe settings"), settings=UserSettings
):
PreferencesBaseDialog.__init__(
self,
parent=parent,
giface=giface,
title=title,
settings=settings,
size=(-1, 300),
)
# create notebook pages
self._createMirrorModePage(self.notebook)
self.SetMinSize(self.GetBestSize())
self.SetSize(self.size)
def _createMirrorModePage(self, notebook):
"""Create notebook page for general settings"""
panel = SP.ScrolledPanel(parent=notebook)
panel.SetupScrolling(scroll_x=False, scroll_y=True)
notebook.AddPage(page=panel, text=_("Mirror mode"))
border = wx.BoxSizer(wx.VERTICAL)
box = StaticBox(parent=panel, label=" %s " % _("Mirrored cursor"))
sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
row = 0
gridSizer.Add(
StaticText(parent=panel, label=_("Color:")),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
pos=(row, 0),
)
color = csel.ColourSelect(
parent=panel,
colour=UserSettings.Get(group="mapswipe", key="cursor", subkey="color"),
size=globalvar.DIALOG_COLOR_SIZE,
)
color.SetName("GetColour")
self.winId["mapswipe:cursor:color"] = color.GetId()
gridSizer.Add(color, pos=(row, 1), flag=wx.ALIGN_RIGHT)
row += 1
gridSizer.Add(
StaticText(parent=panel, label=_("Shape:")),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
pos=(row, 0),
)
cursors = wx.Choice(
parent=panel,
choices=self.settings.Get(
group="mapswipe",
key="cursor",
subkey=["type", "choices"],
settings_type="internal",
),
name="GetSelection",
)
cursors.SetSelection(
self.settings.Get(
group="mapswipe", key="cursor", subkey=["type", "selection"]
)
)
self.winId["mapswipe:cursor:type:selection"] = cursors.GetId()
gridSizer.Add(
cursors,
flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
pos=(row, 1),
)
row += 1
gridSizer.Add(
StaticText(parent=panel, label=_("Line width:")),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
pos=(row, 0),
)
width = SpinCtrl(
parent=panel,
min=1,
max=10,
initial=self.settings.Get(group="mapswipe", key="cursor", subkey="width"),
name="GetValue",
)
self.winId["mapswipe:cursor:width"] = width.GetId()
gridSizer.Add(
width,
flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
pos=(row, 1),
)
row += 1
gridSizer.Add(
StaticText(parent=panel, label=_("Size:")),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
pos=(row, 0),
)
size = SpinCtrl(
parent=panel,
min=4,
max=50,
initial=self.settings.Get(group="mapswipe", key="cursor", subkey="size"),
name="GetValue",
)
self.winId["mapswipe:cursor:size"] = size.GetId()
gridSizer.Add(
size,
flag=wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
pos=(row, 1),
)
gridSizer.AddGrowableCol(1)
sizer.Add(gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=3)
border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
panel.SetSizer(border)
return panel
|