2 # Purpose: XRC editor, toolbar
3 # Author: Roman Rolinsky <rolinsky@mema.ucl.ac.be>
7 from xxx
import * # xxx imports globals and params
8 from tree
import ID_NEW
15 GROUP_WINDOWS
, GROUP_MENUS
, GROUP_SIZERS
, GROUP_CONTROLS
= range(GROUPNUM
)
17 # States depending on current selection and Control/Shift keys
18 STATE_ROOT
, STATE_MENUBAR
, STATE_TOOLBAR
, STATE_MENU
, STATE_ELSE
= range(5)
20 # Left toolbar for GUI elements
23 def __init__(self
, parent
):
24 if wxPlatform
== '__WXGTK__':
25 wxPanel
.__init
__(self
, parent
, -1,
26 style
=wxRAISED_BORDER|wxWANTS_CHARS
)
28 wxPanel
.__init
__(self
, parent
, -1, style
=wxWANTS_CHARS
)
29 # Create sizer for groups
30 self
.sizer
= wxBoxSizer(wxVERTICAL
)
31 # Data to create buttons
32 pullDownMenu
= g
.pullDownMenu
34 self
.ctrl
= self
.shift
= False
35 # Current state (what to enable/disable)
39 (ID_NEW
.FRAME
, images
.getToolFrameBitmap()),
40 (ID_NEW
.DIALOG
, images
.getToolDialogBitmap()),
41 (ID_NEW
.PANEL
, images
.getToolPanelBitmap())],
43 (ID_NEW
.TOOL_BAR
, images
.getToolToolBarBitmap()),
44 (ID_NEW
.MENU_BAR
, images
.getToolMenuBarBitmap()),
45 (ID_NEW
.MENU
, images
.getToolMenuBitmap()),
46 (ID_NEW
.TOOL
, images
.getToolToolBitmap()),
47 (ID_NEW
.MENU_ITEM
, images
.getToolMenuItemBitmap()),
48 (ID_NEW
.SEPARATOR
, images
.getToolSeparatorBitmap())],
50 (ID_NEW
.BOX_SIZER
, images
.getToolBoxSizerBitmap()),
51 (ID_NEW
.STATIC_BOX_SIZER
, images
.getToolStaticBoxSizerBitmap()),
52 (ID_NEW
.GRID_SIZER
, images
.getToolGridSizerBitmap()),
53 (ID_NEW
.FLEX_GRID_SIZER
, images
.getToolFlexGridSizerBitmap()),
54 (ID_NEW
.SPACER
, images
.getToolSpacerBitmap())],
56 (ID_NEW
.STATIC_TEXT
, images
.getToolStaticTextBitmap()),
57 (ID_NEW
.STATIC_BITMAP
, images
.getToolStaticBitmapBitmap()),
58 (ID_NEW
.STATIC_LINE
, images
.getToolStaticLineBitmap()),
60 (ID_NEW
.BUTTON
, images
.getToolButtonBitmap()),
61 (ID_NEW
.BITMAP_BUTTON
, images
.getToolBitmapButtonBitmap()),
62 (ID_NEW
.STATIC_BOX
, images
.getToolStaticBoxBitmap()),
64 (ID_NEW
.TEXT_CTRL
, images
.getToolTextCtrlBitmap()),
65 (ID_NEW
.COMBO_BOX
, images
.getToolComboBoxBitmap()),
66 (ID_NEW
.CHOICE
, images
.getToolChoiceBitmap()),
68 (ID_NEW
.RADIO_BUTTON
, images
.getToolRadioButtonBitmap()),
69 (ID_NEW
.CHECK_BOX
, images
.getToolCheckBoxBitmap()),
70 (ID_NEW
.RADIO_BOX
, images
.getToolRadioBoxBitmap()),
72 (ID_NEW
.SPIN_CTRL
, images
.getToolSpinCtrlBitmap()),
73 (ID_NEW
.SPIN_BUTTON
, images
.getToolSpinButtonBitmap()),
74 (ID_NEW
.SCROLL_BAR
, images
.getToolScrollBarBitmap()),
76 (ID_NEW
.SLIDER
, images
.getToolSliderBitmap()),
77 (ID_NEW
.GAUGE
, images
.getToolGaugeBitmap()),
78 (ID_NEW
.TREE_CTRL
, images
.getToolTreeCtrlBitmap()),
80 (ID_NEW
.LIST_BOX
, images
.getToolListBoxBitmap()),
81 (ID_NEW
.CHECK_LIST
, images
.getToolCheckListBitmap()),
82 (ID_NEW
.LIST_CTRL
, images
.getToolListCtrlBitmap()),
84 (ID_NEW
.NOTEBOOK
, images
.getToolNotebookBitmap()),
86 (ID_NEW
.UNKNOWN
, images
.getToolUnknownBitmap())]
91 self
.AddButton(b
[0], b
[1], g
.pullDownMenu
.createMap
[b
[0]])
92 self
.SetAutoLayout(True)
93 self
.SetSizerAndFit(self
.sizer
)
94 # Allow to be resized in vertical direction only
95 self
.SetSizeHints(self
.GetSize()[0], -1)
97 EVT_COMMAND_RANGE(self
, ID_NEW
.PANEL
, ID_NEW
.LAST
,
98 wxEVT_COMMAND_BUTTON_CLICKED
, g
.frame
.OnCreate
)
99 EVT_KEY_DOWN(self
, self
.OnKeyDown
)
100 EVT_KEY_UP(self
, self
.OnKeyUp
)
102 def AddButton(self
, id, image
, text
):
103 button
= wxBitmapButton(self
, id, image
, size
=self
.TOOL_SIZE
,
104 style
=wxBU_AUTODRAW|wxNO_BORDER|wxWANTS_CHARS
)
105 EVT_KEY_DOWN(button
, self
.OnKeyDown
)
106 EVT_KEY_UP(button
, self
.OnKeyUp
)
107 button
.SetToolTipString(text
)
108 self
.curSizer
.Add(button
)
109 self
.groups
[-1][1][id] = button
111 def AddGroup(self
, name
):
112 # Each group is inside box
113 box
= wxStaticBox(self
, -1, name
, style
=wxWANTS_CHARS
)
114 box
.SetFont(smallerFont
)
115 boxSizer
= wxStaticBoxSizer(box
, wxVERTICAL
)
117 self
.curSizer
= wxGridSizer(0, 3)
118 boxSizer
.Add(self
.curSizer
)
119 self
.sizer
.Add(boxSizer
, 0, wxTOP | wxLEFT | wxRIGHT
, 4)
120 self
.groups
.append((box
,{}))
122 # Enable/disable group
123 def EnableGroup(self
, gnum
, enable
= True):
124 grp
= self
.groups
[gnum
]
125 grp
[0].Enable(enable
)
126 for b
in grp
[1].values(): b
.Enable(enable
)
128 # Enable/disable group item
129 def EnableGroupItem(self
, gnum
, id, enable
= True):
130 grp
= self
.groups
[gnum
]
131 grp
[1][id].Enable(enable
)
133 # Enable/disable group items
134 def EnableGroupItems(self
, gnum
, ids
, enable
= True):
135 grp
= self
.groups
[gnum
]
137 grp
[1][id].Enable(enable
)
140 def OnKeyDown(self
, evt
):
141 if evt
.GetKeyCode() == WXK_CONTROL
:
143 elif evt
.GetKeyCode() == WXK_SHIFT
:
145 self
.UpdateIfNeeded()
148 def OnKeyUp(self
, evt
):
149 if evt
.GetKeyCode() == WXK_CONTROL
:
151 elif evt
.GetKeyCode() == WXK_SHIFT
:
153 self
.UpdateIfNeeded()
156 def OnMouse(self
, evt
):
157 # Update control and shift states
158 g
.tree
.ctrl
= evt
.ControlDown()
159 g
.tree
.shift
= evt
.ShiftDown()
160 self
.UpdateIfNeeded()
163 # Update UI after key presses, if necessary
164 def UpdateIfNeeded(self
):
166 if self
.ctrl
!= tree
.ctrl
or self
.shift
!= tree
.shift
:
167 # Enabling is needed only for ctrl
168 if self
.ctrl
!= tree
.ctrl
: self
.UpdateUI()
169 self
.ctrl
= tree
.ctrl
170 self
.shift
= tree
.shift
177 g
.frame
.SetStatusText(status
, 1)
181 if not self
.IsShown(): return
183 pullDownMenu
= g
.pullDownMenu
185 item
= tree
.selection
186 # If nothing selected, disable everything and return
189 for grp
in range(GROUPNUM
):
190 self
.EnableGroup(grp
, False)
193 if tree
.ctrl
: needInsert
= True
194 else: needInsert
= tree
.NeedInsert(item
)
195 # Enable depending on selection
196 if item
== tree
.root
or needInsert
and tree
.GetItemParent(item
) == tree
.root
:
199 xxx
= tree
.GetPyData(item
).treeObject()
200 # Check parent for possible child nodes if inserting sibling
201 if needInsert
: xxx
= xxx
.parent
202 if xxx
.__class
__ == xxxMenuBar
:
203 state
= STATE_MENUBAR
204 elif xxx
.__class
__ in [xxxToolBar
, xxxTool
] or \
205 xxx
.__class
__ == xxxSeparator
and xxx
.parent
.__class
__ == xxxToolBar
:
206 state
= STATE_TOOLBAR
207 elif xxx
.__class
__ in [xxxMenu
, xxxMenuItem
]:
212 # Enable depending on selection
213 if state
!= self
.state
:
215 for grp
in range(GROUPNUM
):
216 self
.EnableGroup(grp
, False)
218 if state
== STATE_ROOT
:
219 self
.EnableGroup(GROUP_WINDOWS
, True)
220 self
.EnableGroup(GROUP_MENUS
, True)
222 self
.EnableGroupItems(GROUP_MENUS
,
227 elif state
== STATE_MENUBAR
:
228 self
.EnableGroup(GROUP_MENUS
)
229 self
.EnableGroupItems(GROUP_MENUS
,
234 elif state
== STATE_TOOLBAR
:
235 self
.EnableGroup(GROUP_MENUS
)
236 self
.EnableGroupItems(GROUP_MENUS
,
242 self
.EnableGroup(GROUP_CONTROLS
)
243 self
.EnableGroupItems(GROUP_CONTROLS
,
247 elif state
== STATE_MENU
:
248 self
.EnableGroup(GROUP_MENUS
)
249 self
.EnableGroupItems(GROUP_MENUS
,
255 self
.EnableGroup(GROUP_WINDOWS
)
256 self
.EnableGroupItems(GROUP_WINDOWS
,
260 self
.EnableGroup(GROUP_MENUS
)
261 self
.EnableGroupItems(GROUP_MENUS
,
269 self
.EnableGroup(GROUP_SIZERS
)
270 self
.EnableGroup(GROUP_CONTROLS
)
271 # Special case for notebook (always executed)
272 if state
== STATE_ELSE
:
273 if xxx
.__class
__ == xxxNotebook
:
274 self
.EnableGroup(GROUP_SIZERS
, False)
276 self
.EnableGroup(GROUP_SIZERS
)
277 if not (xxx
.isSizer
or xxx
.parent
and xxx
.parent
.isSizer
):
278 self
.EnableGroupItem(GROUP_SIZERS
, ID_NEW
.SPACER
, False)