29 |
import sys, os |
import sys, os |
30 |
from wxPython.wx import * |
from wxPython.wx import * |
31 |
from gnue.common import GDebug |
from gnue.common import GDebug |
32 |
from gnue.forms import GFObjects, GFEvent |
from gnue.forms import GFObjects |
33 |
from gnue.forms.uidrivers.wx import UIdriver as UIwxpython |
from gnue.forms.uidrivers.wx import UIdriver as UIwxpython |
34 |
from gnue.designer.PopupMenu import PageMenu |
from gnue.designer.PopupMenu import PageMenu |
35 |
from gnue.designer import Incubator |
from gnue.designer.forms import Incubator |
36 |
|
from gnue.designer.TemplateParser import TemplateParser |
37 |
|
from gnue.common.events import Event |
38 |
|
|
39 |
# My support files |
# My support files |
40 |
from Utils import * |
from Utils import * |
77 |
self.mode = 'move' |
self.mode = 'move' |
78 |
self.__x = 0 |
self.__x = 0 |
79 |
self.__y = 0 |
self.__y = 0 |
80 |
|
self.__ox = 0 |
81 |
|
self.__oy = 0 |
82 |
|
|
83 |
instance.rootObject.walk (self.inventoryObject) |
instance.rootObject.walk (self.inventoryObject) |
84 |
try: |
try: |
186 |
# TODO: adjust label width to match new length...this shouldn't be here |
# TODO: adjust label width to match new length...this shouldn't be here |
187 |
if object._type == 'GFLabel': |
if object._type == 'GFLabel': |
188 |
mods = [] |
mods = [] |
189 |
for modification in modifications: |
for field, value in modifications: |
|
field, value = modification |
|
190 |
if field=='text': |
if field=='text': |
191 |
#TODO: this will butcher align=center setups |
#TODO: this will butcher align=center setups |
192 |
if (not hasattr(object,'alignment')) or ( object.alignment == 'left'): |
if (not hasattr(object,'alignment')) or ( object.alignment == 'left'): |
326 |
else: |
else: |
327 |
GDebug.printMesg(7, 'Drawing item of type %s' % (object._type)) |
GDebug.printMesg(7, 'Drawing item of type %s' % (object._type)) |
328 |
object._widgetHandler = WidgetHandler(self, object) |
object._widgetHandler = WidgetHandler(self, object) |
329 |
cevent = GFEvent.GFEvent('CreateWidget',None, |
|
330 |
|
cevent = Event('CreateWidget',None, |
331 |
object=object, |
object=object, |
332 |
container=self.panel, |
container=self.panel, |
333 |
textWidth=self.textWidth, |
textWidth=self.textWidth, |
335 |
widgetWidth=self.widgetWidth, |
widgetWidth=self.widgetWidth, |
336 |
widgetHeight=self.widgetHeight, |
widgetHeight=self.widgetHeight, |
337 |
interface=self, |
interface=self, |
338 |
|
eventHandler=None, |
339 |
initialize=0) |
initialize=0) |
340 |
|
|
341 |
object._widget = self.widgets[object._type](cevent) |
object._widget = self.widgets[object._type](cevent) |
427 |
|
|
428 |
|
|
429 |
self.panel.SetCursor(wxSTANDARD_CURSOR) |
self.panel.SetCursor(wxSTANDARD_CURSOR) |
430 |
|
wxSetCursor(wxSTANDARD_CURSOR) |
431 |
|
|
432 |
|
|
433 |
areaSelected = (x1 <> x2 or y1 <> y2) |
areaSelected = (x1 <> x2 or y1 <> y2) |
434 |
|
|
435 |
|
event.Skip() |
436 |
|
|
437 |
if self.mode == 'move': |
if self.mode == 'move': |
438 |
if areaSelected: |
if areaSelected: |
439 |
# We are selecting an area |
# We are selecting an area |
440 |
self.page.walk(self.selectWidgetInArea, x1, y1, x2, y2) |
self.page.walk(self.selectWidgetInArea, x1, y1, x2, y2) |
441 |
|
|
442 |
else: |
elif self.mode == 'positioning': |
|
|
|
|
# We are creating a widget |
|
|
|
|
|
mode = self.mode |
|
|
self.toolbar.resetTool(mode) |
|
|
self.mode = 'move' |
|
|
|
|
|
type = None |
|
|
attributes = {'x' : x1, 'y' : y1} |
|
|
parent = self.block |
|
|
checkblock = 1 |
|
443 |
|
|
444 |
if areaSelected: |
if areaSelected: |
445 |
attributes['width'] = x2 - x1 + 1 |
width = x2 - x1 + 1 |
446 |
attributes['height'] = y2 - y1 + 1 |
height = y2 - y1 + 1 |
447 |
|
else: |
448 |
|
width = None |
449 |
|
height = None |
450 |
|
|
451 |
if mode in ('box','button','label'): |
PrepositioningTimer(self.endPrePositioningTemplate,x1,y1,width,height).Start(100,1) |
|
parent = self.page |
|
|
type = mode |
|
|
checkblock = 0 |
|
|
|
|
|
elif modeEntryMap.has_key(mode): |
|
|
type = 'entry' |
|
|
attributes.update(modeEntryMap[mode]) |
|
|
|
|
|
elif mode in ('scrollbar',): |
|
|
type = 'scrollbar' |
|
|
|
|
|
|
|
|
# Create a new block if one is needed and none exists |
|
|
if checkblock and self.block is None: |
|
|
|
|
|
parent = Incubator.createObject( |
|
|
self._instance, |
|
|
self._instance.rootObject, |
|
|
'block', |
|
|
parent=self.page, |
|
|
attributes={}) |
|
|
|
|
|
|
|
|
if type is not None: |
|
|
# |
|
|
# Create our new object |
|
|
# |
|
|
object = Incubator.createObject( |
|
|
self._instance, |
|
|
self._instance.rootObject, |
|
|
type, |
|
|
parent=parent, |
|
|
attributes=attributes) |
|
452 |
|
|
|
self._currentSelection[object._widgetHandler] = 1 |
|
|
object._widgetHandler.setSelected(1) |
|
453 |
|
|
|
event.Skip() |
|
454 |
|
|
455 |
|
|
456 |
def selectWidgetInArea(self, object, x1, y1, x2, y2): |
def selectWidgetInArea(self, object, x1, y1, x2, y2): |
527 |
widget.relativeMove(0,1) |
widget.relativeMove(0,1) |
528 |
|
|
529 |
|
|
530 |
# |
def startPrePositioningTemplate(self, template): |
531 |
# |
self.mode = 'positioning' |
532 |
# |
##self.panel.SetCursor(wxCROSS_CURSOR) |
533 |
##class FeedbackBitmap: |
wxSetCursor(wxCROSS_CURSOR) |
534 |
## def __init__(self, width, height): |
self.__template = template |
535 |
## |
|
536 |
## if width < 2: width = 2 |
|
537 |
## if height < 2: height = 2 |
def endPrePositioningTemplate(self, x, y, width=None, height=None): |
538 |
## |
TemplateParser(self._instance, self._instance.rootObject, |
539 |
### topbot = '"' + ". " * int(width/2) + divmod(width,2)[1] * '.' + '"' |
self._instance, self.__template, currentObject=self.block or self.page).run(x=x, y=y, |
540 |
## topbot = '"' + ".." * int(width/2) + divmod(width,2)[1] * '.' + '"' |
width=width, |
541 |
## mid = '".' + " " * (width - 2) + '.",\n' |
height=height) |
542 |
## |
self._instance.dispatchEvent(Event('EndWizard', template=self.__template)) |
543 |
## xpm = '/* XPM */\n' \ |
self.mode = 'move' |
544 |
## + 'static char * text1_xpm[] = {\n' \ |
|
|
## + '"%s %s 2 1",\n' % (width, height) \ |
|
|
## + '" g None",\n' \ |
|
|
## + '". g #000000",\n' \ |
|
|
## + topbot + '\n' \ |
|
|
## + mid * (height - 2) + topbot + '};\n' |
|
|
## |
|
|
## print xpm |
|
|
## |
|
|
## self.bitmap=wxResourceRegisterIconData("mymoveicon",xpm) |
|
|
## print self.bitmap |
|
|
### dc = wxMemoryDC() |
|
|
### dc.SelectObject(self.bitmap) |
|
|
### dc.BeginDrawing() |
|
|
### dc.DrawRectangle(0,0,width, height) |
|
|
### dc.SetBrush(wxBLACK_BRUSH) |
|
|
### dc.SetPen(wxBLACK_PEN) |
|
|
### dc.EndDrawing() |
|
|
### self._icon = wxIcon(width, height) |
|
|
## print self.bitmap |
|
|
## |
|
|
## |
|
|
## def icon(self): |
|
|
### return self._icon |
|
|
## return self.bitmap |
|
545 |
|
|
546 |
|
|
547 |
|
class PrepositioningTimer(wxTimer): |
548 |
|
def __init__(self, method, *args, **params): |
549 |
|
self.__method = method |
550 |
|
self.__args = args |
551 |
|
self.__params = params |
552 |
|
wxTimer.__init__(self) |
553 |
|
|
554 |
modeEntryMap = { |
def Notify(self): |
555 |
'entrynum': { 'typecast': 'number'}, |
self.__method(*self.__args, **self.__params) |
|
'entrytext': { 'typecast': 'text' }, |
|
|
'entrydate': { 'typecast': 'date' }, |
|
|
'entrydrop': { 'typecast': 'text', |
|
|
'style':'dropdown' }, |
|
|
'entrycheck': { 'typecast': 'text', |
|
|
'style':'checkbox' } } |
|
556 |
|
|
557 |
|
|