Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Help writing plugin

Help
2008-08-31
2013-05-01
  • StrontiumDog
    StrontiumDog
    2008-08-31

    Hi, I am trying to write a plugin to support AuiNotebook controls.

    I have modified the FlatNotebook plugin, and think I have it right (I don't really know because I can't find any docs on writing plugins).

    It doesn't work I get the following error:
    Traceback (most recent call last):
      File "/usr/share/boa-constructor/Views/Designer.py", line 1597, in OnControlSelect
        dsgn.selectControlByPos(ctrl, pos, event.ShiftDown())
      File "/usr/share/boa-constructor/Views/Designer.py", line 953, in selectControlByPos
        ctrlName = self.newControl(parent, CtrlClass, CtrlCompanion, pos)
      File "/usr/share/boa-constructor/Views/Designer.py", line 508, in newControl
        companion.designTimeControl(position, size), parentName)
      File "/usr/share/boa-constructor/Plug-ins/AUI_Notebook.plug-in.py", line 69, in designTimeControl
        ctrl = ContainerDTC.designTimeControl(self, position, size, args)
      File "/usr/share/boa-constructor/Companions/BaseCompanions.py", line 596, in designTimeControl
        self.control = self.ctrlClass(**self.designTimeDefaults(position, size))
      File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/aui.py", line 1368, in __init__
        _aui.AuiNotebook_swiginit(self,_aui.new_AuiNotebook(*args, **kwargs))
    TypeError: 'name' is an invalid keyword argument for this function

    And here is the code for the plugin, any help or advice would be appreciated:

    import wx

    import Plugins

    from Utils import _

    try:

        import wx.aui

    except ImportError:

        raise Plugins.SkipPluginSilently, _('Module %s not found')%'wx.aui'

    from Companions.ContainerCompanions import BookCtrlDTC

    from Companions.EventCollections import *

    EventCategories['AuiNotebookEvent'] = \

    ('wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE',

      'wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSED',

      'wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED',

      'wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGING',

      'wx.aui.EVT_AUINOTEBOOK_BUTTON',

      'wx.aui.EVT_AUINOTEBOOK_BEGIN_DRAG',

      'wx.aui.EVT_AUINOTEBOOK_END_DRAG',

      'wx.aui.EVT_AUINOTEBOOK_DRAG_MOTION',

      'wx.aui.EVT_AUINOTEBOOK_ALLOW_DND',

      'wx.aui.EVT_AUINOTEBOOK_DRAG_DONE',

      'wx.aui.EVT_AUINOTEBOOK_BG_DCLICK',

      'wx.aui.EVT_AUINOTEBOOK_TAB_MIDDLE_DOWN',

      'wx.aui.EVT_AUINOTEBOOK_TAB_MIDDLE_UP',

      'wx.aui.EVT_AUINOTEBOOK_TAB_RIGHT_DOWN',

      'wx.aui.EVT_AUINOTEBOOK_TAB_RIGHT_UP')

    commandCategories.append('AuiNotebookEvent')

    class AUINotebookDTC(Constructors.WindowConstr, ContainerDTC):

        bookCtrlName = 'wx.aui.AuiNotebook'

        def __init__(self, name, designer, parent, ctrlClass):

            ContainerDTC.__init__(self, name, designer, parent, ctrlClass)

            self.editors.update({'Pages':     CollectionPropEdit,

                                 'ImageList': ImageListClassLinkPropEdit})

            self.subCompanions['Pages'] = BookCtrlPagesCDTC

            self.letClickThru = True

            self.windowStyles = \

                ['wx.aui.AUI_NB_TOP',

                 'wx.aui.AUI_NB_LEFT',

                 'wx.aui.AUI_NB_RIGHT',

                 'wx.aui.AUI_NB_BOTTOM',

                 'wx.aui.AUI_NB_TAB_SPLIT',

                 'wx.aui.AUI_NB_TAB_MOVE',

                 'wx.aui.AUI_NB_TAB_EXTERNAL_MOVE',

                 'wx.aui.AUI_NB_TAB_FIXED_WIDTH',

                 'wx.aui.AUI_NB_SCROLL_BUTTONS',

                 'wx.aui.AUI_NB_WINDOWLIST_BUTTON',

                 'wx.aui.AUI_NB_CLOSE_BUTTON',

                 'wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB',

                 'wx.aui.AUI_NB_CLOSE_ON_ALL_TABS',

                 'wx.aui.AUI_NB_MIDDLE_CLICK_CLOSE',

                 'wx.aui.AUI_NB_DEFAULT_STYLE'] + self.windowStyles

        def designTimeDefaults(self, position = wx.DefaultPosition, size = wx.DefaultSize):

            defs = ContainerDTC.designTimeDefaults(self, position = wx.DefaultPosition, size = wx.DefaultSize)

            defs['style'] |= wx.aui.AUI_NB_DEFAULT_STYLE

            defs['style'] &= ~(wx.aui.AUI_NB_DEFAULT_STYLE)

            return defs

        def designTimeControl(self, position, size, args = None):

            if args is not None:

                args['style'] |= wx.aui.AUI_NB_DEFAULT_STYLE

                args['style'] &= ~(wx.aui.AUI_NB_DEFAULT_STYLE)

            ctrl = ContainerDTC.designTimeControl(self, position, size, args)

            ctrl.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED,

                  self.OnPageChanged, id=ctrl.GetId())

            ctrl.SetWindowStyleFlag = lambda s: None

            return ctrl       

        def events(self):

            return ContainerDTC.events(self) + ['AuiNotebookEvent']

       

        def writeImports(self):

            return '\n'.join( (BookCtrlDTC.writeImports(self), 'import wx.aui'))

        def properties(self):

            props = ContainerDTC.properties(self)

            props.update({'Pages': ('NoneRoute', None, None)})

            del props['Sizer']

            return props

        def designTimeSource(self, position = 'wx.DefaultPosition', size = 'wx.DefaultSize'):

            return {'pos':   position,

                    'size':  self.getDefCtrlSize(),

                    'style': '0',

                    'name':  `self.name`}

        def dependentProps(self):

            return ContainerDTC.dependentProps(self) + ['ImageList', 'Pages']

        def dontPersistProps(self):

            return ContainerDTC.dontPersistProps(self) + ['Selection']

        def defaultAction(self):

            self.designer.inspector.props.getNameValue('Pages').propEditor.edit(None)

        def OnPageChanged(self, event):

            try:

                if self.collections.has_key('Pages'):

                    self.collections['Pages'].updateSelection(event.GetSelection())

                    wx.PostEvent(self.control, wx.SizeEvent( self.control.GetSize() ))

            except Exception, err:

                print 'OnPageChanged exception', str(err)

            event.Skip()

        def notification(self, compn, action):

            ContainerDTC.notification(self, compn, action)

            if action == 'delete':

                if self.control.GetImageList() == compn.control:

                    self.propRevertToDefault('ImageList', 'SetImageList')

                    self.control.SetImageList(None)

    Plugins.registerComponent('User', wx.aui.AuiNotebook,

          'wx.aui.AuiNotebook', AUINotebookDTC)

    def getAuiNotebookData():

        return \

    '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x18\x00\x00\x00\x18\x08\x06\

    \x00\x00\x00\xe0w=\xf8\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\

    \x00\x9bIDATH\x89cddbf\xa0%`\xa2\xa9\xe9\xf4\xb0\x80\x05\xc6\xf8\xf7\xf7\xcf\

    \x7f\xbc.afa$\xc7\x02FF&f\x86\x7f\x7f\xff\xfc?~\xe48^\x85\xfb\xf6\xefc\xa8\

    \xae\xad\xc6j16\xc7\xc1\x1c\xc4\x82\xa1\x03\x0f\xc0\xe6\x88\xe6\x86F\xac\x8e\

    knh\xfc_\xdbP\xcf\x88\x12\x07V\xb6Vp\x1a\x99M\t@\xf1\xc1\xb1\xc3\xc7Pht\xb6\

    \xa5\x8d%\x86\x01\xd8\xc4\x18\x18 A\x8aa\x01>\xe0\xe4\xe8\x845\x88\x08\x81\

    \xa1\x9f\x0fF-\x18\xb5\x80r\x00\xcfh\xb0\x9cGm\xc08Z\xa3\x8dZ@1\x00\x006M0\

    \x0b(3z\x16\x00\x00\x00\x00IEND\xaeB`\x82'

    Preferences.IS.registerImage('Images/Palette/wx.aui.AuiNotebook.png', getAuiNotebookData())

     
    • StrontiumDog
      StrontiumDog
      2008-08-31

      Well I fixed that problem, and have muddled it through till it sort of works (code below).  My problem is

      in:
      class AuiBookCtrlPagesCDTC(BookCtrlPagesCDTC):

          def __init__(self, name, designer, parentCompanion, ctrl):

              BookCtrlPagesCDTC.__init__(self, name, designer, parentCompanion, ctrl)

              self.editors = {'Page': ClassLinkConstrPropEdit,

      #                        'caption': StrConstrPropEdit,

                              'Selected' : BoolConstrPropEdit} #,

      #                        'bitmap': IntConstrPropEdit}

      If I dont comment these out then I get errors, but if i do comment them out the error goes away, but I cant edit those properties.  The error is something about an unknown "Key"

      Plugin code follows

      import wx

      import Plugins

      from Utils import _

      try:

          import wx.aui

      except ImportError:

          raise Plugins.SkipPluginSilently, _('Module %s not found')%'wx.aui'

      from Companions.ContainerCompanions import BookCtrlDTC

      from Companions.EventCollections import *

      EventCategories['AuiNotebookEvent'] = \

      ('wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE',

        'wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSED',

        'wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED',

        'wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGING',

        'wx.aui.EVT_AUINOTEBOOK_BUTTON',

        'wx.aui.EVT_AUINOTEBOOK_BEGIN_DRAG',

        'wx.aui.EVT_AUINOTEBOOK_END_DRAG',

        'wx.aui.EVT_AUINOTEBOOK_DRAG_MOTION',

        'wx.aui.EVT_AUINOTEBOOK_ALLOW_DND',

        'wx.aui.EVT_AUINOTEBOOK_DRAG_DONE',

        'wx.aui.EVT_AUINOTEBOOK_BG_DCLICK',

        'wx.aui.EVT_AUINOTEBOOK_TAB_MIDDLE_DOWN',

        'wx.aui.EVT_AUINOTEBOOK_TAB_MIDDLE_UP',

        'wx.aui.EVT_AUINOTEBOOK_TAB_RIGHT_DOWN',

        'wx.aui.EVT_AUINOTEBOOK_TAB_RIGHT_UP')

      commandCategories.append('AuiNotebookEvent')

      class AUINotebookDTC(BookCtrlDTC):

          bookCtrlName = 'wx.aui.AuiNotebook'

          def __init__(self, name, designer, parent, ctrlClass):

              ContainerDTC.__init__(self, name, designer, parent, ctrlClass)

              self.editors.update({'Pages':     CollectionPropEdit,

                                   'ImageList': ImageListClassLinkPropEdit})

              self.subCompanions['Pages'] = AuiBookCtrlPagesCDTC

              self.letClickThru = True

              self.windowStyles = \

                  ['wx.aui.AUI_NB_TOP',

                   'wx.aui.AUI_NB_LEFT',

                   'wx.aui.AUI_NB_RIGHT',

                   'wx.aui.AUI_NB_BOTTOM',

                   'wx.aui.AUI_NB_TAB_SPLIT',

                   'wx.aui.AUI_NB_TAB_MOVE',

                   'wx.aui.AUI_NB_TAB_EXTERNAL_MOVE',

                   'wx.aui.AUI_NB_TAB_FIXED_WIDTH',

                   'wx.aui.AUI_NB_SCROLL_BUTTONS',

                   'wx.aui.AUI_NB_WINDOWLIST_BUTTON',

                   'wx.aui.AUI_NB_CLOSE_BUTTON',

                   'wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB',

                   'wx.aui.AUI_NB_CLOSE_ON_ALL_TABS',

                   'wx.aui.AUI_NB_MIDDLE_CLICK_CLOSE',

                   'wx.aui.AUI_NB_DEFAULT_STYLE'] + self.windowStyles

          def designTimeDefaults(self, position = wx.DefaultPosition, size = wx.DefaultSize):

              defs = ContainerDTC.designTimeDefaults(self, position = wx.DefaultPosition, size = wx.DefaultSize)

              defs['style'] |= wx.aui.AUI_NB_DEFAULT_STYLE

              defs['style'] &= ~(wx.aui.AUI_NB_DEFAULT_STYLE)

              return defs

          def designTimeControl(self, position, size, args = None):

              if args is not None:

                  args['style'] |= wx.aui.AUI_NB_DEFAULT_STYLE

                  args['style'] &= ~(wx.aui.AUI_NB_DEFAULT_STYLE)

              ctrl = ContainerDTC.designTimeControl(self, position, size, args)

              ctrl.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED,

                    self.OnPageChanged, id=ctrl.GetId())

              ctrl.SetWindowStyleFlag = lambda s: None

              return ctrl       

          def events(self):

              return ContainerDTC.events(self) + ['AuiNotebookEvent']

         

          def writeImports(self):

              return '\n'.join( (ContainerDTC.writeImports(self), 'import wx.aui'))

          def designTimeSource(self, position = 'wx.DefaultPosition', size = 'wx.DefaultSize'):

              return {'pos':   position,

                      'size':  self.getDefCtrlSize(),

                      'style': '0'}

      Plugins.registerComponent('User', wx.aui.AuiNotebook,

            'wx.aui.AuiNotebook', AUINotebookDTC)

      def getAuiNotebookData():

          return \

      '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x18\x00\x00\x00\x18\x08\x06\

      \x00\x00\x00\xe0w=\xf8\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\

      \x00\x9bIDATH\x89cddbf\xa0%`\xa2\xa9\xe9\xf4\xb0\x80\x05\xc6\xf8\xf7\xf7\xcf\

      \x7f\xbc.afa$\xc7\x02FF&f\x86\x7f\x7f\xff\xfc?~\xe48^\x85\xfb\xf6\xefc\xa8\

      \xae\xad\xc6j16\xc7\xc1\x1c\xc4\x82\xa1\x03\x0f\xc0\xe6\x88\xe6\x86F\xac\x8e\

      knh\xfc_\xdbP\xcf\x88\x12\x07V\xb6Vp\x1a\x99M\t@\xf1\xc1\xb1\xc3\xc7Pht\xb6\

      \xa5\x8d%\x86\x01\xd8\xc4\x18\x18 A\x8aa\x01>\xe0\xe4\xe8\x845\x88\x08\x81\

      \xa1\x9f\x0fF-\x18\xb5\x80r\x00\xcfh\xb0\x9cGm\xc08Z\xa3\x8dZ@1\x00\x006M0\

      \x0b(3z\x16\x00\x00\x00\x00IEND\xaeB`\x82'

      Preferences.IS.registerImage('Images/Palette/wx.aui.AuiNotebook.png', getAuiNotebookData())

      class AuiBookCtrlPagesCDTC(BookCtrlPagesCDTC):

          def __init__(self, name, designer, parentCompanion, ctrl):

              BookCtrlPagesCDTC.__init__(self, name, designer, parentCompanion, ctrl)

              self.editors = {'Page': ClassLinkConstrPropEdit,

      #                        'caption': StrConstrPropEdit,

                              'Selected' : BoolConstrPropEdit} #,

      #                        'bitmap': IntConstrPropEdit}

          def constructor(self):

              return {'Page': 'page', 'Caption': 'caption',

                      'Selected' : 'select', 'Bitmap': 'bitmap'}

          def properties(self):

              props = CollectionDTC.properties(self)

              props.update({'Page': ('NoneRoute', None, None),
                            'caption': ('IndexRoute', wx.aui.AuiNotebook.GetPageText.im_func, wx.aui.AuiNotebook.SetPageText.im_func),
                    'Selected' : ('CompnRoute', self.GetPageSelected, self.SetPageSelected),

                            'bitmap': ('IndexRoute', wx.aui.AuiNotebook.GetPageBitmap.im_func, wx.aui.AuiNotebook.SetPageBitmap.im_func)})

              return props

          def designTimeSource(self, wId, method=None):

              return {'page': 'None',

                      'caption': `'%s%d'%(self.propName, wId)`,

                      'select': 'True',

                      'bitmap': 'wx.NullBitmap'}

          def applyDesignTimeDefaults(self, params, method=None):
          prms = copy.copy(params)

              page = BlankWindowPage(self.control, self.designer, params, 'page')

              self.tempPlaceHolders.append(page)

              if params['page'] != 'None':

                  ctrl = self.designer.objects[prms['page'][5:]][1]

                  ctrl.Reparent(page)

                  page.ctrl = ctrl

              del prms['page']

              params = self.designTimeDefaults(prms, method)

              params['page'] = page

          print params

              getattr(self.control, self.insertionMethod)(**params)

          def writeCollectionItems(self, output, stripFrmId=''):

              CollectionDTC.writeCollectionItems(self, output, stripFrmId)

              warn = 0

              for constr in self.textConstrLst:

                  if constr.params['page'] == 'None':

                      wx.LogWarning('No control for %s, page %s'%(

                            self.parentCompanion.name, constr.params['caption']))

                      warn = 1

              if warn:

                  wx.LogWarning(_('The red-dashed area of a %s page must contain\n'\

                  'a control or the generated source will be invalid outside the '\

                  'Designer')% self.parentCompanion.bookCtrlName)