commit-gnue
[Top][All Lists]
Advanced

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

gnue/designer/src/forms LayoutEditor.py


From: Jason Cater
Subject: gnue/designer/src/forms LayoutEditor.py
Date: Fri, 25 Jan 2002 22:29:31 -0500

CVSROOT:        /home/cvs
Module name:    gnue
Changes by:     Jason Cater <address@hidden>    02/01/25 22:29:30

Modified files:
        designer/src/forms: LayoutEditor.py 

Log message:
        all kinds of nifty new mouse functions like cross-hair selection of 
widgets, cross-hair width/height of new widgets, etc

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/designer/src/forms/LayoutEditor.py.diff?cvsroot=OldCVS&tr1=1.7&tr2=1.8&r1=text&r2=text

Patches:
Index: gnue/designer/src/forms/LayoutEditor.py
diff -c gnue/designer/src/forms/LayoutEditor.py:1.7 
gnue/designer/src/forms/LayoutEditor.py:1.8
*** gnue/designer/src/forms/LayoutEditor.py:1.7 Fri Jan 25 18:46:17 2002
--- gnue/designer/src/forms/LayoutEditor.py     Fri Jan 25 22:29:30 2002
***************
*** 66,71 ****
--- 66,73 ----
      self.widgetList = []
  
      self.mode = 'move'
+     self.__x = 0
+     self.__y = 0
  
      instance.rootObject.walk (self.inventoryObject)
  
***************
*** 259,269 ****
        page.walk(self.__drawItem)
  
  
- 
      EVT_CHAR(self.panel, self.keyTrap)
      EVT_LEFT_UP(self.panel, self.OnLeftUp)
      EVT_RIGHT_UP(self.panel, self.OnRightUp)
  
    def __drawItem(self, object):
      if self.widgets.has_key(object.getObjectType()) and \
         (not hasattr(object, 'hidden') or not object.hidden):
--- 261,273 ----
        page.walk(self.__drawItem)
  
  
      EVT_CHAR(self.panel, self.keyTrap)
+     EVT_LEFT_DOWN(self.panel, self.OnLeftDown)
+     EVT_MOTION(self.panel, self.OnMotion)
      EVT_LEFT_UP(self.panel, self.OnLeftUp)
      EVT_RIGHT_UP(self.panel, self.OnRightUp)
  
+ 
    def __drawItem(self, object):
      if self.widgets.has_key(object.getObjectType()) and \
         (not hasattr(object, 'hidden') or not object.hidden):
***************
*** 300,374 ****
      self._instance.onSetCurrentObject(b, None)
  
  
!   def OnLeftUp(self, event):
  
!      for selection in self._currentSelection.keys():
!        selection.setSelected(0)
!      self._currentSelection = {}
  
!      if self.mode == 'move':
!        event.Skip()
!        return
  
!      x, y = event.GetPositionTuple()
  
!      x = int(x / self.gridWidth)
!      y = int(y / self.gridHeight)
  
-      mode = self.mode
-      self.toolbar.resetTool(mode)
-      self.mode = 'move'
  
  
-      type = None
-      attributes = {'x':x,'y':y}
-      parent = self.block
-      checkblock = 1
  
!      if mode in ('box','button','label'):
!        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)
  
!        self._currentSelection[object._widgetHandler] = 1
!        object._widgetHandler.setSelected(1)
  
!      event.Skip()
  
  
  
-   def OnRightUp(self, event):
  
      self.toolbar.resetTool(self.mode)
      self.mode = 'move'
  
--- 304,451 ----
      self._instance.onSetCurrentObject(b, None)
  
  
!   def OnLeftDown(self, event):
!     # Save starting coordinates for cross-selection box
!     x, y = event.GetPositionTuple()
! 
  
!     self.panel.SetCursor(wxCROSS_CURSOR)
  
!     x = int(x / self.gridWidth) * self.gridWidth
!     y = int(y / self.gridHeight) * self.gridHeight
  
!     self.__brush = wxBrush(wxWHITE, style=wxTRANSPARENT)
  
!     self.__x = x
!     self.__y = y
!     self.__ox = None
!     self.__oy = None
!     event.Skip()
  
  
+   # Used by the dragging routines to draw a selection box
+   def xorBox(self, x1, y1, x2, y2, x3=None, y3=None):
+     dc = wxClientDC(self.panel)
+     dc.SetBrush(self.__brush)
+     dc.SetPen(wxGREY_PEN)
+     dc.SetLogicalFunction(wxXOR)
+ 
+     if x3 != None:
+       dc.DrawRectangle(x1,y1,x3-x1,y3-y1)
+ 
+     dc.DrawRectangle(x1,y1,x2-x1,y2-y1)
+ 
+ 
+   def OnMotion(self, event):
+     # draw cross-selection box
+     if event.LeftIsDown():
+       x, y = event.GetPositionTuple()
+       self.xorBox(self.__x, self.__y, x, y, self.__ox, self.__oy)
+ 
+       self.__ox = x
+       self.__oy = y
+ 
+     event.Skip()
+ 
+ 
+   def OnLeftUp(self, event):
+ 
+     for selection in self._currentSelection.keys():
+       selection.setSelected(0)
+ 
+     self._currentSelection = {}
+ 
+     if self.__ox != None:
+       self.xorBox(self.__x, self.__y, self.__ox, self.__oy)
+       self.__ox = None
+       self.__oy = None
+ 
+     x, y = event.GetPositionTuple()
+ 
+     # Set x1,y1 to be smaller coordinates, and x2,y2 to be larger
+     x1, x2 = order(int(self.__x / self.gridWidth), int(x / self.gridWidth))
+     y1, y2 = order(int(self.__y / self.gridHeight),int(y / self.gridHeight))
  
  
!     self.panel.SetCursor(wxSTANDARD_CURSOR)
  
