commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/designer/src/forms/LayoutEditor LayoutEdit...


From: Jason Cater
Subject: gnue/designer/src/forms/LayoutEditor LayoutEdit...
Date: Wed, 30 Jan 2002 12:29:47 -0500

CVSROOT:        /cvsroot/gnue
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    02/01/30 12:29:46

Modified files:
        designer/src/forms/LayoutEditor: LayoutEditor.py 
Added files:
        designer/src/forms/LayoutEditor: DisplayDropTarget.py 
                                         GridPane.py PopupEditor.py 
                                         PropertyBar.py Utils.py 
                                         WidgetHandler.py 
                                         WidgetHighlighter.py 

Log message:
        split LayoutEditor into manageable file sizes

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/forms/LayoutEditor/DisplayDropTarget.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/forms/LayoutEditor/GridPane.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/forms/LayoutEditor/PopupEditor.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/forms/LayoutEditor/PropertyBar.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/forms/LayoutEditor/Utils.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/forms/LayoutEditor/WidgetHandler.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/forms/LayoutEditor/WidgetHighlighter.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/forms/LayoutEditor/LayoutEditor.py.diff?tr1=1.12&tr2=1.13&r1=text&r2=text

Patches:
Index: gnue/designer/src/forms/LayoutEditor/LayoutEditor.py
diff -c gnue/designer/src/forms/LayoutEditor/LayoutEditor.py:1.12 
gnue/designer/src/forms/LayoutEditor/LayoutEditor.py:1.13
*** gnue/designer/src/forms/LayoutEditor/LayoutEditor.py:1.12   Wed Jan 30 
11:34:52 2002
--- gnue/designer/src/forms/LayoutEditor/LayoutEditor.py        Wed Jan 30 
12:29:46 2002
***************
*** 26,39 ****
  # NOTES:
  
  
! import sys, os, cPickle
  from wxPython.wx import *
  from gnue.common import GDebug, GConfig
  from gnue.forms import UIwxpython, GFObjects
  from gnue.designer.PopupMenu import PageMenu
  from gnue.designer import Incubator
  
! import LayoutEditorTools
  
  class LayoutEditor (wxPanel):
    def __init__(self, instance, parentWindow):
--- 26,46 ----
  # NOTES:
  
  
! import sys, os
  from wxPython.wx import *
  from gnue.common import GDebug, GConfig
  from gnue.forms import UIwxpython, GFObjects
  from gnue.designer.PopupMenu import PageMenu
  from gnue.designer import Incubator
  
! # My support files
! from Utils import *
! from LayoutEditorTools import LayoutEditorTools
! from GridPane import GridPane
! from WidgetHandler import WidgetHandler
! from PropertyBar import PropertyBar
! from DisplayDropTarget import DisplayDropTarget
! 
  
  class LayoutEditor (wxPanel):
    def __init__(self, instance, parentWindow):
***************
*** 45,51 ****
      self._app = instance._app
      self.widgets = {}
      self.widgets.update(UIwxpython.WIDGETS)
!     self.toolbar = LayoutEditorTools.LayoutEditorTools(self, self.frame)
      del self.widgets['GFPage']
  
      self.notebook = wxNotebook(self, -1, pos=wxPoint(4, 4), 
size=wxSize(32,32))
--- 52,58 ----
      self._app = instance._app
      self.widgets = {}
      self.widgets.update(UIwxpython.WIDGETS)
!     self.toolbar = LayoutEditorTools(self, self.frame)
      del self.widgets['GFPage']
  
      self.notebook = wxNotebook(self, -1, pos=wxPoint(4, 4), 
size=wxSize(32,32))
***************
*** 107,113 ****
        return
      if hasattr(object, '_widgetHandler'):
        self.propBar.setCurrentObject(object)
!     if handler != __name__:
        self._setCurrentPage(object)
  
  
--- 114,120 ----
        return
      if hasattr(object, '_widgetHandler'):
        self.propBar.setCurrentObject(object)
!     if handler != "Forms::LayoutEditor":
        self._setCurrentPage(object)
  
  
***************
*** 153,159 ****
      if object == None:
        return
  
!     if handler != __name__:
        origpage = self.page
  
        if object._type != 'GFPage':
--- 160,166 ----
      if object == None:
        return
  
!     if handler != "Forms::LayoutEditor":
        origpage = self.page
  
        if object._type != 'GFPage':
