main logo
Subject: [dabo-dev] dabo Commit 683
Author: noreply .at. paulmcnett D.O.T com
Posted: 2004/12/30 14:03:51
 
View Entire Thread
New Search


dabo Commit
Revision 683
Date: 2004-12-30 11:03:50 -0800 (Thu, 30 Dec 2004)
Author: ed

Log:
Added constants so that we can check for dialog return values without having to use wx constants.

Fixed some item selection code in dListBox.

Got dDialog to work well, and added a subclass named dOkCancelDialog. This subclass automatically adds OK and Cancel buttons, and return the Dabo constants DLG_OK and DLG_CANCEL, respectively. Also added dFieldDialog, which is a wrapper around the wx.FileDialog.

Updated test.py to work with Dialogs instead of just Frames.



Changed:
U trunk/dConstants.py
U trunk/ui/uiwx/__init__.py
U trunk/ui/uiwx/dDialog.py
A trunk/ui/uiwx/dFileDialog.py
U trunk/ui/uiwx/dListBox.py
U trunk/ui/uiwx/test.py

Diff:
Modified: trunk/dConstants.py
===================================================================
--- trunk/dConstants.py 2004-12-29 02:34:51 UTC (rev 682)
+++ trunk/dConstants.py 2004-12-30 19:03:50 UTC (rev 683)
@@ -24,3 +24,6 @@
CURSOR_MEMENTO = "dabo-memento"
CURSOR_NEWFLAG = "dabo-newrec"
CURSOR_TMPKEY_FIELD = "dabo-tmpKeyField"
+
+DLG_OK = 0
+DLG_CANCEL = -1

Modified: trunk/ui/uiwx/__init__.py
===================================================================
--- trunk/ui/uiwx/__init__.py 2004-12-29 02:34:51 UTC (rev 682)
+++ trunk/ui/uiwx/__init__.py 2004-12-30 19:03:50 UTC (rev 683)
@@ -35,7 +35,9 @@
from dDateTextBox import dDateTextBox
from dDropdownList import dDropdownList
from dDialog import dDialog
+from dDialog import dOkCancelDialog
from dEditBox import dEditBox
+from dFileDialog import dFileDialog
from dForm import dForm
from dFormDataNav import dFormDataNav
from dFormMain import dFormMain

Modified: trunk/ui/uiwx/dDialog.py
===================================================================
--- trunk/ui/uiwx/dDialog.py 2004-12-29 02:34:51 UTC (rev 682)
+++ trunk/ui/uiwx/dDialog.py 2004-12-30 19:03:50 UTC (rev 683)
@@ -1,15 +1,83 @@
import wx
-import dSizer, dFormMixin
+import dabo
+#dabo.ui.loadUI("wx")
+import dabo.dEvents as dEvents
+import dabo.dConstants as k

-class dDialog(wx.Dialog, dFormMixin.dFormMixin):
+class dDialog(wx.Dialog):
_IsContainer = True

def __init__(self, parent=None, properties=None, *args, **kwargs):
self._baseClass = dDialog
- preClass = wx.PreDialog
+ self.BaseClass = dDialog
+ super(dDialog,self).__init__(parent=parent, style=wx.DEFAULT_DIALOG_STYLE)
+ self.Centre()
+ self._modal = True
+ self.Sizer = dabo.ui.dSizer("vertical")
+
+ def show(self):
+ if self._modal:
+ return self.ShowModal()
+ else:
+ return self.Show(True)
+
+ def _getCaption(self):
+ return self.GetTitle()
+ def _setCaption(self, val):
+ self.SetTitle(val)
+ def _getModal(self):
+ return self._modal
+ def _setModal(self, val):
+ self._modal = val
+
+ Caption = property(_getCaption, _setCaption, None,
+ "The text that appears in the dialog's title bar (str)" )
+ Modal = property(_getModal, _setModal, None,
+ "Determines if the dialog is shown modal (default) or modeless. (bool)")
+
+
+
+class dOkCancelDialog(dDialog):
+ def __init__(self, parent=None, properties=None, *args, **kwargs):
+ self._baseClass = dOkCancelDialog
+ self.BaseClass = dOkCancelDialog
+ super(dOkCancelDialog, self).__init__(parent=parent, properties=properties)

- kwargs["style"] = wx.DEFAULT_DIALOG_STYLE
- dFormMixin.dFormMixin.__init__(self, preClass, parent, properties, *args, **kwargs)
+ # Hook method, so that we add the buttons last
+ self.addControls()
+
+ hs = dabo.ui.dSizer("H")
+ self.btnOK = dabo.ui.dCommandButton(self, Caption="OK")
+ hs.append(self.btnOK, 0, "expand")
+ self.btnOK.bindEvent(dEvents.Hit, self.OnOK)
+ hs.append( (16, 1) )

- self.Sizer = dSizer.dSizer("vertical")
+ self.btnCancel = dabo.ui.dCommandButton(self, Caption="Cancel")
+ self.btnCancel.bindEvent(dEvents.Hit, self.OnCancel)
+ hs.append(self.btnCancel, 0, "expand")

+ self.Sizer.append(hs, 0, "expand", alignment=("bottom", "middle"), border=10)
+
+ self.Layout()
+ w, h = self.GetSize()
+ self.Sizer.SetDimension(0, 0, w, h)
+ self.Layout()
+
+ def addControls(self):
+ """Use this method to add controls to the dialog. The OK/Cancel
+ buttons will be added after this method runs, so that they appear
+ at the bottom of the dialog
+ """
+ pass
+
+ def OnOK(self, evt):
+ self.EndModal(k.DLG_OK)
+ def OnCancel(self, evt):
+ self.EndModal(k.DLG_CANCEL)
+
+
+
+if __name__ == "__main__":
+ import test
+ test.Test().runTest(dDialog)
+ test.Test().runTest(dOkCancelDialog)

Added: trunk/ui/uiwx/dFileDialog.py
===================================================================
--- trunk/ui/uiwx/dFileDialog.py 2004-12-29 02:34:51 UTC (rev 682)
+++ trunk/ui/uiwx/dFileDialog.py 2004-12-30 19:03:50 UTC (rev 683)
@@ -0,0 +1,64 @@
+import wx
+
+class dFileDialog(wx.FileDialog):
+ _IsContainer = False
+
+ def __init__(self, parent=None, message="Choose a file", defaultDir="",
+ defaultFile="", wildcard="*.*", style=wx.OPEN):
+ self._baseClass = dFileDialog
+ super(dFileDialog, self).__init__(parent=parent, message=message,
+ defaultDir=defaultDir, defaultFile=defaultFile,
+ wildcard=wildcard, style=style)
+ self._dir = self._fname = self._msg = self._path = self._wildcard = ""
+
+
+ def show(self):
+ res = self.ShowModal()
+ if res == wx.ID_OK:
+ self._dir = self.GetDirectory()
+ self._fname = self.GetFilename()
+ self._path = self.GetPath()
+ else:
+ self._dir = self._fname = self._path = ""
+
+
+ def _getDir(self):
+ return self._dir
+ def _setDir(self, dir):
+ self.SetDirectory(dir)
+
+ def _getFileName(self):
+ return self._fname
+ def _setFileName(self, fn):
+ self.SetFilename(fn)
+
+ def _getMessage(self):
+ return self._msg
+ def _setMessage(self, msg):
+ self.SetMessage(msg)
+
+ def _getPath(self):
+ return self._path
+ def _setPath(self, pth):
+ self.SetPath(pth)
+
+ def _getWildcard(self):
+ return self._wildcard
+ def _setWildcard(self, txt):
+ self.SetWildcard(txt)
+
+ Directory = property(_getDir, _setDir, None,
+ "The directory of the selected file. (str)")
+
+ FileName = property(_getFileName, _setFileName, None,
+ "The name of the selected file. (str)")
+
+ Message = property(_getMessage, _setMessage, None,
+ "The prompt displayed to the user. (str)")
+
+ Path = property(_getPath, _setPath, None,
+ "The full path of the selected file. (str)")
+
+ Wildcard = property(_getWildcard, _setWildcard, None,
+ "The wildcard that will limit the files displayed in the dialog. (str)")
+


