commit-gnue
[Top][All Lists]
Advanced

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

r6655 - trunk/gnue-forms/src/uidrivers/wx/widgets/form


From: kilo
Subject: r6655 - trunk/gnue-forms/src/uidrivers/wx/widgets/form
Date: Mon, 8 Nov 2004 16:11:14 -0600 (CST)

Author: kilo
Date: 2004-11-08 16:11:13 -0600 (Mon, 08 Nov 2004)
New Revision: 6655

Modified:
   trunk/gnue-forms/src/uidrivers/wx/widgets/form/widget.py
   trunk/gnue-forms/src/uidrivers/wx/widgets/form/wrappers.py
Log:
Added comments

Modified: trunk/gnue-forms/src/uidrivers/wx/widgets/form/widget.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx/widgets/form/widget.py    2004-11-08 
16:55:22 UTC (rev 6654)
+++ trunk/gnue-forms/src/uidrivers/wx/widgets/form/widget.py    2004-11-08 
22:11:13 UTC (rev 6655)
@@ -18,14 +18,13 @@
 #
 # Copyright 2000-2004 Free Software Foundation
 #
-# FILE:
-# UIwxpython.py
-#
 # DESCRIPTION:
 # A wxPython based user interface driver for GNUe forms.
 #
 # NOTES:
 #
+# $Id$
+
 import string
 
 from wxPython.wx import *
@@ -38,20 +37,30 @@
 from gnue.forms.uidrivers.wx.MenuBar import MenuBar
 from gnue.forms.uidrivers.wx.ToolBar import ToolBar
 
-#
-# UIForm
-#
-# Widget set specific function that creates a single instance of a Form widget
-#
+# =============================================================================
+# Wrap an UI layer around a wx Form widget
+# =============================================================================
 class UIForm(UIHelper):
+  """
+  Handles a single instance of a wx Form widget.
+  """
 
+  # --------------------------------------------------------------------------
+  # Constructor
+  # --------------------------------------------------------------------------
   def __init__(self, event):
-    self._uiPageList=[]
+    self._uiPageList = []
     self.statusBar = None
     UIHelper.__init__(self, event)
 
 
+  # --------------------------------------------------------------------------
+  # Create a wx form widget
+  # --------------------------------------------------------------------------
   def _createWidget(self, event, spacer):
+    """
+    Creates a new wx form widget.
+    """
     object = event.object
 
     #
@@ -61,13 +70,11 @@
 
     formWidth = int(self._form._layout.Char__width)
     formHeight = int(self._form._layout.Char__height)
-    self._visibleSize = wxSize(formWidth*self._uiDriver.widgetWidth,
-                      formHeight*self._uiDriver.widgetHeight)
+    self._visibleSize = wxSize(formWidth * self._uiDriver.widgetWidth,
+                      formHeight * self._uiDriver.widgetHeight)
+    self._formSize = formSize = wxSize(formWidth * self._uiDriver.widgetWidth,
+                      (formHeight + self.menu_sb_space) * 
self._uiDriver.widgetHeight)
 
-    self._formSize = formSize = wxSize(formWidth*self._uiDriver.widgetWidth,
-                      
(formHeight+self.menu_sb_space)*self._uiDriver.widgetHeight)
-
-
     # The main frame of this form
     if self._form.style != 'dialog':
       if self._uiDriver._parentContainer:
@@ -75,23 +82,22 @@
       else:
         self.mainWindow = wxFrame(NULL, -1, "", wxDefaultPosition)
     else:
-      self.mainWindow = wxDialog(NULL,-1,"",wxDefaultPosition)
+      self.mainWindow = wxDialog(NULL, -1, "", wxDefaultPosition)
 
     self.containerFrame = self.mainWindow
 
     self.mainWindow.SetTitle(wxEncode(self._form.title))
-    EVT_CLOSE(self.mainWindow,self.closeTrap)
-    initFont(self.mainWindow,1)
+    EVT_CLOSE(self.mainWindow, self.closeTrap)
+    initFont(self.mainWindow, 1)
 
     # The status bar
     if not self._form._features['GUI:STATUSBAR:SUPPRESS']:
-      if isinstance(self.mainWindow,wxFrame):
+      if isinstance(self.mainWindow, wxFrame):
         self.statusBar = self.containerFrame.CreateStatusBar()
         self.statusBar.SetFieldsCount(5)
-        self.statusBar.SetStatusWidths([-1,50,50,75,75])
-        initFont(self.statusBar,0)
+        self.statusBar.SetStatusWidths([-1, 50, 50, 75, 75])
+        initFont(self.statusBar, 0)
 
-
     # The window in which pages will be rendered
     if object._layout.tabbed != 'none':
       self._wrapper = wrappers.TabbedWrapper(self)
@@ -101,8 +107,6 @@
     newWidget = self._wrapper.pane
     self._containerToolkitWidget = newWidget
 
-
-
     # Add the menu
     if not self._form._features['GUI:MENUBAR:SUPPRESS']:
       MenuBar(self._uiDriver, self.containerFrame, self._form)
@@ -111,61 +115,67 @@
     if not self._form._features['GUI:TOOLBAR:SUPPRESS']:
       ToolBar(self._uiDriver, self.containerFrame, self._form)
 
-
-
     self._eventHandler = event.eventHandler
     self._wrapper.finalize()
 
     return newWidget
 
 
-  #
-  # closeTrap
-  #
-  # intercepts the applications closure and generates an event to the form 
requesting
-  # closure.  Allows the form to control closure.  If the form approves it'll 
send
-  # back an event closing the application
-  #`
-  def closeTrap(self,event):
+  # --------------------------------------------------------------------------
+  # Intercepts the application's closure and generates an event to the form
+  # requesting closure.
+  # Allows the form to control closure. If the form approves it'll send
+  # back an event closing the application.
+  # --------------------------------------------------------------------------
+  def closeTrap(self, event):
+    """
+    Intercept application closure request and so allow the form to control
+    (approve/disallow) closure.
+    """
     form = self._form
 
     if event.CanVeto():
-      self._uiDriver.dispatchEvent('requestEXIT',_form=self._form)
+      self._uiDriver.dispatchEvent('requestEXIT', _form=self._form)
     else:
       object = _eventObjTowxWindow(event)
       object.Destroy()
       # wxExit() TODO: Try and work this into navigator or here if it still 
hangs
 
 
-  #
-  # gotoPage
-  #
+  # --------------------------------------------------------------------------
   # Makes the requested page visible while hiding the others
-  #
-  def gotoPage(self,page):
+  # --------------------------------------------------------------------------
+  def gotoPage(self, page):
+    """
+    Make the requested page visible, hide others.
+    """
     self._wrapper.setPage(page.widgets[0])
 
 
-  #
-  # _setStatusBar
-  #
-  def _setStatusBar(self,tip, statusValue, insertValue, currentRecord, 
maxRecord, currentPage, maxPage):
+  # --------------------------------------------------------------------------
+  # Set statusbar values
+  # --------------------------------------------------------------------------
+  def _setStatusBar(self, tip, statusValue, insertValue, currentRecord, 
maxRecord, currentPage, maxPage):
+    """
+    Sets statusbar values.
+    """
     if not self.statusBar:
       return
 
-    if tip != None: self.statusBar.SetStatusText(wxEncode(tip),0)
+    if tip:
+      self.statusBar.SetStatusText(wxEncode(tip), 0)
 
     if statusValue:
-      self.statusBar.SetStatusText(wxEncode(statusValue),1)
+      self.statusBar.SetStatusText(wxEncode(statusValue), 1)
 
     if insertValue:
-      self.statusBar.SetStatusText(wxEncode(insertValue),2)
+      self.statusBar.SetStatusText(wxEncode(insertValue), 2)
 
-    if currentRecord and  maxRecord:
-      self.statusBar.SetStatusText(string.strip("%s/%s" % 
(currentRecord,maxRecord)),3)
+    if currentRecord and maxRecord:
+      self.statusBar.SetStatusText(string.strip("%s/%s" % (currentRecord, 
maxRecord)), 3)
 
-    if currentPage and  maxPage:
-      self.statusBar.SetStatusText(string.strip("%s/%s" % 
(currentPage,maxPage)),4)
+    if currentPage and maxPage:
+      self.statusBar.SetStatusText(string.strip("%s/%s" % (currentPage, 
maxPage)), 4)
 
     #
     # Adjust the status fields to reflect width of text in them
