- last one from me for the work Metallicow has done

- adding a few demos
- moved demo list and image list to external module
This commit is contained in:
Werner F Bruhin
2014-01-29 15:53:40 +01:00
committed by Robin Dunn
parent a1492d304b
commit 4c45ee11db
11 changed files with 1144 additions and 273 deletions

115
demo/FileCtrl.py Normal file
View File

@@ -0,0 +1,115 @@
#!/usr/bin/env python
import wx
#---------------------------------------------------------------------------
class FileCtrl(wx.FileCtrl):
def __init__(self, parent, id=wx.ID_ANY, defaultDirectory="",
defaultFilename="",
wildCard=wx.FileSelectorDefaultWildcardStr,
style=wx.FC_DEFAULT_STYLE,
# | wx.FC_OPEN
# | wx.FC_SAVE
# | wx.FC_MULTIPLE
# | wx.FC_NOSHOWHIDDEN
pos=wx.DefaultPosition, size=wx.DefaultSize, name="filectrl"):
wx.FileCtrl.__init__(self, parent, id, defaultDirectory, defaultFilename,
wildCard, style, pos, size, name)
self.Bind(wx.EVT_FILECTRL_FILEACTIVATED, self.OnFileActivated)
self.Bind(wx.EVT_FILECTRL_SELECTIONCHANGED, self.OnSelectionChanged)
self.Bind(wx.EVT_FILECTRL_FOLDERCHANGED, self.OnFolderChanged)
self.Bind(wx.EVT_FILECTRL_FILTERCHANGED, self.OnFilterChanged)
def OnFileActivated(self, event):
self.GetGrandParent().SetStatusText('File Activated: %s' % self.GetFilename())
def OnSelectionChanged(self, event):
self.GetGrandParent().SetStatusText('Selection Changed: %s' % self.GetPath())
def OnFolderChanged(self, event):
self.GetGrandParent().SetStatusText('Directory Changed: %s' % self.GetDirectory())
def OnFilterChanged(self, event):
self.GetGrandParent().SetStatusText('Filter Changed: %s' % self.GetFilterIndex())
class MyFrame(wx.Frame):
def __init__(self, parent, id, title, pos=wx.DefaultPosition,
size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE):
wx.Frame.__init__(self, parent, id, title, pos, size, style)
self.CreateStatusBar()
panel = wx.Panel(self)
fc = FileCtrl(panel)
vsizer = wx.BoxSizer(wx.VERTICAL)
vsizer.Add(fc, 1, wx.EXPAND | wx.ALL, 0)
panel.SetSizer(vsizer)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
def OnCloseWindow(self, event):
self.Destroy()
#---------------------------------------------------------------------------
class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent)
b = wx.Button(self, -1, "Create and Show a FileCtrl")
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
def OnButton(self, evt):
win = MyFrame(self, -1, "This is a wx.FileCtrl",
style=wx.DEFAULT_FRAME_STYLE)
win.Show(True)
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
#---------------------------------------------------------------------------
overview = """\
This control allows the user to select a file.
Two implementations of this class exist, one for Gtk and another
generic one for all the other ports.
This class is only available if USE_FILECTRL is set to 1.
------------------------------------------------------------------
Window Styles
FileCtrl supports the following styles:
* FC_DEFAULT_STYLE: The default style: FC_OPEN
* FC_OPEN: Creates an file control suitable for opening files. Cannot be combined with FC_SAVE.
* FC_SAVE: Creates an file control suitable for saving files. Cannot be combined with FC_OPEN.
* FC_MULTIPLE: For open control only, Allows selecting multiple files. Cannot be combined with FC_SAVE
* FC_NOSHOWHIDDEN: Hides the "Show Hidden Files" checkbox (Generic only)
Events
* EVT_FILECTRL_FILEACTIVATED: The user activated a file(by double-clicking or pressing Enter)
* EVT_FILECTRL_SELECTIONCHANGED: The user changed the current selection(by selecting or deselecting a file)
* EVT_FILECTRL_FOLDERCHANGED: The current folder of the file control has been changed
* EVT_FILECTRL_FILTERCHANGED: The current file filter of the file control has been changed.
"""
if __name__ == '__main__':
import sys
import os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])

View File