!     areaSelected = (x1 <> x2 or y1 <> y2)
  
!     if self.mode == 'move':
!       if areaSelected:
!         # We are selecting an area
!         self.page.walk(self.selectWidgetInArea, x1, y1, x2, y2)
  
+     else:
  
!        # 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
! 
!        if areaSelected:
!          attributes['width']  = x2 - x1 + 1
!          attributes['height'] = y2 - y1 + 1
! 
!        if mode in ('box','button','label'):
!          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)
  
!          self._currentSelection[object._widgetHandler] = 1
!          object._widgetHandler.setSelected(1)
  
!     event.Skip()
  
  
+   def selectWidgetInArea(self, object, x1, y1, x2, y2):
+     try:
+       if x1 <= object.x <= x2 and \
+          y1 <= object.y <= y2:
+         self._currentSelection[object._widgetHandler] = 1
+         object._widgetHandler.setSelected(1)
+     except AttributeError:
+       # Not all child objects have coordinates (x,y)
+       pass
  
  
+   def OnRightUp(self, event):
      self.toolbar.resetTool(self.mode)
      self.mode = 'move'
  
***************
*** 510,540 ****
  
  
    def OnLeftDown(self, event):
-     print "OnLeftDown"
      self.mouseStartX, self.mouseStartY = event.GetPositionTuple()
      self._iMoved = 0
  
      if not self.instance._currentSelection.has_key(self):
-       self._alreadySelected = 1
        self.instance._currentSelection[self] = 1
        self.instance._instance.onSetCurrentObject(self.object,__name__)
        self.setSelected(1)
  
      event.Skip()
  
  
    def beginDragDrop(self, event):
  
-     print "beginDragDrop"
- 
      # Drag and drop TODO: This needs changed to pull all selected widgets
  
      object = self.object
  
      data = [ { "Type" : "selectedWidgets",
!                "Attributes": {'startingX': object.x,
!                               'startingY': object.y,
!                               }
                 }]
  #        "name": dname,
  #        "table": object.name,
--- 587,619 ----
  
  
    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,
***************
*** 544,560 ****
      do = wxCustomDataObject(wxCustomDataFormat("GNUeDesVisualElement"))
      do.SetData(cPickle.dumps(data,1))
  
! #    icon = FeedbackBitmap(10,10).icon()
!     dropSource = MoveDropSource(self, self.instance) #, icon)
      dropSource.SetData(do)
      result = dropSource.DoDragDrop(true)
      event.Skip()
-     print "EndDragDrop"
- 
  
  
    def OnLeftUp(self, event):
-     print "OnLeftUp"
      if self._iMoved:
        self._iMoved = 0
      elif not event.ShiftDown():
--- 623,636 ----
      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():
***************
*** 672,720 ****
      wxDropSource.__init__(self, *args, **parms)
  
    def GiveFeedback(self, effect, scrolling=0):
- ##    print "Giving feedback"
      return 0
  
  
  #
  #
  #
! class FeedbackBitmap:
!   def __init__(self, width, height):
! 
!     if width < 2: width = 2
!     if height < 2: height = 2
! 
!     topbot = ". " * int(width/2) + divmod(width,2)[1] * '.'
!     mid = '".' + " " * width -2 + '.",\n'
! 
!     xpm = '/* XPM */\n' \
!         + 'static char * text1_xpm[] = {' \
!         + '"%s %s 2 1",' \
!         + '"       g None",' \
!         + '".      g #000000",' % (width, height) \
!         + topbot + "\n"
! 
!     xpm += mid * (height - 2) + topbot + "};\n"
! 
!     print xpm
! 
!     self.bitmap=wxNullIcon
!     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
  
  
  #
--- 748,795 ----
      wxDropSource.__init__(self, *args, **parms)
  
    def GiveFeedback(self, effect, scrolling=0):
      return 0
  
  
  #
  #
  #
! ##class FeedbackBitmap:
! ##  def __init__(self, width, height):
! ##
! ##    if width < 2: width = 2
! ##    if height < 2: height = 2
! ##
! ###    topbot = '"' + ". " * int(width/2) + divmod(width,2)[1] * '.' + '"'
! ##    topbot = '"' + ".." * int(width/2) + divmod(width,2)[1] * '.' + '"'
! ##    mid = '".' + " " * (width - 2) + '.",\n'
! ##
! ##    xpm = '/* XPM */\n' \
! ##        + '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
  
  
  #
***************
*** 1165,1171 ****
          attributes['y'] = y
  
  
- 
          #
          # Create our new object
          #
--- 1240,1245 ----
***************
*** 1181,1186 ****
--- 1255,1269 ----
      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.
+ 
+ 
+ #
+ # Convenience function for inplace sorting
+ #
+ def order(*p):
+   rv = list(p) # Convert the tuple to a list
+   rv.sort()
+   return rv
  
  
  modeEntryMap = {



reply via email to

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