@@ -173,10 +183,10 @@
     # This is a hack
     #
     tipWidth = -1 # Fill whatever remains
-    statusWidth,unused = 
self.statusBar.GetTextExtent(self.statusBar.GetStatusText(1))
-    insertWidth,unused = 
self.statusBar.GetTextExtent(self.statusBar.GetStatusText(2))
-    recordWidth,unused = 
self.statusBar.GetTextExtent(self.statusBar.GetStatusText(3))
-    pageWidth,unused = 
self.statusBar.GetTextExtent(self.statusBar.GetStatusText(4))
+    statusWidth, unused = 
self.statusBar.GetTextExtent(self.statusBar.GetStatusText(1))
+    insertWidth, unused = 
self.statusBar.GetTextExtent(self.statusBar.GetStatusText(2))
+    recordWidth, unused = 
self.statusBar.GetTextExtent(self.statusBar.GetStatusText(3))
+    pageWidth, unused = 
self.statusBar.GetTextExtent(self.statusBar.GetStatusText(4))
 
     # Either double the width if it's set or default to 5
     statusWidth = statusWidth and (statusWidth * 2) or 5
@@ -184,13 +194,27 @@
     recordWidth = recordWidth and (recordWidth * 2) or 5
     pageWidth   = pageWidth   and (pageWidth   * 2) or 5
 
-    
self.statusBar.SetStatusWidths([tipWidth,statusWidth,insertWidth,recordWidth,pageWidth])
+    self.statusBar.SetStatusWidths([tipWidth, statusWidth, insertWidth, 
recordWidth, pageWidth])
 
 
+  # ---------------------------------------------------------------------------
+  # Show the form
+  # ---------------------------------------------------------------------------
   def show(self):
+    """
+    Display the form.
+    """
     self.containerFrame.Show(1)
 #    self.mainWindow.Show(1)
+
+
+  # ---------------------------------------------------------------------------
+  # Show the form modal mode
+  # ---------------------------------------------------------------------------
   def showModal(self):
+    """
+    Display the form in modal windowing mode.
+    """
     self.containerFrame.ShowModal()
 #    self.mainWindow.ShowModal()
 


Property changes on: trunk/gnue-forms/src/uidrivers/wx/widgets/form/widget.py
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: trunk/gnue-forms/src/uidrivers/wx/widgets/form/wrappers.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx/widgets/form/wrappers.py  2004-11-08 
16:55:22 UTC (rev 6654)
+++ trunk/gnue-forms/src/uidrivers/wx/widgets/form/wrappers.py  2004-11-08 
22:11:13 UTC (rev 6655)
@@ -18,18 +18,16 @@
 #
 # Copyright 2000-2004 Free Software Foundation
 #
-# FILE:
-# UIwxpython.py
-#
 # DESCRIPTION:
 # A wxPython based user interface driver for GNUe forms.
 #
 # NOTES:
 #
+# $Id$
+
 import string, sys
 from gnue.common import events
 from gnue.common.apps import GDebug
-
 from gnue.forms.uidrivers.wx.common import *
 
 from wxPython.wx import *
@@ -42,14 +40,24 @@
   USING_WX_22 = 0
 
 
+# ============================================================================
+# Wrap a scrollable window
+# ============================================================================
 class ScrollableWrapper(wxScrolledWindow):
+  """
+  Wrapper class for scrollable windows.
+  """
+
+  # --------------------------------------------------------------------------
+  # Constructor
+  # --------------------------------------------------------------------------
   def __init__(self, uiform):
     self.uiform = uiform
     self.frame = frame = uiform.containerFrame
     self.form = form = uiform._form
     self.margin = 6
     if sys.platform == 'win32':
-      pos = wxPoint(0,35)
+      pos = wxPoint(0, 35)
     else:
       pos = wxDefaultPosition
     wxScrolledWindow.__init__(self, frame, -1, pos)
@@ -58,16 +66,22 @@
     EVT_SIZE(self.frame, self.OnFrameSize)
     formWidth = int(form._layout.Char__width)
     formHeight = int(form._layout.Char__height)
-    self.layoutSize = wxSize(formWidth*uiform._uiDriver.widgetWidth,
-                      formHeight*uiform._uiDriver.widgetHeight)
+    self.layoutSize = wxSize(formWidth * uiform._uiDriver.widgetWidth,
+                      formHeight * uiform._uiDriver.widgetHeight)
     self._fitted = 0
     self._pageList = []
 
+
+  # --------------------------------------------------------------------------
+  # Initial panel window setup during init
+  # not a wxPanel set per page right after this
+  # --------------------------------------------------------------------------
   def finalize(self):
-    # This is the initial panel window setup during init
-    # not a wxPanel set per page right after this
-    w,h = self.pane.GetSizeTuple()
-    self.spacerpane.SetSize(wxSize(w+self.margin*2, h+self.margin*2))
+    """
+    Initial panel window setup during init.
+    """
+    w, h = self.pane.GetSizeTuple()
+    self.spacerpane.SetSize(wxSize(w + self.margin * 2, h + self.margin * 2))
     self.spacerpane.SetPosition(wxPoint(self.margin, self.margin))
     try:
       self.SetVirtualSize(self.spacerpane.GetSize())
@@ -77,11 +91,24 @@
     self.fixScrollbars()
 
 
+  # --------------------------------------------------------------------------
+  # Handles frame resizing
+  # --------------------------------------------------------------------------
   def OnFrameSize(self, event):
+    """
+    Handles frame resize request.
+    """
     self.SetSize(self.frame.GetClientSize())
     self.fixScrollbars()
 
+
+  # --------------------------------------------------------------------------
+  # Sets scrollbar pos and size correctly
+  # --------------------------------------------------------------------------
   def fixScrollbars(self):
+    """
+    Sets correct scrollbar position and size.
+    """
     x1, y1 = self.frame.GetClientSizeTuple()
     x2, y2 = self.spacerpane.GetSizeTuple()
     if x1 < x2 or y1 < y2:
@@ -90,15 +117,21 @@
       self.SetScrollbars(0, 0, 0, 0)
 
 
+# ============================================================================
+# Wrap a tabbed (notebook-paged) window
+# ============================================================================
+class TabbedWrapper(ScrollableWrapper):
+  """
+  Wrapper class for tabbed windows.
+  """
 
-#
-# Notebook pages
-#
-class TabbedWrapper(ScrollableWrapper):
+  # --------------------------------------------------------------------------
+  # Constructor
+  # --------------------------------------------------------------------------
   def __init__(self, *args, **parms):
     ScrollableWrapper.__init__(self, *args, **parms)
     tabstyle  = _tabStyles[self.form._layout.tabbed]
