📄 foldpanelbar.py
字号:
self._single = wx.CheckBox(item, -1, "&Only This Caption")
self._pnl.AddFoldPanelWindow(item, self._single, fpb.FPB_ALIGN_WIDTH,
fpb.FPB_DEFAULT_SPACING, 10)
# one more panel to finish it
cs = fpb.CaptionBarStyle()
cs.SetCaptionStyle(fpb.CAPTIONBAR_RECTANGLE)
item = self._pnl.AddFoldPanel("Misc Stuff", collapsed=True, foldIcons=Images,
cbstyle=cs)
button2 = wx.Button(item, wx.NewId(), "Collapse All")
self._pnl.AddFoldPanelWindow(item, button2)
self._pnl.AddFoldPanelWindow(item, wx.StaticText(item, -1, "Enter Some Comments"),
fpb.FPB_ALIGN_WIDTH, 5, 20)
self._pnl.AddFoldPanelWindow(item, wx.TextCtrl(item, -1, "Comments"),
fpb.FPB_ALIGN_WIDTH, fpb.FPB_DEFAULT_SPACING, 10)
button2.Bind(wx.EVT_BUTTON, self.OnCollapseMe)
self.radiocontrols = [currStyle, radio1, radio2, radio3, radio4]
self._leftWindow1.SizeWindows()
def OnCreateBottomStyle(self, event):
# recreate with style collapse to bottom, which means
# all panels that are collapsed are placed at the bottom,
# or normal
if event.IsChecked():
self.GetMenuBar().Check(self._singlestyle, False)
self.GetMenuBar().Check(self._exclusivestyle, False)
self._flags = self._flags & ~fpb.FPB_SINGLE_FOLD
self._flags = self._flags & ~fpb.FPB_EXCLUSIVE_FOLD
self._flags = self._flags | fpb.FPB_COLLAPSE_TO_BOTTOM
else:
self._flags = self._flags & ~fpb.FPB_COLLAPSE_TO_BOTTOM
self.ReCreateFoldPanel(self._flags)
def OnCreateNormalStyle(self, event):
# recreate with style where only one panel at the time is
# allowed to be opened
if event.IsChecked():
self.GetMenuBar().Check(self._bottomstyle, False)
self.GetMenuBar().Check(self._exclusivestyle, False)
self._flags = self._flags & ~fpb.FPB_EXCLUSIVE_FOLD
self._flags = self._flags & ~fpb.FPB_COLLAPSE_TO_BOTTOM
self._flags = self._flags | fpb.FPB_SINGLE_FOLD
else:
self._flags = self._flags & ~fpb.FPB_SINGLE_FOLD
self.ReCreateFoldPanel(self._flags)
def OnCreateExclusiveStyle(self, event):
# recreate with style where only one panel at the time is
# allowed to be opened and the others are collapsed to bottom
if event.IsChecked():
self.GetMenuBar().Check(self._singlestyle, False)
self.GetMenuBar().Check(self._bottomstyle, False)
self._flags = self._flags & ~fpb.FPB_SINGLE_FOLD
self._flags = self._flags & ~fpb.FPB_COLLAPSE_TO_BOTTOM
self._flags = self._flags | fpb.FPB_EXCLUSIVE_FOLD
else:
self._flags = self._flags & ~fpb.FPB_EXCLUSIVE_FOLD
self.ReCreateFoldPanel(self._flags)
def OnCollapseMe(self, event):
for i in range(0, self._pnl.GetCount()):
item = self._pnl.GetFoldPanel(i)
self._pnl.Collapse(item)
def OnExpandMe(self, event):
col1 = wx.Colour(self._rslider1.GetValue(), self._gslider1.GetValue(),
self._bslider1.GetValue())
col2 = wx.Colour(self._rslider2.GetValue(), self._gslider2.GetValue(),
self._bslider2.GetValue())
style = fpb.CaptionBarStyle()
style.SetFirstColour(col1)
style.SetSecondColour(col2)
counter = 0
for items in self.radiocontrols:
if items.GetValue():
break
counter = counter + 1
if counter == 0:
mystyle = fpb.CAPTIONBAR_GRADIENT_V
elif counter == 1:
mystyle = fpb.CAPTIONBAR_GRADIENT_H
elif counter == 2:
mystyle = fpb.CAPTIONBAR_SINGLE
elif counter == 3:
mystyle = fpb.CAPTIONBAR_RECTANGLE
else:
mystyle = fpb.CAPTIONBAR_FILLED_RECTANGLE
style.SetCaptionStyle(mystyle)
self._pnl.ApplyCaptionStyleAll(style)
def OnSlideColour(self, event):
col1 = wx.Colour(self._rslider1.GetValue(), self._gslider1.GetValue(),
self._bslider1.GetValue())
col2 = wx.Colour(self._rslider2.GetValue(), self._gslider2.GetValue(),
self._bslider2.GetValue())
style = fpb.CaptionBarStyle()
counter = 0
for items in self.radiocontrols:
if items.GetValue():
break
counter = counter + 1
if counter == 0:
mystyle = fpb.CAPTIONBAR_GRADIENT_V
elif counter == 1:
mystyle = fpb.CAPTIONBAR_GRADIENT_H
elif counter == 2:
mystyle = fpb.CAPTIONBAR_SINGLE
elif counter == 3:
mystyle = fpb.CAPTIONBAR_RECTANGLE
else:
mystyle = fpb.CAPTIONBAR_FILLED_RECTANGLE
style.SetFirstColour(col1)
style.SetSecondColour(col2)
style.SetCaptionStyle(mystyle)
item = self._pnl.GetFoldPanel(0)
self._pnl.ApplyCaptionStyle(item, style)
def OnStyleChange(self, event):
style = fpb.CaptionBarStyle()
eventid = event.GetId()
if eventid == self.ID_USE_HGRADIENT:
style.SetCaptionStyle(fpb.CAPTIONBAR_GRADIENT_H)
elif eventid == self.ID_USE_VGRADIENT:
style.SetCaptionStyle(fpb.CAPTIONBAR_GRADIENT_V)
elif eventid == self.ID_USE_SINGLE:
style.SetCaptionStyle(fpb.CAPTIONBAR_SINGLE)
elif eventid == self.ID_USE_RECTANGLE:
style.SetCaptionStyle(fpb.CAPTIONBAR_RECTANGLE)
elif eventid == self.ID_USE_FILLED_RECTANGLE:
style.SetCaptionStyle(fpb.CAPTIONBAR_FILLED_RECTANGLE)
else:
raise "ERROR: Undefined Style Selected For CaptionBar: " + repr(eventid)
col1 = wx.Colour(self._rslider1.GetValue(), self._gslider1.GetValue(),
self._bslider1.GetValue())
col2 = wx.Colour(self._rslider2.GetValue(), self._gslider2.GetValue(),
self._bslider2.GetValue())
style.SetFirstColour(col1)
style.SetSecondColour(col2)
if self._single.GetValue():
item = self._pnl.GetFoldPanel(1)
self._pnl.ApplyCaptionStyle(item, style)
else:
self._pnl.ApplyCaptionStyleAll(style)
def CreateMenuBar(self, with_window=False):
# Make a menubar
file_menu = wx.Menu()
FPBTEST_QUIT = wx.NewId()
FPBTEST_REFRESH = wx.NewId()
FPB_BOTTOM_FOLD = wx.NewId()
FPB_SINGLE_FOLD = wx.NewId()
FPB_EXCLUSIVE_FOLD = wx.NewId()
FPBTEST_TOGGLE_WINDOW = wx.NewId()
FPBTEST_ABOUT = wx.NewId()
file_menu.Append(FPBTEST_QUIT, "&Exit")
option_menu = None
if with_window:
# Dummy option
option_menu = wx.Menu()
option_menu.Append(FPBTEST_REFRESH, "&Refresh picture")
# make fold panel menu
fpb_menu = wx.Menu()
fpb_menu.AppendCheckItem(FPB_BOTTOM_FOLD, "Create with &fpb.FPB_COLLAPSE_TO_BOTTOM")
# Now Implemented!
fpb_menu.AppendCheckItem(FPB_SINGLE_FOLD, "Create with &fpb.FPB_SINGLE_FOLD")
# Now Implemented!
fpb_menu.AppendCheckItem(FPB_EXCLUSIVE_FOLD, "Create with &fpb.FPB_EXCLUSIVE_FOLD")
fpb_menu.AppendSeparator()
fpb_menu.Append(FPBTEST_TOGGLE_WINDOW, "&Toggle FoldPanelBar")
help_menu = wx.Menu()
help_menu.Append(FPBTEST_ABOUT, "&About")
menu_bar = wx.MenuBar()
menu_bar.Append(file_menu, "&File")
menu_bar.Append(fpb_menu, "&FoldPanel")
if option_menu:
menu_bar.Append(option_menu, "&Options")
menu_bar.Append(help_menu, "&Help")
self.Bind(wx.EVT_MENU, self.OnAbout, id=FPBTEST_ABOUT)
self.Bind(wx.EVT_MENU, self.OnQuit, id=FPBTEST_QUIT)
self.Bind(wx.EVT_MENU, self.OnToggleWindow, id=FPBTEST_TOGGLE_WINDOW)
self.Bind(wx.EVT_MENU, self.OnCreateBottomStyle, id=FPB_BOTTOM_FOLD)
self.Bind(wx.EVT_MENU, self.OnCreateNormalStyle, id=FPB_SINGLE_FOLD)
self.Bind(wx.EVT_MENU, self.OnCreateExclusiveStyle, id=FPB_EXCLUSIVE_FOLD)
self._bottomstyle = FPB_BOTTOM_FOLD
self._singlestyle = FPB_SINGLE_FOLD
self._exclusivestyle = FPB_EXCLUSIVE_FOLD
return menu_bar
# ----------------------------------------------------------------------------
# Collapsed Demo Implementation
# ----------------------------------------------------------------------------
class FoldTestPanel(wx.Panel):
def __init__(self, parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize,
style=wx.NO_BORDER | wx.TAB_TRAVERSAL):
wx.Panel.__init__(self, parent, id, pos, size, style)
self.CreateControls()
self.GetSizer().Fit(self)
self.GetSizer().SetSizeHints(self)
self.GetSizer().Layout()
self.Bind(fpb.EVT_CAPTIONBAR, self.OnPressCaption)
def OnPressCaption(self, event):
event.Skip()
def CreateControls(self):
sizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(sizer)
subpanel = wx.Panel(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
wx.NO_BORDER | wx.TAB_TRAVERSAL)
sizer.Add(subpanel, 1, wx.GROW | wx.ADJUST_MINSIZE, 5)
subsizer = wx.BoxSizer(wx.VERTICAL)
subpanel.SetSizer(subsizer)
itemstrings = ["One", "Two", "Three"]
item5 = wx.Choice(subpanel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
itemstrings, 0)
subsizer.Add(item5, 0, wx.GROW | wx.ALL, 5)
item6 = wx.TextCtrl(subpanel, wx.ID_ANY, "", wx.DefaultPosition, wx.DefaultSize,
wx.TE_MULTILINE)
subsizer.Add(item6, 1, wx.GROW | wx.ALL, 5)
item7 = wx.RadioButton(subpanel, wx.ID_ANY, "I Like This", wx.DefaultPosition,
wx.DefaultSize, 0)
item7.SetValue(True)
subsizer.Add(item7, 0, wx.ALIGN_LEFT | wx.ALL, 5)
item8 = wx.RadioButton(subpanel, wx.ID_ANY, "I Hate It", wx.DefaultPosition,
wx.DefaultSize, 0)
item8.SetValue(False)
subsizer.Add(item8, 0, wx.ALIGN_LEFT | wx.ALL, 5)
# ----------------------------------------------------------------------------
class Collapsed(wx.Frame):
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -