More minor demo fixes and updates for Py3, Phoenix, etc.

This commit is contained in:
Robin Dunn
2016-08-10 15:56:04 -07:00
parent 9fe03f7570
commit 9d5e743e50
9 changed files with 67 additions and 95 deletions

View File

@@ -551,37 +551,35 @@ class TestSelectionPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.list = wx.ListBox(self, -1,
(-1, -1), (-1, -1),
[])
self.list.Fit()
self.list = wx.ListBox(self, size=(300,150))
self.Bind(wx.EVT_LISTBOX, self.OnSelect, self.list)
self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnDClick, self.list)
btn = wx.Button(self, -1, "Try it!", (120, 10))
btn.Bind(wx.EVT_BUTTON, self.OnDClick)
self.text = wx.TextCtrl(self, -1, "",
(10, 115),
(200, 50),
wx.TE_MULTILINE | wx.TE_READONLY)
self.text = wx.TextCtrl(self, style = wx.TE_MULTILINE | wx.TE_READONLY)
for item in theTests:
self.list.Append(item[0])
self.list.SetSelection(0)
wx.CallAfter(self.list.EnsureVisible, 0)
hsizer = wx.BoxSizer(wx.HORIZONTAL)
hsizer.Add(self.list, 1, wx.ALL, 8)
hsizer.Add(btn, 0, wx.ALL, 8)
vsizer = wx.BoxSizer(wx.VERTICAL)
vsizer.Add(hsizer)
vsizer.Add(self.text, 1, wx.EXPAND | wx.ALL, 8)
self.SetSizerAndFit(vsizer)
self.SetSizer(vsizer)
def OnSelect(self, event):
pos = self.list.GetSelection()
self.text.SetValue(theTests[pos][2])
def OnDClick(self, event):
pos = self.list.GetSelection()
title = theTests[pos][0]

View File

@@ -10,15 +10,22 @@ class TestPanel(wx.Panel):
self.log = log
self.count = 0
wx.StaticText(self, -1, "This is a wx.Slider.", (45, 15))
label = wx.StaticText(self, -1, "This is a wx.Slider.")
slider = wx.Slider(
self, 100, 25, 1, 100, (30, 60), (250, -1),
wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS
self, 100, 25, 1, 100, size=(250, -1),
style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS
)
slider.SetTickFreq(5)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add((1,20))
sizer.Add(label, 0, wx.LEFT, 20)
sizer.Add((1,10))
sizer.Add(slider, 0, wx.LEFT, 20)
self.SetSizer(sizer)
#----------------------------------------------------------------------
@@ -35,10 +42,6 @@ def runTest(frame, nb, log):
overview = """\
A slider is a control with a handle which can be pulled back and forth to
change the value.
In Windows versions below Windows 95, a scrollbar is used to simulate the slider.
In Windows 95, the track bar control is used.
"""

View File

@@ -27,7 +27,7 @@ class TestPanel(wx.Panel):
self.log.write("before Play...\n")
sound.Play(wx.adv.SOUND_SYNC)
self.log.write("...after Play\n")
except NotImplementedError, v:
except NotImplementedError as v:
wx.MessageBox(str(v), "Exception Message")
@@ -45,7 +45,7 @@ class TestPanel(wx.Panel):
self.sound = sound # save a reference (This shoudln't be needed, but there seems to be a bug...)
# wx.YieldIfNeeded()
self.log.write("...after Play\n")
except NotImplementedError, v:
except NotImplementedError as v:
wx.MessageBox(str(v), "Exception Message")
@@ -62,7 +62,7 @@ class TestPanel(wx.Panel):
# another way to do it.
wx.adv.Sound.PlaySound(dlg.GetPath(), wx.adv.SOUND_SYNC)
except NotImplementedError, v:
except NotImplementedError as v:
wx.MessageBox(str(v), "Exception Message")
dlg.Destroy()

View File

@@ -32,7 +32,6 @@ class TestPanel(wx.Panel):
bmp = images.Robin.GetBitmap()
StaticBitmap(self, -1, bmp, (80, 150))
StaticText(self, -1, "Hey, if Ousterhout can do it, so can I.", (200, 175))
#----------------------------------------------------------------------

View File

@@ -1,15 +1,7 @@
#!/usr/bin/env python
# 11/21/2003 - Jeff Grimmett (grimmtooth@softhome.net)
#
# o wx.TheClipboard.Flush() generates a warning on program exit.
import wx
import wx.stc as stc
import images
#----------------------------------------------------------------------
debug = 1
@@ -171,43 +163,20 @@ def runTest(frame, nb, log):
p.SetAutoLayout(True)
#ed.SetBufferedDraw(False)
#ed.StyleClearAll()
#ed.SetScrollWidth(800)
#ed.SetWrapMode(True)
#ed.SetUseAntiAliasing(False)
#ed.SetViewEOL(True)
#ed.CmdKeyClear(stc.STC_KEY_BACK,
# stc.STC_SCMOD_CTRL)
#ed.CmdKeyAssign(stc.STC_KEY_BACK,
# stc.STC_SCMOD_CTRL,
# stc.STC_CMD_DELWORDLEFT)
ed.SetText(demoText)
# if wx.USE_UNICODE:
import codecs
decode = codecs.lookup("utf-8")[1]
ed.GotoPos(ed.GetLength())
ed.AddText("\n\nwx.StyledTextCtrl can also do Unicode:\n")
uniline = ed.GetCurrentLine()
unitext, l = decode('\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd - '
'\xd0\xbb\xd1\x83\xd1\x87\xd1\x88\xd0\xb8\xd0\xb9 '
'\xd1\x8f\xd0\xb7\xd1\x8b\xd0\xba \xd0\xbf\xd1\x80\xd0\xbe\xd0\xb3\xd1\x80\xd0\xb0\xd0\xbc\xd0\xbc\xd0\xb8\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb0\xd0\xbd\xd0\xb8\xd1\x8f!\n\n')
unitext, l = decode(b'\xd0\x9f\xd0\xb8\xd1\x82\xd0\xbe\xd0\xbd - ' +
b'\xd0\xbb\xd1\x83\xd1\x87\xd1\x88\xd0\xb8\xd0\xb9 ' +
b'\xd1\x8f\xd0\xb7\xd1\x8b\xd0\xba \xd0\xbf\xd1\x80\xd0\xbe\xd0\xb3\xd1\x80\xd0\xb0\xd0\xbc\xd0\xbc\xd0\xb8\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb0\xd0\xbd\xd0\xb8\xd1\x8f!\n\n')
ed.AddText('\tRussian: ')
ed.AddText(unitext)
ed.GotoPos(0)
#else:
# #ed.StyleSetFontEncoding(stc.STC_STYLE_DEFAULT, wx.FONTENCODING_KOI8)
# #text = u'\u041f\u0438\u0442\u043e\u043d - \u043b\u0443\u0447\u0448\u0438\u0439 \u044f\u0437\u044b\u043a \n\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f!'
# #text = text.encode('koi8-r')
# #ed.StyleSetFontEncoding(stc.STC_STYLE_DEFAULT, wx.FONTENCODING_BIG5)
# #text = u'Python \u662f\u6700\u597d\u7684\u7de8\u7a0b\u8a9e\u8a00\uff01'
# #text = text.encode('big5')
# ed.GotoPos(ed.GetLength())
# ed.AddText('\n\n' + text)
ed.EmptyUndoBuffer()

View File

@@ -24,7 +24,7 @@ class TablePanel(wx.Panel):
box = wx.BoxSizer(wx.VERTICAL)
box.Add((20, 30))
keys = buttonDefs.keys()
keys = list(buttonDefs.keys())
keys.sort()
for k in keys:
@@ -38,8 +38,8 @@ class TablePanel(wx.Panel):
def OnButton(self, evt):
funct = buttonDefs[evt.GetId()][0]
code = 'self.' + funct + '()'
eval(code)
funct = getattr(self, funct)
funct()
def ReadData(self):
test_file = "./data/testtable.txt"

View File

@@ -1,11 +1,9 @@
#!/usr/bin/env python
import random
import time
from six.moves import _thread
import random
import time
import thread
import wx
import wx.lib.newevent
import wx
import wx.lib.newevent
#----------------------------------------------------------------------
@@ -23,7 +21,7 @@ class CalcBarThread:
def Start(self):
self.keepGoing = self.running = True
thread.start_new_thread(self.Run, ())
_thread.start_new_thread(self.Run, ())
def Stop(self):
self.keepGoing = False

View File