@@ -91,279 +91,8 @@ DEFAULT_PERSPECTIVE = "Default Perspective"
#---------------------------------------------------------------------------
_demoPngs = ["overview", "recent", "frame", "dialog", "moredialog", "core",
"book", "customcontrol", "morecontrols", "layout", "process",
"clipboard", "images", "miscellaneous"]
_treeList = [
# new stuff
('Recent Additions/Updates', [
'BannerWindow',
'RichToolTip',
'NotificationMessage',
'PropertyGrid',
'SystemSettings',
'GridLabelRenderer',
'InfoBar',
'WrapSizer',
'UIActionSimulator',
'GraphicsGradient',
'PDFViewer',
'ItemsPicker',
'CommandLinkButton',
'DVC_DataViewModel',
'DVC_IndexListModel',
'DVC_ListCtrl',
'DVC_TreeCtrl',
'DVC_CustomRenderer',
'PenAndBrushStyles',
'HTML2_WebView',
]),
# managed windows == things with a (optional) caption you can close
('Frames and Dialogs', [
'AUI_DockingWindowMgr',
'AUI_MDI',
'Dialog',
'Frame',
'MDIWindows',
'MiniFrame',
'Wizard',
]),
# the common dialogs
('Common Dialogs', [
'AboutBox',
'ColourDialog',
'DirDialog',
'FileDialog',
'FindReplaceDialog',
'FontDialog',
'MessageDialog',
'MultiChoiceDialog',
'PageSetupDialog',
'PrintDialog',
'ProgressDialog',
'SingleChoiceDialog',
'TextEntryDialog',
]),
# dialogs from libraries
('More Dialogs', [
'ImageBrowser',
'ScrolledMessageDialog',
]),
# core controls
('Core Windows/Controls', [
'BitmapButton',
'Button',
'CheckBox',
'CheckListBox',
'Choice',
'ComboBox',
'CommandLinkButton',
'DVC_CustomRenderer',
'DVC_DataViewModel',
'DVC_IndexListModel',
'DVC_ListCtrl',
'DVC_TreeCtrl',
'Gauge',
'Grid',
'Grid_MegaExample',
'GridLabelRenderer',
'ListBox',
'ListCtrl',
'ListCtrl_virtual',
'ListCtrl_edit',
'Menu',
'PopupMenu',
'PopupWindow',
'RadioBox',
'RadioButton',
'SashWindow',
'ScrolledWindow',
'SearchCtrl',
'Slider',
'SpinButton',
'SpinCtrl',
'SpinCtrlDouble',
'SplitterWindow',
'StaticBitmap',
'StaticBox',
'StaticText',
'StatusBar',
'StockButtons',
'TextCtrl',
'ToggleButton',
'ToolBar',
'TreeCtrl',
'Validator',
]),
('"Book" Controls', [
'AUI_Notebook',
'Choicebook',
'FlatNotebook',
'Listbook',
'Notebook',
'Toolbook',
'Treebook',
]),
('Custom Controls', [
'AnalogClock',
'ColourSelect',
'ComboTreeBox',
'Editor',
'GenericButtons',
'GenericDirCtrl',
'ItemsPicker',
'LEDNumberCtrl',
'MultiSash',
'PlateButton',
'PopupControl',
'PyColourChooser',
'TreeListCtrl',
]),
# controls coming from other libraries
('More Windows/Controls', [
'ActiveX_FlashWindow',
'ActiveX_IEHtmlWindow',
'ActiveX_PDFWindow',
'BitmapComboBox',
'Calendar',
'CalendarCtrl',
'CheckListCtrlMixin',
'CollapsiblePane',
'ComboCtrl',
'ContextHelp',
'DatePickerCtrl',
'DynamicSashWindow',
'EditableListBox',
'ExpandoTextCtrl',
'FancyText',
'FileBrowseButton',
'FloatBar',
'FloatCanvas',
'HtmlWindow',
'HTML2_WebView',
'InfoBar',
'IntCtrl',
'MVCTree',
'MaskedEditControls',
'MaskedNumCtrl',
'MediaCtrl',
'MultiSplitterWindow',
'OwnerDrawnComboBox',
'Pickers',
'PropertyGrid',
'PyCrust',
'PyPlot',
'PyShell',
'ResizeWidget',
'RichTextCtrl',
'ScrolledPanel',
'SplitTree',
'StyledTextCtrl_1',
'StyledTextCtrl_2',
'TablePrint',
'Throbber',
'Ticker',
'TimeCtrl',
'TreeMixin',
'VListBox',
]),
# How to lay out the controls in a frame/dialog
('Window Layout', [
'GridBagSizer',
'LayoutAnchors',
'LayoutConstraints',
'Layoutf',
'RowColSizer',
'ScrolledPanel',
'SizedControls',
'Sizers',
'WrapSizer',
'XmlResource',
'XmlResourceHandler',
'XmlResourceSubclass',
]),
# ditto
('Process and Events', [
'DelayedResult',
'EventManager',
'KeyEvents',
'Process',
'PythonEvents',
'Threads',
'Timer',
##'infoframe', # needs better explanation and some fixing
]),
# Clipboard and DnD
('Clipboard and DnD', [
'CustomDragAndDrop',
'DragAndDrop',
'URLDragAndDrop',
]),
# Images
('Using Images', [
'AdjustChannels',
'AlphaDrawing',
'AnimateCtrl',
'ArtProvider',
'BitmapFromBuffer',
'Cursor',
'DragImage',
'Image',
'ImageAlpha',
'ImageFromStream',
'Img2PyArtProvider',
'Mask',
'RawBitmapAccess',
'Throbber',
]),
# Other stuff
('Miscellaneous', [
'AlphaDrawing',
'Cairo',
'Cairo_Snippets',
'ColourDB',
##'DialogUnits', # needs more explanations
'DragScroller',
'DrawXXXList',
'FileHistory',
'FontEnumerator',
'GraphicsContext',
'GraphicsGradient',
'GLCanvas',
'I18N',
'Joystick',
'MimeTypesManager',
'MouseGestures',
'OGL',
'PDFViewer',
'PenAndBrushStyles',
'PrintFramework',
'PseudoDC',
'RendererNative',
'ShapedWindow',
'Sound',
'StandardPaths',
'SystemSettings',
'UIActionSimulator',
'Unicode',
]),
('Check out the samples dir too', [] ),
]
# get images and demo list
from main_globals import _demoPngs, _treeList
#---------------------------------------------------------------------------

151
demo/MouseState.py Normal file
View File

@@ -0,0 +1,151 @@
#!/usr/bin/env python
import wx
import wx.stc as stc
demoText = """\
wx.MouseState
In this demo we will replicate the styled text ctrl's mousewheel functionality
and also show how to add a new feature...
Drum roll please.
Shift+MouseWheel = Horizontal Scrolling
Alt+MouseWheel = Hyper Scrolling
ba dump dump chshshshshshshsh%s
bada-boom! ...
...
..
%s
%s
""" % ('sh' * 300, '.\n' * 50, ('Hyper Scroll or Horizontal Scroll... ' * 50 + '\n') * 300)
class MySTC(stc.StyledTextCtrl):
def __init__(self, parent, id, log):
stc.StyledTextCtrl.__init__(self, parent, id)
self.log = log
self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel)
def OnMouseWheel(self, event):
"""
wx.EVT_MOUSEWHEEL
Allow Shift + MouseWheel Horizontal Scrolling
"""
xoffset = self.GetXOffset()
wr = event.GetWheelRotation()
ms = wx.GetMouseState()
ctrlDown = ms.ControlDown()
shiftDown = ms.ShiftDown()
altDown = ms.AltDown()
print('GetWheelRotation: ', wr)
#negative/down Ex: -120
#positive/up Ex: 120
# print('GetWheelDelta: ', event.GetWheelDelta())
# print('GetXOffset: ', xoffset)
if xoffset < 0: # Dont scroll back past zero position
self.SetXOffset(0)
self.Refresh()
return
#-- Alt + MouseWheel = Hyper Scrolling Vertically
#Imitate hyperscrolling functionality with a clickwheel only style mouse
if altDown and wr < 0 and not shiftDown and not ctrlDown:
while wx.GetKeyState(wx.WXK_ALT):
wx.MilliSleep(1)
self.LineScroll(0, 1)
# print('Alt + WheelDown')
return
elif altDown and wr > 0 and not shiftDown and not ctrlDown:
while wx.GetKeyState(wx.WXK_ALT):
wx.MilliSleep(1)
self.LineScroll(0, -1)
# print('Alt + WheelUp')
return
#-- Shift + MouseWheel = Scroll Horizontally
if shiftDown and wr < 0 and not altDown and not ctrlDown:
self.SetXOffset(xoffset + 30)
# print('Shift + WheelDown')
return
elif shiftDown and wr > 0 and not altDown and not ctrlDown:
if not xoffset <= 0:
self.SetXOffset(xoffset - 30)
# print('Shift + WheelUp')
return
else:
return
#-- Ctrl + MouseWheel = Zoom
# Duplicate Default stc ctrl zooming behavior to bypass
# (MouseWheel not working after a undetermined amount of time)BUG
if ctrlDown and wr < 0 and not altDown and not shiftDown:
self.SetZoom(self.GetZoom() - 1)
# print('Ctrl + WheelDown')
return
elif ctrlDown and wr > 0 and not altDown and not shiftDown:
self.SetZoom(self.GetZoom() + 1)
# print('Ctrl + WheelUp')
return
#-- MouseWheel = Scroll Vertically
# Duplicate Default stc scrolling behavior to bypass
# (MouseWheel not working after a undetermined amount of time)BUG
elif wr < 0:
self.LineScroll(0, 3)
# print('WheelDown')
return
elif wr > 0:
self.LineScroll(0, -3)
# print('WheelUp')
return
#----------------------------------------------------------------------
_USE_PANEL = 1
def runTest(frame, nb, log):
if not _USE_PANEL:
ed = p = MySTC(nb, -1, log)
else:
p = wx.Panel(nb, -1, style=wx.NO_FULL_REPAINT_ON_RESIZE)
ed = MySTC(p, -1, log)
s = wx.BoxSizer(wx.HORIZONTAL)
s.Add(ed, 1, wx.EXPAND)
p.SetSizer(s)
p.SetAutoLayout(True)
ed.SetText(demoText)
ed.EmptyUndoBuffer()
return p
#----------------------------------------------------------------------
overview = """\
wx.MouseState
Represents the mouse state.
This class is used as a base class by MouseEvent and so its
methods may be used to obtain information about the mouse state
for the mouse events. It also inherits from KeyboardState and so
carries information about the keyboard state and not only the mouse one.
"""
if __name__ == '__main__':
import sys
import os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])

187
demo/Overlay.py Normal file
View File

@@ -0,0 +1,187 @@
#!/usr/bin/env python
from collections import OrderedDict
import wx
#---------------------------------------------------------------------------
class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent, wx.ID_ANY, style=wx.CLIP_CHILDREN)
## self.SetDoubleBuffered(True)
self.background = wx.Brush(self.GetBackgroundColour())
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_SIZE, self.OnSize)
#--Rubberband Overlay
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
self.Bind(wx.EVT_MOTION, self.OnMouseMove)
self.startPos = None
self.endPos = None
self.overlay = wx.Overlay()
self.cropbitmap = wx.Bitmap('bitmaps/cropshot24x20.png', wx.BITMAP_TYPE_PNG)
self.wxPenStylesDict = OrderedDict([
('Solid' , wx.PENSTYLE_SOLID),
('Dot' , wx.PENSTYLE_DOT),
('Long Dash' , wx.PENSTYLE_LONG_DASH),
('Short Dash' , wx.PENSTYLE_SHORT_DASH),
('Dot Dash' , wx.PENSTYLE_DOT_DASH),
('User Dash' , wx.PENSTYLE_USER_DASH),
('Transparent' , wx.PENSTYLE_TRANSPARENT),
('Stipple' , wx.PENSTYLE_STIPPLE),
('BDiagonal Hatch' , wx.PENSTYLE_BDIAGONAL_HATCH),
('CrossDiag Hatch' , wx.PENSTYLE_CROSSDIAG_HATCH),
('FDiagonal Hatch' , wx.PENSTYLE_FDIAGONAL_HATCH),
('Cross Hatch' , wx.PENSTYLE_CROSS_HATCH),
('Horizontal Hatch' , wx.PENSTYLE_HORIZONTAL_HATCH),
('Vertical Hatch' , wx.PENSTYLE_VERTICAL_HATCH),
('First Hatch' , wx.PENSTYLE_FIRST_HATCH),
('Last Hatch' , wx.PENSTYLE_LAST_HATCH),
])
list = []
for key, value in self.wxPenStylesDict.items():
list.append(key)
self.penstylesCombo = wx.ComboBox(self, -1, choices=list,
pos=(10, 5), size=(100, -1),
style=wx.CB_READONLY)
self.penstylesCombo.SetSelection(0)
self.penstylesCombo.SetToolTip('Pen Style')
self.overlayPenWidth = wx.SpinCtrl(self, -1, value='',
pos=(120, 5),
size=(100, -1),
style=wx.SP_ARROW_KEYS,
min=1, max=24, initial=1)
self.overlayPenWidth.SetToolTip('Pen Width')
self.overlayPenColor = wx.ColourPickerCtrl(self, -1, colour=wx.BLUE,
pos=(230, 5), size=(100, -1))
self.overlayPenColor.SetToolTip('Pen Color')
self.OnSize()
def OnLeftDown(self, event):
# Capture the mouse and save the starting posiiton for the rubber-band
self.CaptureMouse()
self.startPos = event.GetPosition()
## print('self.startPos:', self.startPos)
self.SetFocus()
## print('OnLeftDown')
def OnMouseMove(self, event):
if event.Dragging() and event.LeftIsDown():
evtPos = event.GetPosition()
try:
rect = wx.Rect(topLeft=self.startPos, bottomRight=evtPos)
except TypeError as exc: # topLeft = NoneType. Attempting to double click image or something
return
except Exception as exc:
raise exc
# Draw the rubber-band rectangle using an overlay so it
# will manage keeping the rectangle and the former window
# contents separate.
dc = wx.ClientDC(self)
odc = wx.DCOverlay(self.overlay, dc)
odc.Clear()
dc.SetPen(wx.Pen(colour=self.overlayPenColor.GetColour(),
width=self.overlayPenWidth.GetValue(),
style=self.wxPenStylesDict[self.penstylesCombo.GetString(self.penstylesCombo.GetSelection())]))
if 'wxMac' in wx.PlatformInfo:
dc.SetBrush(wx.Brush(wx.Colour(0xC0, 0xC0, 0xC0, 0x80)))
else:
dc.SetBrush(wx.TRANSPARENT_BRUSH)
dc.DrawRectangle(rect)
#Draw Pos Text
## text = u'%s'%evtPos
## width, height = dc.GetTextExtent(text)
## dc.DrawText(text, x=evtPos[0]+2, y=evtPos[1]-height)
if evtPos[0] < self.startPos[0]: # draw on left side of rect, not inside it
dc.DrawBitmap(self.cropbitmap,
evtPos[0] - 25 - self.overlayPenWidth.GetValue(),
evtPos[1] - 17)
else:
dc.DrawBitmap(self.cropbitmap,
evtPos[0] + 2 + self.overlayPenWidth.GetValue(),
evtPos[1] - 17)
del odc # Make sure the odc is destroyed before the dc is.
## print('OnMouseMove')
def OnLeftUp(self, event):
if self.HasCapture():
self.ReleaseMouse()
self.endPos = event.GetPosition()
## print('StartPos: %s' %self.startPos)
## print('EndPos: %s' %self.endPos)
self.startPos = None
self.endPos = None
# When the mouse is released we reset the overlay and it
# restores the former content to the window.
dc = wx.ClientDC(self)
odc = wx.DCOverlay(self.overlay, dc)
odc.Clear()
del odc
self.overlay.Reset()
## print('OnLeftUp')
def OnSize(self, event=None):
x, y = self.GetSize()
if x <= 0 or y <= 0:
return
self.buffer = wx.Bitmap(x, y)
dc = wx.MemoryDC()
dc.SelectObject(self.buffer)
dc.SetBackground(self.background)
dc.Clear()
dc.DrawBitmap(wx.Bitmap('bitmaps/snakey_render.png'), 10, 35)
dc.DrawBitmap(wx.Bitmap('bitmaps/honeycomb300.png'), 100, 210)
del dc
self.Refresh()
self.Update()
def OnPaint(self, event):
dc = wx.BufferedPaintDC(self, self.buffer)
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
#---------------------------------------------------------------------------
overview = """\
Creates an overlay over an existing window, allowing for
manipulations like rubberbanding, etc
"""
if __name__ == '__main__':
import sys
import os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])

159
demo/RearrangeDialog.py Normal file
View File

@@ -0,0 +1,159 @@
#!/usr/bin/env python
import random
import wx
globalItems = ['New', 'Open', 'Save', 'Save As...', 'Cut', 'Copy', 'Paste',
'Delete', 'Select All', 'Find', 'About', 'Help', 'Exit',
'Python is the Best!']
random.shuffle(globalItems)
globalOrder = []
length = len(globalItems)
# print(length)
for num in range(0, length):
globalOrder.append(num)
random.shuffle(globalOrder)
# print(len(globalOrder))
randomShuffleCheckedOnce = True
globalCheckedStrings = []
class MyRearrangeDialog(wx.RearrangeDialog):
def __init__(self, parent, message, title, order, items):
wx.RearrangeDialog.__init__(self, parent, message, title, order, items)
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.HORIZONTAL)
self.lc = self.GetList()
sizer.Add(wx.StaticText(panel, wx.ID_ANY,
"Number of checked boxes:"))
self.lenItems = len(items)
self.tc = wx.TextCtrl(panel, wx.ID_ANY, "%s" % self.lenItems,
style=wx.TE_READONLY)
self.lc.Bind(wx.EVT_CHECKLISTBOX, self.OnCheck)
self.lc.Bind(wx.EVT_LISTBOX, self.OnListBox)
self.lc.Bind(wx.EVT_CONTEXT_MENU, self.OnContextMenu)
sizer.Add(self.tc)
panel.SetSizer(sizer)
self.AddExtraControls(panel)
global randomShuffleCheckedOnce
global globalCheckedStrings
if randomShuffleCheckedOnce:
globalCheckedStrings = []
for i in range(0, self.lenItems):
bool = random.randint(0, 1)
# print(bool)
if bool:
self.lc.Check(item=i, check=False)
globalCheckedStrings.append(0)
else:
globalCheckedStrings.append(1)
randomShuffleCheckedOnce = False
else:
for i in range(0, self.lenItems):
if globalCheckedStrings[i]:
self.lc.Check(item=i, check=True)
else:
self.lc.Check(item=i, check=False)
self.checkedItems = self.lc.GetCheckedItems()
self.checkedStrings = self.lc.GetCheckedStrings()
#Update the TextCtrl
self.tc.SetValue("%s" % len(self.checkedItems))
def OnListBox(self, event):
print('You Selected %s' % (self.lc.GetString(event.GetSelection())))
def OnCheck(self, event):
print('You Checked %s %s' % (self.lc.GetString(event.GetSelection()),
self.lc.IsChecked(event.GetSelection())))
#Update the TextCtrl
self.checkedItems = self.lc.GetCheckedItems()
self.tc.SetValue("%s" % len(self.checkedItems))
def OnUnCheckOrCheckAll(self, event):
doWhat = str(event.GetId()).endswith('1')
# print('doWhat', doWhat)
for i in range(0, self.lenItems):
if doWhat:
self.lc.Check(i, True)
else:
self.lc.Check(i, False)
self.checkedItems = self.lc.GetCheckedItems()
self.tc.SetValue("%s" % len(self.checkedItems))
def OnContextMenu(self, event):
menu = wx.Menu()
ID_UNCHECKALL = 1000
ID_CHECKALL = 1001
mi1 = wx.MenuItem(menu, ID_UNCHECKALL, 'UnCheck All', 'UnCheck All')
mi2 = wx.MenuItem(menu, ID_CHECKALL, 'Check All', 'Check All')
menu.Append(mi1)
menu.Append(mi2)
menu.Bind(wx.EVT_MENU, self.OnUnCheckOrCheckAll, id=ID_UNCHECKALL)
menu.Bind(wx.EVT_MENU, self.OnUnCheckOrCheckAll, id=ID_CHECKALL)
self.PopupMenu(menu)
menu.Destroy()
#---------------------------------------------------------------------------
class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent, -1)
b = wx.Button(self, -1, "Create and Show a RearrangeDialog", (50, 50))
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
def OnButton(self, evt):
global globalOrder
global globalItems
global globalCheckedStrings
rd = MyRearrangeDialog(self, message="Rearrangeify Stuff!",
title="This is a wx.RearrangeDialog",
order=globalOrder, items=globalItems)
if rd.ShowModal() == wx.ID_OK:
# print('GetOrder: ', rd.GetOrder())
globalOrder = list(range(rd.lenItems))
globalItems = []
globalCheckedStrings = []
for i in range(0, rd.lenItems):
# print(rd.lc.GetString(i))
globalItems.append(rd.lc.GetString(i))
# print(rd.lc.IsChecked(i))
if rd.lc.IsChecked(i):
globalCheckedStrings.append(1)
else:
globalCheckedStrings.append(0)
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
#---------------------------------------------------------------------------
overview = """\
A RearrangeDialog is a dialog that allows the user to rearrange
the specified items.
This dialog can be used to allow the user to modify the order
of the items and to enable or disable them individually.
"""
if __name__ == '__main__':
import sys
import os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])

