main logo
Subject: [dabo-dev] dabodesigner Commit 2
Author: noreply (at) paulmcnett .D.O.T com
Posted: 2004/03/31 19:19:12
 
View Entire Thread
New Search


dabodesigner Commit
Revision 2
Date: 2004-03-31 16:19:12 -0800 (Wed, 31 Mar 2004)
Author: ed

Log:
First pass at creating a design surface. So far, this much is working:

- instantiation of 4 types of controls
- selection/deselection of controls, with the proper drawing of selection handles
- dragging of controls to reposition
- definition of some intial internal properties to be set for each control type
- display of dragging rectangle for *some* controls

There are problems with some of these controls responding to some mouse events. These will have to be worked out in the future.

This is the last version that will be using the 2.4 version of wxPython. All further work will be using 2.5 as the development base.


Changed:
A trunk/dDesignerMixin.py
A trunk/daboDesigner.py
A trunk/handle.png

Diff:
Added: trunk/dDesignerMixin.py
===================================================================
--- trunk/dDesignerMixin.py 2004-03-31 23:28:01 UTC (rev 1)
+++ trunk/dDesignerMixin.py 2004-04-01 00:19:12 UTC (rev 2)
@@ -0,0 +1,152 @@
+import wx
+
+class dDesignerMixin:
+ """
+ The purpose of this mixin class is to add the features to the native
+ controls so that they will work in the dabo form design surface.
+ """
+
+ stdProps = {
+ "wxButton": {
+ "name" : "",
+ "label" : "",
+ "default": False
+ },
+ "wxTextCtl" : {
+ "name" : "",
+ "text": "",
+ "selectOnEntry" : True,
+ "readOnly" : False
+ },
+ "wxCheckBox" : {
+ "name" : "",
+ "label" : "",
+ "checked" : False,
+ "alignRight" : False
+ },
+ "wxListBox" : {
+ "name" : "",
+ "selectMultiple" : False,
+ "sorted" : False
+ }
+ }
+
+
+ def __init__(self, parent, name="", *args, **kwargs):
+ self._props = {"base": self.superControl.__name__}
+ self.parent = parent
+ self.dragging = False
+ self.lastPos = self.GetPosition()
+ wx.EVT_LEFT_DOWN(self, self.onMouseDown)
+ wx.EVT_LEFT_UP(self, self.onMouseUp)
+ wx.EVT_MOTION(self, self.onMouseDrag)
+
+ # Add in the base properties
+ baseName = self._props["base"]
+ if self.stdProps.has_key(baseName):
+ std = self.stdProps[baseName]
+ for prop, defa in std.items():
+ self._props[prop] = defa
+
+ # Try to set any initialized props
+ self._props["name"] = name
+ try:
+ lab = self.GetLabel()
+ if lab:
+ self._props["label"] = lab
+ except: pass
+
+ # Initialize the draw client
+ self.dc = wx.ClientDC(self.parent)
+ self.dc.SetPen(wx.Pen("black", 1, wx.DOT))
+ self.dc.SetBrush(wx.TRANSPARENT_BRUSH)
+ self.dc.SetLogicalFunction(wx.INVERT)
+
+
+
+
+ def setName(self, nm):
+ self.name = nm
+ self._props["name"] = nm
+
+ def foo(self, evt):
+ print " FOO! "
+
+
+ def onMouseDown(self, evt):
+ pos = wx.GetMousePosition()
+ self.startPos = self.parent.ScreenToClient(pos)
+ self.xOffset, self.yOffset = self.ScreenToClient(pos)
+ self.dragging = True
+ self.parent.hideAllHandles()
+
+# drop = wx.DropSource(self)
+# data = wx.TextDataObject("doh")
+# drop.SetData(data)
+# drop.DoDragDrop()
+
+# evt.Skip()
+
+ def onMouseUp(self, evt):
+ if self.dragging:
+ pos = wx.GetMousePosition()
+ gpx, gpy = self.parent.ScreenToClient(pos)
+ newpos = ( (gpx-self.xOffset), (gpy-self.yOffset) )
+ self.Move( newpos )
+ self.dragging = False
+ self.drawOutline(self.lastPos)
+ self.parent.setSelectedControl(self)
+
+
+ def onMouseDrag(self, evt):
+ if not evt.Dragging():
+ return
+ # Erase the old outline
+ self.drawOutline(self.lastPos)
+ pos = wx.GetMousePosition()
+ gpx, gpy = self.parent.ScreenToClient(pos)
+ newpos = ( (gpx-self.xOffset), (gpy-self.yOffset) )
+ self.drawOutline( newpos )
+
+
+ def drawOutline(self, pos):
+ """ Used to display the current position of the control while
+ being dragged.
+ """
+ position = [pos[0], pos[1]]
+# position[0] = position[0] - self.xOffset
+# position[1] = position[1] - self.yOffset
+ sz = self.GetSize()
+ self.dc.DrawRectangle(position[0], position[1], sz[0], sz[1])
+ self.lastPos = position
+
+
+
+
+
+
+
+class dDesButton(wx.Button, dDesignerMixin):
+ def __init__(self, parent, ID, label, name="dDesButton",
+ pos=wx.DefaultPosition): #, size=wx.DefaultSize):
+ wx.Button.__init__(self, parent, ID, label, pos=pos) ###, size=size, name=name)
+
+# def __init__(self, parent, id, label, pos=wx.DefaultPosition,
+# size=wx.DefaultSize, style=0,
+# validator=wx.DefaultValidator, name='button'):
+
+ dDesignerMixin.__init__(self, name)
+
+
+class dDesTextBox(wx.TextCtrl, dDesignerMixin):
+ def __init__(self, parent, id, pos=wx.DefaultPosition, name="dDesTextBox"):
+ wx.TextCtrl.__init__(self, parent, id, pos=pos)
+ dDesignerMixin.__init__(self, name)
+
+
+
+
+
+
+if __name__ == "__main__":
+ pass
\ No newline at end of file


Property changes on: trunk/dDesignerMixin.py
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:eol-style
+ native

Added: trunk/daboDesigner.py
===================================================================
--- trunk/daboDesigner.py 2004-03-31 23:28:01 UTC (rev 1)
+++ trunk/daboDesigner.py 2004-04-01 00:19:12 UTC (rev 2)
@@ -0,0 +1,176 @@
+import wx
+from dabo import *
+from dabo.ui import *
+from dDesignerMixin import *
+
+
+class AddDesignFrame(wx.Frame):
+ def __init__(self, parent, ID, title, pos=wx.DefaultPosition,
+ size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE):
+ wx.Frame.__init__(self, parent, ID, title, pos, size, style)
+
+ self.panel = AddDesignPanel(self, -1)
+ self.panel.setup()
+
+ def onClose(self, event):
+ self.Close()
+
+
+
+class AddDesignPanel(wx.Panel):
+ def setup(self):
+ self.custControls = []
+ self.ctlTypes = ["None", "Button", "TextBox", "Check Box", "List Box"]
+ self.opgCtrl = wx.RadioBox(self, -1, "Control Type", wx.Point(120,5),
+ wx.DefaultSize, self.ctlTypes )
+ wx.EVT_LEFT_DOWN(self, self.onLeftDown)
+ wx.EVT_LEFT_UP(self, self.onLeftUp)
+ wx.EVT_MOTION(self, self.onMouseDrag)
+ saveId = wx.NewId()
+ self.saveBtn = wx.Button(self, saveId, "Save", wx.Point(5,5))
+ wx.EVT_BUTTON(self, saveId, self.onSave)
+
+ # Need to store references to handles along with the ID of the
+ # control they are enclosing
+ self.handles = {}
+ # Name of each handle in a set. The names are abbreviations for
+ # "Top Left", "Top Middle", etc.
+ self.handleNames = ("TL", "TM", "TR", "ML", "MR", "BL", "BM", "BR")
+ # Create the bitmap for the handles
+ img = wx.ImageFromStream(open("handle.png"))
+ self.handleBmp = wx.BitmapFromImage(img)
+
+ def createHandles(self, ctl):
+ handleSet = {}
+ for nm in self.handleNames:
+ h = wx.StaticBitmap(self, -1, self.handleBmp, name=nm )
+ h.Show(False)
+ handleSet[nm] = h
+ self.handles[ctl.GetId()] = h
+ return handleSet
+
+ def onSave(self, evt):
+ print "- "*10, " Controls ", "- "*10
+ for ctl in self.custControls:
+ print ctl._props, ctl.GetPosition(), ctl.GetSize()
+ #print ctl.__dict__
+
+
+# def onMouseDrag(self, evt):
+# evt.Skip()
+#
+#
+ def getControlClass(self, base):
+ class controlMix(base, dDesignerMixin):
+ superControl = base
+ superMixin = dDesignerMixin
+ def __init__(self, *args, **kwargs):
+ if hasattr(base, "__init__"):
+ apply(base.__init__,(self,) + args, kwargs)
+ parent = args[0]
+ dDesignerMixin.__init__(self, parent, **kwargs)
+ if base.__name__ in ("wxButton", ):
+ wx.EVT_BUTTON(self, self.GetId(), self.onMouseUp)
+ ctlName = base.__name__.replace("wx", "") + str(len(self.custControls)+1)
+ return controlMix, ctlName
+
+
+
+ def onLeftDown(self, evt): evt.Skip()
+
+ def onLeftUp(self, evt):
+ pnt = wx.Point(evt.m_x, evt.m_y)
+ ctlType = self.opgCtrl.GetSelection()
+ ctlId = wx.NewId()
+ ctl = None
+ if ctlType == 1:
+ # Button
+ cls, nm = self.getControlClass(wx.Button)
+ ctl = cls(self, ctlId, "Button", pos=pnt, name=nm)
+ #ctl = wx.Button(self, ctlId, "Add", pos=pnt)
+ elif ctlType == 2:
+ # Textbox
+ cls, nm = self.getControlClass(wx.TextCtrl)
+ ctl = cls(self, ctlId, pos=pnt, name=nm)
+ #ctl = dTextBox(self, ctlId, pos=pnt)
+ elif ctlType == 3:
+ # check box
+ cls, nm = self.getControlClass(wx.CheckBox)
+ ctl = cls(self, ctlId, "Check", pos=pnt, name=nm)
+ elif ctlType == 4:
+ # list box
+ cls, nm = self.getControlClass(wx.ListBox)
+ ctl = cls(self, ctlId, pos=pnt, size=(50,100), name=nm)
+
+ if ctl:
+ self.custControls.append(ctl)
+ self.hideAllHandles()
+ self.setSelectedControl(ctl)
+ else:
+ self.hideAllHandles()
+
+
+ def hideAllHandles(self):
+ ks = self.handles.keys()
+ for key in ks:
+ self.hideHandles(ID=key)
+
+ def hideHandles(self, ctl=None, ID=None):
+ if ID is None:
+ ID = ctl.GetId()
+
+ if self.handles.has_key(ID):
+ hnd = self.handles[ID]
+ for nm,h in hnd.items():
+ h.Destroy()
+ del self.handles[ID]
+
+
+ def setSelectedControl(self, ctl):
+ left, top = ctl.GetPosition()
+ wid, ht = ctl.GetSize()
+
+ hnds = self.createHandles(ctl)
+
+ handleW, handleH = hnds["TL"].GetSize()
+ handleMid = int(handleH /2)
+ hnds["TL"].SetPosition(wx.Point(left-handleW, top-handleH))
+ hnds["TM"].SetPosition(wx.Point( (left+(wid/2)-handleMid),
+ top-handleH) )
+ hnds["TR"].SetPosition(wx.Point(left+wid, top-handleH))
+
+ hnds["ML"].SetPosition(wx.Point(left-handleW, top+(ht/2)-handleMid))
+ hnds["MR"].SetPosition(wx.Point(left+wid, top+(ht/2)-handleMid))
+
+ hnds["BL"].SetPosition(wx.Point(left-handleW, top+ht))
+ hnds["BM"].SetPosition(wx.Point( (left+(wid/2)-handleMid),
+ top+ht) )
+ hnds["BR"].SetPosition(wx.Point(left+wid, top+ht))
+
+ for hnd in hnds.values():
+ hnd.Raise()
+ hnd.Show(True)
+
+ self.handles[ctl.GetId()] = hnds
+
+
+ def onCtlLeftDown(self, evt):
+ ctl = evt.GetEventObject()
+ if ctl:
+ #self.setSelectedControl(ctl)
+ self.GetParent().remove(self)
+ del self
+
+
+
+
+
+
+
+if __name__ == "__main__":
+ app = wx.PySimpleApp()
+
+ w = AddDesignFrame(None, -1, "Dabo Designer", size=(550,400) )
+ w.Show(True)
+
+ app.MainLoop()
\ No newline at end of file


Property changes on: trunk/daboDesigner.py
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:eol-style
+ native

Added: trunk/handle.png
===================================================================
(Binary files differ)


Property changes on: trunk/handle.png
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ application/octet-stream



 
©2004 noreply AT paulmcnett DO.T com
<-- Prior Message New Search Next Message -->