***************
*** 170,176 ****
      if object == None:
        return
      self.propBar.onModifyObject(object, handler, modifications)
!     if handler != __name__:
        if object._type == 'GFPage':
          self.notebook.SetPageText(self._notebookMap[object],object.name)
          self.notebook.SetSelection(self.notebook.GetSelection())
--- 177,183 ----
      if object == None:
        return
      self.propBar.onModifyObject(object, handler, modifications)
!     if handler != "Forms::LayoutEditor":
        if object._type == 'GFPage':
          self.notebook.SetPageText(self._notebookMap[object],object.name)
          self.notebook.SetSelection(self.notebook.GetSelection())
***************
*** 186,192 ****
    def onDeleteObject (self, object, handler):
      if object == None:
        return
!     if handler != __name__:
        if object._type == 'GFPage':
          index = self._notebookMap[object]
          for i in range(index+1, len(self._notebookMap.keys())/2):
--- 193,199 ----
    def onDeleteObject (self, object, handler):
      if object == None:
        return
!     if handler != "Forms::LayoutEditor":
        if object._type == 'GFPage':
          index = self._notebookMap[object]
          for i in range(index+1, len(self._notebookMap.keys())/2):
***************
*** 298,304 ****
    def OnPageSelected(self, event):
      p = self._notebookMap[event.GetSelection()]
      if p != self.page:
!       self._instance.onSetCurrentObject(p, __name__)
      self._setCurrentPage(p)
  
  
--- 305,311 ----
    def OnPageSelected(self, event):
      p = self._notebookMap[event.GetSelection()]
      if p != self.page:
!       self._instance.onSetCurrentObject(p, "Forms::LayoutEditor")
      self._setCurrentPage(p)
  
  
***************
*** 514,813 ****
  #
  #
  #
