示例#1
0
def run():
    # Parse the XML file(s) building a collection of Extractor objects
    module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING)
    etgtools.parseDoxyXML(module, ITEMS)

    #-----------------------------------------------------------------
    # Tweak the parsed meta objects in the module object as needed for
    # customizing the generated code and docstrings.

    module.addHeaderCode("#include <wx/wrapsizer.h>")

    c = module.find('wxWrapSizer')
    assert isinstance(c, etgtools.ClassDef)
    tools.fixSizerClass(c)

    c.find('IsSpaceItem').ignore(False)
    c.find('IsSpaceItem').isVirtual = True

    #-----------------------------------------------------------------
    tools.doCommonTweaks(module)
    tools.runGenerators(module)
示例#2
0
def run():
    # Parse the XML file(s) building a collection of Extractor objects
    module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING)
    etgtools.parseDoxyXML(module, ITEMS)

    #-----------------------------------------------------------------
    # Tweak the parsed meta objects in the module object as needed for
    # customizing the generated code and docstrings.

    module.addHeaderCode("#include <wx/wrapsizer.h>")

    c = module.find('wxWrapSizer')
    assert isinstance(c, etgtools.ClassDef)
    tools.fixSizerClass(c)

    c.find('IsSpaceItem').ignore(False)
    c.find('IsSpaceItem').isVirtual = True



    #-----------------------------------------------------------------
    tools.doCommonTweaks(module)
    tools.runGenerators(module)