Property changes on: trunk/ui/uiwx/dFileDialog.py
___________________________________________________________________
Name: svn:eol-style
+ native

Modified: trunk/ui/uiwx/dListBox.py
===================================================================
--- trunk/ui/uiwx/dListBox.py 2004-12-29 02:34:51 UTC (rev 682)
+++ trunk/ui/uiwx/dListBox.py 2004-12-30 19:03:50 UTC (rev 683)
@@ -21,7 +21,12 @@
def _initEvents(self):
super(dListBox, self)._initEvents()
self.Bind(wx.EVT_LISTBOX, self._onWxHit)
-
+
+
+ def clearSelections(self):
+ for elem in self.GetSelections():
+ self.SetSelection(elem, False)
+

# Property get/set/del methods follow. Scroll to bottom to see the property
# definitions themselves.
@@ -38,11 +43,12 @@
self._choices = list(choices)
self.AppendItems(self._choices)

- # Try to get back to the same row:
- try:
- self.Value = oldVal
- except ValueError:
- self.PositionValue = 0
+ if oldVal is not None:
+ # Try to get back to the same row:
+ try:
+ self.Value = oldVal
+ except ValueError:
+ self.PositionValue = 0

def _getKeys(self):
try:
@@ -93,7 +99,7 @@
value = (value,)

# Clear all current selections:
- self.SetSelection(-1)
+ self.clearSelections()

# Select items that match indices in value:
for key in value:
@@ -131,7 +137,7 @@
value = (value,)

# Clear all current selections:
- self.SetSelection(-1)
+ self.clearSelections()

# Select items that match indices in value:
for index in value:
@@ -167,7 +173,7 @@
value = (value,)

# Clear all current selections:
- self.SetSelection(-1)
+ self.clearSelections()

# Select items that match the string tuple:
for string in value:

Modified: trunk/ui/uiwx/test.py
===================================================================
--- trunk/ui/uiwx/test.py 2004-12-29 02:34:51 UTC (rev 682)
+++ trunk/ui/uiwx/test.py 2004-12-30 19:03:50 UTC (rev 683)
@@ -25,10 +25,12 @@
def runTest(self, classRefs, *args, **kwargs):
if type(classRefs) not in (tuple, list):
classRefs = (classRefs,)
- if issubclass(classRefs[0], wx.Frame):
+ isDialog = False
+ if issubclass(classRefs[0], (wx.Frame, wx.Dialog)):
# Can't display a frame within another frame, so create this
# class as the main frame
frame = classRefs[0](None, *args, **kwargs)
+ isDialog = (issubclass(classRefs[0], wx.Dialog))
else:
frame = wx.Frame(None, -1, "")
frame.SetSizer(ui.dSizer("Vertical"))
@@ -42,7 +44,6 @@
# Some controls don't report sizing correctly, so set a minimum
w = max(w, 100)
h = max(h, 50)
- print "SZ", w, h

frame.SetSize( (w+10, h+30) )
if len(classRefs) > 1:
@@ -51,10 +52,15 @@
frame.SetLabel("Test of %s" % object.BaseClass.__name__)
object.SetFocus()

- frame.Show()
- frame.Layout()
- #object.Show()
- self.app.MainLoop()
+ if isDialog:
+ ret = frame.ShowModal()
+ print ret
+ frame.Destroy()
+ else:
+ frame.Show()
+ frame.Layout()
+ self.app.MainLoop()
+

def testAll(self):
""" Create a dForm and populate it with example dWidgets.




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