-    self.pane = notebook = wxNotebook(self.spacerpane,-1, #wxPoint(6,6),
+    self.pane = notebook = wxNotebook(self.spacerpane, -1, #wxPoint(6,6),
                                       style=tabstyle)
     self.notebooksizer = sizer1 = wxNotebookSizer(notebook)
 
@@ -111,8 +144,14 @@
     self.__notebookLoopTrap = 0
     EVT_NOTEBOOK_PAGE_CHANGING(notebook, notebook.GetId(), 
self.notebookTabHandler)
 
+
+  # --------------------------------------------------------------------------
+  # Create and add a new page
+  # --------------------------------------------------------------------------
   def createPage(self, object):
-
+    """
+    Creates a new page (tab) and adds it to the pages collection.
+    """
     sizer = wxBoxSizer(wxVERTICAL)
     newWidget = wxPanel(self.pane, -1, size=self.layoutSize)
     sizer.Add(newWidget, 0, wxCENTER)
@@ -120,44 +159,65 @@
     newWidget.SetSizer(sizer)
 
     self._pageList.append(newWidget)
-    tabtitle=hasattr(object,'caption') and object.caption or object.name
-    self.pane.AddPage(newWidget,wxEncode(tabtitle))
+    tabtitle = hasattr(object,'caption') and object.caption or object.name
+    self.pane.AddPage(newWidget, wxEncode(tabtitle))
     self.pane.SetClientSize(self.layoutSize)
     self.fit()
     return newWidget
 
+
+  # --------------------------------------------------------------------------
+  # Fit window size
+  # --------------------------------------------------------------------------
   def fit(self):
+    """
+    Fits window size to client area.
+    """
     if self._fitted: return
+
     self.notebooksizer.Layout()
     self.notebooksizer.SetSizeHints(self.pane)
     self.SetClientSize(self.layoutSize)
+
     if not USING_WX_22:
-      w,h = self.pane.GetSizeTuple()
-      w += self.margin*2
-      h += self.margin*2
-      self.spacerpane.SetSize(wxSize(w,h))
+      w, h = self.pane.GetSizeTuple()
+      w += self.margin * 2
+      h += self.margin * 2
+      self.spacerpane.SetSize(wxSize(w, h))
       self.SetSize(self.spacerpane.GetSize())
     else:
       # TODO: How fscking sad to have to do this.
       # TODO: but, I can't get wx 2.2 to cooperate
-      w,h = self.GetClientSizeTuple()
-      self.spacerpane.SetSize(wxSize(w+20, h+50))
-      self.SetSize(wxSize(w+20, h+50))
+      w, h = self.GetClientSizeTuple()
+      w += 20
+      h += 50
+      self.spacerpane.SetSize(wxSize(w, h))
+      self.SetSize(wxSize(w, h))
     self.frame.SetClientSize(self.GetSize())
     self._fitted = 1
 
 
+  # --------------------------------------------------------------------------
   # Catch the tab changes
-  def notebookTabHandler(self,event):
+  # --------------------------------------------------------------------------
+  def notebookTabHandler(self, event):
+    """
+    Handles tab change requests.
+    """
     if event.GetEventType() == wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING:
       self.__alreadyChanged = True
-      self.uiform._eventHandler('requestPAGE',event.GetSelection(), 
_form=self.form)
+      self.uiform._eventHandler('requestPAGE', event.GetSelection(), 
_form=self.form)
       del self.__alreadyChanged
 
+
+  # --------------------------------------------------------------------------
+  # Trick to trap mouse page changes that causes SetSelection to be called 2x
+  # --------------------------------------------------------------------------
   def setPage(self, page):
+    """
+    Handles double SetSelection calls during mouse page changes.
+    """
     try:
-      # This is to trap mouse page changes, which 
-      # causes SetSelection to be called twice 
       self.__alreadyChanged
       return
     except AttributeError:
@@ -165,16 +225,30 @@
       self.pane.SetSelection(pageId)
 
 
-#
-# Single pages
-#
+# ============================================================================
+# Wrap a single page window
+# ============================================================================
 class PlainWrapper(ScrollableWrapper):
+  """
+  Wrapper class for single page windows.
+  """
+
+  # --------------------------------------------------------------------------
+  # Constructor
+  # --------------------------------------------------------------------------
   def __init__(self, *args, **parms):
     ScrollableWrapper.__init__(self, *args, **parms)
     self.pane = wxPanel(self.spacerpane, -1, size=self.layoutSize, 
pos=wxPoint(self.margin, self.margin))
     self.pane.Show(1)
 
+
+  # --------------------------------------------------------------------------
+  # Create and add a new page
+  # --------------------------------------------------------------------------
   def createPage(self, object):
+    """
+    Creates a new page (tab) and adds it to the pages collection.
+    """
     newWidget = wxPanel(self.pane, -1,  size=self.layoutSize)
 
     # Only show first page
@@ -187,8 +261,16 @@
     self.fit()
     return newWidget
 
+
+  # --------------------------------------------------------------------------
+  # Fit window size
+  # --------------------------------------------------------------------------
   def fit(self):
+    """
+    Fits window size to client area.
+    """
     if self._fitted: return
+
     self.pane.SetClientSize(self.layoutSize)
     self.pane.Fit()
     self.SetClientSize(self.pane.GetSize())
@@ -196,7 +278,14 @@
     self.frame.Fit()
     self._fitted = 1
 
+
+  # --------------------------------------------------------------------------
+  # Set current page
+  # --------------------------------------------------------------------------
   def setPage(self, page):
+    """
+    Sets current page.
+    """
     for p in self._pageList:
       if p != page:
         p.Show(0)


Property changes on: trunk/gnue-forms/src/uidrivers/wx/widgets/form/wrappers.py
___________________________________________________________________
Name: svn:keywords
   + Id





reply via email to

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