示例#3
0
def run():
    # Parse the XML file(s) building a collection of Extractor objects
    module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING)
    etgtools.parseDoxyXML(module, ITEMS)

    #-----------------------------------------------------------------
    # Tweak the parsed meta objects in the module object as needed for
    # customizing the generated code and docstrings.


    c = module.find('wxSizerItem')
    assert isinstance(c, etgtools.ClassDef)
    tools.removeVirtuals(c)
    
    # ctors taking a sizer transfer ownership
    for m in c.find('wxSizerItem').all():
        if m.findItem('sizer'):
            m.find('sizer').transfer = True

    c.find('AssignSizer.sizer').transfer = True
    
    # userData args transfer ownership too, and we'll use wxPyUserData
    # instead of any wxObject
    for m in c.allItems():
        if isinstance(m, etgtools.MethodDef) and m.findItem('userData'):
            m.find('userData').transfer = True
            m.find('userData').type = 'wxPyUserData*'
            
    gud = c.find('GetUserData')
    gud.type = 'wxPyUserData*'
    gud.setCppCode('return dynamic_cast<wxPyUserData*>(self->GetUserData());')

    # these have been deprecated for a while so go ahead and get rid of them
    c.find('SetWindow').ignore()
    c.find('SetSizer').ignore()
    c.find('SetSpacer').ignore()

    c.addPrivateCopyCtor()

    #---------------------------------------------
    c = module.find('wxSizer')
    assert isinstance(c, etgtools.ClassDef)
    tools.fixSizerClass(c)
    c.addPrivateCopyCtor()
    c.addPrivateAssignOp()
    
    for func in c.findAll('Add') + c.findAll('Insert') + c.findAll('Prepend'):
        if func.findItem('sizer'):
            func.find('sizer').transfer = True
        if func.findItem('userData'):
            func.find('userData').transfer = True
            func.find('userData').type = 'wxPyUserData*'
        if func.findItem('item'):
            func.find('item').transfer = True
            
    c.find('GetChildren').overloads = []
    c.find('GetChildren').noCopy = True
    
    # Needs wxWin 2.6 compatibility
    c.find('Remove').findOverload('(wxWindow *window)').ignore()

    c.addPyMethod('AddMany', '(self, items)', 
        doc="""\
        :meth:`AddMany` is a convenience method for adding several items to a sizer
        at one time. Simply pass it a list of tuples, where each tuple
        consists of the parameters that you would normally pass to the :meth:`Add`
        method.
        """,        
        body="""\
        for item in items:
            if not isinstance(item, (tuple, list)):
                item = (item, )
            self.Add(*item)
        """)

    c.addCppMethod('wxSizerItem*', 'Add', 
                   '(const wxSize& size, int proportion=0, int flag=0, '
                   'int border=0, wxPyUserData* userData /Transfer/ = NULL)',
        doc="Add a spacer using a :class:`Size` object.",
        body="return self->Add(size->x, size->y, proportion, flag, border, userData);")

    c.addCppMethod('wxSizerItem*', 'Prepend', 
                   '(const wxSize& size, int proportion=0, int flag=0, '
                   'int border=0, wxPyUserData* userData /Transfer/ = NULL)',
        doc="Prepend a spacer using a :class:`Size` object.",
        body="return self->Prepend(size->x, size->y, proportion, flag, border, userData);")

    c.addCppMethod('wxSizerItem*', 'Insert', 
                   '(size_t index, const wxSize& size, int proportion=0, int flag=0, '
                   'int border=0, wxPyUserData* userData /Transfer/ = NULL)',
        doc="Insert a spacer using a :class:`Size` object.",
        body="return self->Insert(index, size->x, size->y, proportion, flag, border, userData);")


    c.addCppMethod('wxSizerItem*', 'Add', 
                   '(const wxSize& size, const wxSizerFlags& flags)',
        doc="Add a spacer using a :class:`Size` object.",
        body="return self->Add(size->x, size->y, *flags);")

    c.addCppMethod('wxSizerItem*', 'Prepend', 
                   '(const wxSize& size, const wxSizerFlags& flags)',
        doc="Prepend a spacer using a :class:`Size` object.",
        body="return self->Prepend(size->x, size->y, *flags);")

    c.addCppMethod('wxSizerItem*', 'Insert', 
                   '(size_t index, const wxSize& size, const wxSizerFlags& flags)',
        doc="Insert a spacer using a :class:`Size` object.",
        body="return self->Insert(index, size->x, size->y, *flags);")

    c.addPyMethod('__nonzero__', '(self)',
        doc="Can be used to test if the C++ part of the sizer still exists, with \n"
            "code like this::\n\n"
            "    if theSizer:\n"
            "        doSomething()",
        body="""\
        import wx.siplib
        return not wx.siplib.isdeleted(self)
        """)
    c.addPyCode('Sizer.__bool__ = Sizer.__nonzero__') # For Python 3


    
    #---------------------------------------------
    c = module.find('wxBoxSizer')
    tools.fixSizerClass(c)
    c.find('wxBoxSizer.orient').default = 'wxHORIZONTAL'


    #---------------------------------------------
    c = module.find('wxStaticBoxSizer')
    tools.fixSizerClass(c)
    c.find('wxStaticBoxSizer.orient').default = 'wxHORIZONTAL'


    #---------------------------------------------
    c = module.find('wxGridSizer')
    tools.fixSizerClass(c)

    c.addPyMethod('CalcRowsCols', '(self)',
        doc="""\
        CalcRowsCols() -> (rows, cols)

        Calculates how many rows and columns will be in the sizer based
        on the current number of items and also the rows, cols specified
        in the constructor.
        """,
        body="""\
        nitems = len(self.GetChildren())
        rows = self.GetRows()
        cols = self.GetCols()
        assert rows != 0 or cols != 0, "Grid sizer must have either rows or columns fixed"
        if cols != 0:
            rows = (nitems + cols - 1) / cols
        elif rows != 0:
            cols = (nitems + rows - 1) / rows
        return (rows, cols)
        """)
    
    #---------------------------------------------
    c = module.find('wxFlexGridSizer')
    tools.fixSizerClass(c)

    
    #---------------------------------------------
    c = module.find('wxStdDialogButtonSizer')
    tools.fixSizerClass(c)


    
    module.addPyCode("PySizer = wx.deprecated(Sizer, 'Use Sizer instead.')")
        
    module.addItem(tools.wxListWrapperTemplate('wxSizerItemList', 'wxSizerItem', module))
    

    #-----------------------------------------------------------------
    tools.doCommonTweaks(module)
    tools.runGenerators(module)