- class WidgetHandler(wxEvtHandler):
-   def __init__(self, instance, object):
-     wxEvtHandler.__init__(self)
-     self.instance = instance
-     self.object = object
-     self.hasFocus = 0
-     self.highlightBox = WidgetHighlighter(self.instance.panel)
-     self._iMoved = 0
-     self._alreadySelected = 0
-     self._popup_editor = None
-     
-   def initialize(self, widget):
-     self.widget = widget.widgets[0]
-     self.mainWidget = widget
-     self.selected = 0
- 
-     self.recalcBoundaries()
- 
-     for widget in self.mainWidget.widgets:
-       widget.SetCursor (wxSTANDARD_CURSOR)
-       if isinstance(widget, wxWindow):
-         widget.Enable(0)
-       self.setAllChildren(EVT_KEY_UP, widget, self.instance.keyTrap)
-       self.setAllChildren(EVT_SET_FOCUS, widget, self.focusGainedTrap)
-       self.setAllChildren(EVT_KILL_FOCUS, widget, self.focusLostTrap)
-       self.setAllChildren(EVT_LEFT_UP, widget, self.OnLeftUp)
-       self.setAllChildren(EVT_LEFT_DOWN, widget, self.OnLeftDown)
-       self.setAllChildren(EVT_RIGHT_DOWN, widget, self.OnRightDown)
-       self.setAllChildren(EVT_RIGHT_UP, widget, self.OnRightUp)
-       self.setAllChildren(EVT_MOTION, widget, self.OnMotion)
-       self.setAllChildren(EVT_LEFT_DCLICK, widget, self.OnEditProperties)
-     self.setAllChildren(EVT_KEY_UP, self.highlightBox, self.instance.keyTrap)
-     self.setAllChildren(EVT_SET_FOCUS, self.highlightBox, 
self.focusGainedTrap)
-     self.setAllChildren(EVT_KILL_FOCUS, self.highlightBox, self.focusLostTrap)
-     self.setAllChildren(EVT_LEFT_UP, self.highlightBox, self.OnLeftUp)
-     self.setAllChildren(EVT_LEFT_DOWN, self.highlightBox, self.OnLeftDown)
-     self.setAllChildren(EVT_RIGHT_UP, self.highlightBox, self.OnRightUp)
-     self.setAllChildren(EVT_MOTION, self.highlightBox, self.OnMotion)
- 
-     self.widget.Refresh()
- 
-   def recalcBoundaries(self):
-     x1,y1,x2,y2 = (9999999,9999999,0,0)
- 
-     for widget in self.mainWidget.widgets:
-       tx, ty = widget.GetPositionTuple()
-       tw, th = widget.GetSizeTuple()
-       self.instance.positionMappings[widget] = [tx,ty,tx+tw-1,ty+tw-1,self]
-       if tx < x1:
-         x1 = tx
-       if ty < y1:
-         y1 = ty
-       if tw + tx > x2:
-         x2 = tw + tx
-       if th + ty > y2:
-         y2 = th + ty
- 
-     self.highlightBox.setBoundary(x1-2,y1-2,x2+2,y2+2)
-     for widget in self.mainWidget.widgets:
-        widget.Refresh()
- 
- 
-   def setSelected(self, selected):
-     self.selected = selected
-     self.highlightBox.setSelected(selected)
- 
- 
-   def setAllChildren(self, event, widget, trap):
-     try:
-       event(widget, trap)
-     except:
-       pass
-     for child in widget.GetChildren():
-       self.setAllChildren(event, child, trap)
- 
-   def focusGainedTrap(self, event):
-     self.instance.panel.SetFocus()
-     pass
- #    event.Skip()
- 
-   def focusLostTrap(self, event):
-     event.Skip()
- 
- 
-   def OnLeftDown(self, event):
-     self.mouseStartX, self.mouseStartY = event.GetPositionTuple()
-     self._iMoved = 0
- 
-     if not self.instance._currentSelection.has_key(self):
-       self.instance._currentSelection[self] = 1
-       self.instance._instance.onSetCurrentObject(self.object,__name__)
-       self.setSelected(1)
-       self._alreadySelected = 0
-     else:
-       self._alreadySelected = 1
- 
-     event.Skip()
- 
- 
-   def beginDragDrop(self, event):
- 
-     # Drag and drop TODO: This needs changed to pull all selected widgets
- 
-     object = self.object
- 
-     x,y = event.GetPositionTuple()
- 
-     data = [ { "Type" : "selectedWidgets",
-                "Attributes": {
-                    'startingX': object.x + int(x/self.instance.gridWidth),
-                    'startingY': object.y + int(y/self.instance.gridHeight),
-                    }
-                }]
- #        "name": dname,
- #        "table": object.name,
- #        "database": self.connectionName } }
- #
- #
-     do = wxCustomDataObject(wxCustomDataFormat("GNUeDesVisualElement"))
-     do.SetData(cPickle.dumps(data,1))
- 
- ##    icon = FeedbackBitmap(10,10).icon()
-     dropSource = MoveDropSource(self, self.instance)
-     dropSource.SetData(do)
-     result = dropSource.DoDragDrop(true)
-     event.Skip()
- 
- 
-   def OnLeftUp(self, event):
-     if self._iMoved:
-       self._iMoved = 0
-     elif not event.ShiftDown():
-       # Select only 1 widget
-       for selection in self.instance._currentSelection.keys():
-         selection.setSelected(0)
-       self.instance._currentSelection = {self:1}
-       self.setSelected(1)
-     elif self._alreadySelected:
-       # Remove widget from selection hash
-       del self.instance._currentSelection[self]
-       self.setSelected(0)
- 
-     self._alreadySelected = 0
-     event.Skip()
- 
- 
-   def OnMotion(self, event):
- 
-     if not self._iMoved and event.LeftIsDown():
-       self._iMoved = 1
-       self.beginDragDrop(event)
- 
-     event.Skip()
- 
- 
-   def OnRightDown(self, event):
-     event.Skip()
- 
- 
-   def OnRightUp(self, event):
-     pt = event.GetPositionTuple()
-     self.instance._instance.onSetCurrentObject(self.object, None)
-     wxPyTypeCast(event.GetEventObject(),'wxWindow') \
-        .PopupMenu(self.object._popupMenu, pt)
-     event.Skip()
- 
- 
-   def _endPopupEditor(self, success, value=""):
-     if success:
-       self.object.__dict__[self.__popupAttr] = value
-       self.instance._instance.onModifyObject(self.object,
-             __name__, ((self.__popupAttr, value),))
-       self.widget.SetLabel(value or "<Unset>")
-       if self.object._type == 'GFLabel':
-         width = len(value or 10)
-         self.widget.SetSize((width * self.instance.gridWidth,
-                             self.widget.GetSize().height))
-         self.recalcBoundaries()
-         self.setSelected(self.selected)
- 
- 
-   def OnEditProperties(self, event):
- 
-     if self.object._type in ('GFBox','GFLabel'):
-       # Create a popup text editor for the labels
-       if self.object._type == 'GFBox':
-         self.__popupAttr = 'label'
-         x = self.widget.GetPosition().x + (self.instance.gridWidth/2)
-         width = (self.object.width - 2) * self.instance.gridWidth
-       else:
-         self.__popupAttr = 'text'
-         x = self.widget.GetPosition().x
-         width = self.widget.GetSize().width + self.instance.gridWidth
- 
-       self.instance.clearSelections()
-       if self._popup_editor:
-         self._popup_editor.Destroy()
-       self._popup_editor = PopupEditor(self.instance.workspace,
-           self._endPopupEditor,
-           x + self.instance.panel.GetPosition().x,
-           self.widget.GetPosition().y + self.instance.panel.GetPosition().y,
-           width,
-           self.instance.gridHeight,
-           self.object.__dict__[self.__popupAttr]).SetFocus()
- 
-       self._popup_editor.SetFocus()
- 
-     else:
-       # Signal the Properties dialog
-       self.instance._instance.propertyEditorWindow.Show(1)
-       self.instance._instance.propertyEditorWindow.Raise()
-       self.instance._instance.propertyEditorWindow.SetFocus()
- 
-   #
-   # Resize the current widget.  dx and dy are incremental
-   # resize units. (e.g, (-1,0) means make the widget one
-   # unit smaller than it currently is.
-   #
-   def relativeResize(self, dx, dy):
-     if not (dx or dy):
-       return 0
- 
-     nx = dx * self.instance.gridWidth
-     ny = dy * self.instance.gridHeight
- 
-     if (self.object.width + dx < 0 or self.object.height + dy < 0):
-       return 0
-     else:
-       for widget in self.mainWidget.widgets:
-         x,y = widget.GetSizeTuple()
-         widget.SetSize(wxSize(x + nx,y + ny))
-       changes = []
-       if dx:
-         self.object.width = self.object.width + dx
-         changes.append(['width',self.object.width])
-       if dy:
-         self.object.height = self.object.height + dy
-         changes.append(['height',self.object.height])
-       self.instance._instance.onModifyObject(self.object, __name__, changes)
-       self.recalcBoundaries()
- 
- 
-   #
-   # Move the current widget. dx and dy are increments.
-   # (e.g., (-1,-2) means move the object up one unit
-   # and left two units.
-   #
-   def relativeMove(self, dx, dy):
-     if not (dx or dy):
-       return 0
- 
-     nx = dx * self.instance.gridWidth
-     ny = dy * self.instance.gridHeight
- 
-     if (self.object.x + dx < 0 or self.object.y + dy < 0):
-       return 0
-     else:
-       for widget in self.mainWidget.widgets:
-         x,y = widget.GetPositionTuple()
-         widget.SetPosition(wxPoint(x + nx,y + ny))
-       changes = []
-       if dx:
-         self.object.x = self.object.x + dx
-         changes.append(['x',self.object.x])
-       if dy:
-         self.object.y = self.object.y + dy
-         changes.append(['y',self.object.y])
-       self.instance._instance.onModifyObject(self.object, __name__, changes)
-       self.recalcBoundaries()
- 
-   #
-   # Recursively destroy this widget set
-   #
-   def Destroy(self):
-     self.highlightBox.Destroy()
-     for widget in self.mainWidget.widgets:
-       widget.Destroy()
- 
- #
- #
- #
- class MoveDropSource(wxDropSource):
- 
-   def __init__(self, handler, *args, **parms):
-     self.__handler = handler
-     wxDropSource.__init__(self, *args, **parms)
- 
-   def GiveFeedback(self, effect, scrolling=0):
-     return 0
- 
- 
- #
- #
- #
  ##class FeedbackBitmap:
  ##  def __init__(self, width, height):
  ##
