1 |
# Copyright (c) 2001, 2003 by Intevation GmbH |
# Copyright (c) 2003-2005 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Jonathan Coles <[email protected]> |
# Jan-Oliver Wagner <[email protected]> (2003-2004) |
4 |
|
# Martin Schulze <[email protected]> (2004) |
5 |
|
# Frank Koormann <[email protected]> (2003) |
6 |
|
# Bernhard Herzog <[email protected]> (2003) |
7 |
|
# Jonathan Coles <[email protected]> (2003) |
8 |
# |
# |
9 |
# This program is free software under the GPL (>=v2) |
# This program is free software under the GPL (>=v2) |
10 |
# Read the file COPYING coming with Thuban for details. |
# Read the file COPYING coming with Thuban for details. |
12 |
"""Dialog for classifying how layers are displayed""" |
"""Dialog for classifying how layers are displayed""" |
13 |
|
|
14 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
15 |
|
# $Source$ |
16 |
|
# $Id$ |
17 |
|
|
18 |
import copy |
import copy |
19 |
|
|
26 |
from Thuban import _ |
from Thuban import _ |
27 |
from Thuban.UI.common import Color2wxColour, wxColour2Color |
from Thuban.UI.common import Color2wxColour, wxColour2Color |
28 |
|
|
29 |
|
from Thuban.Model.messages import MAP_LAYERS_REMOVED, LAYER_SHAPESTORE_REPLACED |
30 |
from Thuban.Model.range import Range |
from Thuban.Model.range import Range |
31 |
from Thuban.Model.classification import \ |
from Thuban.Model.classification import \ |
32 |
Classification, ClassGroupDefault, \ |
Classification, ClassGroupDefault, \ |
33 |
ClassGroupSingleton, ClassGroupRange, ClassGroupMap, \ |
ClassGroupSingleton, ClassGroupRange, ClassGroupMap, \ |
34 |
ClassGroupProperties |
ClassGroupProperties |
35 |
|
|
36 |
from Thuban.Model.color import Color |
from Thuban.Model.color import Transparent |
37 |
|
|
38 |
from Thuban.Model.layer import Layer, \ |
from Thuban.Model.layer import Layer |
39 |
SHAPETYPE_ARC, SHAPETYPE_POLYGON, SHAPETYPE_POINT |
from Thuban.Model.data import SHAPETYPE_ARC, SHAPETYPE_POLYGON, SHAPETYPE_POINT |
40 |
|
|
41 |
from Thuban.UI.classgen import ClassGenDialog, ClassGenerator |
from Thuban.UI.classgen import ClassGenDialog |
42 |
|
from Thuban.UI.colordialog import ColorDialog |
43 |
|
|
44 |
from dialogs import NonModalDialog |
from Thuban.UI.layerproperties import LayerProperties |
45 |
|
from messages import MAP_REPLACED |
|
ID_CLASS_TABLE = 40011 |
|
46 |
|
|
47 |
|
|
48 |
# table columns |
# table columns |
73 |
clazz -- the working classification that this grid should |
clazz -- the working classification that this grid should |
74 |
use for display. |
use for display. |
75 |
""" |
""" |
76 |
|
wxGrid.__init__(self, parent, -1, style = 0) |
|
wxGrid.__init__(self, parent, ID_CLASS_TABLE, style = 0) |
|
77 |
|
|
78 |
self.classifier = classifier |
self.classifier = classifier |
79 |
|
|
89 |
#print "GetCellAttr ", row, col |
#print "GetCellAttr ", row, col |
90 |
#wxGrid.GetCellAttr(self, row, col) |
#wxGrid.GetCellAttr(self, row, col) |
91 |
|
|
92 |
def CreateTable(self, clazz, shapeType, group = None): |
def CreateTable(self, clazz, fieldType, shapeType, group = None): |
93 |
|
|
94 |
assert isinstance(clazz, Classification) |
assert isinstance(clazz, Classification) |
95 |
|
|
109 |
self.SetSelectionMode(wxGrid.wxGridSelectRows) |
self.SetSelectionMode(wxGrid.wxGridSelectRows) |
110 |
self.ClearSelection() |
self.ClearSelection() |
111 |
|
|
112 |
table.Reset(clazz, shapeType, group) |
table.Reset(clazz, fieldType, shapeType, group) |
113 |
|
|
114 |
def GetCurrentSelection(self): |
def GetCurrentSelection(self): |
115 |
"""Return the currently highlighted rows as an increasing list |
"""Return the currently highlighted rows as an increasing list |
158 |
group = self.GetTable().GetClassGroup(sel[0]) |
group = self.GetTable().GetClassGroup(sel[0]) |
159 |
if isinstance(group, ClassGroupDefault): |
if isinstance(group, ClassGroupDefault): |
160 |
wxMessageDialog(self, |
wxMessageDialog(self, |
161 |
"The Default group cannot be removed.", |
_("The Default group cannot be removed."), |
162 |
style = wxOK | wxICON_EXCLAMATION).ShowModal() |
style = wxOK | wxICON_EXCLAMATION).ShowModal() |
163 |
return |
return |
164 |
|
|
263 |
|
|
264 |
|
|
265 |
def __init__(self, view = None): |
def __init__(self, view = None): |
|
#def __init__(self, clazz, shapeType, view = None): |
|
266 |
"""Constructor. |
"""Constructor. |
267 |
|
|
268 |
shapeType -- the type of shape that the layer uses |
shapeType -- the type of shape that the layer uses |
279 |
|
|
280 |
self.SetView(view) |
self.SetView(view) |
281 |
|
|
282 |
def Reset(self, clazz, shapeType, group = None): |
def Reset(self, clazz, fieldType, shapeType, group = None): |
283 |
"""Reset the table with the given data. |
"""Reset the table with the given data. |
284 |
|
|
285 |
This is necessary because wxWindows does not allow a grid's |
This is necessary because wxWindows does not allow a grid's |
297 |
|
|
298 |
self.GetView().BeginBatch() |
self.GetView().BeginBatch() |
299 |
|
|
300 |
self.fieldType = clazz.GetFieldType() |
self.fieldType = fieldType |
301 |
self.shapeType = shapeType |
self.shapeType = shapeType |
302 |
|
|
303 |
self.SetClassification(clazz, group) |
self.SetClassification(clazz, group) |
320 |
self.GetView().FitInside() |
self.GetView().FitInside() |
321 |
|
|
322 |
def GetClassification(self): |
def GetClassification(self): |
323 |
|
"""Return the current classification.""" |
324 |
return self.clazz |
return self.clazz |
325 |
|
|
326 |
def SetClassification(self, clazz, group = None): |
def SetClassification(self, clazz, group = None): |
327 |
|
"""Fill in the table with the given classification. |
328 |
|
Select the given group if group is not None. |
329 |
|
""" |
330 |
|
|
331 |
self.GetView().BeginBatch() |
self.GetView().BeginBatch() |
332 |
|
|
334 |
|
|
335 |
row = -1 |
row = -1 |
336 |
self.clazz = clazz |
self.clazz = clazz |
337 |
|
|
338 |
self.__NotifyRowChanges(old_len, self.GetNumberRows()) |
self.__NotifyRowChanges(old_len, self.GetNumberRows()) |
339 |
|
|
340 |
# |
# |
347 |
|
|
348 |
self.__Modified() |
self.__Modified() |
349 |
|
|
|
|
|
350 |
self.GetView().EndBatch() |
self.GetView().EndBatch() |
351 |
self.GetView().FitInside() |
self.GetView().FitInside() |
352 |
|
|
353 |
def __NotifyRowChanges(self, curRows, newRows): |
def __NotifyRowChanges(self, curRows, newRows): |
354 |
|
"""Make sure table updates correctly if the number of |
355 |
|
rows changes. |
356 |
|
""" |
357 |
# |
# |
358 |
# silly message processing for updates to the number of |
# silly message processing for updates to the number of |
359 |
# rows and columns |
# rows and columns |
372 |
self.GetView().ProcessTableMessage(msg) |
self.GetView().ProcessTableMessage(msg) |
373 |
self.GetView().FitInside() |
self.GetView().FitInside() |
374 |
|
|
|
|
|
375 |
def __SetRow(self, row, group): |
def __SetRow(self, row, group): |
376 |
"""Set a row's data to that of the group. |
"""Set a row's data to that of the group. |
377 |
|
|
442 |
""" |
""" |
443 |
|
|
444 |
self.SetValueAsCustom(row, col, None, value) |
self.SetValueAsCustom(row, col, None, value) |
445 |
|
|
446 |
def GetValueAsCustom(self, row, col, typeName): |
def GetValueAsCustom(self, row, col, typeName): |
447 |
"""Return the object that is used to represent the given |
"""Return the object that is used to represent the given |
448 |
cell coordinates. This may not be a string. |
cell coordinates. This may not be a string. |
449 |
|
|
450 |
typeName -- unused, but needed to overload wxPyGridTableBase |
typeName -- unused, but needed to overload wxPyGridTableBase |
451 |
""" |
""" |
452 |
|
|
603 |
return self.clazz.GetGroup(row - 1) |
return self.clazz.GetGroup(row - 1) |
604 |
|
|
605 |
def SetClassGroup(self, row, group): |
def SetClassGroup(self, row, group): |
606 |
|
"""Set the given row to properties of group.""" |
607 |
self.__SetRow(row, group) |
self.__SetRow(row, group) |
608 |
self.GetView().Refresh() |
self.GetView().Refresh() |
609 |
|
|
681 |
EB_SELECT_FIELD = 1 |
EB_SELECT_FIELD = 1 |
682 |
EB_GEN_CLASS = 2 |
EB_GEN_CLASS = 2 |
683 |
|
|
684 |
class Classifier(NonModalDialog): |
class Classifier(LayerProperties): |
685 |
|
|
686 |
type2string = {None: _("None"), |
type2string = {None: _("None"), |
687 |
FIELDTYPE_STRING: _("Text"), |
FIELDTYPE_STRING: _("Text"), |
689 |
FIELDTYPE_DOUBLE: _("Decimal")} |
FIELDTYPE_DOUBLE: _("Decimal")} |
690 |
|
|
691 |
def __init__(self, parent, name, layer, group = None): |
def __init__(self, parent, name, layer, group = None): |
692 |
NonModalDialog.__init__(self, parent, name, "") |
"""Create a Properties/Classification dialog for a layer. |
693 |
|
The layer is part of map. If group is not None, select that |
694 |
self.__SetTitle(layer.Title()) |
group in the classification table. |
695 |
|
""" |
696 |
|
|
697 |
self.layer = layer |
LayerProperties.__init__(self, parent, name, layer) |
698 |
|
|
699 |
self.originalClass = self.layer.GetClassification() |
self.layer.Subscribe(LAYER_SHAPESTORE_REPLACED, |
700 |
field = self.originalClass.GetField() |
self.layer_shapestore_replaced) |
|
fieldType = self.originalClass.GetFieldType() |
|
701 |
|
|
702 |
self.genDlg = None |
self.genDlg = None |
703 |
|
self.group = group |
704 |
|
|
705 |
############################ |
LayerProperties.dialog_layout(self) |
|
# Create the controls |
|
|
# |
|
706 |
|
|
707 |
panel = wxPanel(self, -1) |
def dialog_layout(self, panel, panelBox): |
708 |
|
|
709 |
text_title = wxTextCtrl(panel, ID_PROPERTY_TITLE, layer.Title()) |
if self.layer.HasClassification(): |
|
# |
|
|
# make field choice box |
|
|
# |
|
|
self.fields = wxChoice(panel, ID_PROPERTY_SELECT,) |
|
|
|
|
|
self.num_cols = layer.table.NumColumns() |
|
|
# just assume the first field in case one hasn't been |
|
|
# specified in the file. |
|
|
self.__cur_field = 0 |
|
|
|
|
|
self.fields.Append("<None>") |
|
|
|
|
|
if self.originalClass.GetFieldType() is None: |
|
|
self.fields.SetClientData(0, copy.deepcopy(self.originalClass)) |
|
|
else: |
|
|
self.fields.SetClientData(0, None) |
|
|
|
|
|
for i in range(self.num_cols): |
|
|
name = layer.table.Column(i).name |
|
|
self.fields.Append(name) |
|
|
|
|
|
if name == field: |
|
|
self.__cur_field = i + 1 |
|
|
self.fields.SetClientData(i + 1, |
|
|
copy.deepcopy(self.originalClass)) |
|
|
else: |
|
|
self.fields.SetClientData(i + 1, None) |
|
|
|
|
|
|
|
|
self.fieldTypeText = wxStaticText(panel, -1, "") |
|
|
|
|
|
button_gen = wxButton(panel, ID_PROPERTY_GENCLASS, _("Generate Class")) |
|
|
|
|
|
button_add = wxButton(panel, ID_PROPERTY_ADD, _("Add")) |
|
|
button_moveup = wxButton(panel, ID_PROPERTY_MOVEUP, _("Move Up")) |
|
|
button_movedown = wxButton(panel, ID_PROPERTY_MOVEDOWN, _("Move Down")) |
|
|
button_edit = wxButton(panel, ID_PROPERTY_EDITSYM, _("Edit Symbol")) |
|
|
button_remove = wxButton(panel, ID_PROPERTY_REMOVE, _("Remove")) |
|
|
|
|
|
|
|
|
button_try = wxButton(panel, ID_PROPERTY_TRY, _("Try")) |
|
|
button_revert = wxButton(panel, ID_PROPERTY_REVERT, _("Revert")) |
|
|
button_ok = wxButton(panel, wxID_OK, _("OK")) |
|
|
button_ok.SetDefault() |
|
|
button_close = wxButton(panel, wxID_CANCEL, _("Close")) |
|
710 |
|
|
711 |
self.classGrid = ClassGrid(panel, self) |
self.fieldTypeText = wxStaticText(panel, -1, "") |
712 |
|
|
713 |
# calling __SelectField after creating the classGrid fills in the |
self.originalClass = self.layer.GetClassification() |
714 |
# grid with the correct information |
self.originalClassField = self.layer.GetClassificationColumn() |
715 |
self.fields.SetSelection(self.__cur_field) |
field = self.originalClassField |
716 |
self.__SelectField(self.__cur_field, group = group) |
fieldType = self.layer.GetFieldType(field) |
717 |
|
|
718 |
############################ |
table = self.layer.ShapeStore().Table() |
719 |
# Layout the controls |
# |
720 |
# |
# make field choice box |
721 |
|
# |
722 |
topBox = wxBoxSizer(wxVERTICAL) |
self.fields = wxChoice(panel, ID_PROPERTY_SELECT,) |
|
panelBox = wxBoxSizer(wxVERTICAL) |
|
|
|
|
|
sizer = wxBoxSizer(wxHORIZONTAL) |
|
|
sizer.Add(wxStaticText(panel, -1, _("Title: ")), |
|
|
0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 4) |
|
|
sizer.Add(text_title, 1, wxGROW, 0) |
|
|
|
|
|
panelBox.Add(sizer, 0, wxGROW, 4) |
|
|
|
|
|
panelBox.Add(wxStaticText(panel, -1, |
|
|
_("Type: %s") % layer.ShapeType()), |
|
|
0, wxALIGN_LEFT | wxALL, 4) |
|
|
|
|
|
classBox = wxStaticBoxSizer( |
|
|
wxStaticBox(panel, -1, _("Classification")), wxVERTICAL) |
|
|
|
|
|
|
|
|
sizer = wxBoxSizer(wxHORIZONTAL) |
|
|
sizer.Add(wxStaticText(panel, ID_PROPERTY_FIELDTEXT, _("Field: ")), |
|
|
0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 4) |
|
|
sizer.Add(self.fields, 1, wxGROW | wxALL, 4) |
|
|
|
|
|
classBox.Add(sizer, 0, wxGROW, 4) |
|
|
|
|
|
classBox.Add(self.fieldTypeText, 0, |
|
|
wxGROW | wxALIGN_LEFT | wxALL | wxADJUST_MINSIZE, 4) |
|
|
|
|
|
controlBox = wxBoxSizer(wxHORIZONTAL) |
|
|
controlButtonBox = wxBoxSizer(wxVERTICAL) |
|
723 |
|
|
724 |
controlButtonBox.Add(button_gen, 0, wxGROW|wxALL, 4) |
self.num_cols = table.NumColumns() |
725 |
controlButtonBox.Add(button_add, 0, wxGROW|wxALL, 4) |
# just assume the first field in case one hasn't been |
726 |
controlButtonBox.Add(button_moveup, 0, wxGROW|wxALL, 4) |
# specified in the file. |
727 |
controlButtonBox.Add(button_movedown, 0, wxGROW|wxALL, 4) |
self.__cur_field = 0 |
|
controlButtonBox.Add(button_edit, 0, wxGROW|wxALL, 4) |
|
|
controlButtonBox.Add(60, 20, 0, wxGROW|wxALL|wxALIGN_BOTTOM, 4) |
|
|
controlButtonBox.Add(button_remove, 0, wxGROW|wxALL|wxALIGN_BOTTOM, 4) |
|
728 |
|
|
729 |
controlBox.Add(self.classGrid, 1, wxGROW, 0) |
self.fields.Append("<None>") |
|
controlBox.Add(controlButtonBox, 0, wxGROW, 10) |
|
730 |
|
|
731 |
classBox.Add(controlBox, 1, wxGROW, 10) |
if fieldType is None: |
732 |
panelBox.Add(classBox, 1, wxGROW, 0) |
self.fields.SetClientData(0, copy.deepcopy(self.originalClass)) |
733 |
|
else: |
734 |
|
self.fields.SetClientData(0, None) |
735 |
|
|
736 |
|
for i in range(self.num_cols): |
737 |
|
name = table.Column(i).name |
738 |
|
self.fields.Append(name) |
739 |
|
|
740 |
|
if name == field: |
741 |
|
self.__cur_field = i + 1 |
742 |
|
self.fields.SetClientData(i + 1, |
743 |
|
copy.deepcopy(self.originalClass)) |
744 |
|
else: |
745 |
|
self.fields.SetClientData(i + 1, None) |
746 |
|
|
747 |
buttonBox = wxBoxSizer(wxHORIZONTAL) |
button_gen = wxButton(panel, ID_PROPERTY_GENCLASS, |
748 |
buttonBox.Add(button_try, 0, wxALL, 4) |
_("Generate Class")) |
749 |
buttonBox.Add(60, 20, 0, wxALL, 4) |
button_add = wxButton(panel, ID_PROPERTY_ADD, |
750 |
buttonBox.Add(button_revert, 0, wxALL, 4) |
_("Add")) |
751 |
buttonBox.Add(60, 20, 0, wxALL, 4) |
button_moveup = wxButton(panel, ID_PROPERTY_MOVEUP, |
752 |
buttonBox.Add(button_ok, 0, wxALL, 4) |
_("Move Up")) |
753 |
buttonBox.Add(60, 20, 0, wxALL, 4) |
button_movedown = wxButton(panel, ID_PROPERTY_MOVEDOWN, |
754 |
buttonBox.Add(button_close, 0, wxALL, 4) |
_("Move Down")) |
755 |
panelBox.Add(buttonBox, 0, |
button_edit = wxButton(panel, ID_PROPERTY_EDITSYM, |
756 |
wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 0) |
_("Edit Symbol")) |
757 |
|
button_remove = wxButton(panel, ID_PROPERTY_REMOVE, |
758 |
panel.SetAutoLayout(True) |
_("Remove")) |
759 |
panel.SetSizer(panelBox) |
|
760 |
panelBox.Fit(panel) |
self.classGrid = ClassGrid(panel, self) |
761 |
panelBox.SetSizeHints(panel) |
|
762 |
|
# calling __SelectField after creating the classGrid fills in the |
763 |
|
# grid with the correct information |
764 |
|
self.fields.SetSelection(self.__cur_field) |
765 |
|
self.__SelectField(self.__cur_field, group = self.group) |
766 |
|
|
767 |
|
|
768 |
|
classBox = wxStaticBoxSizer( |
769 |
|
wxStaticBox(panel, -1, _("Classification")), wxVERTICAL) |
770 |
|
|
771 |
|
|
772 |
|
sizer = wxBoxSizer(wxHORIZONTAL) |
773 |
|
sizer.Add(wxStaticText(panel, ID_PROPERTY_FIELDTEXT, _("Field: ")), |
774 |
|
0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 4) |
775 |
|
sizer.Add(self.fields, 1, wxGROW | wxALL, 4) |
776 |
|
|
777 |
|
classBox.Add(sizer, 0, wxGROW, 4) |
778 |
|
|
779 |
|
classBox.Add(self.fieldTypeText, 0, |
780 |
|
wxGROW | wxALIGN_LEFT | wxALL | wxADJUST_MINSIZE, 4) |
781 |
|
|
782 |
|
controlBox = wxBoxSizer(wxHORIZONTAL) |
783 |
|
controlButtonBox = wxBoxSizer(wxVERTICAL) |
784 |
|
|
785 |
|
controlButtonBox.Add(button_gen, 0, wxGROW|wxALL, 4) |
786 |
|
controlButtonBox.Add(button_add, 0, wxGROW|wxALL, 4) |
787 |
|
controlButtonBox.Add(button_moveup, 0, wxGROW|wxALL, 4) |
788 |
|
controlButtonBox.Add(button_movedown, 0, wxGROW|wxALL, 4) |
789 |
|
controlButtonBox.Add(button_edit, 0, wxGROW|wxALL, 4) |
790 |
|
controlButtonBox.Add( (60, 20), 0, wxGROW|wxALL|wxALIGN_BOTTOM, 4) |
791 |
|
controlButtonBox.Add(button_remove, 0, |
792 |
|
wxGROW|wxALL|wxALIGN_BOTTOM, 4) |
793 |
|
|
794 |
topBox.Add(panel, 1, wxGROW | wxALL, 4) |
controlBox.Add(self.classGrid, 1, wxGROW, 0) |
795 |
|
controlBox.Add(controlButtonBox, 0, wxGROW, 10) |
796 |
|
|
797 |
self.SetAutoLayout(True) |
classBox.Add(controlBox, 1, wxGROW, 10) |
798 |
self.SetSizer(topBox) |
panelBox.Add(classBox, 1, wxGROW, 0) |
|
topBox.Fit(self) |
|
|
topBox.SetSizeHints(self) |
|
|
self.Layout() |
|
799 |
|
|
|
########### |
|
800 |
|
|
801 |
EVT_CHOICE(self, ID_PROPERTY_SELECT, self._OnFieldSelect) |
EVT_CHOICE(self, ID_PROPERTY_SELECT, self._OnFieldSelect) |
|
EVT_TEXT(self, ID_PROPERTY_TITLE, self._OnTitleChanged) |
|
|
EVT_BUTTON(self, wxID_OK, self._OnOK) |
|
|
EVT_BUTTON(self, ID_PROPERTY_TRY, self._OnTry) |
|
|
EVT_BUTTON(self, wxID_CANCEL, self._OnCloseBtn) |
|
|
EVT_BUTTON(self, ID_PROPERTY_REVERT, self._OnRevert) |
|
|
|
|
802 |
EVT_BUTTON(self, ID_PROPERTY_ADD, self._OnAdd) |
EVT_BUTTON(self, ID_PROPERTY_ADD, self._OnAdd) |
803 |
EVT_BUTTON(self, ID_PROPERTY_EDITSYM, self._OnEditSymbol) |
EVT_BUTTON(self, ID_PROPERTY_EDITSYM, self._OnEditSymbol) |
804 |
EVT_BUTTON(self, ID_PROPERTY_REMOVE, self._OnRemove) |
EVT_BUTTON(self, ID_PROPERTY_REMOVE, self._OnRemove) |
806 |
EVT_BUTTON(self, ID_PROPERTY_MOVEUP, self._OnMoveUp) |
EVT_BUTTON(self, ID_PROPERTY_MOVEUP, self._OnMoveUp) |
807 |
EVT_BUTTON(self, ID_PROPERTY_MOVEDOWN, self._OnMoveDown) |
EVT_BUTTON(self, ID_PROPERTY_MOVEDOWN, self._OnMoveDown) |
808 |
|
|
809 |
###################### |
def unsubscribe_messages(self): |
810 |
|
"""Unsubscribe from all messages.""" |
811 |
self.fields.SetFocus() |
LayerProperties.unsubscribe_messages(self) |
812 |
self.haveApplied = False |
self.layer.Unsubscribe(LAYER_SHAPESTORE_REPLACED, |
813 |
|
self.layer_shapestore_replaced) |
814 |
|
|
815 |
|
def layer_shapestore_replaced(self, *args): |
816 |
|
"""Subscribed to the map's LAYER_SHAPESTORE_REPLACED message. |
817 |
|
Close self. |
818 |
|
""" |
819 |
|
self.Close() |
820 |
|
|
821 |
def EditSymbol(self, row): |
def EditSymbol(self, row): |
822 |
|
"""Open up a dialog where the user can select the properties |
823 |
|
for a group. |
824 |
|
""" |
825 |
table = self.classGrid.GetTable() |
table = self.classGrid.GetTable() |
826 |
prop = table.GetValueAsCustom(row, COL_SYMBOL, None) |
prop = table.GetValueAsCustom(row, COL_SYMBOL, None) |
827 |
|
|
828 |
# get a new ClassGroupProperties object and copy the |
# get a new ClassGroupProperties object and copy the |
829 |
# values over to our current object |
# values over to our current object |
830 |
propDlg = SelectPropertiesDialog(NULL, prop, self.layer.ShapeType()) |
propDlg = SelectPropertiesDialog(self, prop, self.layer.ShapeType()) |
831 |
|
|
832 |
self.Enable(False) |
self.Enable(False) |
833 |
if propDlg.ShowModal() == wxID_OK: |
if propDlg.ShowModal() == wxID_OK: |
835 |
table.SetValueAsCustom(row, COL_SYMBOL, None, new_prop) |
table.SetValueAsCustom(row, COL_SYMBOL, None, new_prop) |
836 |
self.Enable(True) |
self.Enable(True) |
837 |
propDlg.Destroy() |
propDlg.Destroy() |
838 |
|
|
839 |
def _SetClassification(self, clazz): |
def _SetClassification(self, clazz): |
840 |
|
"""Called from the ClassGen dialog when a new classification has |
841 |
|
been created and should be set in the table. |
842 |
|
""" |
843 |
|
# FIXME: This could be implemented using a message |
844 |
|
|
845 |
self.fields.SetClientData(self.__cur_field, clazz) |
self.fields.SetClientData(self.__cur_field, clazz) |
846 |
self.classGrid.GetTable().SetClassification(clazz) |
self.classGrid.GetTable().SetClassification(clazz) |
847 |
|
|
848 |
def __BuildClassification(self, fieldIndex, copyClass = False): |
def __BuildClassification(self, fieldIndex, copyClass=False, force=False): |
849 |
|
"""Pack the classification setting into a Classification object. |
850 |
|
Returns (Classification, fieldName) where fieldName is the selected |
851 |
|
field in the table that the classification should be used with. |
852 |
|
""" |
853 |
|
|
854 |
# numRows = self.classGrid.GetNumberRows() |
# numRows = self.classGrid.GetNumberRows() |
855 |
# assert numRows > 0 # there should always be a default row |
# assert numRows > 0 # there should always be a default row |
856 |
|
|
|
# clazz = Classification() |
|
857 |
if fieldIndex == 0: |
if fieldIndex == 0: |
858 |
fieldName = None |
fieldName = None |
859 |
fieldType = None |
fieldType = None |
861 |
fieldName = self.fields.GetString(fieldIndex) |
fieldName = self.fields.GetString(fieldIndex) |
862 |
fieldType = self.layer.GetFieldType(fieldName) |
fieldType = self.layer.GetFieldType(fieldName) |
863 |
|
|
864 |
clazz = self.classGrid.GetTable().GetClassification() |
clazz = self.fields.GetClientData(fieldIndex) |
865 |
|
if clazz is None or self.classGrid.GetTable().IsModified() or force: |
866 |
if copyClass: |
clazz = self.classGrid.GetTable().GetClassification() |
867 |
clazz = copy.deepcopy(clazz) |
if copyClass: |
868 |
|
clazz = copy.deepcopy(clazz) |
|
clazz.SetField(fieldName) |
|
|
clazz.SetFieldType(fieldType) |
|
|
|
|
|
|
|
|
# table = self.classGrid.GetTable() |
|
|
# clazz.SetDefaultGroup(table.GetClassGroup(0)) |
|
|
|
|
|
# for i in range(1, numRows): |
|
|
# clazz.AppendGroup(table.GetClassGroup(i)) |
|
869 |
|
|
870 |
return clazz |
return clazz, fieldName |
871 |
|
|
872 |
def __SetGridTable(self, fieldIndex, group = None): |
def __SetGridTable(self, fieldIndex, group = None): |
873 |
|
"""Set the table with the classification associated with the |
874 |
|
selected field at fieldIndex. Select the specified group |
875 |
|
if group is not None. |
876 |
|
""" |
877 |
|
|
878 |
clazz = self.fields.GetClientData(fieldIndex) |
clazz = self.fields.GetClientData(fieldIndex) |
879 |
|
|
884 |
self.layer.GetClassification(). |
self.layer.GetClassification(). |
885 |
GetDefaultGroup().GetProperties())) |
GetDefaultGroup().GetProperties())) |
886 |
|
|
887 |
fieldName = self.fields.GetString(fieldIndex) |
fieldName = self.fields.GetString(fieldIndex) |
888 |
fieldType = self.layer.GetFieldType(fieldName) |
fieldType = self.layer.GetFieldType(fieldName) |
|
clazz.SetFieldType(fieldType) |
|
889 |
|
|
890 |
self.classGrid.CreateTable(clazz, self.layer.ShapeType(), group) |
self.classGrid.CreateTable(clazz, fieldType, |
891 |
|
self.layer.ShapeType(), group) |
892 |
|
|
893 |
def __SetFieldTypeText(self, fieldIndex): |
def __SetFieldTypeText(self, fieldIndex): |
894 |
|
"""Set the field type string using the data type of the field |
895 |
|
at fieldIndex. |
896 |
|
""" |
897 |
fieldName = self.fields.GetString(fieldIndex) |
fieldName = self.fields.GetString(fieldIndex) |
898 |
fieldType = self.layer.GetFieldType(fieldName) |
fieldType = self.layer.GetFieldType(fieldName) |
899 |
|
|
911 |
assert oldIndex >= -1 |
assert oldIndex >= -1 |
912 |
|
|
913 |
if oldIndex != -1: |
if oldIndex != -1: |
914 |
clazz = self.__BuildClassification(oldIndex) |
clazz, name = self.__BuildClassification(oldIndex, force = True) |
915 |
self.fields.SetClientData(oldIndex, clazz) |
self.fields.SetClientData(oldIndex, clazz) |
916 |
|
|
917 |
self.__SetGridTable(newIndex, group) |
self.__SetGridTable(newIndex, group) |
918 |
|
|
919 |
self.__EnableButtons(EB_SELECT_FIELD, newIndex != 0) |
self.__EnableButtons(EB_SELECT_FIELD) |
920 |
|
|
921 |
self.__SetFieldTypeText(newIndex) |
self.__SetFieldTypeText(newIndex) |
922 |
|
|
923 |
def __SetTitle(self, title): |
def __SetTitle(self, title): |
924 |
|
"""Set the title of the dialog.""" |
925 |
if title != "": |
if title != "": |
926 |
title = ": " + title |
title = ": " + title |
927 |
|
|
928 |
self.SetTitle(_("Layer Properties") + title) |
self.SetTitle(_("Layer Properties") + title) |
929 |
|
|
930 |
def _OnEditSymbol(self, event): |
def _OnEditSymbol(self, event): |
931 |
|
"""Open up a dialog for the user to select group properties.""" |
932 |
sel = self.classGrid.GetCurrentSelection() |
sel = self.classGrid.GetCurrentSelection() |
933 |
|
|
934 |
if len(sel) == 1: |
if len(sel) == 1: |
939 |
self.__SelectField(index, self.__cur_field) |
self.__SelectField(index, self.__cur_field) |
940 |
self.__cur_field = index |
self.__cur_field = index |
941 |
|
|
942 |
def _OnTry(self, event): |
def OnTry(self, event): |
943 |
"""Put the data from the table into a new Classification and hand |
"""Put the data from the table into a new Classification and hand |
944 |
it to the layer. |
it to the layer. |
945 |
""" |
""" |
946 |
|
|
947 |
clazz = self.fields.GetClientData(self.__cur_field) |
if self.layer.HasClassification(): |
948 |
|
clazz = self.fields.GetClientData(self.__cur_field) |
949 |
|
|
950 |
# |
# |
951 |
# only build the classification if there wasn't one to |
# only build the classification if there wasn't one to |
952 |
# to begin with or it has been modified |
# to begin with or it has been modified |
953 |
# |
# |
954 |
self.classGrid.SaveEditControlValue() |
self.classGrid.SaveEditControlValue() |
955 |
if clazz is None or self.classGrid.GetTable().IsModified(): |
clazz, name = self.__BuildClassification(self.__cur_field, True) |
|
clazz = self.__BuildClassification(self.__cur_field, True) |
|
956 |
|
|
957 |
self.layer.SetClassification(clazz) |
self.layer.SetClassificationColumn(name) |
958 |
|
self.layer.SetClassification(clazz) |
959 |
|
|
960 |
self.haveApplied = True |
self.haveApplied = True |
961 |
|
|
962 |
def _OnOK(self, event): |
def OnOK(self, event): |
963 |
self._OnTry(event) |
self.OnTry(event) |
|
self.Close() |
|
|
|
|
|
def OnClose(self, event): |
|
|
NonModalDialog.OnClose(self, event) |
|
|
|
|
|
def _OnCloseBtn(self, event): |
|
|
"""Close is similar to Cancel except that any changes that were |
|
|
made and applied remain applied, but the currently displayed |
|
|
classification is discarded. |
|
|
""" |
|
|
|
|
964 |
self.Close() |
self.Close() |
965 |
|
|
966 |
def _OnRevert(self, event): |
def OnRevert(self, event): |
967 |
"""The layer's current classification stays the same.""" |
"""The layer's current classification stays the same.""" |
968 |
if self.haveApplied: |
if self.haveApplied and self.layer.HasClassification(): |
969 |
|
self.layer.SetClassificationColumn(self.originalClassField) |
970 |
self.layer.SetClassification(self.originalClass) |
self.layer.SetClassification(self.originalClass) |
971 |
|
|
972 |
#self.Close() |
#self.Close() |
978 |
self.classGrid.DeleteSelectedRows() |
self.classGrid.DeleteSelectedRows() |
979 |
|
|
980 |
def _OnGenClass(self, event): |
def _OnGenClass(self, event): |
981 |
|
"""Open up a dialog for the user to generate classifications.""" |
982 |
|
|
983 |
self.genDlg = ClassGenDialog(self, self.layer, |
self.genDlg = ClassGenDialog(self, self.layer, |
984 |
self.fields.GetString(self.__cur_field)) |
self.fields.GetString(self.__cur_field)) |
985 |
|
|
986 |
EVT_CLOSE(self.genDlg, self._OnGenDialogClose) |
EVT_CLOSE(self.genDlg, self._OnGenDialogClose) |
987 |
|
|
988 |
self.__EnableButtons(EB_GEN_CLASS, False) |
self.__EnableButtons(EB_GEN_CLASS) |
989 |
|
|
990 |
self.genDlg.Show() |
self.genDlg.Show() |
991 |
|
|
992 |
def _OnGenDialogClose(self, event): |
def _OnGenDialogClose(self, event): |
993 |
|
"""Reenable buttons after the generate classification |
994 |
|
dialog is closed. |
995 |
|
""" |
996 |
self.genDlg.Destroy() |
self.genDlg.Destroy() |
997 |
self.__EnableButtons(EB_GEN_CLASS, True) |
self.genDlg = None |
998 |
|
self.__EnableButtons(EB_GEN_CLASS) |
999 |
|
|
1000 |
def _OnMoveUp(self, event): |
def _OnMoveUp(self, event): |
1001 |
|
"""When the user clicks MoveUp, try to move a group up one row.""" |
1002 |
sel = self.classGrid.GetCurrentSelection() |
sel = self.classGrid.GetCurrentSelection() |
1003 |
|
|
1004 |
if len(sel) == 1: |
if len(sel) == 1: |
1014 |
self.classGrid.MakeCellVisible(i - 1, 0) |
self.classGrid.MakeCellVisible(i - 1, 0) |
1015 |
|
|
1016 |
def _OnMoveDown(self, event): |
def _OnMoveDown(self, event): |
1017 |
|
"""When the user clicks MoveDown, try to move a group down one row.""" |
1018 |
sel = self.classGrid.GetCurrentSelection() |
sel = self.classGrid.GetCurrentSelection() |
1019 |
|
|
1020 |
if len(sel) == 1: |
if len(sel) == 1: |
1030 |
self.classGrid.MakeCellVisible(i + 1, 0) |
self.classGrid.MakeCellVisible(i + 1, 0) |
1031 |
|
|
1032 |
def _OnTitleChanged(self, event): |
def _OnTitleChanged(self, event): |
1033 |
|
"""Update the dialog title when the user changed the layer name.""" |
1034 |
obj = event.GetEventObject() |
obj = event.GetEventObject() |
1035 |
|
|
1036 |
self.layer.SetTitle(obj.GetValue()) |
self.layer.SetTitle(obj.GetValue()) |
1037 |
self.__SetTitle(self.layer.Title()) |
self.__SetTitle(self.layer.Title()) |
1038 |
|
|
1039 |
self.__EnableButtons(EB_LAYER_TITLE, self.layer.Title() != "") |
self.__EnableButtons(EB_LAYER_TITLE) |
1040 |
|
|
1041 |
def __EnableButtons(self, case, enable): |
def __EnableButtons(self, case): |
1042 |
|
"""Helper method that enables/disables the appropriate buttons |
1043 |
|
based on the case provided. Cases are constants beginning with EB_. |
1044 |
|
""" |
1045 |
|
|
1046 |
|
list = {wxID_OK : True, |
1047 |
|
wxID_CANCEL : True, |
1048 |
|
ID_PROPERTY_ADD : True, |
1049 |
|
ID_PROPERTY_MOVEUP : True, |
1050 |
|
ID_PROPERTY_MOVEDOWN : True, |
1051 |
|
ID_PROPERTY_REMOVE : True, |
1052 |
|
ID_PROPERTY_SELECT : True, |
1053 |
|
ID_PROPERTY_FIELDTEXT : True, |
1054 |
|
ID_PROPERTY_GENCLASS : True, |
1055 |
|
ID_PROPERTY_EDITSYM : True} |
1056 |
|
|
1057 |
if case == EB_LAYER_TITLE: |
if case == EB_LAYER_TITLE: |
1058 |
list = (wxID_OK, |
if self.layer.Title() == "": |
1059 |
wxID_CANCEL) |
list[wxID_OK] = False |
1060 |
|
list[wxID_CANCEL] = False |
1061 |
|
|
1062 |
elif case == EB_SELECT_FIELD: |
elif case == EB_SELECT_FIELD: |
1063 |
list = (ID_PROPERTY_GENCLASS, |
if self.fields.GetSelection() == 0: |
1064 |
ID_PROPERTY_ADD, |
list[ID_PROPERTY_GENCLASS] = False |
1065 |
ID_PROPERTY_MOVEUP, |
list[ID_PROPERTY_ADD] = False |
1066 |
ID_PROPERTY_MOVEDOWN, |
list[ID_PROPERTY_MOVEUP] = False |
1067 |
ID_PROPERTY_EDITSYM, |
list[ID_PROPERTY_MOVEDOWN] = False |
1068 |
ID_PROPERTY_REMOVE) |
list[ID_PROPERTY_REMOVE] = False |
1069 |
|
|
1070 |
elif case == EB_GEN_CLASS: |
elif case == EB_GEN_CLASS: |
1071 |
list = (ID_PROPERTY_SELECT, |
if self.genDlg is not None: |
1072 |
ID_PROPERTY_FIELDTEXT, |
list[ID_PROPERTY_SELECT] = False |
1073 |
ID_PROPERTY_GENCLASS, |
list[ID_PROPERTY_FIELDTEXT] = False |
1074 |
ID_PROPERTY_EDITSYM) |
list[ID_PROPERTY_GENCLASS] = False |
1075 |
|
|
1076 |
|
for id, enable in list.items(): |
1077 |
|
win = self.FindWindowById(id) |
1078 |
|
if win: |
1079 |
|
win.Enable(enable) |
1080 |
|
|
1081 |
for id in list: |
ID_SELPROP_SPINCTRL_LINEWIDTH = 4002 |
|
self.FindWindowById(id).Enable(enable) |
|
|
|
|
|
ID_SELPROP_SPINCTRL = 4002 |
|
1082 |
ID_SELPROP_PREVIEW = 4003 |
ID_SELPROP_PREVIEW = 4003 |
1083 |
ID_SELPROP_STROKECLR = 4004 |
ID_SELPROP_STROKECLR = 4004 |
1084 |
ID_SELPROP_FILLCLR = 4005 |
ID_SELPROP_FILLCLR = 4005 |
1085 |
ID_SELPROP_STROKECLRTRANS = 4006 |
ID_SELPROP_STROKECLRTRANS = 4006 |
1086 |
ID_SELPROP_FILLCLRTRANS = 4007 |
ID_SELPROP_FILLCLRTRANS = 4007 |
1087 |
|
ID_SELPROP_SPINCTRL_SIZE = 4008 |
1088 |
|
|
1089 |
class SelectPropertiesDialog(wxDialog): |
class SelectPropertiesDialog(wxDialog): |
1090 |
|
"""Dialog that allows the user to select group properties.""" |
1091 |
|
|
1092 |
def __init__(self, parent, prop, shapeType): |
def __init__(self, parent, prop, shapeType): |
1093 |
|
"""Open the dialog with the initial prop properties and shapeType.""" |
1094 |
|
|
1095 |
wxDialog.__init__(self, parent, -1, _("Select Properties"), |
wxDialog.__init__(self, parent, -1, _("Select Properties"), |
1096 |
style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) |
style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) |
1097 |
|
|
1148 |
ctrlBox.Add(fillColorBox, 0, |
ctrlBox.Add(fillColorBox, 0, |
1149 |
wxALIGN_CENTER_HORIZONTAL | wxALL | wxGROW, 4) |
wxALIGN_CENTER_HORIZONTAL | wxALL | wxGROW, 4) |
1150 |
|
|
1151 |
|
# Line width selection |
1152 |
spinBox = wxBoxSizer(wxHORIZONTAL) |
spinBox = wxBoxSizer(wxHORIZONTAL) |
1153 |
spinBox.Add(wxStaticText(self, -1, _("Line Width: ")), |
spinBox.Add(wxStaticText(self, -1, _("Line Width: ")), |
1154 |
0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 4) |
0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 4) |
1155 |
self.spinCtrl = wxSpinCtrl(self, ID_SELPROP_SPINCTRL, |
self.spinCtrl_linewidth = wxSpinCtrl(self, |
1156 |
min=1, max=10, |
ID_SELPROP_SPINCTRL_LINEWIDTH, |
1157 |
value=str(prop.GetLineWidth()), |
min=1, max=10, |
1158 |
initial=prop.GetLineWidth()) |
value=str(prop.GetLineWidth()), |
1159 |
|
initial=prop.GetLineWidth()) |
1160 |
|
|
1161 |
EVT_SPINCTRL(self, ID_SELPROP_SPINCTRL, self._OnSpin) |
EVT_SPINCTRL(self, ID_SELPROP_SPINCTRL_LINEWIDTH, |
1162 |
|
self._OnSpinLineWidth) |
|
spinBox.Add(self.spinCtrl, 0, wxALIGN_LEFT | wxALL, 4) |
|
1163 |
|
|
1164 |
|
spinBox.Add(self.spinCtrl_linewidth, 0, wxALIGN_LEFT | wxALL, 4) |
1165 |
ctrlBox.Add(spinBox, 0, wxALIGN_RIGHT | wxALL, 0) |
ctrlBox.Add(spinBox, 0, wxALIGN_RIGHT | wxALL, 0) |
1166 |
|
|
1167 |
|
# Size selection |
1168 |
|
if shapeType == SHAPETYPE_POINT: |
1169 |
|
spinBox = wxBoxSizer(wxHORIZONTAL) |
1170 |
|
spinBox.Add(wxStaticText(self, -1, _("Size: ")), |
1171 |
|
0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 4) |
1172 |
|
self.spinCtrl_size = wxSpinCtrl(self, ID_SELPROP_SPINCTRL_SIZE, |
1173 |
|
min=1, max=100, |
1174 |
|
value=str(prop.GetSize()), |
1175 |
|
initial=prop.GetSize()) |
1176 |
|
|
1177 |
|
EVT_SPINCTRL(self, ID_SELPROP_SPINCTRL_SIZE, self._OnSpinSize) |
1178 |
|
|
1179 |
|
spinBox.Add(self.spinCtrl_size, 0, wxALIGN_LEFT | wxALL, 4) |
1180 |
|
ctrlBox.Add(spinBox, 0, wxALIGN_RIGHT | wxALL, 0) |
1181 |
|
|
1182 |
|
|
1183 |
itemBox.Add(ctrlBox, 0, wxALIGN_RIGHT | wxALL | wxGROW, 0) |
itemBox.Add(ctrlBox, 0, wxALIGN_RIGHT | wxALL | wxGROW, 0) |
1184 |
topBox.Add(itemBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0) |
topBox.Add(itemBox, 1, wxALIGN_LEFT | wxALL | wxGROW, 0) |
1185 |
|
|
1188 |
# |
# |
1189 |
buttonBox = wxBoxSizer(wxHORIZONTAL) |
buttonBox = wxBoxSizer(wxHORIZONTAL) |
1190 |
button_ok = wxButton(self, wxID_OK, _("OK")) |
button_ok = wxButton(self, wxID_OK, _("OK")) |
1191 |
button_ok.SetDefault() |
buttonBox.Add(button_ok, 0, wxRIGHT|wxEXPAND, 10) |
|
buttonBox.Add(button_ok, 0, wxALL, 4) |
|
1192 |
buttonBox.Add(wxButton(self, wxID_CANCEL, _("Cancel")), |
buttonBox.Add(wxButton(self, wxID_CANCEL, _("Cancel")), |
1193 |
0, wxALL, 4) |
0, wxRIGHT|wxEXPAND, 10) |
1194 |
topBox.Add(buttonBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM, 10) |
topBox.Add(buttonBox, 0, wxALIGN_RIGHT|wxBOTTOM|wxTOP, 10) |
1195 |
|
|
1196 |
|
button_ok.SetDefault() |
1197 |
|
|
1198 |
#EVT_BUTTON(self, wxID_OK, self._OnOK) |
#EVT_BUTTON(self, wxID_OK, self._OnOK) |
1199 |
#EVT_BUTTON(self, ID_SELPROP_CANCEL, self._OnCancel) |
#EVT_BUTTON(self, ID_SELPROP_CANCEL, self._OnCancel) |
1200 |
|
|
1201 |
self.SetAutoLayout(True) |
self.SetAutoLayout(True) |
1202 |
self.SetSizer(topBox) |
self.SetSizer(topBox) |
1203 |
topBox.Fit(self) |
topBox.Fit(self) |
1209 |
def OnCancel(self, event): |
def OnCancel(self, event): |
1210 |
self.EndModal(wxID_CANCEL) |
self.EndModal(wxID_CANCEL) |
1211 |
|
|
1212 |
def _OnSpin(self, event): |
def _OnSpinLineWidth(self, event): |
1213 |
self.prop.SetLineWidth(self.spinCtrl.GetValue()) |
self.prop.SetLineWidth(self.spinCtrl_linewidth.GetValue()) |
1214 |
|
self.previewWin.Refresh() |
1215 |
|
|
1216 |
|
def _OnSpinSize(self, event): |
1217 |
|
self.prop.SetSize(self.spinCtrl_size.GetValue()) |
1218 |
self.previewWin.Refresh() |
self.previewWin.Refresh() |
1219 |
|
|
1220 |
def __GetColor(self, cur): |
def __GetColor(self, cur): |
1221 |
dialog = wxColourDialog(self) |
dialog = ColorDialog(self) |
1222 |
if cur is not Color.Transparent: |
dialog.SetColor(cur) |
|
dialog.GetColourData().SetColour(Color2wxColour(cur)) |
|
1223 |
|
|
1224 |
ret = None |
ret = None |
1225 |
if dialog.ShowModal() == wxID_OK: |
if dialog.ShowModal() == wxID_OK: |
1226 |
ret = wxColour2Color(dialog.GetColourData().GetColour()) |
ret = dialog.GetColor() |
1227 |
|
|
1228 |
dialog.Destroy() |
dialog.Destroy() |
1229 |
|
|
1230 |
return ret |
return ret |
1231 |
|
|
1232 |
def _OnChangeLineColor(self, event): |
def _OnChangeLineColor(self, event): |
1233 |
clr = self.__GetColor(self.prop.GetLineColor()) |
clr = self.__GetColor(self.prop.GetLineColor()) |
1234 |
if clr is not None: |
if clr is not None: |
1236 |
self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer |
self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer |
1237 |
|
|
1238 |
def _OnChangeLineColorTrans(self, event): |
def _OnChangeLineColorTrans(self, event): |
1239 |
self.prop.SetLineColor(Color.Transparent) |
self.prop.SetLineColor(Transparent) |
1240 |
self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer |
self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer |
1241 |
|
|
1242 |
def _OnChangeFillColor(self, event): |
def _OnChangeFillColor(self, event): |
1243 |
clr = self.__GetColor(self.prop.GetFill()) |
clr = self.__GetColor(self.prop.GetFill()) |
1244 |
if clr is not None: |
if clr is not None: |
1246 |
self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer |
self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer |
1247 |
|
|
1248 |
def _OnChangeFillColorTrans(self, event): |
def _OnChangeFillColorTrans(self, event): |
1249 |
self.prop.SetFill(Color.Transparent) |
self.prop.SetFill(Transparent) |
1250 |
self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer |
self.previewWin.Refresh() # XXX: work around, see ClassDataPreviewer |
1251 |
|
|
1252 |
def GetClassGroupProperties(self): |
def GetClassGroupProperties(self): |
1254 |
|
|
1255 |
|
|
1256 |
class ClassDataPreviewWindow(wxWindow): |
class ClassDataPreviewWindow(wxWindow): |
1257 |
|
"""A custom window that draws group properties using the correct shape.""" |
1258 |
|
|
1259 |
def __init__(self, rect, prop, shapeType, |
def __init__(self, rect, prop, shapeType, |
1260 |
parent = None, id = -1, size = wxDefaultSize): |
parent = None, id = -1, size = wxDefaultSize): |
1261 |
|
"""Draws the appropriate shape as specified with shapeType using |
1262 |
|
prop properities. |
1263 |
|
""" |
1264 |
if parent is not None: |
if parent is not None: |
1265 |
wxWindow.__init__(self, parent, id, (0, 0), size) |
wxWindow.__init__(self, parent, id, (0, 0), size) |
1266 |
EVT_PAINT(self, self._OnPaint) |
EVT_PAINT(self, self._OnPaint) |
1289 |
self.previewer.Draw(dc, rect, self.prop, self.shapeType) |
self.previewer.Draw(dc, rect, self.prop, self.shapeType) |
1290 |
|
|
1291 |
class ClassDataPreviewer: |
class ClassDataPreviewer: |
1292 |
|
"""Class that actually draws a group property preview.""" |
1293 |
|
|
1294 |
def Draw(self, dc, rect, prop, shapeType): |
def Draw(self, dc, rect, prop, shapeType): |
1295 |
|
"""Draw the property. |
1296 |
|
|
1297 |
|
returns: (w, h) as adapted extend if the drawing size |
1298 |
|
exceeded the given rect. This can only be the case |
1299 |
|
for point symbols. If the symbol fits the given rect, |
1300 |
|
None is returned. |
1301 |
|
""" |
1302 |
|
|
1303 |
assert dc is not None |
assert dc is not None |
1304 |
assert isinstance(prop, ClassGroupProperties) |
assert isinstance(prop, ClassGroupProperties) |
1314 |
h = rect.GetHeight() |
h = rect.GetHeight() |
1315 |
|
|
1316 |
stroke = prop.GetLineColor() |
stroke = prop.GetLineColor() |
1317 |
if stroke is Color.Transparent: |
if stroke is Transparent: |
1318 |
pen = wxTRANSPARENT_PEN |
pen = wxTRANSPARENT_PEN |
1319 |
else: |
else: |
1320 |
pen = wxPen(Color2wxColour(stroke), |
pen = wxPen(Color2wxColour(stroke), |
1322 |
wxSOLID) |
wxSOLID) |
1323 |
|
|
1324 |
stroke = prop.GetFill() |
stroke = prop.GetFill() |
1325 |
if stroke is Color.Transparent: |
if stroke is Transparent: |
1326 |
brush = wxTRANSPARENT_BRUSH |
brush = wxTRANSPARENT_BRUSH |
1327 |
else: |
else: |
1328 |
brush = wxBrush(Color2wxColour(stroke), wxSOLID) |
brush = wxBrush(Color2wxColour(stroke), wxSOLID) |
1338 |
|
|
1339 |
elif shapeType == SHAPETYPE_POINT: |
elif shapeType == SHAPETYPE_POINT: |
1340 |
|
|
1341 |
dc.DrawCircle(x + w/2, y + h/2, |
dc.DrawCircle(x + w/2, y + h/2, prop.GetSize()) |
1342 |
(min(w, h) - prop.GetLineWidth())/2) |
circle_size = prop.GetSize() * 2 + prop.GetLineWidth() * 2 |
1343 |
|
new_h = h |
1344 |
|
new_w = w |
1345 |
|
if h < circle_size: new_h = circle_size |
1346 |
|
if w < circle_size: new_w = circle_size |
1347 |
|
if new_h > h or new_w > w: |
1348 |
|
return (new_w, new_h) |
1349 |
|
|
1350 |
elif shapeType == SHAPETYPE_POLYGON: |
elif shapeType == SHAPETYPE_POLYGON: |
1351 |
dc.DrawRectangle(x, y, w, h) |
dc.DrawRectangle(x, y, w, h) |
1352 |
|
|
1353 |
|
return None |
1354 |
|
|
1355 |
class ClassRenderer(wxPyGridCellRenderer): |
class ClassRenderer(wxPyGridCellRenderer): |
1356 |
|
"""A wrapper class that can be used to draw group properties in a |
1357 |
|
grid table. |
1358 |
|
""" |
1359 |
|
|
1360 |
def __init__(self, shapeType): |
def __init__(self, shapeType): |
1361 |
wxPyGridCellRenderer.__init__(self) |
wxPyGridCellRenderer.__init__(self) |
1373 |
rect.GetWidth(), rect.GetHeight()) |
rect.GetWidth(), rect.GetHeight()) |
1374 |
|
|
1375 |
if not isinstance(data, ClassGroupMap): |
if not isinstance(data, ClassGroupMap): |
1376 |
self.previewer.Draw(dc, rect, data.GetProperties(), self.shapeType) |
new_size = self.previewer.Draw(dc, rect, data.GetProperties(), |
1377 |
|
self.shapeType) |
1378 |
|
if new_size is not None: |
1379 |
|
(new_w, new_h) = new_size |
1380 |
|
grid.SetRowSize(row, new_h) |
1381 |
|
grid.SetColSize(col, new_h) |
1382 |
|
grid.ForceRefresh() |
1383 |
|
|
1384 |
|
# now that we know the height, redraw everything |
1385 |
|
rect.SetHeight(new_h) |
1386 |
|
rect.SetWidth(new_w) |
1387 |
|
dc.DestroyClippingRegion() |
1388 |
|
dc.SetClippingRegion(rect.GetX(), rect.GetY(), |
1389 |
|
rect.GetWidth(), rect.GetHeight()) |
1390 |
|
dc.SetPen(wxPen(wxLIGHT_GREY)) |
1391 |
|
dc.SetBrush(wxBrush(wxLIGHT_GREY, wxSOLID)) |
1392 |
|
dc.DrawRectangle(rect.GetX(), rect.GetY(), |
1393 |
|
rect.GetWidth(), rect.GetHeight()) |
1394 |
|
self.previewer.Draw(dc, rect, data.GetProperties(), |
1395 |
|
self.shapeType) |
1396 |
|
|
1397 |
if isSelected: |
if isSelected: |
1398 |
dc.SetPen(wxPen(wxBLACK, 1, wxSOLID)) |
dc.SetPen(wxPen(wxBLACK, 1, wxSOLID)) |
1404 |
dc.DestroyClippingRegion() |
dc.DestroyClippingRegion() |
1405 |
|
|
1406 |
|
|
1407 |
class ClassGroupPropertiesCtrl(wxWindow, wxControl): |
class ClassGroupPropertiesCtrl(wxControl): |
1408 |
|
"""A custom window and control that draw a preview of group properties |
1409 |
|
and can open a dialog to modify the properties if the user double-clicks |
1410 |
|
it. |
1411 |
|
""" |
1412 |
|
|
1413 |
def __init__(self, parent, id, props, shapeType, |
def __init__(self, parent, id, props, shapeType, |
1414 |
size = wxDefaultSize, style = 0): |
size = wxDefaultSize, style = 0): |
1415 |
|
wxControl.__init__(self, parent, id, size = size, style = style) |
1416 |
|
|
1417 |
wxWindow.__init__(self, parent, id, size = size, style = style) |
self.parent = parent |
1418 |
|
|
1419 |
self.SetProperties(props) |
self.SetProperties(props) |
1420 |
self.SetShapeType(shapeType) |
self.SetShapeType(shapeType) |
1454 |
self.Refresh() |
self.Refresh() |
1455 |
|
|
1456 |
def AllowEdit(self, allow): |
def AllowEdit(self, allow): |
1457 |
|
"""Allow/Disallow double-clicking on the control.""" |
1458 |
self.allowEdit = allow |
self.allowEdit = allow |
1459 |
|
|
1460 |
def DoEdit(self): |
def DoEdit(self): |
1461 |
|
"""Open the properties selector dialog.""" |
1462 |
|
|
1463 |
if not self.allowEdit: return |
if not self.allowEdit: return |
1464 |
|
|
1465 |
propDlg = SelectPropertiesDialog(NULL, |
propDlg = SelectPropertiesDialog(self.parent, |
1466 |
self.GetProperties(), |
self.GetProperties(), |
1467 |
self.GetShapeType()) |
self.GetShapeType()) |
1468 |
|
|
1475 |
|
|
1476 |
def _OnLeftDClick(self, event): |
def _OnLeftDClick(self, event): |
1477 |
self.DoEdit() |
self.DoEdit() |
1478 |
|
|