示例#4
0
文件: gbsizer.py 项目: swt2c/Phoenix
def run():
    # Parse the XML file(s) building a collection of Extractor objects
    module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING)
    etgtools.parseDoxyXML(module, ITEMS)

    #-----------------------------------------------------------------
    # Tweak the parsed meta objects in the module object as needed for
    # customizing the generated code and docstrings.

    c = module.find('wxGBPosition')
    assert isinstance(c, etgtools.ClassDef)

    # allow a 2 element sequence to be auto converted
    c.convertFromPyObject = tools.convertTwoIntegersTemplate('wxGBPosition')

    c.addCppMethod('PyObject*',
                   'Get',
                   '()',
                   """\
        return sipBuildResult(0, "(ii)", self->GetRow(), self->GetCol());
        """,
                   pyArgsString="() -> (row, col)",
                   briefDoc="Return the row and col properties as a tuple.")
    c.addCppMethod('void',
                   'Set',
                   '(int row=0, int col=0)',
                   """\
        self->SetRow(row);
        self->SetCol(col);
        """,
                   briefDoc="Set both the row and column properties.")

    # Add sequence protocol methods and other goodies
    c.addPyMethod('__str__', '(self)', 'return str(self.Get())')
    c.addPyMethod('__repr__', '(self)',
                  'return "wx.GBPosition"+str(self.Get())')
    c.addPyMethod('__len__', '(self)', 'return len(self.Get())')
    c.addPyMethod('__nonzero__', '(self)', 'return self.Get() != (0,0)')
    c.addPyMethod('__reduce__', '(self)', 'return (GBPosition, self.Get())')
    c.addPyMethod('__getitem__', '(self, idx)', 'return self.Get()[idx]')
    c.addPyMethod(
        '__setitem__', '(self, idx, val)', """\
                  if idx == 0: self.Row = val
                  elif idx == 1: self.Col = val
                  else: raise IndexError
                  """)
    c.addPyCode('GBPosition.__safe_for_unpickling__ = True')

    # In addition to the normal Row and Col properties let's also have lower
    # case versions.
    c.addProperty("Row GetRow SetRow")
    c.addProperty("Col GetCol SetCol")
    c.addProperty("row GetRow SetRow")
    c.addProperty("col GetCol SetCol")

    #-----------------------------------------------------------------
    c = module.find('wxGBSpan')
    assert isinstance(c, etgtools.ClassDef)

    # allow a 2 element sequence to be auto converted
    c.convertFromPyObject = tools.convertTwoIntegersTemplate('wxGBSpan')

    c.addCppMethod(
        'PyObject*',
        'Get',
        '()',
        """\
        return sipBuildResult(0, "(ii)", self->GetRowspan(), self->GetColspan());
        """,
        pyArgsString="() -> (rowspan, colspan)",
        briefDoc="Return the rowspan and colspan properties as a tuple.")
    c.addCppMethod('void',
                   'Set',
                   '(int rowspan=0, int colspan=0)',
                   """\
        self->SetRowspan(rowspan);
        self->SetColspan(colspan);
        """,
                   briefDoc="Set both the rowspan and colspan properties.")

    # Add sequence protocol methods and other goodies
    c.addPyMethod('__str__', '(self)', 'return str(self.Get())')
    c.addPyMethod('__repr__', '(self)', 'return "wx.GBSpan"+str(self.Get())')
    c.addPyMethod('__len__', '(self)', 'return len(self.Get())')
    c.addPyMethod('__nonzero__', '(self)', 'return self.Get() != (0,0)')
    c.addPyMethod('__reduce__', '(self)', 'return (GBSpan, self.Get())')
    c.addPyMethod('__getitem__', '(self, idx)', 'return self.Get()[idx]')
    c.addPyMethod(
        '__setitem__', '(self, idx, val)', """\
                  if idx == 0: self.Rowspan = val
                  elif idx == 1: self.Colspan = val
                  else: raise IndexError
                  """)
    c.addPyCode('GBSpan.__safe_for_unpickling__ = True')

    # In addition to the normal Rowspan and Colspan properties let's also have lower
    # case versions.
    c.addProperty("Rowspan GetRowspan SetRowspan")
    c.addProperty("Colspan GetColspan SetColspan")
    c.addProperty("rowspan GetRowspan SetRowspan")
    c.addProperty("colspan GetColspan SetColspan")

    #-----------------------------------------------------------------
    c = module.find('wxGBSizerItem')
    assert isinstance(c, etgtools.ClassDef)

    # transfer ownership of a sizer if the item is managing one
    c.find('wxGBSizerItem.sizer').transfer = True

    # deal with userData args in the ctors
    for m in c.find('wxGBSizerItem').all():
        if isinstance(m, etgtools.MethodDef) and m.findItem('userData'):
            m.find('userData').transfer = True
            m.find('userData').type = 'wxPyUserData*'

    # ignore some overloads that would be ambiguous from Python
    c.find('GetPos').findOverload('row').ignore()
    c.find('GetSpan').findOverload('rowspan').ignore()

    c.find('GetEndPos.row').out = True
    c.find('GetEndPos.col').out = True

    #-----------------------------------------------------------------
    c = module.find('wxGridBagSizer')
    assert isinstance(c, etgtools.ClassDef)

    tools.fixSizerClass(c)

    for func in c.findAll('Add'):
        if func.findItem('sizer'):
            func.find('sizer').transfer = True
        if func.findItem('userData'):
            func.find('userData').transfer = True
            func.find('userData').type = 'wxPyUserData*'
        if func.findItem('item'):
            func.find('item').transfer = True

    c.addCppMethod(
        'wxSizerItem*',
        'Add', '(const wxSize& size, const wxGBPosition& pos, '
        'const wxGBSpan& span = wxDefaultSpan, int flag = 0, '
        'int border = 0, wxObject* userData /Transfer/ = NULL)',
        doc="Add a spacer using a :class:`Size` object.",
        body=
        "return self->Add(size->x, size->y, *pos, *span, flag, border, userData);"
    )

    c.addPyCode(
        "GridBagSizer.CheckForIntersectionPos = wx.deprecated(GridBagSizer.CheckForIntersection, 'Use CheckForIntersection instead.')"
    )

    # TODO: In Classic we had GetChildren return a list of wxGBSizerItems (in
    # a faked out way). Figure out how to do that here too....

    #module.addItem(
    #    tools.wxListWrapperTemplate('wxGBSizerItemList', 'wxGBSizerItem', module, 'wxSizerItem'))

    #-----------------------------------------------------------------
    tools.doCommonTweaks(module)
    tools.runGenerators(module)
