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

📄 edit_sizers.py

📁 用python写的ide开发环境,巨强大,不过需要wxpython的支持
💻 PY
📖 第 1 页 / 共 5 页
字号:
            sizer_tmp.Add(prop['border'].panel, 0, wx.EXPAND)            sizer_tmp.Add(prop['flag'].panel, 0, wx.EXPAND)        else:            # button to Fit parent            FIT_ID = wx.NewId()            self.fit_btn = wx.Button(panel, FIT_ID, _('Fit parent'))            wx.EVT_BUTTON(self.fit_btn, FIT_ID, self.fit_parent)            sizer_tmp.Add(self.fit_btn, 0, wx.ALL|wx.EXPAND, 5)        panel.SetAutoLayout(True)        panel.SetSizer(sizer_tmp)        sizer_tmp.Fit(panel)                w, h = panel.GetClientSizeTuple()        self.notebook.AddPage(panel, _("Common"))        panel.SetScrollbars(1, 5, 1, int(math.ceil(h/5.0)))    def popup_menu(self, event):        """\        pops up a menu to add or remove slots from self, or to remove self        from the application.        """        if self._btn: self._btn.popup_menu(event)        #self._btn.PopupMenu(self._btn._rmenu, event.GetPosition())    def set_name(self, value):        value = "%s" % value        if not config.preferences.allow_duplicate_names and \               (self.widget and common.app_tree.has_name(value, self.node)):            misc.wxCallAfter(                wx.MessageBox, _('Name "%s" is already in use.\n'                'Please enter a different one.') % value, _("Error"),                wx.OK|wx.ICON_ERROR)            self.name_prop.set_value(self.name)            return        if not re.match(self.set_name_pattern, value):            self.name_prop.set_value(self.name)        else:            oldname = self.name            self.name = value            self._btn.set_menu_title(value)            try: common.app_tree.refresh_name(self.node, oldname) #, self.name)            except AttributeError:                import traceback; traceback.print_exc()            self.property_window.SetTitle(_('Properties - <%s>') % self.name)    set_name_pattern = re.compile('^[a-zA-Z_]+[\w0-9]*$')                def __getitem__(self, value):        return self.access_functions[value]    def show_properties(self, *args):        """\        Updates common.property_panel to show the notebook with the Properties        of self        """        if not self.window.is_visible(): return        if not self.notebook:            self.create_properties()        sizer_tmp = self.property_window.GetSizer()        #sizer_tmp = wxPyTypeCast(sizer_tmp, "wxBoxSizer")        #child = wxPyTypeCast(sizer_tmp.GetChildren()[0], "wxSizerItem")        child = sizer_tmp.GetChildren()[0]        #w = wxPyTypeCast(child.GetWindow(), "wxWindow")        w = child.GetWindow()        if w is self.notebook: return        try:            index = -1            title = w.GetPageText(w.GetSelection())            for i in range(self.notebook.GetPageCount()):                if self.notebook.GetPageText(i) == title:                    index = i                    break        except AttributeError, e:            #print e            index = -1        w.Hide()        if 0 <= index < self.notebook.GetPageCount():            self.notebook.SetSelection(index)        self.notebook.Reparent(self.property_window)        child.SetWindow(self.notebook)        w.Reparent(misc.hidden_property_panel)        # ALB moved this before Layout, it seems to be needed for wx2.6...        self.notebook.Show()        self.notebook.SetSize(self.property_window.GetClientSize())        self.property_window.Layout()        self.property_window.SetTitle(_('Properties - <%s>') % self.name)        if hasattr(self, 'node'): common.app_tree.select_item(self.node)        try: self._btn.SetFocus()        except AttributeError: pass            def fit_parent(self, *args):        """\        Tell the sizer to resize the window to match the sizer's minimal size        """        if self.widget and self.window.widget:            self.widget.Fit(self.window.widget)            #self.widget.SetSizeHints(self.window.widget)            self.window.widget.Layout()        def add_item(self, item, pos=None, option=0, flag=0, border=0, size=None,                 force_layout=True):        """\        Adds an item to self.        """        option = int(option); flag = int(flag); border = int(border)        if pos is None:            pos = len(self.children)##             self.children.append(SizerItem(item, pos, option, flag, border,##                                            size))            self.add_slot()        try:            old_child = self.children[pos]            if isinstance(old_child.item, SizerSlot):                old_child.item.delete(False)                        self.children[pos] = SizerItem(item, pos, option, flag, border,                                           size)        except IndexError: # this shouldn't happen!            import traceback; traceback.print_exc()            print self.children, pos            raise SystemExit        if hasattr(item, 'set_containing_sizer'):            item.set_containing_sizer(self)        else:            item.sizer = self        item.pos = pos        self._add_item_widget(item, pos, option, flag, border, size,                              force_layout)            def _add_item_widget(self, item, pos, option, flag, border, size,                         force_layout):        if not self.widget: return # nothing more to do        if not item.widget: return        try:            elem = self.widget.GetChildren()[pos]        except IndexError: # this happens after loading from xml            # I have to set wxADJUST_MINSIZE to handle a bug that I'm not            # able to detect (yet): if the width or height of a widget is -1,            # the layout is messed up!                        self.widget.Add(item.widget, option, flag, border)            if size: w, h = size            else: w, h = item.widget.GetBestSize()            if w == -1: w = item.widget.GetBestSize()[0]            if h == -1: h = item.widget.GetBestSize()[1]            self.widget.SetItemMinSize(item.widget, w, h)            return        if not misc.check_wx_version(2, 5):            if elem.IsWindow(): # remove the previous item at pos                w = elem.GetWindow()                elem.SetWindow(None)                w.Destroy()            try: # let's see if the item to add is a window                elem.SetWindow(item.widget)            except TypeError: # suppose the item to add is a sizer                elem.SetSizer(item.widget)            elem.SetOption(option)            elem.SetFlag(flag)            elem.SetBorder(border)        else:            self.widget.Insert(pos, item.widget, option, flag, border)            self.widget.Remove(pos+1)            if elem.IsWindow():                w = elem.GetWindow()                w.SetContainingSizer(None)                w.Destroy()                        try: # if the item was a window, set its size to a reasonable value##         if elem.IsWindow():            if size: w, h = size            else: w, h = item.widget.GetBestSize()            if w == -1: w = item.widget.GetBestSize()[0]            if h == -1: h = item.widget.GetBestSize()[1]            option = 0            if misc.check_wx_version(2, 5): option = elem.GetProportion()            else: option = elem.GetOption()            flag = elem.GetFlag()            if not size or (option == 0 or not (flag & wx.EXPAND)):                self.widget.SetItemMinSize(item.widget, w, h)            else:                w, h = item.widget.GetBestSize()                self.widget.SetItemMinSize(item.widget, w, h)                #*item.widget.GetBestSize())            #self.widget.SetItemMinSize(item.widget, w, h)        except Exception, e:            #import traceback; traceback.print_exc()            pass        if force_layout: self.layout() # update the layout of self    def _fix_notebook(self, pos, notebook_sizer, force_layout=True):        """\        Replaces the widget at 'pos' with 'notebook_sizer': this is intended        to be used by wxNotebook widgets, to add the notebook sizer to this        sizer.        This is a hack, but it's the best I could find without having to        rewrite too much code :-(        """        # no error checking at all, this is a "protected" method, so it should        # be safe to assume the caller knows how to use it        item = self.widget.GetChildren()[pos]        if not misc.check_wx_version(2, 5):            item.SetWindow(None)        else:            if item.IsWindow():                w = item.GetWindow()                w.SetContainingSizer(None)        item.SetSizer(notebook_sizer)        if force_layout:            self.layout()           def set_item(self, pos, option=None, flag=None, border=None, size=None,                 force_layout=True):        """\        Updates the layout of the item at the given pos.        """        try: item = self.children[pos]        except IndexError: # this shouldn't happen            import traceback; traceback.print_exc()            raise SystemExit        if option is not None:            option = int(option)            item.option = option        if flag is not None:            flag = int(flag)            item.flag = flag        if border is not None:            border = int(border)            item.border = border        if size is not None: item.size = size        self._set_item_widget(pos, option, flag, border, size, force_layout)    def _set_item_widget(self, pos, option, flag, border, size, force_layout):        if not self.widget: return                try: elem = self.widget.GetChildren()[pos]        except IndexError: return # this may happen during xml loading        if option is not None:            if not misc.check_wx_version(2, 5):                elem.SetOption(option)            else:                elem.SetProportion(option)        if flag is not None:            elem.SetFlag(flag)        if border is not None:            elem.SetBorder(border)        if elem.IsWindow():            item = elem.GetWindow()            if size is None: size = elem.GetSize()            w, h = size            if w == -1: w = item.GetBestSize()[0]            if h == -1: h = item.GetBestSize()[1]            newelem = wx.SizerItem()            newelem.SetWindow(item)            newelem.SetFlag(elem.GetFlag())            newelem.SetBorder(elem.GetBorder())            if misc.check_wx_version(2, 5):                newelem.SetProportion(elem.GetProportion())            else:                newelem.SetOption(elem.GetOption())            newelem.SetInitSize(w, h)            self.widget.InsertItem(pos, newelem)            #self.children[pos] = newelem            self.widget.Remove(pos+1)                    if force_layout:            self.layout(True)            #try: self.sizer.Layout()            #except AttributeError: pass    def remove_item(self, elem, force_layout=True):        """\        Removes elem from self.        """        if elem:            for c in self.children[elem.pos+1:]: c.item.pos -= 1            del self.children[elem.pos]        if self.widget and elem.widget:            self.widget.Remove(elem.widget)            if force_layout:                self.layout(True)                #if not self.toplevel: self.sizer.Layout()    Remove = remove_item # maybe this is needed, I have to check...    def layout(self, recursive=True):        #if not self.widget or not self.window.is_visible(): return        if not self.widget: return        from edit_windows import TopLevelBase        if self.toplevel and not isinstance(self.window, TopLevelBase) and \                hasattr(self.window.sizer, 'widget'):            if not self.window.properties['size'].is_active():                szr = self.window.sizer.widget                w, h = self.window.widget.GetBestSize()                szr.SetItemMinSize(self.window.widget, w, h)            if self.window.sizer is not self:                self.window.sizer.layout(False)            else:                szr.Layout()            return        elif self.toplevel and isinstance(self.window, TopLevelBase):            #self.window.widget.Layout()            self.widget.Layout()            evt = wx.SizeEvent(self.window.widget.GetSize(),                              self.window.widget.GetId())            wx.PostEvent(self.window.widget, evt)            # don't change the size of the window            if misc.check_wx_version(2, 4, 1) and \                   not misc.check_wx_version(2, 6, 0):                # this seems to work bad for 2.4.0 (and 2.6 too... 2005-05-01)                self.widget.FitInside(self.window.widget)            return        self.widget.SetMinSize(self.widget.CalcMin())        self.widget.Layout()        for c in self.children:            try:                c.item.widget.Refresh()            except Exception, e: pass        if recursive:            if getattr(self, 'sizer', None) is not None:                self.sizer.layout(recursive)    # 2002-10-09 -------------------------------------------------------------    def change_item_pos(self, item, new_pos, force_layout=True):        """\        Changes the position of the 'item' so that it is at 'new_pos'        'new_pos' must be a valid position        """        if not self.widget: return        #print        

⌨️ 快捷键说明

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