Commits

riaan  committed 3bccac6

Forced ClientSize property to be added to frame src, for x-platform behaviour. Added warning for disconnecting menubars on GTK. Added Range property for SpinButtons.

  • Participants
  • Parent commits becf998

Comments (0)

Files changed (1)

File Companions/Companions.py

 #
 # Created:     1999
 # RCS-ID:      $Id$
-# Copyright:   (c) 1999, 2000 Riaan Booysen
+# Copyright:   (c) 1999 - 2001 Riaan Booysen
 # Licence:     GPL
 #----------------------------------------------------------------------
 
+""" Classes defining and implementing the design time behaviour of controls """
+
+import copy
+
 from wxPython.wx import *
 
-# XXX Fix these to not import * !
-from PropEdit.PropertyEditors import *
-from PropEdit.Enumerations import *
-from EventCollections import *
-from BaseCompanions import *
-from Constructors import *
-from Preferences import wxDefaultFrameSize, wxDefaultFramePos
-import PaletteStore
-import copy
-
 print 'importing extra wxPython libraries'
 from wxPython.grid import wxGrid
 from wxPython.html import wxHtmlWindow
 from wxPython.lib.anchors import LayoutAnchors
 from wxPython.calendar import *
 from wxPython.utils import *
+from wxPython.ogl import *
+
+# XXX Fix less of these to import * !
+from PropEdit.PropertyEditors import *
+from PropEdit.Enumerations import *
+from EventCollections import *
+from BaseCompanions import *
+from Constructors import *
+from Preferences import wxDefaultFrameSize, wxDefaultFramePos
+import PaletteStore
+
 #wxCalendarCtrl
 
 PaletteStore.paletteLists.update({'ContainersLayout': [],
     def extraConstrProps(self):
         return {}
 
+    def dontPersistProps(self):
+        # Note this is a workaround for a problem on wxGTK where the size
+        # passed to the frame constructor is actually means ClientSize on wxGTK
+        # By having this property always set, this overrides the frame size
+        # and uses the same size on Win and Lin
+        props = ContainerDTC.dontPersistProps(self) 
+        props.remove('ClientSize')
+        return props
+
     def hideDesignTime(self):
         hdt = ContainerDTC.hideDesignTime(self) + ['Label', 'Constraints', 'Anchors']
         hdt.remove('Title')
             if mb and mb.GetId() == compn.control.GetId():
                 self.propRevertToDefault('MenuBar', 'SetMenuBar')
                 self.control.SetMenuBar(None)
+                if wxPlatform == '__WXGTK__':
+                    wxLogWarning('GTK only allows connecting the wxMenuBar once to the wxFrame')
 
             # ToolBar
             tb = self.control.GetToolBar()
                 self.propRevertToDefault('ToolBar', 'SetToolBar')
                 self.control.SetToolBar(None)
 
+    def updatePosAndSize(self):
+        ContainerDTC.updatePosAndSize(self)
+        # Argh, this is needed so that ClientSize is up to date
+        # XXX Delete links to frame bars so client size is accurate
+        self.control.SetToolBar(None)
+        self.control.SetStatusBar(None)
+        self.control.SetMenuBar(None)
+        if self.textPropList:
+            for prop in self.textPropList:
+                if prop.prop_name == 'ClientSize':
+                    size = self.control.GetClientSize()
+                    prop.params = ['wxSize(%d, %d)' % (size.x, size.y)]
+
 class FrameDTC(FramesConstr, BaseFrameDTC):
     #wxDocs = HelpCompanions.wxFrameDocs
     pass
         dts = BaseFrameDTC.designTimeSource(self)
         dts.update({'style': 'wxDEFAULT_DIALOG_STYLE'})
         return dts
+#wxSystemSettings_GetSystemColour(wxSYS_COLOUR_BTNFACE)
 
     def events(self):
         return BaseFrameDTC.events(self) + ['DialogEvent']
                              'SashVisibleRight' : SashVisiblePropEdit,
                              'SashVisibleBottom' : SashVisiblePropEdit})
         self.windowStyles = ['wxSW_3D', 'wxSW_3DSASH', 'wxSW_3DBORDER',
-                                  'wxSW_BORDER'] + self.windowStyles
+                             'wxSW_BORDER'] + self.windowStyles
         self.edgeNameMap = {'SashVisibleLeft'  : wxSASH_LEFT,
                             'SashVisibleTop'   : wxSASH_TOP,
                             'SashVisibleRight' : wxSASH_RIGHT,
                             'SashVisibleBottom': wxSASH_BOTTOM}
