⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 codegen.py

📁 用python写的ide开发环境,巨强大,不过需要wxpython的支持
💻 PY
📖 第 1 页 / 共 2 页
字号:
                          escape(item.short_help))                if item.long_help:                    write('    '*(tabs+1) + '<longhelp>%s</longhelp>\n' % \                          escape(item.long_help))                if item.bitmap1:                    write('    '*(tabs+1) + '<bitmap>%s</bitmap>\n' % \                          escape(item.bitmap1))                if item.bitmap2:                    write('    '*(tabs+1) + '<bitmap2>%s</bitmap2>\n' % \                          escape(item.bitmap2))                try:                    # again, it seems that XRC doesn't support "radio" tools                    if int(item.type) == 1:                        write('    '*(tabs+1) + '<toggle>1</toggle>\n')                    # the above has been fixed on CVS, so add a radio if                    # it's there                    elif int(item.type) == 2:                        write('    '*(tabs+1) + '<radio>1</radio>\n')                except ValueError:                    pass                write('    '*tabs + '</object>\n')                def write(self, outfile, tabs):            tools = self.code_obj.properties['toolbar']            write = outfile.write            write('    '*tabs + '<object class="wxToolBar" name=%s>\n' % \                  quoteattr(self.name))            for prop_name in 'bitmapsize', 'margins':                prop = self.code_obj.properties.get(prop_name)                if prop:                    try:                        w, h = [int(i) for i in prop.split(',')]                        write('    ' * (tabs+1) + '<%s>%s, %s</%s>\n' \                              % (prop_name, w, h, prop_name))                    except:                        pass            for prop_name in 'packing', 'separation':                prop = self.code_obj.properties.get(prop_name)                if prop:                    write('    ' * (tabs+1) + '<%s>%s</%s>\n' % \                          (prop_name, escape(prop), prop_name))            style = self.code_obj.properties.get('style')            if style:                style = style.split('|')                style.append('wxTB_HORIZONTAL')                write('    '*(tabs+1) + '<style>%s</style>\n' % \                      escape('|'.join(style)))            for t in tools:                self.append_item(t, outfile, tabs+1)            write('    '*tabs + '</object>\n')    # end of class ToolBarXrcObject        return ToolBarXrcObject(obj)class CppCodeGenerator:    constructor = [('wxWindow*', 'parent'), ('int', 'id'),                   ('const wxPoint&', 'pos', 'wxDefaultPosition'),                   ('const wxSize&', 'size', 'wxDefaultSize'),                   ('long', 'style', 'wxTB_HORIZONTAL|wxTB_NOBORDER')]    def get_code(self, obj):        """\        generates C++ code for the toolbar of a wxFrame.        """        cppgen = common.code_writers['C++']        style = obj.properties.get('style')        if style:            style = ', wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL|' + \                    style        else:            style = ''        init = [ '%s = new %s(this, -1%s);\n' % (obj.name, obj.klass, style),                 'SetToolBar(%s);\n' % obj.name ]        init.extend(self.get_properties_code(obj))        ids = self.get_ids_code(obj)        return init, ids, [], []    def get_properties_code(self, obj):        cppgen = common.code_writers['C++']        tools = obj.properties['toolbar']        out = []        append = out.append        prop = obj.properties        if obj.is_toplevel: obj_name = ''        else: obj_name = obj.name + '->'        bitmapsize = obj.properties.get('bitmapsize')        if bitmapsize:            try:                w, h = [int(i) for i in bitmapsize.split(',')]                append('%sSetToolBitmapSize(wxSize(%s, %s));\n' % \                       (obj_name, w, h))            except:                pass        margins = obj.properties.get('margins')        if margins:            try:                w, h = [int(i) for i in margins.split(',')]                append('%sSetMargins(wxSize(%s, %s));\n' % \                       (obj_name, w, h))            except:                pass        packing = prop.get('packing')        if packing:            append('%sSetToolPacking(%s);\n' % (obj_name, packing))        separation = prop.get('separation')        if separation:            append('%sSetToolSeparation(%s);\n' % (obj_name, separation))        def _get_bitmap(bitmap):            if not bitmap:                return 'wxNullBitmap'            elif bitmap.startswith('var:'):                return 'wxBitmap(%s, wxBITMAP_TYPE_ANY)' % bitmap[4:].strip()            elif bitmap.startswith('code:'):                return '(%s)' % bitmap[5:].strip()            else:                return 'wxBitmap(%s, wxBITMAP_TYPE_ANY)' % \                       cppgen.quote_str(bitmap, False, False)                        for tool in tools:            if tool.id == '---': # item is a separator                append('%sAddSeparator();\n' % obj_name)            else:                name, val = cppgen.generate_code_id(None, tool.id)                if not name and (not val or val == '-1'):                    id = 'wxNewId()'                else:                    id = val                kinds = ['wxITEM_NORMAL', 'wxITEM_CHECK', 'wxITEM_RADIO']                try:                    kind = kinds[int(tool.type)]                except (IndexError, ValueError):                    kind = 'wxITEM_NORMAL'                bmp1 = _get_bitmap(tool.bitmap1)                bmp2 = _get_bitmap(tool.bitmap2)                append('%sAddTool(%s, %s, %s, %s, %s, %s, %s);\n' %                       (obj_name, id, cppgen.quote_str(tool.label),                        bmp1, bmp2, kind, cppgen.quote_str(tool.short_help),                        cppgen.quote_str(tool.long_help)))        append('%sRealize();\n' % obj_name)        return out    def get_ids_code(self, obj):        cppgen = common.code_writers['C++']        ids = []        tools = obj.properties['toolbar']                for item in tools:            if item.id == '---': # item is a separator                pass # do nothing            else:                name, val = cppgen.generate_code_id(None, item.id)                if name.find('=') != -1:                    ids.append(name)##                 if item.id:##                     tokens = item.id.split('=')##                     if len(tokens) > 1:##                         id = tokens[0]##                         ids.append(' = '.join(tokens))        return ids    def get_events(self,obj):        cppgen = common.code_writers['C++']        out = []        def do_get(tool):            ret = []            name, val = cppgen.generate_code_id(None, tool.id)            if not val: val = '-1' # but this is wrong anyway...            if tool.handler:                ret.append((val, 'EVT_TOOL', tool.handler, 'wxCommandEvent'))            return ret        for tool in obj.properties['toolbar']:            out.extend(do_get(tool))        return out# end of class CppCodeGeneratordef initialize():    common.class_names['EditToolBar'] = 'wxToolBar'    common.toplevels['EditToolBar'] = 1    pygen = common.code_writers.get('python')    if pygen:        pygen.add_widget_handler('wxToolBar', PythonCodeGenerator())        pygen.add_property_handler('tools', ToolsHandler)    xrcgen = common.code_writers.get('XRC')    if xrcgen:        xrcgen.add_widget_handler('wxToolBar', xrc_code_generator)        xrcgen.add_property_handler('tools', ToolsHandler)    cppgen = common.code_writers.get('C++')    if cppgen:        cppgen.add_widget_handler('wxToolBar', CppCodeGenerator())        cppgen.add_property_handler('tools', ToolsHandler)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -