41 |
class WidgetHandler(wxEvtHandler): |
class WidgetHandler(wxEvtHandler): |
42 |
def __init__(self, instance, object): |
def __init__(self, instance, object): |
43 |
wxEvtHandler.__init__(self) |
wxEvtHandler.__init__(self) |
44 |
self.instance = instance |
self.editor = instance |
45 |
self.object = object |
self.object = object |
46 |
self.hasFocus = 0 |
self.hasFocus = 0 |
47 |
self.highlightBox = WidgetHighlighter(self.instance.panel) |
self.highlightBox = WidgetHighlighter(self.editor.panel) |
48 |
self._iMoved = 0 |
self._iMoved = 0 |
49 |
self._alreadySelected = 0 |
self._alreadySelected = 0 |
50 |
self._popup_editor = None |
self._popup_editor = None |
69 |
except: |
except: |
70 |
pass |
pass |
71 |
|
|
72 |
self.setAllChildren(EVT_KEY_UP, widget, self.instance.keyTrap) |
self.setAllChildren(EVT_KEY_UP, widget, self.editor.keyTrap) |
73 |
self.setAllChildren(EVT_SET_FOCUS, widget, self.focusGainedTrap) |
self.setAllChildren(EVT_SET_FOCUS, widget, self.focusGainedTrap) |
74 |
self.setAllChildren(EVT_KILL_FOCUS, widget, self.focusLostTrap) |
self.setAllChildren(EVT_KILL_FOCUS, widget, self.focusLostTrap) |
75 |
self.setAllChildren(EVT_LEFT_UP, widget, self.OnLeftUp) |
self.setAllChildren(EVT_LEFT_UP, widget, self.OnLeftUp) |
77 |
self.setAllChildren(EVT_RIGHT_DOWN, widget, self.OnRightDown) |
self.setAllChildren(EVT_RIGHT_DOWN, widget, self.OnRightDown) |
78 |
self.setAllChildren(EVT_RIGHT_UP, widget, self.OnRightUp) |
self.setAllChildren(EVT_RIGHT_UP, widget, self.OnRightUp) |
79 |
self.setAllChildren(EVT_MOTION, widget, self.OnMotion) |
self.setAllChildren(EVT_MOTION, widget, self.OnMotion) |
80 |
self.setAllChildren(EVT_LEFT_DCLICK, widget, self.OnEditProperties) |
self.setAllChildren(EVT_LEFT_DCLICK, widget, self.onLeftDClick) |
81 |
self.setAllChildren(EVT_KEY_UP, self.highlightBox, self.instance.keyTrap) |
self.setAllChildren(EVT_KEY_UP, self.highlightBox, self.editor.keyTrap) |
82 |
self.setAllChildren(EVT_SET_FOCUS, self.highlightBox, self.focusGainedTrap) |
self.setAllChildren(EVT_SET_FOCUS, self.highlightBox, self.focusGainedTrap) |
83 |
self.setAllChildren(EVT_KILL_FOCUS, self.highlightBox, self.focusLostTrap) |
self.setAllChildren(EVT_KILL_FOCUS, self.highlightBox, self.focusLostTrap) |
84 |
self.setAllChildren(EVT_LEFT_UP, self.highlightBox, self.OnLeftUp) |
self.setAllChildren(EVT_LEFT_UP, self.highlightBox, self.OnLeftUp) |
94 |
for widget in self.mainWidget.widgets: |
for widget in self.mainWidget.widgets: |
95 |
tx, ty = widget.GetPositionTuple() |
tx, ty = widget.GetPositionTuple() |
96 |
tw, th = widget.GetSizeTuple() |
tw, th = widget.GetSizeTuple() |
97 |
self.instance.positionMappings[widget] = [tx,ty,tx+tw-1,ty+tw-1,self] |
self.editor.positionMappings[widget] = [tx,ty,tx+tw-1,ty+tw-1,self] |
98 |
if tx < x1: |
if tx < x1: |
99 |
x1 = tx |
x1 = tx |
100 |
if ty < y1: |
if ty < y1: |
124 |
self.setAllChildren(event, child, trap) |
self.setAllChildren(event, child, trap) |
125 |
|
|
126 |
def focusGainedTrap(self, event): |
def focusGainedTrap(self, event): |
127 |
self.instance.panel.SetFocus() |
self.editor.panel.SetFocus() |
128 |
pass |
pass |
129 |
# event.Skip() |
# event.Skip() |
130 |
|
|
142 |
|
|
143 |
data = [ { "Type" : "selectedWidgets", |
data = [ { "Type" : "selectedWidgets", |
144 |
"Attributes": { |
"Attributes": { |
145 |
'startingX': object.Char__x + int(x/self.instance.gridWidth), |
'startingX': object.Char__x + int(x/self.editor.gridWidth), |
146 |
'startingY': object.Char__y + int(y/self.instance.gridHeight), |
'startingY': object.Char__y + int(y/self.editor.gridHeight), |
147 |
} |
} |
148 |
}] |
}] |
149 |
# "name": dname, |
# "name": dname, |
155 |
do.SetData(cPickle.dumps(data,1)) |
do.SetData(cPickle.dumps(data,1)) |
156 |
|
|
157 |
## icon = FeedbackBitmap(10,10).icon() |
## icon = FeedbackBitmap(10,10).icon() |
158 |
dropSource = MoveDropSource(self, self.instance) |
dropSource = MoveDropSource(self, self.editor) |
159 |
dropSource.SetData(do) |
dropSource.SetData(do) |
160 |
result = dropSource.DoDragDrop(true) |
result = dropSource.DoDragDrop(true) |
161 |
event.Skip() |
event.Skip() |
162 |
|
|
163 |
|
|
164 |
def OnLeftDown(self, event): |
def OnLeftDown(self, event): |
|
self.mouseStartX, self.mouseStartY = event.GetPositionTuple() |
|
|
self._iMoved = 0 |
|
165 |
|
|
166 |
if event.ShiftDown(): |
if self.editor.mode == 'move': |
167 |
selections = self.instance._currentSelection[:] |
|
168 |
else: |
self.mouseStartX, self.mouseStartY = event.GetPositionTuple() |
169 |
selections = [] |
self._iMoved = 0 |
170 |
|
|
|
if self.object in selections: |
|
171 |
if event.ShiftDown(): |
if event.ShiftDown(): |
172 |
del selections[selections.index(self.object)] |
selections = self.editor._currentSelection[:] |
173 |
|
else: |
174 |
|
selections = [] |
175 |
|
|
176 |
|
if self.object in selections: |
177 |
|
if event.ShiftDown(): |
178 |
|
del selections[selections.index(self.object)] |
179 |
|
else: |
180 |
|
selections.append(self.object) |
181 |
|
|
182 |
|
self.editor._instance.dispatchEvent('ObjectSelected',object=self.object, |
183 |
|
originator="Forms::LayoutEditor", |
184 |
|
selection=selections) |
185 |
else: |
else: |
186 |
selections.append(self.object) |
xo, yo = self.widget.GetPosition() |
187 |
|
x, y = event.GetPositionTuple() |
188 |
|
self.editor.handleLeftDown(x+xo,y+yo) |
189 |
|
|
|
self.instance._instance.dispatchEvent('ObjectSelected',object=self.object, |
|
|
originator="Forms::LayoutEditor", |
|
|
selection=selections) |
|
190 |
event.Skip() |
event.Skip() |
191 |
|
|
192 |
|
|
193 |
def OnLeftUp(self, event): |
def OnLeftUp(self, event): |
194 |
if self._iMoved: |
if self.editor.mode == 'move': |
195 |
self._iMoved = 0 |
if self._iMoved: |
196 |
|
self._iMoved = 0 |
197 |
|
else: |
198 |
|
xo, yo = self.widget.GetPosition() |
199 |
|
x, y = event.GetPositionTuple() |
200 |
|
self.editor.handleLeftUp(x+xo,y+yo) |
201 |
|
|
202 |
event.Skip() |
event.Skip() |
203 |
|
|
216 |
|
|
217 |
|
|
218 |
def OnRightUp(self, event): |
def OnRightUp(self, event): |
219 |
pt = event.GetPositionTuple() |
if self.editor.mode == 'move': |
220 |
self.instance.dispatchEvent('ObjectSelected',object=self.object, originator=None) |
pt = event.GetPositionTuple() |
221 |
wxPyTypeCast(event.GetEventObject(),'wxWindow') \ |
self.editor.dispatchEvent('ObjectSelected',object=self.object, originator=None) |
222 |
.PopupMenu(self.object._popupMenu, pt) |
wxPyTypeCast(event.GetEventObject(),'wxWindow') \ |
223 |
|
.PopupMenu(self.object._popupMenu, pt) |
224 |
event.Skip() |
event.Skip() |
225 |
|
|
226 |
|
|
233 |
oldVals = {self.__popupAttr:None} |
oldVals = {self.__popupAttr:None} |
234 |
newVals = {self.__popupAttr: value} |
newVals = {self.__popupAttr: value} |
235 |
self.object.__dict__.update(newVals) |
self.object.__dict__.update(newVals) |
236 |
self.instance.dispatchEvent('ObjectModified', object=self.object, |
self.editor.dispatchEvent('ObjectModified', object=self.object, |
237 |
originator="Forms::LayoutEditor", |
originator="Forms::LayoutEditor", |
238 |
old=oldVals, |
old=oldVals, |
239 |
new=newVals) |
new=newVals) |
243 |
self.widget.SetLabel(value or "<Unset>") |
self.widget.SetLabel(value or "<Unset>") |
244 |
if self.object._type == 'GFLabel': |
if self.object._type == 'GFLabel': |
245 |
width = len(value) or 10 |
width = len(value) or 10 |
246 |
self.widget.SetSize((width * self.instance.gridWidth, |
self.widget.SetSize((width * self.editor.gridWidth, |
247 |
self.widget.GetSize().height)) |
self.widget.GetSize().height)) |
248 |
self.recalcBoundaries() |
self.recalcBoundaries() |
249 |
self.setSelected(self.selected) |
self.setSelected(self.selected) |
250 |
|
|
251 |
|
|
252 |
def OnEditProperties(self, event): |
def onLeftDClick(self, event): |
253 |
|
|
254 |
if self.object._type in ('GFBox','GFLabel'): |
if self.editor.mode == 'move': |
255 |
# Create a popup text editor for the labels |
if self.object._type in ('GFBox','GFLabel'): |
256 |
if self.object._type == 'GFBox': |
# Create a popup text editor for the labels |
257 |
self.__popupAttr = 'label' |
if self.object._type == 'GFBox': |
258 |
x = self.widget.GetPosition().x + (self.instance.gridWidth/2) |
self.__popupAttr = 'label' |
259 |
width = (self.object.Char__width - 2) * self.instance.gridWidth |
x = self.widget.GetPosition().x + (self.editor.gridWidth/2) |
260 |
else: |
width = (self.object.Char__width - 2) * self.editor.gridWidth |
261 |
self.__popupAttr = 'text' |
else: |
262 |
x = self.widget.GetPosition().x |
self.__popupAttr = 'text' |
263 |
width = self.widget.GetSize().width + self.instance.gridWidth |
x = self.widget.GetPosition().x |
264 |
|
width = self.widget.GetSize().width + self.editor.gridWidth |
265 |
self._popup_editor = PopupEditor(self.instance.workspace, |
|
266 |
self._endPopupEditor, |
self._popup_editor = PopupEditor(self.editor.workspace, |
267 |
x + self.instance.panel.GetPosition().x, |
self._endPopupEditor, |
268 |
self.widget.GetPosition().y + self.instance.panel.GetPosition().y, |
x + self.editor.panel.GetPosition().x, |
269 |
width, |
self.widget.GetPosition().y + self.editor.panel.GetPosition().y, |
270 |
self.instance.gridHeight, |
width, |
271 |
self.object.__dict__[self.__popupAttr]) |
self.editor.gridHeight, |
272 |
|
self.object.__dict__[self.__popupAttr]) |
273 |
|
|
274 |
self._popup_editor.SetFocus() |
self._popup_editor.SetFocus() |
275 |
|
|
276 |
else: |
else: |
277 |
# Signal the Properties dialog |
# Signal the Properties dialog |
278 |
self.instance._instance.dispatchEvent('Show:Tool:objectProperties') |
self.editor._instance.dispatchEvent('Show:Tool:objectProperties') |
279 |
|
|
280 |
|
|
281 |
# |
# |
287 |
if not (dx or dy): |
if not (dx or dy): |
288 |
return 0 |
return 0 |
289 |
|
|
290 |
nx = dx * self.instance.gridWidth |
nx = dx * self.editor.gridWidth |
291 |
ny = dy * self.instance.gridHeight |
ny = dy * self.editor.gridHeight |
292 |
|
|
293 |
try: |
try: |
294 |
self.object.Char__height |
self.object.Char__height |
313 |
self.object.Char__height = self.object.Char__height + dy |
self.object.Char__height = self.object.Char__height + dy |
314 |
newVals['Char:height'] = self.object.Char__height |
newVals['Char:height'] = self.object.Char__height |
315 |
|
|
316 |
self.instance.dispatchEvent('ObjectModified', object=self.object, |
self.editor.dispatchEvent('ObjectModified', object=self.object, |
317 |
originator="Forms::LayoutEditor", |
originator="Forms::LayoutEditor", |
318 |
old=oldVals, |
old=oldVals, |
319 |
new=newVals) |
new=newVals) |
330 |
if not (dx or dy): |
if not (dx or dy): |
331 |
return 0 |
return 0 |
332 |
|
|
333 |
nx = dx * self.instance.gridWidth |
nx = dx * self.editor.gridWidth |
334 |
ny = dy * self.instance.gridHeight |
ny = dy * self.editor.gridHeight |
335 |
|
|
336 |
if (self.object.Char__x + dx < 0 or self.object.Char__y + dy < 0): |
if (self.object.Char__x + dx < 0 or self.object.Char__y + dy < 0): |
337 |
return 0 |
return 0 |
350 |
self.object.Char__y += dy |
self.object.Char__y += dy |
351 |
newVals['Char:y'] = self.object.Char__y |
newVals['Char:y'] = self.object.Char__y |
352 |
|
|
353 |
self.instance.dispatchEvent('ObjectModified', object=self.object, |
self.editor.dispatchEvent('ObjectModified', object=self.object, |
354 |
originator="Forms::LayoutEditor", |
originator="Forms::LayoutEditor", |
355 |
old=oldVals, |
old=oldVals, |
356 |
new=newVals) |
new=newVals) |
365 |
# TODO: Why the fsck can't I Destroy() this thing!?!??!? |
# TODO: Why the fsck can't I Destroy() this thing!?!??!? |
366 |
self.widget.Show(0) |
self.widget.Show(0) |
367 |
|
|
368 |
self.instance = None |
self.editor = None |
369 |
self.object = None |
self.object = None |
370 |
self.highlightBox.Destroy() |
self.highlightBox.Destroy() |
371 |
self.highlightBox = None |
self.highlightBox = None |