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

📄 edit_sizers.py

📁 用python写的ide开发环境,巨强大,不过需要wxpython的支持
💻 PY
📖 第 1 页 / 共 5 页
字号:
        old_pos = item.pos        import copy        new_item = copy.copy(self.children[old_pos])        if old_pos > new_pos:            for c in self.children[new_pos:old_pos]:                c.item.update_pos(c.item.pos + 1)            self.children.insert(new_pos, new_item)            del self.children[old_pos+1]        else:            for c in self.children[old_pos+1:new_pos+1]:                c.item.update_pos(c.item.pos - 1)            del self.children[old_pos]            #self.children.insert(new_pos+1, new_item)            self.children.insert(new_pos, new_item)        item.update_pos(new_pos)        elem = self.widget.GetChildren()[old_pos]        # always set the sizer to None because otherwise it will be Destroy'd        elem.SetSizer(None)        # this fake_win trick seems necessary because wxSizer::Remove(int pos)        # doesn't seem to work with grid sizers :-\        fake_win = wx.Window(self.window.widget, -1)        elem.SetWindow(fake_win)        self.widget.Remove(fake_win)        fake_win.Destroy()        self.widget.Insert(new_pos, item.widget, int(item.get_option()),                           item.get_int_flag(), int(item.get_border()))        common.app_tree.change_node_pos(item.node, new_pos-1)        common.app_tree.select_item(item.node)        if force_layout:            self.layout()            if wx.Platform == '__WXMSW__': self.window.widget.Refresh()        #print [c.item.name for c in self.children]    # ------------------------------------------------------------------------    def set_option(self, value):        """\        If self is not a toplevel sizer, update the layout to reflect the value        of the option property        """        self.option = int(value)        try:            self.sizer.set_item(self.pos, option=self.option)            #print self.name, 'set_option', self.option        except AttributeError, e: pass        self.finish_set()    def set_flag(self, value):        """\        If self is not a toplevel sizer, update the layout to reflect the        value of the flag property        """        value = self.sizer_properties['flag'].prepare_value(value)        flags = 0        for v in range(len(value)):            if value[v]:                flags |= self.flags_pos[v]        self.flag = flags        try: self.sizer.set_item(self.pos, flag=flags)        except AttributeError, e: pass        self.finish_set()    def set_border(self, value):        """\        If self is not a toplevel sizer, update the layout to reflect        value of the border property        """        self.border = int(value)        try: self.sizer.set_item(self.pos, border=self.border)        except AttributeError, e: print e    def get_option(self):        if not hasattr(self, 'sizer'): return '1'        return str(self.option)    def get_flag(self):        retval = [0] * len(self.flags_pos)        if not hasattr(self, 'sizer'): return retval        try:            flag = self.flag            for i in range(len(self.flags_pos)):                if flag & self.flags_pos[i]: retval[i] = 1            # patch to make wxALL work            if retval[1:5] == [1, 1, 1, 1]:                retval[0] = 1; retval[1:5] = [0, 0, 0, 0]            else:                retval[0] = 0        except AttributeError: pass        return retval    def get_int_flag(self):        try: return self.flag        except AttributeError: return wx.EXPAND    def get_border(self):        if not hasattr(self, 'sizer'): return '0'        return str(self.border)    def remove(self):        # this function is here for clipboard compatibility        if not self._btn: return        self._btn._remove()    def delete(self):        """\        ``Destructor''        """        self._rmenu = None        if self._btn: self._btn.Destroy()        if self.notebook:##             for p in self.properties.itervalues():##                 if p.panel: p.panel.Destroy()##             if self.name_prop.panel: self.name_prop.panel.Destroy()##             if self.klass_prop.panel: self.klass_prop.panel.Destroy()##             if hasattr(self, 'sizer_properties'):##                 for p in self.sizer_properties.itervalues():##                     if p.panel: p.panel.Destroy()            nb_szr = self.notebook.sizer            self.notebook.DeleteAllPages()            self.notebook.Destroy()            if nb_szr is not None: nb_szr.Destroy()        for c in self.children:            if c.item and isinstance(c.item, SizerSlot): c.item.delete()        if self.toplevel:            self.window.set_sizer(None)    if wx.Platform == '__WXMSW__':        def finish_set(self):            for c in self.children:                if c.item.widget:                    try: c.item.widget.Refresh()                    except AttributeError: pass # sizers have no Refresh    else:        def finish_set(self): pass    def refresh(self, *args):        # this will be self.widget.Refresh        for c in self.children:            if c.item.widget:                 try: c.item.widget.Refresh()                except AttributeError: pass    def update_view(self, selected):        if self._btn is not None:            color = wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE)            if selected:                color = wx.RED            self._btn.SetBackgroundColour(color)            self._btn.Refresh(True)    def add_slot(self, *args, **kwds):        """\        adds a slot to the sizer, i.e. a fake window that will accept the        dropping of widgets        """        tmp = SizerSlot(self.window, self, len(self.children))        item = SizerItem(tmp, len(self.children), 1, wx.EXPAND)        self.children.append(item)        if not self.widget: return        tmp.show_widget(True) # create the actual SizerSlot widget        self.widget.Add(tmp.widget, 1, wx.EXPAND)        self.widget.SetItemMinSize(tmp.widget, 20, 20)        force_layout = kwds.get('force_layout', True)        if force_layout: self.layout(True)        common.app_tree.app.saved = False    def insert_slot(self, *args, **kwds):        """\        inserts a slot into the sizer: the user will be asked for a position        before which to insert the SizerSlot object. This method is meaningful        only in an interactive session        """        if not self.widget: return        dialog = InsertDialog(len(self.children)-1)        if dialog.ShowModal() == wx.ID_OK:            pos = dialog.pos + 1            tmp = SizerSlot(self.window, self, pos)            for c in self.children[pos:]:                c.item.pos += 1            self.children.insert(pos, SizerItem(tmp, pos, 1, wx.EXPAND, 0))            tmp.show_widget(True) # create the actual SizerSlot            self.widget.Insert(pos, tmp.widget, 1, wx.EXPAND)            self.widget.SetItemMinSize(tmp.widget, 20, 20)            force_layout = kwds.get('force_layout', True)            if force_layout: self.layout(True)            common.app_tree.app.saved = False        dialog.Destroy()    def free_slot(self, pos, force_layout=True):        """\        Replaces the element at pos with an empty slot        """        tmp = SizerSlot(self.window, self, pos)        item = SizerItem(tmp, pos, 1, wx.EXPAND, 0)        self.children[pos] = item        if self.widget:            tmp.show_widget(True) # create the actual SizerSlot            if misc.check_wx_version(2, 6):                self.widget.Insert(pos+1, tmp.widget, 1, wx.EXPAND)                self.widget.Detach(pos)            else:                elem = self.widget.GetChildren()[pos]                elem.SetWindow(tmp.widget)                elem.SetSizer(None)                if not misc.check_wx_version(2, 5):                    elem.SetOption(1)                else:                    elem.SetProportion(1)                elem.SetBorder(0)                elem.SetFlag(wx.EXPAND)            if force_layout: self.layout()    def is_visible(self):        return self.window.is_visible()                def clipboard_copy(self, *args):        """\        returns a copy of self to be inserted in the clipboard        """        #if not self.toplevel:        import clipboard        clipboard.copy(self)    def clipboard_cut(self, *args):        #if not self.toplevel:        import clipboard        clipboard.cut(self)    def post_load(self):        """\        Called after the loading of an app from an XML file, before showing        the hierarchy of widget for the first time.         This is used only for container widgets, to adjust their size        appropriately.        """        if not self.toplevel: return        if not self.window.properties['size'].is_active():            self.fit_parent()            import config            w, h = self.widget.GetSize()            prefix = ''            if config.preferences.use_dialog_units:                w, h = self.window.widget.ConvertPixelSizeToDialog(                    self.widget.GetSize())                prefix = 'd'            self.window.set_size('%s, %s%s' % (w, h, prefix))# end of class SizerBaseclass wxGladeBoxSizer(wx.BoxSizer):    def SetItemMinSize(self, item, w, h):        try:            w2, h2 = item.GetBestSize()            if w == -1: w = w2            if h == -1: h = h2        except AttributeError:            pass        wx.BoxSizer.SetItemMinSize(self, item, w, h)# end of class wxGladeBoxSizerclass EditBoxSizer(SizerBase):    """\    Class to handle wxBoxSizer objects    """    def __init__(self, name, window, orient=wx.VERTICAL, elements=3,                 toplevel=True, show=True):        SizerBase.__init__(self, name, 'wxBoxSizer', window, toplevel, show)        self.access_functions['orient'] = (self.get_orient, self.set_orient)        self.properties = {'orient': HiddenProperty(self, 'orient',                                                    (orient==wx.HORIZONTAL and                                                     'wxHORIZONTAL' or                                                     'wxVERTICAL')) }        class Dummy:            widget = None            name = ""        # add to self.children the SizerItem for self._btn        self.children = [SizerItem(Dummy(), 0, 0, wx.EXPAND)]        for i in range(1, elements+1):            tmp = SizerSlot(self.window, self, i)            self.children.append(SizerItem(tmp, i, 1, wx.EXPAND))                self.orient = orient    def create_widget(self):        self.widget = wxGladeBoxSizer(self.orient)        self.widget.Add(self._btn, 0, wx.EXPAND)        to_lay_out = []        for c in self.children[1:]: # we've already added self._btn            c.item.show_widget(True)            if isinstance(c.item, SizerSlot):                self.widget.Add(c.item.widget, 1, wx.EXPAND)                self.widget.SetItemMinSize(c.item.widget, 20, 20)            else:                sp = c.item.properties.get('size')                if sp and sp.is_active():                    if (c.option != 0 or (c.flag & wx.EXPAND)) and \                           (misc.check_wx_version(2, 4) or \                            not (c.flag & wx.FIXED_MINSIZE)):                        c.item.widget.Layout()                        w, h = c.item.widget.GetBestSize()                        if misc.check_wx_version(2, 5):                            #print "HERE:", w, h                            c.item.widget.SetMinSize((w, h))                    else:##                     if misc.check_wx_version(2, 4) or \##                            ((c.flag & wxFIXED_MINSIZE) and \##                             (c.option == 0 or not (c.flag & wxEXPAND))):                        size = sp.get_value().strip()                        if size[-1] == 'd':                            size = size[:-1]                            use_dialog_units = True                        else: use_dialog_units = False                        w, h = [ int(v) for v in size.split(',') ]                        if use_dialog_units:                            w, h = wx.DLG_SZE(c.item.widget, (w, h))##                     else:##                         w, h = c.item.widget.GetBestSize()                        # now re-set the item to update the size correctly...                        to_lay_out.append((c.item.pos, (w, h)))##                 else:##                     w, h = c.item.widget.GetBestSize()##                 self.widget.SetItemMinSize(c.item.widget, w, h)        for pos, size in to_lay_out:            self.set_item(pos, size=size, force_layout=False)        self.layout(True)        if not self.toplevel and getattr(self, 'sizer'):            # hasattr(self, 'sizer') is False only in case of a 'change_sizer'            # call            self.sizer.add_item(self, self.pos, self.option, self.flag,                                self.border, self.widget.GetMinSize())    def get_orient(self):        od = { wx.HORIZONTAL: 'wxHORIZONTAL',

⌨️ 快捷键说明

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