86
demo/RichMessageDialog.py Normal file
View File

@@ -0,0 +1,86 @@
#!/usr/bin/env python
import wx
class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent, -1)
self.bannish = False
self.annoy = True
b = wx.Button(self, -1, "Create and Show a wx.RichMessageDialog", (50, 50))
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
def OnButton(self, event):
if self.bannish:
print("That's rich!")
return
def DING():
"""Add some audacity...erm annoyance"""
wx.Bell()
DING()
event.Skip()
dlg = wx.RichMessageDialog(self, "Hey You! I'm a rich irritating dialog!")
dlg.ShowDetailedText(("bla bla bla " * 3) + '\n...\n\n' +
"Detailed Text(translated) == Don't show the welcome dialog again"
"\n(That almost always seems to popup...)")
dlg.ShowCheckBox("Bannish me forever")
dlg.ShowModal() # return value ignored as we have "Ok" only anyhow
for i in range(0, 10):
wx.CallLater(500, DING)
if dlg.IsCheckBoxChecked():
# ... make sure we won't show it again the next time ...
self.bannish = True # Plonk!
DING()
dlg.Destroy()
#---------------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
#---------------------------------------------------------------------------
overview = """\
A RichMessageDialog...
Extension of MessageDialog with additional functionality.
This class adds the possibility of using a checkbox (that is especially useful
for implementing the "Don't ask me again" kind of dialogs) and an extra explanatory
text which is initially collapsed and not shown to the user but can be expanded to
show more information.
Notice that currently the native dialog is used only under MSW when using Vista or
later Windows version. Elsewhere, or for older versions of Windows, a generic
implementation which is less familiar to the users is used. Because of this it's
recommended to use this class only if you do need its extra functionality and use
MessageDialog which does have native implementation under all platforms otherwise.
However if you do need to put e.g. a checkbox in a dialog, you should definitely
consider using this class instead of using your own custom dialog because it will
have much better appearance at least under recent Windows versions.
To use this class, you need to create the dialog object and call ShowCheckBox and/or
ShowDetailedText to configure its contents. Other than that, it is used in exactly
the same way as MessageDialog and supports all the styles supported by it. In particular,
ShowModal return value is the same as for MessageDialog. The only difference is that you
need to use IsCheckBoxChecked to examine the checkbox value if you had called ShowCheckBox.
"""
if __name__ == '__main__':
import sys
import os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])

60
demo/TimePickerCtrl.py Normal file
View File

@@ -0,0 +1,60 @@
#!/usr/bin/env python
import wx
import wx.adv
#----------------------------------------------------------------------
class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent, -1)
sizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(sizer)
self.tpc = wx.adv.TimePickerCtrl(self, size=(120, -1),
style = wx.adv.TP_DEFAULT)
self.Bind(wx.adv.EVT_TIME_CHANGED, self.OnTimeChanged, self.tpc)
sizer.Add(self.tpc, 0, wx.ALL, 50)
def OnTimeChanged(self, evt):
self.log.write("OnTimeChanged: hour: %s min: %s sec: %s\n" % self.tpc.GetTime())
#----------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
#----------------------------------------------------------------------
overview = """<html><body>
<h2><center>wx.TimePickerCtrl</center></h2>
<p>
This control allows the user to enter time.
</p>
<p>
It is similar to DatePickerCtrl but is used for time, and not date, selection.
While GetValue and SetValue still work with values of type DateTime (because
wxWidgets doesn't provide a time-only class), their date part is
ignored by this control.
</p>
<p>
It is only available if USE_TIMEPICKCTRL is set to 1.
</p>
<p>
This control currently doesn't have any specific flags.
</p>
</body></html>
"""
if __name__ == '__main__':
import sys
import os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])

68
demo/ToolTip.py Normal file
View File

