mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2025-07-21 20:51:09 +02:00
More tweaks and fixes from testing the demo modules
This commit is contained in:
@@ -25,7 +25,6 @@ class TestPanel(wx.Panel):
|
||||
# Init the context help button.
|
||||
# And even include help text about the help button :-)
|
||||
cBtn = wx.ContextHelpButton(self)
|
||||
cBtn.Bind(wx.EVT_BUTTON, self.OnCtxHelpButton)
|
||||
cBtn.SetHelpText("wx.ContextHelpButton")
|
||||
|
||||
cBtnText = wx.StaticText(self, -1,
|
||||
@@ -72,12 +71,6 @@ class TestPanel(wx.Panel):
|
||||
self.Layout()
|
||||
|
||||
|
||||
def OnCtxHelpButton(self, evt):
|
||||
# This starts a nested event loop which exits when an item has been
|
||||
# clicked on, its help message shown and dismissed.
|
||||
cshelp = wx.ContextHelp(self)
|
||||
|
||||
|
||||
# On the second text control above, we intercept the help event. This is where
|
||||
# we process it. Anything could happen here. In this case we're just printing
|
||||
# some stuff about it, then passing it on with Skip(), at which point we
|
||||
|
@@ -94,7 +94,7 @@ class TestPanel(wx.Panel):
|
||||
image.SetOption(wx.IMAGE_OPTION_CUR_HOTSPOT_Y, 1)
|
||||
|
||||
# make the image into a cursor
|
||||
cursor = wx.CursorFromImage(image)
|
||||
cursor = wx.Cursor(image)
|
||||
|
||||
else:
|
||||
# create one of the stock (built-in) cursors
|
||||
|
@@ -25,20 +25,19 @@ class FrameSimpleDelayedBase(wx.Frame):
|
||||
def __init__(self, *args, **kwds):
|
||||
wx.Frame.__init__(self, *args, **kwds)
|
||||
pnl = wx.Panel(self)
|
||||
self.checkboxUseDelayed = wx.CheckBox(pnl, -1, "Using delayedresult")
|
||||
self.textUseDelayed = wx.StaticText(pnl, -1, "NOT using delayedresult")
|
||||
self.buttonGet = wx.Button(pnl, -1, "Get")
|
||||
self.buttonAbort = wx.Button(pnl, -1, "Abort")
|
||||
self.slider = wx.Slider(pnl, -1, 0, 0, 10, size=(100,-1),
|
||||
style=wx.SL_HORIZONTAL|wx.SL_AUTOTICKS)
|
||||
self.textCtrlResult = wx.TextCtrl(pnl, -1, "", style=wx.TE_READONLY)
|
||||
|
||||
self.checkboxUseDelayed.SetValue(1)
|
||||
self.checkboxUseDelayed.Enable(False)
|
||||
self.buttonAbort.Enable(False)
|
||||
|
||||
vsizer = wx.BoxSizer(wx.VERTICAL)
|
||||
vsizer = wx.BoxSizer(wx.VERTICAL)
|
||||
hsizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
vsizer.Add(self.checkboxUseDelayed, 0, wx.ALL, 10)
|
||||
vsizer.Add(self.textUseDelayed, 0, wx.ALL, 10)
|
||||
hsizer.Add(self.buttonGet, 0, wx.ALL, 5)
|
||||
hsizer.Add(self.buttonAbort, 0, wx.ALL, 5)
|
||||
hsizer.Add(self.slider, 0, wx.ALL, 5)
|
||||
@@ -52,7 +51,6 @@ class FrameSimpleDelayedBase(wx.Frame):
|
||||
|
||||
|
||||
|
||||
|
||||
class FrameSimpleDelayed(FrameSimpleDelayedBase):
|
||||
"""This demos simplistic use of delayedresult module."""
|
||||
|
||||
@@ -61,14 +59,19 @@ class FrameSimpleDelayed(FrameSimpleDelayedBase):
|
||||
self.jobID = 0
|
||||
self.abortEvent = delayedresult.AbortEvent()
|
||||
self.Bind(wx.EVT_CLOSE, self.handleClose)
|
||||
self.textUseDelayed.SetLabel("USING delayedresult")
|
||||
|
||||
|
||||
def setLog(self, log):
|
||||
self.log = log
|
||||
|
||||
|
||||
def handleClose(self, event):
|
||||
"""Only needed because in demo, closing the window does not kill the
|
||||
"""
|
||||
Only needed because in demo, closing the window does not kill the
|
||||
app, so worker thread continues and sends result to dead frame; normally
|
||||
your app would exit so this would not happen."""
|
||||
your app would exit so this would not happen.
|
||||
"""
|
||||
if self.buttonAbort.IsEnabled():
|
||||
self.log( "Exiting: Aborting job %s" % self.jobID )
|
||||
self.abortEvent.set()
|
||||
@@ -88,9 +91,11 @@ class FrameSimpleDelayed(FrameSimpleDelayedBase):
|
||||
|
||||
|
||||
def _resultProducer(self, jobID, abortEvent):
|
||||
"""Pretend to be a complex worker function or something that takes
|
||||
"""
|
||||
Pretend to be a complex worker function or something that takes
|
||||
long time to run due to network access etc. GUI will freeze if this
|
||||
method is not called in separate thread."""
|
||||
method is not called in separate thread.
|
||||
"""
|
||||
import time
|
||||
count = 0
|
||||
while not abortEvent() and count < 50:
|
||||
@@ -112,7 +117,7 @@ class FrameSimpleDelayed(FrameSimpleDelayedBase):
|
||||
assert jobID == self.jobID
|
||||
try:
|
||||
result = delayedResult.get()
|
||||
except Exception, exc:
|
||||
except Exception as exc:
|
||||
self.log( "Result for job %s raised exception: %s" % (jobID, exc) )
|
||||
return
|
||||
|
||||
@@ -125,6 +130,7 @@ class FrameSimpleDelayed(FrameSimpleDelayedBase):
|
||||
self.buttonAbort.Enable(False)
|
||||
|
||||
|
||||
|
||||
class FrameSimpleDirect(FrameSimpleDelayedBase):
|
||||
"""This does not use delayedresult so the GUI will freeze while
|
||||
the GET is taking place."""
|
||||
@@ -132,15 +138,17 @@ class FrameSimpleDirect(FrameSimpleDelayedBase):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.jobID = 1
|
||||
FrameSimpleDelayedBase.__init__(self, *args, **kwargs)
|
||||
self.checkboxUseDelayed.SetValue(False)
|
||||
|
||||
|
||||
|
||||
def setLog(self, log):
|
||||
self.log = log
|
||||
|
||||
|
||||
|
||||
def handleGet(self, event):
|
||||
"""Use delayedresult, this will compute result in separate
|
||||
thread, and will affect GUI response because a thread is not
|
||||
used."""
|
||||
"""
|
||||
Not using delayedresult, this will compute result in the same thread,
|
||||
and will affect GUI response because a thread is not used.
|
||||
"""
|
||||
self.buttonGet.Enable(False)
|
||||
self.buttonAbort.Enable(True)
|
||||
|
||||
@@ -148,18 +156,23 @@ class FrameSimpleDirect(FrameSimpleDelayedBase):
|
||||
result = self._resultProducer(self.jobID)
|
||||
self._resultConsumer( result )
|
||||
|
||||
|
||||
def _resultProducer(self, jobID):
|
||||
"""Pretend to be a complex worker function or something that takes
|
||||
"""
|
||||
Pretend to be a complex worker function or something that takes
|
||||
long time to run due to network access etc. GUI will freeze if this
|
||||
method is not called in separate thread."""
|
||||
method is not called in separate thread.
|
||||
"""
|
||||
import time
|
||||
time.sleep(5)
|
||||
return jobID
|
||||
|
||||
|
||||
def handleAbort(self, event):
|
||||
"""can never be called"""
|
||||
pass
|
||||
|
||||
|
||||
|
||||
def _resultConsumer(self, result):
|
||||
# output result
|
||||
self.log( "Got result for job %s: %s" % (self.jobID, result) )
|
||||
|
@@ -32,25 +32,26 @@ class MyFrame(wx.Frame):
|
||||
panel = wx.Panel(self, -1)
|
||||
|
||||
wx.StaticText(panel, -1, "Size:",
|
||||
wx.DLG_PNT(panel, (4, 4)), wx.DefaultSize
|
||||
panel.DLG_UNIT((4, 4)), wx.DefaultSize
|
||||
)
|
||||
|
||||
wx.StaticText(panel, -1, "Pos:",
|
||||
wx.DLG_PNT(panel, (4, 16)), wx.DefaultSize
|
||||
panel.DLG_UNIT((4, 20)), wx.DefaultSize
|
||||
)
|
||||
|
||||
self.sizeCtrl = wx.TextCtrl(panel, -1, "",
|
||||
wx.DLG_PNT(panel, (24, 4)),
|
||||
wx.DLG_SZE(panel, (36, -1)),
|
||||
panel.DLG_UNIT((24, 4)),
|
||||
panel.DLG_UNIT((36, -1)),
|
||||
wx.TE_READONLY)
|
||||
|
||||
self.posCtrl = wx.TextCtrl(panel, -1, "",
|
||||
wx.DLG_PNT(panel, (24, 16)),
|
||||
wx.DLG_SZE(panel, (36, -1)),
|
||||
panel.DLG_UNIT((24, 20)),
|
||||
panel.DLG_UNIT((36, -1)),
|
||||
wx.TE_READONLY)
|
||||
|
||||
#print(wx.DLG_PNT(panel, (24, 4)), wx.DLG_SZE(panel, (36, -1)))
|
||||
#print(wx.DLG_PNT(panel, (24, 16)),wx.DLG_SZE(panel, (36, -1)))
|
||||
#print(wx.DLG_UNIT(panel, (24, 4)), wx.DLG_UNIT(panel, (36, -1)))
|
||||
#print(panel.DLG_UNIT((24, 16)), panel.DLG_UNIT((36, -1)))
|
||||
|
||||
|
||||
# This method is called automatically when the CLOSE event is
|
||||
# sent to this window
|
||||
|
@@ -38,7 +38,7 @@ def run():
|
||||
c = module.find('wxContextHelpButton')
|
||||
assert isinstance(c, etgtools.ClassDef)
|
||||
tools.fixWindowClass(c)
|
||||
|
||||
|
||||
|
||||
c = module.find('wxHelpProvider')
|
||||
c.abstract = True
|
||||
|
@@ -194,8 +194,16 @@ def run():
|
||||
self.Hide()
|
||||
wx.GetApp().ScheduleForDestruction(self)
|
||||
""")
|
||||
|
||||
|
||||
|
||||
c.addPyMethod('DLG_UNIT', '(self, dlg_unit)',
|
||||
doc="""\
|
||||
A convenience wrapper for :meth:`ConvertDialogToPixels`.
|
||||
""",
|
||||
body="""\
|
||||
return self.ConvertDialogToPixels(dlg_unit)
|
||||
""")
|
||||
|
||||
|
||||
# MSW only. Do we want them wrapped?
|
||||
c.find('GetAccessible').ignore()
|
||||
c.find('SetAccessible').ignore()
|
||||
@@ -333,6 +341,20 @@ def run():
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self._win.Thaw()
|
||||
''')
|
||||
|
||||
module.addPyCode('''\
|
||||
def DLG_UNIT(win, dlg_unit, val2=None):
|
||||
"""
|
||||
Convenience function for converting a wx.Point, wx.Size or
|
||||
(x,y) in dialog units to pixels.
|
||||
"""
|
||||
if val2 is not None:
|
||||
dlg_unit = (dlg_unit, val2)
|
||||
return win.ConvertDialogToPixels(dlg_unit)
|
||||
|
||||
DLG_PNT = wx.deprecated(DLG_UNIT, "Use DLG_UNIT instead.")
|
||||
DLG_SZE = wx.deprecated(DLG_UNIT, "Use DLG_UNIT instead.")
|
||||
''')
|
||||
|
||||
|
||||
# Add a wrapper for wxWindowList and a new iterator class for it that
|
||||
|
@@ -239,7 +239,7 @@ def fixWindowClass(klass, hideVirtuals=True, ignoreProtected=True):
|
||||
parent.transferThis = True
|
||||
# if there is an id param give it a default
|
||||
id = func.findItem('id') or func.findItem('winid')
|
||||
if id:
|
||||
if id and not id.default:
|
||||
id.default = 'wxID_ANY'
|
||||
|
||||
# if there is a pos or size parameter without a default then give it one.
|
||||
|
@@ -13,7 +13,10 @@ class cshelp_Tests(wtc.WidgetTestCase):
|
||||
pnl = wx.Panel(self.frame)
|
||||
pnl.SetHelpText("HelpMe!")
|
||||
cBtn = wx.ContextHelpButton(pnl)
|
||||
|
||||
|
||||
# Make sure we haven't borked the magic ID
|
||||
assert cBtn.GetId() == wx.ID_CONTEXT_HELP
|
||||
|
||||
|
||||
def test_cshelp2(self):
|
||||
wx.wxEVT_HELP
|
||||
|
Reference in New Issue
Block a user