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

📄 notebook.py

📁 用python写的ide开发环境,巨强大,不过需要wxpython的支持
💻 PY
📖 第 1 页 / 共 2 页
字号:
# notebook.py: wxNotebook objects# $Id: notebook.py,v 1.32 2007/08/07 12:15:21 agriggio Exp $## Copyright (c) 2002-2007 Alberto Griggio <agriggio@users.sourceforge.net># License: MIT (see license.txt)# THIS PROGRAM COMES WITH NO WARRANTYimport wximport common, miscfrom tree import Treefrom widget_properties import *from edit_windows import ManagedBase, WindowBasefrom edit_sizers.edit_sizers import Sizer, SizerSlottry:    from panel import EditPanel    _has_panel = Trueexcept ImportError:    _has_panel = Falsedef _ugly_hack_for_win32_notebook_bug(notebook_widget):    """\    The name should say all. The problem is hard to explain, so let me    just illustrate a way to reproduce the bug:    1. create a frame in wxGlade, add a notebook with two pages    2. put a button on the first page, and a text ctrl on the second one    3. save the app    4. exit wxGlade, and comment out the body of this function    5. restart wxGlade and load the previous app    6. Try to click on the button on the first page of the notebook, and see       what happens...    If you don't see what I mean, please drop me an email with your version of    Windows, Python and wxPython, because I really want to understand what's    going on...    So far I've not been able to reproduce the problem on a standalone minimal    app, but as time permits I'll try again... if you succeed, please let me    know.    """    #print '_ugly_hack_for_win32_notebook_bug'    index_ok = notebook_widget.GetSelection()    for i in range(notebook_widget.GetPageCount()):        notebook_widget.GetPage(i).Hide()    notebook_widget.GetPage(index_ok).Show()        class NotebookVirtualSizer(Sizer):    '''\    "Virtual sizer" responsible for the management of the pages of a Notebook.    '''    def __init__(self, *args, **kwds):        Sizer.__init__(self, *args, **kwds)        self._itempos = 0        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.        """        if not self.window.widget:            return        pos -= 1        label, item = self.window.tabs[pos]        if not item or not item.widget:            return        if not (pos < self.window.widget.GetPageCount()):            self.window.widget.AddPage(item.widget, label)        elif self.window.widget.GetPage(pos) is not item.widget:            #self.window.widget.RemovePage(pos)            self.window.widget.DeletePage(pos)            self.window.widget.InsertPage(pos, item.widget, label)            self.window.widget.SetSelection(pos)            try:                misc.wxCallAfter(item.sel_marker.update)            except AttributeError, e:                #print e                pass        if self.window.sizer is not None:            self.window.sizer.set_item(                self.window.pos, size=self.window.widget.GetBestSize())                def add_item(self, item, pos=None, option=0, flag=0, border=0, size=None,                 force_layout=True):        """\        Adds an item to self.window.        """        #print 'pos:', pos, 'item.name:', item.name        self.window.tabs[pos-1][1] = item        item._dont_destroy = True    def free_slot(self, pos, force_layout=True):        """\        Replaces the element at pos with an empty slot        """        if self.window._is_removing_pages or not self.window.widget:            return        slot = SizerSlot(self.window, self, pos)        #print 'free:', slot, slot.pos, pos        slot.show_widget(True)        pos = pos-1        label, item = self.window.tabs[pos]        self.window.widget.RemovePage(pos)        self.window.widget.InsertPage(pos, slot.widget, label)        self.window.widget.SetSelection(pos)        def get_itempos(self, attrs):        """\        Get position of sizer item (used in xml_parse)        """        self._itempos += 1        return self._itempos        def is_virtual(self):        return True# end of class NotebookVirtualSizerclass NotebookPagesProperty(GridProperty):          def write(self, outfile, tabs):        from xml.sax.saxutils import escape, quoteattr        write = outfile.write        write('    ' * tabs + '<tabs>\n')        tab_s = '    ' * (tabs+1)        import widget_properties        value = self.get_value()        for i in range(len(value)):            val = value[i]            v = escape(widget_properties._encode(val[0]))            window = None            try:                t = self.owner.tabs[i]                if t[0] == val[0]: window = t[1]            except: pass            if window:                write('%s<tab window=%s>' % (tab_s, quoteattr(window.name)))                write(v)                write('</tab>\n')        write('    ' * tabs + '</tabs>\n')# end of class NotebookPagesPropertyclass TabsHandler:    def __init__(self, parent):        self.parent = parent        self.tab_names = []        self.curr_tab = []    def start_elem(self, name, attrs):        pass    def end_elem(self, name):        if name == 'tabs':            self.parent.tabs = [[misc.wxstr(name), None] for name in \                                self.tab_names]            self.parent.properties['tabs'].set_value([[name] for name in \                                                      self.tab_names])            return True        elif name == 'tab':            self.tab_names.append("".join(self.curr_tab))            self.curr_tab = []        return False    def char_data(self, data):        self.curr_tab.append(data)# end of class TabsHandlerclass EditNotebook(ManagedBase):    _custom_base_classes = True    events = ['EVT_NOTEBOOK_PAGE_CHANGED', 'EVT_NOTEBOOK_PAGE_CHANGING']        def __init__(self, name, parent, id, style, sizer, pos,                 property_window, show=True):        """\        Class to handle wxNotebook objects        """        ManagedBase.__init__(self, name, 'wxNotebook', parent, id, sizer,                             pos, property_window, show=show)        self.virtual_sizer = NotebookVirtualSizer(self)        self._is_removing_pages = False        self.style = style        self.tabs = [ ['tab1', None] ] # list of pages of this notebook                                       # (actually a list of                                       # 2-list label, window)        self.access_functions['style'] = (self.get_tab_pos, self.set_tab_pos)        self.properties['style'] = HiddenProperty(self, 'style', label=_("style"))        self.access_functions['tabs'] = (self.get_tabs, self.set_tabs)        tab_cols = [('Tab label', GridProperty.STRING)]        self.properties['tabs'] = NotebookPagesProperty(self, 'tabs', None,                                                        tab_cols, label=_("tabs"))        del tab_cols        self.nb_sizer = None        self._create_slots = False        self.no_custom_class = False        self.access_functions['no_custom_class'] = (self.get_no_custom_class,                                                    self.set_no_custom_class)        self.properties['no_custom_class'] = CheckBoxProperty(            self, 'no_custom_class',            label=_("Don't generate code for this custom class"))    def create_widget(self):        self.widget = wx.Notebook(self.parent.widget, self.id, style=self.style)        if not misc.check_wx_version(2, 5, 2):            self.nb_sizer = wx.NotebookSizer(self.widget)    def show_widget(self, yes):        ManagedBase.show_widget(self, yes)        if yes and wx.Platform in ('__WXMSW__', '__WXMAC__'):            misc.wxCallAfter(_ugly_hack_for_win32_notebook_bug, self.widget)        if self._create_slots:

⌨️ 快捷键说明

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