@@ -0,0 +1,68 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import wx
class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent, -1)
self.tt1 = wx.ToolTip("This is a wx.ToolTip.")
self.tt2 = wx.ToolTip("This is\na multi-line\nToolTip.")
self.tt3 = wx.ToolTip("Disabled ToolTips.")
self.tt4 = wx.ToolTip("I will change this on the next line.")
self.tt4.SetTip("ToolTip.GetTip(tt1) = %s" % self.tt1.GetTip())
self.tt5 = wx.ToolTip("hmmm")
self.tt6 = wx.ToolTip("wxPython (Phoenix)\n" * 10)
self.tt7 = wx.ToolTip("Enable ToolTips.")
self.tt8 = wx.ToolTip("bla bla bla" * 50)
## self.tt8.SetMaxWidth(-1)
self.tt8.SetMaxWidth(0)
self.btn1 = wx.Button(self, -1, "Simple ToolTip", pos=(50, 30))
self.btn1.SetToolTip(self.tt1)
self.btn2 = wx.Button(self, -1, "Multi-Line ToolTip", pos=(50, 60))
self.btn2.SetToolTip(self.tt2)
self.btn3 = wx.Button(self, -1, "Disable ToolTips", pos=(50, 90))
self.btn3.SetToolTip(self.tt3)
self.btn3.Bind(wx.EVT_BUTTON, self.OnDisableToolTips)
self.btn4 = wx.Button(self, -1, "ToolTip.GetTip(self.tt1) = %s" % self.tt1.GetTip(), pos=(50, 120))
self.btn4.SetToolTip(self.tt4)
self.btn5 = wx.Button(self, -1, "ToolTip.GetWindow(self.tt2) = %s" % self.tt2.GetWindow(), pos=(50, 150))
self.btn5.SetToolTip(self.tt5)
self.tt5.SetTip("ToolTip.GetWindow(tt2) = %s" % self.tt2.GetWindow())
self.btn6 = wx.Button(self, -1, "ToolTip.SetMaxWidth(-1)", pos=(50, 180))
self.btn6.SetToolTip(self.tt6)
self.btn7 = wx.Button(self, -1, "Enable ToolTips", pos=(50, 210))
self.btn7.SetToolTip(self.tt7)
self.btn7.Bind(wx.EVT_BUTTON, self.OnEnableToolTips)
self.btn8 = wx.Button(self, -1, "ToolTip.SetMaxWidth(0)", pos=(50, 240))
self.btn8.SetToolTip(self.tt8)
def OnDisableToolTips(self, event):
self.tt3.Enable(False)
def OnEnableToolTips(self, event):
self.tt7.Enable(True)
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
#---------------------------------------------------------------------------
overview = """\
wx.ToolTip
"""
if __name__ == '__main__':
import sys
import os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

316
demo/main_globals.py Normal file
View File

@@ -0,0 +1,316 @@
#!/usr/bin/env python
# main_globals.py
"""
Globals for the main.py wxPython demo.
"""
#-------------------------------------------------------------------------------
#
# _demoPngs
#
# These are the images names used in the demo treectrl.
# These come from images.py or bitmaps/imagename.ext
#
# _demoPngs = ["imagename1", "imagename2", "etc"]
#
#-------------------------------------------------------------------------------
_demoPngs = ["overview", "recent", "frame", "dialog", "moredialog", "core",
"book", "customcontrol", "morecontrols", "layout", "process",
"clipboard", "images", "miscellaneous"]
#-------------------------------------------------------------------------------
#
# _treeList
#
# These are the Demo Catagory Headers
# and Demo Module Names(Ex: Frame.py without ext)
#
# ('Demo Catagory Name String', [
# 'DemoModuleName1',
# 'DemoModuleName2',
# 'Etc',
# ]),
#
#-------------------------------------------------------------------------------
_treeList = [
# new stuff
('Recent Additions/Updates', [
'BannerWindow',
'ToolTip',
'RichToolTip',
'NotificationMessage',
'RearrangeDialog',
'MouseState',
'RichMessageDialog',
'FileCtrl',
'Overlay',
'TimePickerCtrl',
'PropertyGrid',
'SystemSettings',
'GridLabelRenderer',
'InfoBar',
'WrapSizer',
'UIActionSimulator',
'GraphicsGradient',
'PDFViewer',
'ItemsPicker',
'CommandLinkButton',
'DVC_DataViewModel',
'DVC_IndexListModel',
'DVC_ListCtrl',
'DVC_TreeCtrl',
'DVC_CustomRenderer',
'PenAndBrushStyles',
'HTML2_WebView',
]),
# managed windows == things with a (optional) caption you can close
('Frames and Dialogs', [
'AUI_DockingWindowMgr',
'AUI_MDI',
'Dialog',
'Frame',
'MDIWindows',
'MiniFrame',
'Wizard',
]),
# the common dialogs
('Common Dialogs', [
'AboutBox',
'ColourDialog',
'DirDialog',
'FileDialog',
'FindReplaceDialog',
'FontDialog',
'MessageDialog',
'MultiChoiceDialog',
'PageSetupDialog',
'PrintDialog',
'ProgressDialog',
'SingleChoiceDialog',
'TextEntryDialog',
]),
# dialogs from libraries
('More Dialogs', [
'ImageBrowser',
'ScrolledMessageDialog',
]),
# core controls
('Core Windows/Controls', [
'BitmapButton',
'Button',
'CheckBox',
'CheckListBox',
'Choice',
'ComboBox',
'CommandLinkButton',
'DVC_CustomRenderer',
'DVC_DataViewModel',
'DVC_IndexListModel',
'DVC_ListCtrl',
'DVC_TreeCtrl',
'Gauge',
'Grid',
'Grid_MegaExample',
'GridLabelRenderer',
'ListBox',
'ListCtrl',
'ListCtrl_virtual',
'ListCtrl_edit',
'Menu',
'PopupMenu',
'PopupWindow',
'RadioBox',
'RadioButton',
'SashWindow',
'ScrolledWindow',
'SearchCtrl',
'Slider',
'SpinButton',
'SpinCtrl',
'SpinCtrlDouble',
'SplitterWindow',
'StaticBitmap',
'StaticBox',
'StaticText',
'StatusBar',
'StockButtons',
'TextCtrl',
'ToggleButton',
'ToolBar',
'TreeCtrl',
'Validator',
]),
('"Book" Controls', [
'AUI_Notebook',
'Choicebook',
'FlatNotebook',
'Listbook',
'Notebook',
'Toolbook',
'Treebook',
]),
('Custom Controls', [
'AnalogClock',
'ColourSelect',
'ComboTreeBox',
'Editor',
'GenericButtons',
'GenericDirCtrl',
'ItemsPicker',
'LEDNumberCtrl',
'MultiSash',
'PlateButton',
'PopupControl',
'PyColourChooser',
'TreeListCtrl',
]),
# controls coming from other libraries
('More Windows/Controls', [
'ActiveX_FlashWindow',
'ActiveX_IEHtmlWindow',
'ActiveX_PDFWindow',
'BitmapComboBox',
'Calendar',
'CalendarCtrl',
'CheckListCtrlMixin',
'CollapsiblePane',
'ComboCtrl',
'ContextHelp',
'DatePickerCtrl',
'DynamicSashWindow',
'EditableListBox',
'ExpandoTextCtrl',
'FancyText',
'FileBrowseButton',
'FloatBar',
'FloatCanvas',
'HtmlWindow',
'HTML2_WebView',
'InfoBar',
'IntCtrl',
'MVCTree',
'MaskedEditControls',
'MaskedNumCtrl',
'MediaCtrl',
'MultiSplitterWindow',
'OwnerDrawnComboBox',
'Pickers',
'PropertyGrid',
'PyCrust',
'PyPlot',
'PyShell',
'ResizeWidget',
'RichTextCtrl',
'ScrolledPanel',
'SplitTree',
'StyledTextCtrl_1',
'StyledTextCtrl_2',
'TablePrint',
'Throbber',
'Ticker',
'TimeCtrl',
'TreeMixin',
'VListBox',
]),
# How to lay out the controls in a frame/dialog
('Window Layout', [
'GridBagSizer',
'LayoutAnchors',
'LayoutConstraints',
'Layoutf',
'RowColSizer',
'ScrolledPanel',
'SizedControls',
'Sizers',
'WrapSizer',
'XmlResource',
'XmlResourceHandler',
'XmlResourceSubclass',
]),
# ditto
('Process and Events', [
'DelayedResult',
'EventManager',
'KeyEvents',
'Process',
'PythonEvents',
'Threads',
'Timer',
##'infoframe', # needs better explanation and some fixing
]),
# Clipboard and DnD
('Clipboard and DnD', [
'CustomDragAndDrop',
'DragAndDrop',
'URLDragAndDrop',
]),
# Images
('Using Images', [
'AdjustChannels',
'AlphaDrawing',
'AnimateCtrl',
'ArtProvider',
'BitmapFromBuffer',
'Cursor',
'DragImage',
'Image',
'ImageAlpha',
'ImageFromStream',
'Img2PyArtProvider',
'Mask',
'RawBitmapAccess',
'Throbber',
]),
# Other stuff
('Miscellaneous', [
'AlphaDrawing',
'Cairo',
'Cairo_Snippets',
'ColourDB',
##'DialogUnits', # needs more explanations
'DragScroller',
'DrawXXXList',
'FileHistory',
'FontEnumerator',
'GetMouseState',
'GraphicsContext',
'GraphicsGradient',
'GLCanvas',
'I18N',
'Joystick',
'MimeTypesManager',
'MouseGestures',
'OGL',
'PDFViewer',
'PenAndBrushStyles',
'PrintFramework',
'PseudoDC',
'RendererNative',
'ShapedWindow',
'Sound',
'StandardPaths',
'SystemSettings',
'UIActionSimulator',
'Unicode',
]),
('Check out the samples dir too', []),
]