示例#5
0
def run():
    # Parse the XML file(s) building a collection of Extractor objects
    module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING)
    etgtools.parseDoxyXML(module, ITEMS)
    
    #-----------------------------------------------------------------
    # Tweak the parsed meta objects in the module object as needed for
    # customizing the generated code and docstrings.
    
    c = module.find('wxGBPosition')
    assert isinstance(c, etgtools.ClassDef)
    
    # allow a 2 element sequence to be auto converted
    c.convertFromPyObject = tools.convertTwoIntegersTemplate('wxGBPosition')
    
    c.addCppMethod('PyObject*', 'Get', '()', """\
        return sipBuildResult(0, "(ii)", self->GetRow(), self->GetCol());
        """, 
        pyArgsString="() -> (row, col)",
        briefDoc="Return the row and col properties as a tuple.")
    c.addCppMethod('void', 'Set', '(int row=0, int col=0)', """\
        self->SetRow(row);
        self->SetCol(col);
        """, 
        briefDoc="Set both the row and column properties.")
    
    # Add sequence protocol methods and other goodies
    c.addPyMethod('__str__', '(self)',             'return str(self.Get())')
    c.addPyMethod('__repr__', '(self)',            'return "wx.GBPosition"+str(self.Get())')
    c.addPyMethod('__len__', '(self)',             'return len(self.Get())')
    c.addPyMethod('__nonzero__', '(self)',         'return self.Get() != (0,0)')
    c.addPyMethod('__reduce__', '(self)',          'return (GBPosition, self.Get())')
    c.addPyMethod('__getitem__', '(self, idx)',    'return self.Get()[idx]')
    c.addPyMethod('__setitem__', '(self, idx, val)',
                  """\
                  if idx == 0: self.Row = val
                  elif idx == 1: self.Col = val
                  else: raise IndexError
                  """) 
    c.addPyCode('GBPosition.__safe_for_unpickling__ = True')

    # In addition to the normal Row and Col properties let's also have lower
    # case versions.
    c.addProperty("Row GetRow SetRow")
    c.addProperty("Col GetCol SetCol")
    c.addProperty("row GetRow SetRow")
    c.addProperty("col GetCol SetCol")


    #-----------------------------------------------------------------
    c = module.find('wxGBSpan')
    assert isinstance(c, etgtools.ClassDef)

    # allow a 2 element sequence to be auto converted
    c.convertFromPyObject = tools.convertTwoIntegersTemplate('wxGBSpan')
    
    c.addCppMethod('PyObject*', 'Get', '()', """\
        return sipBuildResult(0, "(ii)", self->GetRowspan(), self->GetColspan());
        """, 
        pyArgsString="() -> (rowspan, colspan)",
        briefDoc="Return the rowspan and colspan properties as a tuple.")
    c.addCppMethod('void', 'Set', '(int rowspan=0, int colspan=0)', """\
        self->SetRowspan(rowspan);
        self->SetColspan(colspan);
        """, 
        briefDoc="Set both the rowspan and colspan properties.")
    
    # Add sequence protocol methods and other goodies
    c.addPyMethod('__str__', '(self)',             'return str(self.Get())')
    c.addPyMethod('__repr__', '(self)',            'return "wx.GBSpan"+str(self.Get())')
    c.addPyMethod('__len__', '(self)',             'return len(self.Get())')
    c.addPyMethod('__nonzero__', '(self)',         'return self.Get() != (0,0)')
    c.addPyMethod('__reduce__', '(self)',          'return (GBSpan, self.Get())')
    c.addPyMethod('__getitem__', '(self, idx)',    'return self.Get()[idx]')
    c.addPyMethod('__setitem__', '(self, idx, val)',
                  """\
                  if idx == 0: self.Rowspan = val
                  elif idx == 1: self.Colspan = val
                  else: raise IndexError
                  """) 
    c.addPyCode('GBSpan.__safe_for_unpickling__ = True')

    # In addition to the normal Rowspan and Colspan properties let's also have lower
    # case versions.
    c.addProperty("Rowspan GetRowspan SetRowspan")
    c.addProperty("Colspan GetColspan SetColspan")
    c.addProperty("rowspan GetRowspan SetRowspan")
    c.addProperty("colspan GetColspan SetColspan")


    #-----------------------------------------------------------------
    c = module.find('wxGBSizerItem')
    assert isinstance(c, etgtools.ClassDef)

    # transfer ownership of a sizer if the item is managing one
    c.find('wxGBSizerItem.sizer').transfer = True
    
    # deal with userData args in the ctors
    for m in c.find('wxGBSizerItem').all():
        if isinstance(m, etgtools.MethodDef) and m.findItem('userData'):
            m.find('userData').transfer = True
            m.find('userData').type = 'wxPyUserData*'
    
    # ignore some overloads that would be ambiguous from Python
    c.find('GetPos').findOverload('row').ignore()
    c.find('GetSpan').findOverload('rowspan').ignore()
    
    c.find('GetEndPos.row').out = True
    c.find('GetEndPos.col').out = True
    
    #-----------------------------------------------------------------
    c = module.find('wxGridBagSizer')
    assert isinstance(c, etgtools.ClassDef)

    tools.fixSizerClass(c)
    
    for func in c.findAll('Add'):
        if func.findItem('sizer'):
            func.find('sizer').transfer = True
        if func.findItem('userData'):
            func.find('userData').transfer = True
            func.find('userData').type = 'wxPyUserData*'
        if func.findItem('item'):
            func.find('item').transfer = True

    c.addCppMethod('wxSizerItem*', 'Add',
                   '(const wxSize& size, const wxGBPosition& pos, '
                     'const wxGBSpan& span = wxDefaultSpan, int flag = 0, '
                     'int border = 0, wxObject* userData /Transfer/ = NULL)',
        doc="Add a spacer using a :class:`Size` object.",
        body="return self->Add(size->x, size->y, *pos, *span, flag, border, userData);")


    c.addPyCode(
        "GridBagSizer.CheckForIntersectionPos = wx.deprecated(GridBagSizer.CheckForIntersection, 'Use CheckForIntersection instead.')")
    
    # TODO: In Classic we had GetChildren return a list of wxGBSizerItems (in
    # a faked out way). Figure out how to do that here too....
    
    #module.addItem(
    #    tools.wxListWrapperTemplate('wxGBSizerItemList', 'wxGBSizerItem', module, 'wxSizerItem'))
    
    
    #-----------------------------------------------------------------
    tools.doCommonTweaks(module)
    tools.runGenerators(module)