--- 521,526 ----
***************
*** 845,1376 ****
  ###    return self._icon
  ##    return self.bitmap
  
- 
- #
- #
- #
- class WidgetHighlighter:
- 
-   def __init__(self, parent):
-     self.selected = 0
-     self.parent = parent
-     self.x1 = 1
-     self.y1 = 1
-     self.x2 = 2
-     self.y2 = 2
-     self.west = None
-     self.east = None
-     self.north = None
-     self.south = None
-     panelColor = parent.GetBackgroundColour()
-     self.inactiveBorderColor = wxColour(panelColor.Red()-16,
-                  panelColor.Green()-16,
-                  panelColor.Blue()-16)
-     self.activeBorderColor = wxBLUE
- 
-   def createHighlights(self):
-     if self.north:
-       self.Destroy()
-     self.north = wxWindow(self.parent, -1)
-     self.south = wxWindow(self.parent, -1)
-     self.east = wxWindow(self.parent, -1)
-     self.west = wxWindow(self.parent, -1)
-     for object in (self.north,self.south,self.east,self.west):
-       EVT_PAINT(object, self.OnPaint)
-     self.setBoundary(self.x1, self.y1, self.x2, self.y2)
- 
-   def setBoundary(self, x1, y1, x2, y2):
-      self.x1 = x1
-      self.y1 = y1
-      self.x2 = x2
-      self.y2 = y2
- 
-      if self.west:
-        self.west.SetPosition(wxPoint(x1,y1))
-        self.west.SetSize(wxSize(1,y2-y1+1))
-      if self.east:
-        self.east.SetPosition(wxPoint(x2,y1))
-        self.east.SetSize(wxSize(1,y2-y1+1))
-      if self.south:
-        self.south.SetPosition(wxPoint(x1,y2))
-        self.south.SetSize(wxSize(x2-x1+1,1))
-      if self.north:
-        self.north.SetPosition(wxPoint(x1,y1))
-        self.north.SetSize(wxSize(x2-x1+1,1))
- 
-   def GetChildren(self):
-     if self.west:
-       return (self.north, self.south, self.east, self.west)
-     else:
-       return ()
- 
-   def Refresh(self):
-     for object in (self.north,self.south,self.east,self.west):
-       object.Refresh()
- 
-   def Destroy(self):
-     for object in (self.north,self.south,self.east,self.west):
-       if object != None:
-         object.Destroy()
-     self.north = self.south = self.east = self.west = None
- 
- 
-   def setSelected (self, selected):
-     if selected:
-       self.selected = selected
-       self.createHighlights()
-       self.Refresh()
-     else:
-       if self.west:
-         self.west.Destroy()
-       if self.east:
-         self.east.Destroy()
-       if self.north:
-         self.north.Destroy()
-       if self.south:
-         self.south.Destroy()
-       self.west = None
-       self.east = None
-       self.north = None
-       self.south = None
- 
-   def reconfigure(self, event):
-     self.Refresh()
- 
-   def OnPaint(self, event):
-     object = wxPyTypeCast(event.GetEventObject(),'wxWindow')
-     dc = wxPaintDC(object)
-     dc.BeginDrawing()
-     dc.SetBackground(wxBrush(self.parent.GetBackgroundColour(),wxTRANSPARENT))
-     dc.Clear()
-     if self.selected:
-       dc.SetPen(wxPen(self.activeBorderColor))
-     else:
-       dc.SetPen(wxPen(self.inactiveBorderColor))
-     x1,y1 = object.GetSizeTuple()
-     dc.DrawRectangle(0,0,x1,y1)
-     dc.EndDrawing()
- 
-   def OnEraseBackground(self, event):
-     pass
- 
- 
- #
- #
- #
- class GridPane(wxSashWindow):
-   def __init__(self, instance, parent, pos):
-     wxSashWindow.__init__(self, parent, -1, pos=pos, 
style=wxWANTS_CHARS|wxSIMPLE_BORDER)
-     self.__showGrids = 1
-     self.__instance = instance
-     EVT_PAINT(self, self.OnPaint)
- 
-   def OnPaint(self, event):
-     if self.__showGrids:
-       dc = wxPaintDC(self)
-       dc.BeginDrawing()
-       w, h = self.GetSizeTuple()
-       dc.SetPen(wxPen(self.__instance.panelGridColor))
-       for x in range(self.__instance.widgetWidth,w-2, 
self.__instance.widgetWidth):
-         dc.DrawLine(x,0,x,h-1)
- 
-       for y in 
range(self.__instance.widgetHeight,h-2,self.__instance.widgetHeight):
-         dc.DrawLine(0,y,w-1,y)
-       dc.EndDrawing()
-     event.Skip()
- 
- #
- #
- #
- class PropertyBar (wxPanel):
-   def __init__(self, parent):
-     wxPanel.__init__(self, parent, -1, style=wxRAISED_BORDER|wxCLIP_CHILDREN)
-     self.parent = parent
-     self.object = None
-     self.nameLabel = wxStaticText(self, -1, "Name:", pos=wxPoint(4,8))
-     self.nameEditor = wxTextCtrl(self, -1,
-           pos=calcRelPos(self.nameLabel, dx=6, absy=4))
-     self.typeLabel = wxStaticText(self, -1, "Class:",
-           pos=calcRelPos(self.nameEditor, absx=4, dy=8))
-     self.typeEditor = wxTextCtrl(self, -1,
-           pos=calcRelPos(self.nameLabel, self.nameEditor, dx=6, dy=4))
-     self.typeEditor.SetEditable(0)
- 
-     self.xLabel = wxStaticText(self, -1, "x:",
-           pos=calcRelPos(self.nameEditor, dx=10, absy=8))
-     self.xEditor = wxSpinCtrl(self, -1,
-           pos=calcRelPos(self.xLabel, dx=4, absy=6))
-     self.xEditor.SetSize((50, self.xEditor.GetSize().height))
- 
-     self.wLabel = wxStaticText(self, -1, "Width:  ",
-           pos=calcRelPos(self.xEditor, dx=6, absy=8))
-     self.wEditor = wxSpinCtrl(self, -1,
-           pos=calcRelPos(self.wLabel, dx=4, absy=6))
-     self.wEditor.SetSize(self.xEditor.GetSize())
- 
-     self.yLabel = wxStaticText(self, -1, "y:",
-           pos=calcRelPos(self.nameEditor, self.xEditor, dx=10, dy=8))
-     self.yEditor = wxSpinCtrl(self, -1,
-           pos=calcRelPos(self.xLabel, self.xEditor, dx=4, dy=6))
-     self.yEditor.SetSize(self.xEditor.GetSize())
- 
-     self.hLabel = wxStaticText(self, -1, "Height:",
-           pos=calcRelPos(self.xEditor, self.wEditor, dx=6, dy=8))
-     self.hEditor = wxSpinCtrl(self, -1,
-           pos=calcRelPos(self.wLabel, self.wEditor, dx=4, dy=6))
-     self.hEditor.SetSize(self.wEditor.GetSize())
- 
- ##    self.toolpanel = LayoutEditorTools.LayoutEditorTools(self.parent,
- ##          self, -1,
- ##          pos=calcRelPos(self.hEditor,self.hEditor, dx=6, absy=6),
- ##          style=wxSUNKEN_BORDER)
- 
-     self.Fit()
- 
-     EVT_SPINCTRL(self, self.xEditor.GetId(), self.OnXUpdated)
-     EVT_SPINCTRL(self, self.yEditor.GetId(), self.OnYUpdated)
-     EVT_SPINCTRL(self, self.wEditor.GetId(), self.OnWidthUpdated)
-     EVT_SPINCTRL(self, self.hEditor.GetId(), self.OnHeightUpdated)
- 
- 
-   def OnNameUpdated(self, event):
-     self.object.name = self.nameEditor.GetValue()
- #    self.parent._instance.onModifyObject(self.object, __name__,
- 
-   def OnXUpdated(self, event):
-     if hasattr(self.object, 'x'):
-       dx = self.xEditor.GetValue() - self.object.x
-       if dx:
-         self.object._widgetHandler.relativeMove(dx,0)
-     else:
-       self.xEditor.SetValue(0)
- 
-   def OnYUpdated(self, event):
-     if hasattr(self.object, 'y'):
-       dy = self.yEditor.GetValue() - self.object.y
-       if dy:
-         self.object._widgetHandler.relativeMove(0, dy)
-     else:
-       self.yEditor.SetValue(0)
- 
-   def OnWidthUpdated(self, event):
-     if hasattr(self.object, 'width'):
-       dw = self.wEditor.GetValue() - self.object.width
-       if dw:
-         self.object._widgetHandler.relativeResize(dw,0)
-     else:
-       self.wEditor.SetValue(0)
- 
-   def OnHeightUpdated(self, event):
-     if hasattr(self.object, 'height'):
-       dh = self.hEditor.GetValue() - self.object.height
-       if dh:
-         self.object._widgetHandler.relativeResize(0,dh)
-     else:
-       self.hEditor.SetValue(0)
- 
-   def setCurrentObject(self, object):
-     self.object = object
- 
-     self.typeEditor.SetValue(object.getObjectType()[2:])
- 
-     if hasattr(object, 'x'):
-       self.xEditor.SetValue(object.x)
- #      self.xEditor.SetEditable(1)
-     else:
-       self.xEditor.SetValue(0)
- #      self.xEditor.SetEditable(0)
- 
-     if hasattr(object, 'y'):
-       self.yEditor.SetValue(object.y)
- #      self.yEditor.SetEditable(1)
-     else:
-       self.yEditor.SetValue(0)
- #      self.yEditor.SetEditable(0)
- 
-     if hasattr(object, 'width'):
-       self.wEditor.SetValue(object.width)
- #      self.wEditor.SetEditable(1)
-     else:
-       self.wEditor.SetValue(0)
- #      self.wEditor.SetEditable(0)
- 
-     if hasattr(object, 'height'):
-       self.hEditor.SetValue(object.height)
- #      self.hEditor.SetEditable(1)
-     else:
-       self.hEditor.SetValue(0)
- #      self.hEditor.SetEditable(0)
- 
-     if hasattr(object, 'name'):
-       self.nameEditor.SetValue(object.name)
-       self.nameEditor.SetEditable(0)
-     else:
-       self.nameEditor.SetValue(0)
-       self.nameEditor.SetEditable(0)
- 
-   def onModifyObject (self, object, handler, modifications):
-     if object == None:
-       return
-     if object == self.object:
-       for modification in modifications:
-         field, value = modification
-         if field == 'x':
-           self.xEditor.SetValue(value)
-         elif field == 'y':
-           self.yEditor.SetValue(value)
-         elif field == 'width':
-           self.wEditor.SetValue(value)
-         elif field == 'height':
-           self.hEditor.SetValue(value)
-         elif field == 'name':
-           self.nameEditor.SetValue(value)
- 
- 
- def calcRelPos(xsource, ysource=None, absx=None, absy=None, dx=None, dy=None):
-   if ysource == None:
-     ysource = xsource
-   x = xsource.GetPosition().x
-   y = ysource.GetPosition().y
-   w = xsource.GetSize().width
-   h = ysource.GetSize().height
- 
-   if absx != None:
-     x = absx
-   else:
-     x = x + w + dx
- 
-   if absy != None:
-     y = absy
-   else:
-     y = y + h + dy
- 
-   return wxPoint (x,y)
- 
- 
- #
- # Drag and Drop support for our grid
- #
- class DisplayDropTarget(wxPyDropTarget):
- 
-   def __init__(self, editor):
-     wxPyDropTarget.__init__(self)
-     self.editor = editor
- 
-     self.data = wxCustomDataObject(wxCustomDataFormat("GNUeDesVisualElement"))
-     self.SetDataObject(self.data)
- 
-   def OnEnter(self, x, y, d):
-     return d
- 
-   def OnLeave(self):
-     pass
- 
-   def OnDrop(self, x, y):
-     pass
- 
-   def OnDragOver(self, x, y, d):
-     return d
- 
-   # Called when OnDrop returns true.  We need to get the data and
-   # do something with it.
-   def OnData(self, x, y, d):
- 
-     # copy the data from the drag source to our data object
-     if self.GetData():
-       # convert it back to our format
-       data = self.data.GetData()
-       unpickled = cPickle.loads(data)
- 
- 
-       nextY = int(y / self.editor.gridHeight)
- 
-       for params in unpickled:
-         x = int(x / self.editor.gridWidth)
-         y = nextY
- 
-         attributes = params['Attributes']
- 
-         # Entry types require a "block".. find or create one
-         if params['Type'] in ('entry',):
-           try:
-             parent = params['Block']
-           except KeyError:
-             # Find the parent block
- 
-             parent = None
- 
-             if  not attributes.has_key('block') and \
-                 attributes.has_key('datasource'):
- 
-               datasource = string.lower(attributes['datasource'])
- 
-               for child in self.editor.page._children:
-                 if child._type == 'GFBlock' and \
-                   hasattr(child,'datasource') and \
-                   string.lower(child.datasource) == datasource:
-                   parent = child
-                   break
- 
-               if parent is None:
-                 dlg = wxMessageDialog(NULL,
-                   "The current page does not have a block\n"
-                   "corresponding to Data Source %s.\n"
-                   "Create a new block on the current page?" % \
-                        attributes['datasource'],
-                   "No Target Block Found", style=wxYES_NO|wxICON_WARNING)
-                 save = dlg.ShowModal()
-                 dlg.Destroy()
-                 if save == wxID_NO:
-                   return d # TODO: This should actually return a failure
- 
-                 # Create a parent block
-                 parent = Incubator.createObject(
-                             self.editor._instance,
-                             self.editor._instance.rootObject,
-                             'block',
-                             parent=self.editor.page,
-                             attributes={'datasource':datasource})
-             else:
-               for child in self.editor.page._children:
-                 if child._type == 'GFBlock' and \
-                    child.name == attributes['block']:
- 
-                   parent = child
-                   break
- 
- 
-           createLabels = 
string.lower(GConfig.get("CreateLabelsOnDrop","left"))
- 
-           if createLabels != "no":
-             label = params["Label"] + ":"
- 
-             # Figure out the position of the label
-             # If the entry is for a multirow block,
-             # we assume that the label goes above.
-             if createLabels == "left" and\
-                not(hasattr(parent,'rows') and parent.rows > 1 or 0):
-               lx = x - len(label) - 1
-               if lx < 0:
-                 x = len(label) + 1
-                 lx = 0
-               ly = y
-             else:  # "above"
-               nextY += 1
-               lx = x
-               ly = y - 1
- 
-               if ly < 0:
-                 ly = 0
-                 y += 1
- 
-             # Create a label
-             Incubator.createObject(
-                     self.editor._instance,
-                     self.editor._instance.rootObject,
-                     'label',
-                     parent=self.editor.page,
-                     attributes={'x': lx,
-                                 'y': ly,
-                                 'width': len(label),
-                                 'text': label })
-           nextY += 1
- 
-         elif params['Type'] in ('datasource',):
-           parent = self.editor.rootObject
- 
-         elif params['Type'] in ('block',):
-           parent = self.editor.page
-         elif params['Type'] in ('selectedWidgets',):
-           xshift = x - int(attributes['startingX'])
-           yshift = y - int(attributes['startingY'])
-           for uiwidget in self.editor._currentSelection.keys():
-             uiwidget.relativeMove(xshift,yshift)
-         else:
-           parent = self.editor.page
-           nextY += 1
- 
-         attributes['x'] = x
-         attributes['y'] = y
- 
- 
-         #
-         # Create our new object
-         #
-         if not params['Type'] in ('selectedWidgets',):
-           Incubator.createObject(
-             self.editor._instance,
-             self.editor._instance.rootObject,
-             params['Type'],
-             parent=parent,
-             attributes=attributes)
- 
- 
-     return d  # what is returned signals the source what to do
-               # with the original data (move, copy, etc.)  In this
-               # case we just return the suggested value given to us.
- 
- 
- #
- # Our text handler
- #
- # When we are completed, we will call a method passed to us
- # (via complete) along with a success code and the final result
- # (if success = 1)
- #
- class PopupEditor(wxTextCtrl):
-   def __init__(self, panel, complete, x, y, width, height, value):
-     wxTextCtrl.__init__(self, panel, -1, pos=wxPoint(0,0),
-          size=wxSize(10,10),
-          style=wxTE_PROCESS_TAB|wxTE_PROCESS_ENTER|wxSIMPLE_BORDER)
-     self.SetBackgroundColour(color)
-     self.__complete = None
-     self.Show(0)
- 
-     self.SetDimensions(x,y,width, height)
-     self.__complete = complete
-     self.SetValue(value)
-     self.Show(1)
-     self.Raise()
-     self.Enable(1)
-     EVT_CHAR(self, self.OnChar)
-     EVT_KILL_FOCUS(self, self.OnFocusOut)
-     self.SetFocus()
- 
- 
-   def done(self, success):
-     if self.__complete:
-       self.Show(0)
- 
-       if success:
-         self.__complete(1, self.GetValue())
-       else:
-         self.__complete(0)
- 
-       self.__complete = None
- 
- 
-   def OnChar(self, event):
-     if event.GetKeyCode() in (WXK_RETURN, WXK_TAB):
-       self.done(1)
- 
-     elif event.GetKeyCode() == WXK_ESCAPE:
-       self.done(0)
-     else:
-       event.Skip()
- 
-   def OnFocusOut(self, event):
-       self.done(1)
- 
- 
- 
- #
- # Convenience function for inplace sorting
- #
- def order(*p):
-   rv = list(p) # Convert the tuple to a list
-   rv.sort()
-   return rv
  
  
  modeEntryMap = {
--- 558,563 ----



reply via email to

[Prev in Thread] Current Thread [Next in Thread]