@@ -126,31 +126,31 @@ class VirtualTreeCtrl(DemoTreeMixin, wx.TreeCtrl):
pass
class VirtualTreeListCtrl(DemoTreeMixin, wx.adv.TreeListCtrl):
def __init__(self, *args, **kwargs):
kwargs['style'] = wx.TR_DEFAULT_STYLE | wx.TR_FULL_ROW_HIGHLIGHT
super(VirtualTreeListCtrl, self).__init__(*args, **kwargs)
self.AppendColumn('Column 0')
self.AppendColumn('Column 1')
for art in wx.ART_TIP, wx.ART_WARNING:
self.imageList.Add(wx.ArtProvider.GetBitmap(art, wx.ART_OTHER,
(16, 16)))
def OnGetItemText(self, indices, column=0):
# Return a different label depending on column.
return '%s, column %d'%\
(super(VirtualTreeListCtrl, self).OnGetItemText(indices), column)
def OnGetItemImage(self, indices, which, column=0):
# Also change the image of the other columns when the item has
# children.
if column == 0:
return super(VirtualTreeListCtrl, self).OnGetItemImage(indices,
which)
elif self.OnGetChildrenCount(indices):
return 4
else:
return 3
# class VirtualTreeListCtrl(DemoTreeMixin, wx.adv.TreeListCtrl):
# def __init__(self, *args, **kwargs):
# kwargs['style'] = wx.TR_DEFAULT_STYLE | wx.TR_FULL_ROW_HIGHLIGHT
# super(VirtualTreeListCtrl, self).__init__(*args, **kwargs)
# self.AppendColumn('Column 0')
# self.AppendColumn('Column 1')
# for art in wx.ART_TIP, wx.ART_WARNING:
# self.imageList.Add(wx.ArtProvider.GetBitmap(art, wx.ART_OTHER,
# (16, 16)))
#
# def OnGetItemText(self, indices, column=0):
# # Return a different label depending on column.
# return '%s, column %d'%\
# (super(VirtualTreeListCtrl, self).OnGetItemText(indices), column)
#
# def OnGetItemImage(self, indices, which, column=0):
# # Also change the image of the other columns when the item has
# # children.
# if column == 0:
# return super(VirtualTreeListCtrl, self).OnGetItemImage(indices,
# which)
# elif self.OnGetChildrenCount(indices):
# return 4
# else:
# return 3
class VirtualCustomTreeCtrl(DemoTreeMixin,
@@ -192,7 +192,7 @@ class TreeNotebook(wx.Notebook):
super(TreeNotebook, self).__init__(*args, **kwargs)
self.trees = []
for class_, title in [(VirtualTreeCtrl, 'TreeCtrl'),
(VirtualTreeListCtrl, 'TreeListCtrl'),
#(VirtualTreeListCtrl, 'TreeListCtrl'),
(VirtualCustomTreeCtrl, 'CustomTreeCtrl')]:
tree = class_(self, treemodel=treemodel, log=log)
self.trees.append(tree)

View File

@@ -27,6 +27,8 @@ import copy
import types
import wx
import six
class PrintBase(object):
def SetPrintFont(self, font): # set the DC font parameters
fattr = font["Attr"]
@@ -271,7 +273,7 @@ class PrintTableDraw(wx.ScrolledWindow, PrintBase):
self.column.append(pos_x)
#module logic expects two dimensional data -- fix input if needed
if isinstance(self.data,types.StringTypes):
if isinstance(self.data, six.string_types):
self.data = [[copy.copy(self.data)]] # a string becomes a single cell
try:
rows = len(self.data)
@@ -280,7 +282,7 @@ class PrintTableDraw(wx.ScrolledWindow, PrintBase):
rows = 1
first_value = self.data[0]
if isinstance(first_value, types.StringTypes): # a sequence of strings
if isinstance(first_value, six.string_types): # a sequence of strings
if self.label == [] and self.set_column == []:
data = []
for x in self.data: #becomes one column
@@ -560,7 +562,7 @@ class PrintTableDraw(wx.ScrolledWindow, PrintBase):
self.col = 0
max_y = 0
for vtxt in row_val:
if not isinstance(vtxt,types.StringTypes):
if not isinstance(vtxt, six.string_types):
vtxt = str(vtxt)
self.region = self.column[self.col+1] - self.column[self.col]
self.indent = self.column[self.col]
@@ -681,7 +683,10 @@ class PrintTable(object):
self.row_line_colour = {}
self.parentFrame = parentFrame
self.SetPreviewSize()
if parentFrame:
self.SetPreviewSize(parentFrame.GetPosition(), parentFrame.GetSize())
else:
self.SetPreviewSize()
self.printData = wx.PrintData()
self.scale = 1.0