-        for name in self.edgeNameMap.keys():
+        for name in self.edgeNameMap.keys() + ['SashVisible']:
             self.customPropEvaluators[name] = self.EvalSashVisible
-        self.customPropEvaluators['SashVisible'] = self.EvalSashVisible
+        #self.customPropEvaluators['SashVisible'] = self.EvalSashVisible
 
     def properties(self):
         props = ContainerDTC.properties(self)
     def EvalSashVisible(self, exprs, objects):
         res = []
         for expr in exprs:
-            res.append(eval(expr))
+            res.append(self.eval(expr))
         return tuple(res)
 
     def persistProp(self, name, setterName, value):
                     if tph.ctrl == compn.control:
                         tph.clearCtrl()
 
+    def writeCollectionItems(self, output):
+        CollectionDTC.writeCollectionItems(self, output)
+        warn = 0
+        for constr in self.textConstrLst:
+            if constr.params['pPage'] == 'None':
+                wxLogWarning('No control for %s, page %s'%(
+                      self.parentCompanion.name, constr.params['strText']))
+                warn = 1
+        if warn:
+            wxLogWarning('The red-dashed area of a wxNotebook page must contain\n'\
+            'a control or the generated source will be invalid outside the Designer')
+
 
 [wxID_CTRLPARENT, wxID_EDITPASTE, wxID_EDITDELETE,
 ] = map(lambda _bwp_menu: wxNewId(), range(3))
         WindowDTC.__init__(self, name, designer, parent, ctrlClass)
         self.windowStyles = ['wxSP_HORIZONTAL', 'wxSP_VERTICAL',
                              'wxSP_ARROW_KEYS', 'wxSP_WRAP'] + self.windowStyles
+        self.customPropEvaluators['Range'] = self.EvalRange
+
+    def properties(self):
+        props = WindowDTC.properties(self)
+        props['Range'] = ('CompnRoute', self.GetRange, self.SetRange)
+        return props
 
     def designTimeSource(self, position = 'wxDefaultPosition', size = 'wxDefaultSize'):
         return {'pos': position,
         insp.pages.SetSelection(2)
         insp.events.doAddEvent('SpinEvent', 'EVT_SPIN')
 
+    def GetRange(self, dummy):
+        return (self.control.GetMin(), self.control.GetMax())
+
+    def SetRange(self, value):
+        self.control.SetRange(value[0], value[1])
+
+    def EvalRange(self, exprs, objects):
+        res = []
+        for expr in exprs:
+            res.append(self.eval(expr))
+        return tuple(res)
+
+    def persistProp(self, name, setterName, value):
+        if setterName == 'SetRange':
+            rMin, rMax = self.eval(value)
+            newParams = [`rMin`, `rMax`]
+            # edit if exists
+            for prop in self.textPropList:
+                if prop.prop_setter == setterName:
+                    prop.params = newParams
+                    return
+            # add if not defined
+            self.textPropList.append(methodparse.PropertyParse( None, self.name,
+                setterName, newParams, 'SetRange'))
+        else:
+            WindowDTC.persistProp(self, name, setterName, value)
+
 # XXX FreqTick handled wrong
 EventCategories['SliderEvent'] = (EVT_SLIDER,)
 commandCategories.append('SliderEvent')
     'wxColourPtr': ColourDTC,
     'Anchors': AnchorsDTC
 })
-