Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: tabbedpages.py
"""An implementation of tabbed pages using only standard Tkinter.
[0] Fix | Delete
[1] Fix | Delete
Originally developed for use in IDLE. Based on tabpage.py.
[2] Fix | Delete
[3] Fix | Delete
Classes exported:
[4] Fix | Delete
TabbedPageSet -- A Tkinter implementation of a tabbed-page widget.
[5] Fix | Delete
TabSet -- A widget containing tabs (buttons) in one or more rows.
[6] Fix | Delete
[7] Fix | Delete
"""
[8] Fix | Delete
from Tkinter import *
[9] Fix | Delete
[10] Fix | Delete
class InvalidNameError(Exception): pass
[11] Fix | Delete
class AlreadyExistsError(Exception): pass
[12] Fix | Delete
[13] Fix | Delete
[14] Fix | Delete
class TabSet(Frame):
[15] Fix | Delete
"""A widget containing tabs (buttons) in one or more rows.
[16] Fix | Delete
[17] Fix | Delete
Only one tab may be selected at a time.
[18] Fix | Delete
[19] Fix | Delete
"""
[20] Fix | Delete
def __init__(self, page_set, select_command,
[21] Fix | Delete
tabs=None, n_rows=1, max_tabs_per_row=5,
[22] Fix | Delete
expand_tabs=False, **kw):
[23] Fix | Delete
"""Constructor arguments:
[24] Fix | Delete
[25] Fix | Delete
select_command -- A callable which will be called when a tab is
[26] Fix | Delete
selected. It is called with the name of the selected tab as an
[27] Fix | Delete
argument.
[28] Fix | Delete
[29] Fix | Delete
tabs -- A list of strings, the names of the tabs. Should be specified in
[30] Fix | Delete
the desired tab order. The first tab will be the default and first
[31] Fix | Delete
active tab. If tabs is None or empty, the TabSet will be initialized
[32] Fix | Delete
empty.
[33] Fix | Delete
[34] Fix | Delete
n_rows -- Number of rows of tabs to be shown. If n_rows <= 0 or is
[35] Fix | Delete
None, then the number of rows will be decided by TabSet. See
[36] Fix | Delete
_arrange_tabs() for details.
[37] Fix | Delete
[38] Fix | Delete
max_tabs_per_row -- Used for deciding how many rows of tabs are needed,
[39] Fix | Delete
when the number of rows is not constant. See _arrange_tabs() for
[40] Fix | Delete
details.
[41] Fix | Delete
[42] Fix | Delete
"""
[43] Fix | Delete
Frame.__init__(self, page_set, **kw)
[44] Fix | Delete
self.select_command = select_command
[45] Fix | Delete
self.n_rows = n_rows
[46] Fix | Delete
self.max_tabs_per_row = max_tabs_per_row
[47] Fix | Delete
self.expand_tabs = expand_tabs
[48] Fix | Delete
self.page_set = page_set
[49] Fix | Delete
[50] Fix | Delete
self._tabs = {}
[51] Fix | Delete
self._tab2row = {}
[52] Fix | Delete
if tabs:
[53] Fix | Delete
self._tab_names = list(tabs)
[54] Fix | Delete
else:
[55] Fix | Delete
self._tab_names = []
[56] Fix | Delete
self._selected_tab = None
[57] Fix | Delete
self._tab_rows = []
[58] Fix | Delete
[59] Fix | Delete
self.padding_frame = Frame(self, height=2,
[60] Fix | Delete
borderwidth=0, relief=FLAT,
[61] Fix | Delete
background=self.cget('background'))
[62] Fix | Delete
self.padding_frame.pack(side=TOP, fill=X, expand=False)
[63] Fix | Delete
[64] Fix | Delete
self._arrange_tabs()
[65] Fix | Delete
[66] Fix | Delete
def add_tab(self, tab_name):
[67] Fix | Delete
"""Add a new tab with the name given in tab_name."""
[68] Fix | Delete
if not tab_name:
[69] Fix | Delete
raise InvalidNameError("Invalid Tab name: '%s'" % tab_name)
[70] Fix | Delete
if tab_name in self._tab_names:
[71] Fix | Delete
raise AlreadyExistsError("Tab named '%s' already exists" %tab_name)
[72] Fix | Delete
[73] Fix | Delete
self._tab_names.append(tab_name)
[74] Fix | Delete
self._arrange_tabs()
[75] Fix | Delete
[76] Fix | Delete
def remove_tab(self, tab_name):
[77] Fix | Delete
"""Remove the tab named <tab_name>"""
[78] Fix | Delete
if not tab_name in self._tab_names:
[79] Fix | Delete
raise KeyError("No such Tab: '%s" % page_name)
[80] Fix | Delete
[81] Fix | Delete
self._tab_names.remove(tab_name)
[82] Fix | Delete
self._arrange_tabs()
[83] Fix | Delete
[84] Fix | Delete
def set_selected_tab(self, tab_name):
[85] Fix | Delete
"""Show the tab named <tab_name> as the selected one"""
[86] Fix | Delete
if tab_name == self._selected_tab:
[87] Fix | Delete
return
[88] Fix | Delete
if tab_name is not None and tab_name not in self._tabs:
[89] Fix | Delete
raise KeyError("No such Tab: '%s" % page_name)
[90] Fix | Delete
[91] Fix | Delete
# deselect the current selected tab
[92] Fix | Delete
if self._selected_tab is not None:
[93] Fix | Delete
self._tabs[self._selected_tab].set_normal()
[94] Fix | Delete
self._selected_tab = None
[95] Fix | Delete
[96] Fix | Delete
if tab_name is not None:
[97] Fix | Delete
# activate the tab named tab_name
[98] Fix | Delete
self._selected_tab = tab_name
[99] Fix | Delete
tab = self._tabs[tab_name]
[100] Fix | Delete
tab.set_selected()
[101] Fix | Delete
# move the tab row with the selected tab to the bottom
[102] Fix | Delete
tab_row = self._tab2row[tab]
[103] Fix | Delete
tab_row.pack_forget()
[104] Fix | Delete
tab_row.pack(side=TOP, fill=X, expand=0)
[105] Fix | Delete
[106] Fix | Delete
def _add_tab_row(self, tab_names, expand_tabs):
[107] Fix | Delete
if not tab_names:
[108] Fix | Delete
return
[109] Fix | Delete
[110] Fix | Delete
tab_row = Frame(self)
[111] Fix | Delete
tab_row.pack(side=TOP, fill=X, expand=0)
[112] Fix | Delete
self._tab_rows.append(tab_row)
[113] Fix | Delete
[114] Fix | Delete
for tab_name in tab_names:
[115] Fix | Delete
tab = TabSet.TabButton(tab_name, self.select_command,
[116] Fix | Delete
tab_row, self)
[117] Fix | Delete
if expand_tabs:
[118] Fix | Delete
tab.pack(side=LEFT, fill=X, expand=True)
[119] Fix | Delete
else:
[120] Fix | Delete
tab.pack(side=LEFT)
[121] Fix | Delete
self._tabs[tab_name] = tab
[122] Fix | Delete
self._tab2row[tab] = tab_row
[123] Fix | Delete
[124] Fix | Delete
# tab is the last one created in the above loop
[125] Fix | Delete
tab.is_last_in_row = True
[126] Fix | Delete
[127] Fix | Delete
def _reset_tab_rows(self):
[128] Fix | Delete
while self._tab_rows:
[129] Fix | Delete
tab_row = self._tab_rows.pop()
[130] Fix | Delete
tab_row.destroy()
[131] Fix | Delete
self._tab2row = {}
[132] Fix | Delete
[133] Fix | Delete
def _arrange_tabs(self):
[134] Fix | Delete
"""
[135] Fix | Delete
Arrange the tabs in rows, in the order in which they were added.
[136] Fix | Delete
[137] Fix | Delete
If n_rows >= 1, this will be the number of rows used. Otherwise the
[138] Fix | Delete
number of rows will be calculated according to the number of tabs and
[139] Fix | Delete
max_tabs_per_row. In this case, the number of rows may change when
[140] Fix | Delete
adding/removing tabs.
[141] Fix | Delete
[142] Fix | Delete
"""
[143] Fix | Delete
# remove all tabs and rows
[144] Fix | Delete
for tab_name in self._tabs.keys():
[145] Fix | Delete
self._tabs.pop(tab_name).destroy()
[146] Fix | Delete
self._reset_tab_rows()
[147] Fix | Delete
[148] Fix | Delete
if not self._tab_names:
[149] Fix | Delete
return
[150] Fix | Delete
[151] Fix | Delete
if self.n_rows is not None and self.n_rows > 0:
[152] Fix | Delete
n_rows = self.n_rows
[153] Fix | Delete
else:
[154] Fix | Delete
# calculate the required number of rows
[155] Fix | Delete
n_rows = (len(self._tab_names) - 1) // self.max_tabs_per_row + 1
[156] Fix | Delete
[157] Fix | Delete
# not expanding the tabs with more than one row is very ugly
[158] Fix | Delete
expand_tabs = self.expand_tabs or n_rows > 1
[159] Fix | Delete
i = 0 # index in self._tab_names
[160] Fix | Delete
for row_index in xrange(n_rows):
[161] Fix | Delete
# calculate required number of tabs in this row
[162] Fix | Delete
n_tabs = (len(self._tab_names) - i - 1) // (n_rows - row_index) + 1
[163] Fix | Delete
tab_names = self._tab_names[i:i + n_tabs]
[164] Fix | Delete
i += n_tabs
[165] Fix | Delete
self._add_tab_row(tab_names, expand_tabs)
[166] Fix | Delete
[167] Fix | Delete
# re-select selected tab so it is properly displayed
[168] Fix | Delete
selected = self._selected_tab
[169] Fix | Delete
self.set_selected_tab(None)
[170] Fix | Delete
if selected in self._tab_names:
[171] Fix | Delete
self.set_selected_tab(selected)
[172] Fix | Delete
[173] Fix | Delete
class TabButton(Frame):
[174] Fix | Delete
"""A simple tab-like widget."""
[175] Fix | Delete
[176] Fix | Delete
bw = 2 # borderwidth
[177] Fix | Delete
[178] Fix | Delete
def __init__(self, name, select_command, tab_row, tab_set):
[179] Fix | Delete
"""Constructor arguments:
[180] Fix | Delete
[181] Fix | Delete
name -- The tab's name, which will appear in its button.
[182] Fix | Delete
[183] Fix | Delete
select_command -- The command to be called upon selection of the
[184] Fix | Delete
tab. It is called with the tab's name as an argument.
[185] Fix | Delete
[186] Fix | Delete
"""
[187] Fix | Delete
Frame.__init__(self, tab_row, borderwidth=self.bw, relief=RAISED)
[188] Fix | Delete
[189] Fix | Delete
self.name = name
[190] Fix | Delete
self.select_command = select_command
[191] Fix | Delete
self.tab_set = tab_set
[192] Fix | Delete
self.is_last_in_row = False
[193] Fix | Delete
[194] Fix | Delete
self.button = Radiobutton(
[195] Fix | Delete
self, text=name, command=self._select_event,
[196] Fix | Delete
padx=5, pady=1, takefocus=FALSE, indicatoron=FALSE,
[197] Fix | Delete
highlightthickness=0, selectcolor='', borderwidth=0)
[198] Fix | Delete
self.button.pack(side=LEFT, fill=X, expand=True)
[199] Fix | Delete
[200] Fix | Delete
self._init_masks()
[201] Fix | Delete
self.set_normal()
[202] Fix | Delete
[203] Fix | Delete
def _select_event(self, *args):
[204] Fix | Delete
"""Event handler for tab selection.
[205] Fix | Delete
[206] Fix | Delete
With TabbedPageSet, this calls TabbedPageSet.change_page, so that
[207] Fix | Delete
selecting a tab changes the page.
[208] Fix | Delete
[209] Fix | Delete
Note that this does -not- call set_selected -- it will be called by
[210] Fix | Delete
TabSet.set_selected_tab, which should be called when whatever the
[211] Fix | Delete
tabs are related to changes.
[212] Fix | Delete
[213] Fix | Delete
"""
[214] Fix | Delete
self.select_command(self.name)
[215] Fix | Delete
return
[216] Fix | Delete
[217] Fix | Delete
def set_selected(self):
[218] Fix | Delete
"""Assume selected look"""
[219] Fix | Delete
self._place_masks(selected=True)
[220] Fix | Delete
[221] Fix | Delete
def set_normal(self):
[222] Fix | Delete
"""Assume normal look"""
[223] Fix | Delete
self._place_masks(selected=False)
[224] Fix | Delete
[225] Fix | Delete
def _init_masks(self):
[226] Fix | Delete
page_set = self.tab_set.page_set
[227] Fix | Delete
background = page_set.pages_frame.cget('background')
[228] Fix | Delete
# mask replaces the middle of the border with the background color
[229] Fix | Delete
self.mask = Frame(page_set, borderwidth=0, relief=FLAT,
[230] Fix | Delete
background=background)
[231] Fix | Delete
# mskl replaces the bottom-left corner of the border with a normal
[232] Fix | Delete
# left border
[233] Fix | Delete
self.mskl = Frame(page_set, borderwidth=0, relief=FLAT,
[234] Fix | Delete
background=background)
[235] Fix | Delete
self.mskl.ml = Frame(self.mskl, borderwidth=self.bw,
[236] Fix | Delete
relief=RAISED)
[237] Fix | Delete
self.mskl.ml.place(x=0, y=-self.bw,
[238] Fix | Delete
width=2*self.bw, height=self.bw*4)
[239] Fix | Delete
# mskr replaces the bottom-right corner of the border with a normal
[240] Fix | Delete
# right border
[241] Fix | Delete
self.mskr = Frame(page_set, borderwidth=0, relief=FLAT,
[242] Fix | Delete
background=background)
[243] Fix | Delete
self.mskr.mr = Frame(self.mskr, borderwidth=self.bw,
[244] Fix | Delete
relief=RAISED)
[245] Fix | Delete
[246] Fix | Delete
def _place_masks(self, selected=False):
[247] Fix | Delete
height = self.bw
[248] Fix | Delete
if selected:
[249] Fix | Delete
height += self.bw
[250] Fix | Delete
[251] Fix | Delete
self.mask.place(in_=self,
[252] Fix | Delete
relx=0.0, x=0,
[253] Fix | Delete
rely=1.0, y=0,
[254] Fix | Delete
relwidth=1.0, width=0,
[255] Fix | Delete
relheight=0.0, height=height)
[256] Fix | Delete
[257] Fix | Delete
self.mskl.place(in_=self,
[258] Fix | Delete
relx=0.0, x=-self.bw,
[259] Fix | Delete
rely=1.0, y=0,
[260] Fix | Delete
relwidth=0.0, width=self.bw,
[261] Fix | Delete
relheight=0.0, height=height)
[262] Fix | Delete
[263] Fix | Delete
page_set = self.tab_set.page_set
[264] Fix | Delete
if selected and ((not self.is_last_in_row) or
[265] Fix | Delete
(self.winfo_rootx() + self.winfo_width() <
[266] Fix | Delete
page_set.winfo_rootx() + page_set.winfo_width())
[267] Fix | Delete
):
[268] Fix | Delete
# for a selected tab, if its rightmost edge isn't on the
[269] Fix | Delete
# rightmost edge of the page set, the right mask should be one
[270] Fix | Delete
# borderwidth shorter (vertically)
[271] Fix | Delete
height -= self.bw
[272] Fix | Delete
[273] Fix | Delete
self.mskr.place(in_=self,
[274] Fix | Delete
relx=1.0, x=0,
[275] Fix | Delete
rely=1.0, y=0,
[276] Fix | Delete
relwidth=0.0, width=self.bw,
[277] Fix | Delete
relheight=0.0, height=height)
[278] Fix | Delete
[279] Fix | Delete
self.mskr.mr.place(x=-self.bw, y=-self.bw,
[280] Fix | Delete
width=2*self.bw, height=height + self.bw*2)
[281] Fix | Delete
[282] Fix | Delete
# finally, lower the tab set so that all of the frames we just
[283] Fix | Delete
# placed hide it
[284] Fix | Delete
self.tab_set.lower()
[285] Fix | Delete
[286] Fix | Delete
class TabbedPageSet(Frame):
[287] Fix | Delete
"""A Tkinter tabbed-pane widget.
[288] Fix | Delete
[289] Fix | Delete
Constains set of 'pages' (or 'panes') with tabs above for selecting which
[290] Fix | Delete
page is displayed. Only one page will be displayed at a time.
[291] Fix | Delete
[292] Fix | Delete
Pages may be accessed through the 'pages' attribute, which is a dictionary
[293] Fix | Delete
of pages, using the name given as the key. A page is an instance of a
[294] Fix | Delete
subclass of Tk's Frame widget.
[295] Fix | Delete
[296] Fix | Delete
The page widgets will be created (and destroyed when required) by the
[297] Fix | Delete
TabbedPageSet. Do not call the page's pack/place/grid/destroy methods.
[298] Fix | Delete
[299] Fix | Delete
Pages may be added or removed at any time using the add_page() and
[300] Fix | Delete
remove_page() methods.
[301] Fix | Delete
[302] Fix | Delete
"""
[303] Fix | Delete
class Page(object):
[304] Fix | Delete
"""Abstract base class for TabbedPageSet's pages.
[305] Fix | Delete
[306] Fix | Delete
Subclasses must override the _show() and _hide() methods.
[307] Fix | Delete
[308] Fix | Delete
"""
[309] Fix | Delete
uses_grid = False
[310] Fix | Delete
[311] Fix | Delete
def __init__(self, page_set):
[312] Fix | Delete
self.frame = Frame(page_set, borderwidth=2, relief=RAISED)
[313] Fix | Delete
[314] Fix | Delete
def _show(self):
[315] Fix | Delete
raise NotImplementedError
[316] Fix | Delete
[317] Fix | Delete
def _hide(self):
[318] Fix | Delete
raise NotImplementedError
[319] Fix | Delete
[320] Fix | Delete
class PageRemove(Page):
[321] Fix | Delete
"""Page class using the grid placement manager's "remove" mechanism."""
[322] Fix | Delete
uses_grid = True
[323] Fix | Delete
[324] Fix | Delete
def _show(self):
[325] Fix | Delete
self.frame.grid(row=0, column=0, sticky=NSEW)
[326] Fix | Delete
[327] Fix | Delete
def _hide(self):
[328] Fix | Delete
self.frame.grid_remove()
[329] Fix | Delete
[330] Fix | Delete
class PageLift(Page):
[331] Fix | Delete
"""Page class using the grid placement manager's "lift" mechanism."""
[332] Fix | Delete
uses_grid = True
[333] Fix | Delete
[334] Fix | Delete
def __init__(self, page_set):
[335] Fix | Delete
super(TabbedPageSet.PageLift, self).__init__(page_set)
[336] Fix | Delete
self.frame.grid(row=0, column=0, sticky=NSEW)
[337] Fix | Delete
self.frame.lower()
[338] Fix | Delete
[339] Fix | Delete
def _show(self):
[340] Fix | Delete
self.frame.lift()
[341] Fix | Delete
[342] Fix | Delete
def _hide(self):
[343] Fix | Delete
self.frame.lower()
[344] Fix | Delete
[345] Fix | Delete
class PagePackForget(Page):
[346] Fix | Delete
"""Page class using the pack placement manager's "forget" mechanism."""
[347] Fix | Delete
def _show(self):
[348] Fix | Delete
self.frame.pack(fill=BOTH, expand=True)
[349] Fix | Delete
[350] Fix | Delete
def _hide(self):
[351] Fix | Delete
self.frame.pack_forget()
[352] Fix | Delete
[353] Fix | Delete
def __init__(self, parent, page_names=None, page_class=PageLift,
[354] Fix | Delete
n_rows=1, max_tabs_per_row=5, expand_tabs=False,
[355] Fix | Delete
**kw):
[356] Fix | Delete
"""Constructor arguments:
[357] Fix | Delete
[358] Fix | Delete
page_names -- A list of strings, each will be the dictionary key to a
[359] Fix | Delete
page's widget, and the name displayed on the page's tab. Should be
[360] Fix | Delete
specified in the desired page order. The first page will be the default
[361] Fix | Delete
and first active page. If page_names is None or empty, the
[362] Fix | Delete
TabbedPageSet will be initialized empty.
[363] Fix | Delete
[364] Fix | Delete
n_rows, max_tabs_per_row -- Parameters for the TabSet which will
[365] Fix | Delete
manage the tabs. See TabSet's docs for details.
[366] Fix | Delete
[367] Fix | Delete
page_class -- Pages can be shown/hidden using three mechanisms:
[368] Fix | Delete
[369] Fix | Delete
* PageLift - All pages will be rendered one on top of the other. When
[370] Fix | Delete
a page is selected, it will be brought to the top, thus hiding all
[371] Fix | Delete
other pages. Using this method, the TabbedPageSet will not be resized
[372] Fix | Delete
when pages are switched. (It may still be resized when pages are
[373] Fix | Delete
added/removed.)
[374] Fix | Delete
[375] Fix | Delete
* PageRemove - When a page is selected, the currently showing page is
[376] Fix | Delete
hidden, and the new page shown in its place. Using this method, the
[377] Fix | Delete
TabbedPageSet may resize when pages are changed.
[378] Fix | Delete
[379] Fix | Delete
* PagePackForget - This mechanism uses the pack placement manager.
[380] Fix | Delete
When a page is shown it is packed, and when it is hidden it is
[381] Fix | Delete
unpacked (i.e. pack_forget). This mechanism may also cause the
[382] Fix | Delete
TabbedPageSet to resize when the page is changed.
[383] Fix | Delete
[384] Fix | Delete
"""
[385] Fix | Delete
Frame.__init__(self, parent, **kw)
[386] Fix | Delete
[387] Fix | Delete
self.page_class = page_class
[388] Fix | Delete
self.pages = {}
[389] Fix | Delete
self._pages_order = []
[390] Fix | Delete
self._current_page = None
[391] Fix | Delete
self._default_page = None
[392] Fix | Delete
[393] Fix | Delete
self.columnconfigure(0, weight=1)
[394] Fix | Delete
self.rowconfigure(1, weight=1)
[395] Fix | Delete
[396] Fix | Delete
self.pages_frame = Frame(self)
[397] Fix | Delete
self.pages_frame.grid(row=1, column=0, sticky=NSEW)
[398] Fix | Delete
if self.page_class.uses_grid:
[399] Fix | Delete
self.pages_frame.columnconfigure(0, weight=1)
[400] Fix | Delete
self.pages_frame.rowconfigure(0, weight=1)
[401] Fix | Delete
[402] Fix | Delete
# the order of the following commands is important
[403] Fix | Delete
self._tab_set = TabSet(self, self.change_page, n_rows=n_rows,
[404] Fix | Delete
max_tabs_per_row=max_tabs_per_row,
[405] Fix | Delete
expand_tabs=expand_tabs)
[406] Fix | Delete
if page_names:
[407] Fix | Delete
for name in page_names:
[408] Fix | Delete
self.add_page(name)
[409] Fix | Delete
self._tab_set.grid(row=0, column=0, sticky=NSEW)
[410] Fix | Delete
[411] Fix | Delete
self.change_page(self._default_page)
[412] Fix | Delete
[413] Fix | Delete
def add_page(self, page_name):
[414] Fix | Delete
"""Add a new page with the name given in page_name."""
[415] Fix | Delete
if not page_name:
[416] Fix | Delete
raise InvalidNameError("Invalid TabPage name: '%s'" % page_name)
[417] Fix | Delete
if page_name in self.pages:
[418] Fix | Delete
raise AlreadyExistsError(
[419] Fix | Delete
"TabPage named '%s' already exists" % page_name)
[420] Fix | Delete
[421] Fix | Delete
self.pages[page_name] = self.page_class(self.pages_frame)
[422] Fix | Delete
self._pages_order.append(page_name)
[423] Fix | Delete
self._tab_set.add_tab(page_name)
[424] Fix | Delete
[425] Fix | Delete
if len(self.pages) == 1: # adding first page
[426] Fix | Delete
self._default_page = page_name
[427] Fix | Delete
self.change_page(page_name)
[428] Fix | Delete
[429] Fix | Delete
def remove_page(self, page_name):
[430] Fix | Delete
"""Destroy the page whose name is given in page_name."""
[431] Fix | Delete
if not page_name in self.pages:
[432] Fix | Delete
raise KeyError("No such TabPage: '%s" % page_name)
[433] Fix | Delete
[434] Fix | Delete
self._pages_order.remove(page_name)
[435] Fix | Delete
[436] Fix | Delete
# handle removing last remaining, default, or currently shown page
[437] Fix | Delete
if len(self._pages_order) > 0:
[438] Fix | Delete
if page_name == self._default_page:
[439] Fix | Delete
# set a new default page
[440] Fix | Delete
self._default_page = self._pages_order[0]
[441] Fix | Delete
else:
[442] Fix | Delete
self._default_page = None
[443] Fix | Delete
[444] Fix | Delete
if page_name == self._current_page:
[445] Fix | Delete
self.change_page(self._default_page)
[446] Fix | Delete
[447] Fix | Delete
self._tab_set.remove_tab(page_name)
[448] Fix | Delete
page = self.pages.pop(page_name)
[449] Fix | Delete
page.frame.destroy()
[450] Fix | Delete
[451] Fix | Delete
def change_page(self, page_name):
[452] Fix | Delete
"""Show the page whose name is given in page_name."""
[453] Fix | Delete
if self._current_page == page_name:
[454] Fix | Delete
return
[455] Fix | Delete
if page_name is not None and page_name not in self.pages:
[456] Fix | Delete
raise KeyError("No such TabPage: '%s'" % page_name)
[457] Fix | Delete
[458] Fix | Delete
if self._current_page is not None:
[459] Fix | Delete
self.pages[self._current_page]._hide()
[460] Fix | Delete
self._current_page = None
[461] Fix | Delete
[462] Fix | Delete
if page_name is not None:
[463] Fix | Delete
self._current_page = page_name
[464] Fix | Delete
self.pages[page_name]._show()
[465] Fix | Delete
[466] Fix | Delete
self._tab_set.set_selected_tab(page_name)
[467] Fix | Delete
[468] Fix | Delete
def _tabbed_pages(parent):
[469] Fix | Delete
# test dialog
[470] Fix | Delete
root=Tk()
[471] Fix | Delete
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
[472] Fix | Delete
root.geometry("+%d+%d"%(x, y + 175))
[473] Fix | Delete
root.title("Test tabbed pages")
[474] Fix | Delete
tabPage=TabbedPageSet(root, page_names=['Foobar','Baz'], n_rows=0,
[475] Fix | Delete
expand_tabs=False,
[476] Fix | Delete
)
[477] Fix | Delete
tabPage.pack(side=TOP, expand=TRUE, fill=BOTH)
[478] Fix | Delete
Label(tabPage.pages['Foobar'].frame, text='Foo', pady=20).pack()
[479] Fix | Delete
Label(tabPage.pages['Foobar'].frame, text='Bar', pady=20).pack()
[480] Fix | Delete
Label(tabPage.pages['Baz'].frame, text='Baz').pack()
[481] Fix | Delete
entryPgName=Entry(root)
[482] Fix | Delete
buttonAdd=Button(root, text='Add Page',
[483] Fix | Delete
command=lambda:tabPage.add_page(entryPgName.get()))
[484] Fix | Delete
buttonRemove=Button(root, text='Remove Page',
[485] Fix | Delete
command=lambda:tabPage.remove_page(entryPgName.get()))
[486] Fix | Delete
labelPgName=Label(root, text='name of page to add/remove:')
[487] Fix | Delete
buttonAdd.pack(padx=5, pady=5)
[488] Fix | Delete
buttonRemove.pack(padx=5, pady=5)
[489] Fix | Delete
labelPgName.pack(padx=5)
[490] Fix | Delete
entryPgName.pack(padx=5)
[491] Fix | Delete
root.mainloop()
[492] Fix | Delete
[493] Fix | Delete
[494] Fix | Delete
if __name__ == '__main__':
[495] Fix | Delete
from idlelib.idle_test.htest import run
[496] Fix | Delete
run(_tabbed_pages)
[497] Fix | Delete
[498] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function