mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-03-15 13:10:07 +01:00
Trim Whitespace lib directory
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#
|
||||
# 12/17/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o Removed wx prefix from class name,
|
||||
# o Removed wx prefix from class name,
|
||||
# updated reverse renamer
|
||||
#
|
||||
|
||||
|
||||
@@ -68,8 +68,8 @@ class ActiveXCtrl(wx.msw.PyAxBaseWindow):
|
||||
provide a method with the correct name. See the comtypes package
|
||||
documentation for more details.
|
||||
"""
|
||||
|
||||
def __init__(self, parent, axID, wxid=-1, pos=wx.DefaultPosition,
|
||||
|
||||
def __init__(self, parent, axID, wxid=-1, pos=wx.DefaultPosition,
|
||||
size=wx.DefaultSize, style=0, name="activeXCtrl"):
|
||||
"""
|
||||
All parameters are like those used in normal wx.Windows with
|
||||
@@ -87,44 +87,44 @@ class ActiveXCtrl(wx.msw.PyAxBaseWindow):
|
||||
h = size.height
|
||||
if w == -1: w = 20
|
||||
if h == -1: h = 20
|
||||
|
||||
|
||||
# create the control
|
||||
atl.AtlAxWinInit()
|
||||
hInstance = kernel32.GetModuleHandleA(None)
|
||||
hwnd = user32.CreateWindowExA(0, b"AtlAxWin", axID.encode("ASCII"),
|
||||
WS_CHILD | WS_VISIBLE
|
||||
WS_CHILD | WS_VISIBLE
|
||||
| WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
|
||||
x,y, w,h, parent.GetHandle(), None,
|
||||
x,y, w,h, parent.GetHandle(), None,
|
||||
hInstance, 0)
|
||||
assert hwnd != 0
|
||||
|
||||
|
||||
# get the Interface for the Ax control
|
||||
unknown = ct.POINTER(comtypes.IUnknown)()
|
||||
res = atl.AtlAxGetControl(hwnd, ct.byref(unknown))
|
||||
assert res == hr.S_OK
|
||||
self._ax = cc.GetBestInterface(unknown)
|
||||
|
||||
|
||||
# Fetch the interface for IOleInPlaceActiveObject. We'll use this
|
||||
# later to call its TranslateAccelerator method so the AX Control can
|
||||
# deal with things like tab traversal and such within itself.
|
||||
self.ipao = self._ax.QueryInterface(myole4ax.IOleInPlaceActiveObject)
|
||||
|
||||
|
||||
# Use this object as the event sink for the ActiveX events
|
||||
self._evt_connections = []
|
||||
self.AddEventSink(self)
|
||||
|
||||
wx.msw.PyAxBaseWindow.__init__(self, parent, wxid, pos, size, style, name)
|
||||
|
||||
|
||||
# Turn the window handle into a wx.Window and set this object to be that window
|
||||
self.AssociateHandle(hwnd)
|
||||
|
||||
# Set some wx.Window properties
|
||||
if wxid == wx.ID_ANY:
|
||||
if wxid == wx.ID_ANY:
|
||||
wxid = wx.Window.NewControlId()
|
||||
self.SetId(wxid)
|
||||
self.SetName(name)
|
||||
self.SetMinSize(size)
|
||||
|
||||
|
||||
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
|
||||
self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
|
||||
self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroyWindow)
|
||||
@@ -157,20 +157,20 @@ class ActiveXCtrl(wx.msw.PyAxBaseWindow):
|
||||
else:
|
||||
return super(ActiveXCtrl, self).MSWTranslateMessage(msg)
|
||||
|
||||
|
||||
|
||||
# TBD: Are the focus handlers needed?
|
||||
def OnSetFocus(self, evt):
|
||||
self.ipao.OnFrameWindowActivate(True)
|
||||
|
||||
|
||||
def OnKillFocus(self, evt):
|
||||
self.ipao.OnFrameWindowActivate(False)
|
||||
|
||||
def OnDestroyWindow(self, evt):
|
||||
# release our event sinks while the window still exists
|
||||
self._evt_connections = None
|
||||
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# o Updated for wx namespace
|
||||
# o Tested with updated demo
|
||||
#
|
||||
#
|
||||
|
||||
import wx
|
||||
|
||||
@@ -29,8 +29,8 @@ except ImportError:
|
||||
else:
|
||||
raise # original error message
|
||||
else:
|
||||
message = "ActiveXWrapper requires PythonWin. Please install the PyWin32 package."
|
||||
raise ImportError(message)
|
||||
message = "ActiveXWrapper requires PythonWin. Please install the PyWin32 package."
|
||||
raise ImportError(message)
|
||||
|
||||
##from win32con import WS_TABSTOP, WS_VISIBLE
|
||||
WS_TABSTOP = 0x00010000
|
||||
@@ -98,12 +98,12 @@ def MakeActiveXClass(CoClass, eventClass=None, eventObj=None):
|
||||
|
||||
# These functions will be used as methods in the new class
|
||||
def axw__init__(self, parent, ID=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0):
|
||||
|
||||
|
||||
# init base classes
|
||||
pywin.mfc.activex.Control.__init__(self)
|
||||
wx.Window.__init__( self, parent, -1, pos, size, style|wx.NO_FULL_REPAINT_ON_RESIZE)
|
||||
#self.this.own(False) # this should be set in wx.Window.__init__ when it calls _setOORInfo, but...
|
||||
|
||||
|
||||
win32ui.EnableControlContainer()
|
||||
self._eventObj = self._eventObj # move from class to instance
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#
|
||||
# o Updated for wx namespace
|
||||
# o Tested with updated demo
|
||||
#
|
||||
#
|
||||
"""
|
||||
`LayoutAnchors` is a class that implements Delphi's Anchors using
|
||||
`wx.LayoutConstraints`.
|
||||
@@ -62,7 +62,7 @@ class LayoutAnchors(wx.LayoutConstraints):
|
||||
| +-------*-------+ |
|
||||
+-------------------+
|
||||
* = anchored edge
|
||||
|
||||
|
||||
"""
|
||||
def __init__(self, control, left=1, top=1, right=0, bottom=0):
|
||||
wx.LayoutConstraints.__init__(self)
|
||||
@@ -96,7 +96,7 @@ class LayoutAnchors(wx.LayoutConstraints):
|
||||
size.AsIs()
|
||||
else:
|
||||
size.AsIs()
|
||||
|
||||
|
||||
if not side2Anchor:
|
||||
centre.PercentOf(parent, sizeEdge,
|
||||
int(((cPos + cSize / 2.0) / pSize)*100))
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#
|
||||
# o Updated for wx namespace
|
||||
# o Tested with updated demo
|
||||
#
|
||||
#
|
||||
|
||||
"""
|
||||
This module implements various forms of generic buttons, meaning that
|
||||
@@ -47,7 +47,7 @@ Sample usage::
|
||||
# Build a bitmap button and a normal one
|
||||
bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_OTHER, (16, 16))
|
||||
btn1 = buttons.ThemedGenBitmapButton(panel, -1, bmp, pos=(50, 50))
|
||||
|
||||
|
||||
btn2 = buttons.GenButton(panel, -1, "Hello World!", pos=(50, 100))
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ import wx.lib.imageutils as imageutils
|
||||
|
||||
class GenButtonEvent(wx.CommandEvent):
|
||||
""" Event sent from the generic buttons when the button is activated. """
|
||||
|
||||
|
||||
def __init__(self, eventType, id):
|
||||
"""
|
||||
Default class constructor.
|
||||
@@ -74,7 +74,7 @@ class GenButtonEvent(wx.CommandEvent):
|
||||
:param integer `eventType`: the event type;
|
||||
:param integer `id`: the event identifier.
|
||||
"""
|
||||
|
||||
|
||||
wx.CommandEvent.__init__(self, eventType, id)
|
||||
self.isDown = False
|
||||
self.theButton = None
|
||||
@@ -86,7 +86,7 @@ class GenButtonEvent(wx.CommandEvent):
|
||||
|
||||
:param bool `isDown`: ``True`` if the button is clicked, ``False`` otherwise.
|
||||
"""
|
||||
|
||||
|
||||
self.isDown = isDown
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ class GenButtonEvent(wx.CommandEvent):
|
||||
Returns the button toggle status as ``True`` if the button is down, ``False``
|
||||
otherwise.
|
||||
|
||||
:rtype: bool
|
||||
:rtype: bool
|
||||
"""
|
||||
|
||||
return self.isDown
|
||||
@@ -151,17 +151,17 @@ class GenButton(wx.Control):
|
||||
|
||||
.. seealso:: :class:`wx.Button` for a list of valid window styles.
|
||||
"""
|
||||
|
||||
|
||||
cstyle = style
|
||||
if cstyle & wx.BORDER_MASK == 0:
|
||||
cstyle |= wx.BORDER_NONE
|
||||
|
||||
|
||||
wx.Control.__init__(self, parent, id, pos, size, cstyle, validator, name)
|
||||
|
||||
|
||||
self.up = True
|
||||
self.hasFocus = False
|
||||
self.style = style
|
||||
|
||||
|
||||
if style & wx.BORDER_NONE:
|
||||
self.bezelWidth = 0
|
||||
self.useFocusInd = False
|
||||
@@ -194,7 +194,7 @@ class GenButton(wx.Control):
|
||||
need to be bound. Added so :meth:`__init__` doesn't need to be
|
||||
overriden, which is complicated with multiple inheritance.
|
||||
"""
|
||||
|
||||
|
||||
pass
|
||||
|
||||
|
||||
@@ -205,16 +205,16 @@ class GenButton(wx.Control):
|
||||
|
||||
:param `size`: an instance of :class:`wx.Size` or ``None``,
|
||||
in which case the wxPython
|
||||
``wx.DefaultSize`` is used instead.
|
||||
``wx.DefaultSize`` is used instead.
|
||||
"""
|
||||
|
||||
|
||||
if size is None:
|
||||
size = wx.DefaultSize
|
||||
size = wx.DefaultSize
|
||||
|
||||
wx.Control.SetInitialSize(self, size)
|
||||
|
||||
|
||||
SetBestSize = SetInitialSize
|
||||
|
||||
|
||||
|
||||
def DoGetBestSize(self):
|
||||
"""
|
||||
@@ -222,10 +222,10 @@ class GenButton(wx.Control):
|
||||
button based on the label and bezel size.
|
||||
|
||||
:return: An instance of :class:`wx.Size`.
|
||||
|
||||
.. note:: Overridden from :class:`wx.Control`.
|
||||
|
||||
.. note:: Overridden from :class:`wx.Control`.
|
||||
"""
|
||||
|
||||
|
||||
w, h, useMin = self._GetLabelSize()
|
||||
if self.style & wx.BU_EXACTFIT:
|
||||
width = w + 2 + 2 * self.bezelWidth + 4 * int(self.useFocusInd)
|
||||
@@ -240,7 +240,7 @@ class GenButton(wx.Control):
|
||||
height = defSize.height
|
||||
width = width + self.bezelWidth - 1
|
||||
height = height + self.bezelWidth - 1
|
||||
|
||||
|
||||
return wx.Size(width, height)
|
||||
|
||||
|
||||
@@ -260,8 +260,8 @@ class GenButton(wx.Control):
|
||||
the same font/colour attributes as the native :class:`wx.Button`.
|
||||
|
||||
:return: an instance of :class:`wx.VisualAttributes`.
|
||||
|
||||
.. note:: Overridden from :class:`wx.Control`.
|
||||
|
||||
.. note:: Overridden from :class:`wx.Control`.
|
||||
"""
|
||||
|
||||
return wx.Button.GetClassDefaultAttributes()
|
||||
@@ -274,9 +274,9 @@ class GenButton(wx.Control):
|
||||
|
||||
.. note:: Overridden from :class:`wx.Control`.
|
||||
"""
|
||||
|
||||
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def Enable(self, enable=True):
|
||||
"""
|
||||
@@ -298,7 +298,7 @@ class GenButton(wx.Control):
|
||||
|
||||
:param integer `width`: the 3D border width, in pixels.
|
||||
"""
|
||||
|
||||
|
||||
self.bezelWidth = width
|
||||
|
||||
|
||||
@@ -308,7 +308,7 @@ class GenButton(wx.Control):
|
||||
|
||||
:rtype: integer
|
||||
"""
|
||||
|
||||
|
||||
return self.bezelWidth
|
||||
|
||||
|
||||
@@ -318,7 +318,7 @@ class GenButton(wx.Control):
|
||||
|
||||
:param bool `flag`: ``True`` to draw a focus ring, ``False`` otherwise.
|
||||
"""
|
||||
|
||||
|
||||
self.useFocusInd = flag
|
||||
|
||||
|
||||
@@ -329,7 +329,7 @@ class GenButton(wx.Control):
|
||||
|
||||
:rtype: bool
|
||||
"""
|
||||
|
||||
|
||||
return self.useFocusInd
|
||||
|
||||
|
||||
@@ -338,7 +338,7 @@ class GenButton(wx.Control):
|
||||
Calculate a new set of highlight and shadow colours based on
|
||||
the background colour. Works okay if the colour is dark...
|
||||
"""
|
||||
|
||||
|
||||
faceClr = self.GetBackgroundColour()
|
||||
r, g, b, a = faceClr
|
||||
fr, fg, fb = min(255,r+32), min(255,g+32), min(255,b+32)
|
||||
@@ -349,7 +349,7 @@ class GenButton(wx.Control):
|
||||
self.highlightPenClr = wx.Colour(hr,hg,hb)
|
||||
self.focusClr = wx.Colour(hr, hg, hb)
|
||||
|
||||
|
||||
|
||||
def SetBackgroundColour(self, colour):
|
||||
"""
|
||||
Sets the :class:`GenButton` background colour.
|
||||
@@ -400,17 +400,17 @@ class GenButton(wx.Control):
|
||||
if hasattr(tlw, 'SetDefaultItem'):
|
||||
tlw.SetDefaultItem(self)
|
||||
|
||||
|
||||
|
||||
def _GetLabelSize(self):
|
||||
""" Used internally. """
|
||||
|
||||
|
||||
w, h = self.GetTextExtent(self.GetLabel())
|
||||
return w, h, True
|
||||
|
||||
|
||||
def Notify(self):
|
||||
""" Actually sends a ``wx.EVT_BUTTON`` event to the listener (if any). """
|
||||
|
||||
|
||||
evt = GenButtonEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, self.GetId())
|
||||
evt.SetIsDown(not self.up)
|
||||
evt.SetButtonObj(self)
|
||||
@@ -468,7 +468,7 @@ class GenButton(wx.Control):
|
||||
dc.DrawRectangle(bw+2,bw+2, w-bw*2-4, h-bw*2-4)
|
||||
dc.SetLogicalFunction(wx.COPY)
|
||||
|
||||
|
||||
|
||||
def OnPaint(self, event):
|
||||
"""
|
||||
Handles the ``wx.EVT_PAINT`` event for :class:`GenButton`.
|
||||
@@ -510,7 +510,7 @@ class GenButton(wx.Control):
|
||||
|
||||
:param wx.DC `dc`: the device context used to draw the button background.
|
||||
"""
|
||||
|
||||
|
||||
if self.up:
|
||||
colBg = self.GetBackgroundColour()
|
||||
brush = wx.Brush(colBg)
|
||||
@@ -545,7 +545,7 @@ class GenButton(wx.Control):
|
||||
|
||||
if not self.IsEnabled():
|
||||
return
|
||||
|
||||
|
||||
self.up = False
|
||||
self.CaptureMouse()
|
||||
self.SetFocus()
|
||||
@@ -559,10 +559,10 @@ class GenButton(wx.Control):
|
||||
|
||||
:param `event`: a :class:`wx.MouseEvent` event to be processed.
|
||||
"""
|
||||
|
||||
|
||||
if not self.IsEnabled() or not self.HasCapture():
|
||||
return
|
||||
|
||||
|
||||
if self.HasCapture():
|
||||
self.ReleaseMouse()
|
||||
if not self.up: # if the button was down when the mouse was released...
|
||||
@@ -582,11 +582,11 @@ class GenButton(wx.Control):
|
||||
|
||||
if not self.IsEnabled() or not self.HasCapture():
|
||||
return
|
||||
|
||||
|
||||
if event.LeftIsDown() and self.HasCapture():
|
||||
x,y = event.GetPosition()
|
||||
w,h = self.GetClientSize()
|
||||
|
||||
|
||||
if self.up and x<w and x>=0 and y<h and y>=0:
|
||||
self.up = False
|
||||
self.Refresh()
|
||||
@@ -596,7 +596,7 @@ class GenButton(wx.Control):
|
||||
self.up = True
|
||||
self.Refresh()
|
||||
return
|
||||
|
||||
|
||||
event.Skip()
|
||||
|
||||
|
||||
@@ -634,7 +634,7 @@ class GenButton(wx.Control):
|
||||
if self.hasFocus and event.GetKeyCode() == ord(" "):
|
||||
self.up = False
|
||||
self.Refresh()
|
||||
|
||||
|
||||
event.Skip()
|
||||
|
||||
|
||||
@@ -649,7 +649,7 @@ class GenButton(wx.Control):
|
||||
self.up = True
|
||||
self.Notify()
|
||||
self.Refresh()
|
||||
|
||||
|
||||
event.Skip()
|
||||
|
||||
|
||||
@@ -680,7 +680,7 @@ class GenBitmapButton(GenButton):
|
||||
|
||||
.. seealso:: :class:`wx.Button` for a list of valid window styles.
|
||||
"""
|
||||
|
||||
|
||||
self.bmpDisabled = None
|
||||
self.bmpFocus = None
|
||||
self.bmpSelected = None
|
||||
@@ -696,7 +696,7 @@ class GenBitmapButton(GenButton):
|
||||
|
||||
.. seealso:: :meth:`SetBitmapLabel`
|
||||
"""
|
||||
|
||||
|
||||
return self.bmpLabel
|
||||
|
||||
|
||||
@@ -711,7 +711,7 @@ class GenBitmapButton(GenButton):
|
||||
|
||||
return self.bmpDisabled
|
||||
|
||||
|
||||
|
||||
def GetBitmapFocus(self):
|
||||
"""
|
||||
Returns the bitmap for the button's focused state, which may be invalid.
|
||||
@@ -720,7 +720,7 @@ class GenBitmapButton(GenButton):
|
||||
|
||||
.. seealso:: :meth:`SetBitmapFocus`
|
||||
"""
|
||||
|
||||
|
||||
return self.bmpFocus
|
||||
|
||||
|
||||
@@ -746,9 +746,9 @@ class GenBitmapButton(GenButton):
|
||||
|
||||
:meth:`GetBitmapDisabled`, :meth:`SetBitmapLabel`,
|
||||
:meth:`SetBitmapSelected`, :meth:`SetBitmapFocus`
|
||||
|
||||
|
||||
"""
|
||||
|
||||
|
||||
self.bmpDisabled = bitmap
|
||||
|
||||
|
||||
@@ -762,7 +762,7 @@ class GenBitmapButton(GenButton):
|
||||
|
||||
:meth:`GetBitmapFocus`, :meth:`SetBitmapLabel`,
|
||||
:meth:`SetBitmapSelected`, :meth:`SetBitmapDisabled`
|
||||
|
||||
|
||||
"""
|
||||
|
||||
self.bmpFocus = bitmap
|
||||
@@ -779,7 +779,7 @@ class GenBitmapButton(GenButton):
|
||||
|
||||
:meth:`GetBitmapSelected`, :meth:`SetBitmapLabel`,
|
||||
:meth:`SetBitmapDisabled`, :meth:`SetBitmapFocus`
|
||||
|
||||
|
||||
"""
|
||||
|
||||
self.bmpSelected = bitmap
|
||||
@@ -798,7 +798,7 @@ class GenBitmapButton(GenButton):
|
||||
.. note:: This is the bitmap used for the unselected state, and for all other
|
||||
states if no other bitmaps are provided.
|
||||
"""
|
||||
|
||||
|
||||
self.bmpLabel = bitmap
|
||||
if bitmap is not None and createOthers:
|
||||
image = bitmap.ConvertToImage()
|
||||
@@ -808,7 +808,7 @@ class GenBitmapButton(GenButton):
|
||||
|
||||
def _GetLabelSize(self):
|
||||
""" Used internally. """
|
||||
|
||||
|
||||
if not self.bmpLabel:
|
||||
return -1, -1, False
|
||||
|
||||
@@ -835,7 +835,7 @@ class GenBitmapButton(GenButton):
|
||||
|
||||
class GenBitmapTextButton(GenBitmapButton):
|
||||
""" A generic bitmapped button with text label. """
|
||||
|
||||
|
||||
def __init__(self, parent, id=-1, bitmap=wx.NullBitmap, label='',
|
||||
pos = wx.DefaultPosition, size = wx.DefaultSize,
|
||||
style = 0, validator = wx.DefaultValidator,
|
||||
@@ -859,7 +859,7 @@ class GenBitmapTextButton(GenBitmapButton):
|
||||
|
||||
.. seealso:: :class:`wx.Button` for a list of valid window styles.
|
||||
"""
|
||||
|
||||
|
||||
GenBitmapButton.__init__(self, parent, id, bitmap, pos, size, style, validator, name)
|
||||
self.SetLabel(label)
|
||||
|
||||
@@ -977,7 +977,7 @@ class __ToggleMixin(object):
|
||||
|
||||
if not self.IsEnabled() or not self.HasCapture():
|
||||
return
|
||||
|
||||
|
||||
if self.HasCapture():
|
||||
self.ReleaseMouse()
|
||||
self.Refresh()
|
||||
@@ -1004,11 +1004,11 @@ class __ToggleMixin(object):
|
||||
|
||||
if not self.IsEnabled():
|
||||
return
|
||||
|
||||
|
||||
if event.LeftIsDown() and self.HasCapture():
|
||||
x,y = event.GetPosition()
|
||||
w,h = self.GetClientSize()
|
||||
|
||||
|
||||
if x<w and x>=0 and y<h and y>=0:
|
||||
self.up = not self.saveUp
|
||||
self.Refresh()
|
||||
@@ -1055,7 +1055,7 @@ class GenBitmapTextToggleButton(__ToggleMixin, GenBitmapTextButton):
|
||||
|
||||
class __ThemedMixin(object):
|
||||
""" Uses the native renderer to draw the bezel, also handle mouse-overs. """
|
||||
|
||||
|
||||
|
||||
def InitOtherEvents(self):
|
||||
""" Initializes other events needed for themed buttons. """
|
||||
@@ -1063,7 +1063,7 @@ class __ThemedMixin(object):
|
||||
self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouse)
|
||||
self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouse)
|
||||
|
||||
|
||||
|
||||
def OnMouse(self, event):
|
||||
"""
|
||||
Handles the ``wx.EVT_ENTER_WINDOW`` and ``wx.EVT_LEAVE_WINDOW`` events for
|
||||
@@ -1077,7 +1077,7 @@ class __ThemedMixin(object):
|
||||
|
||||
|
||||
def DrawBezel(self, dc, x1, y1, x2, y2):
|
||||
|
||||
|
||||
rect = wx.Rect(x1, y1, x2, y2)
|
||||
if self.up:
|
||||
state = 0
|
||||
@@ -1089,7 +1089,7 @@ class __ThemedMixin(object):
|
||||
if self.GetClientRect().Contains(pt):
|
||||
state |= wx.CONTROL_CURRENT
|
||||
wx.RendererNative.Get().DrawPushButton(self, dc, rect, state)
|
||||
|
||||
|
||||
|
||||
|
||||
class ThemedGenButton(__ThemedMixin, GenButton):
|
||||
@@ -1103,7 +1103,7 @@ class ThemedGenBitmapButton(__ThemedMixin, GenBitmapButton):
|
||||
class ThemedGenBitmapTextButton(__ThemedMixin, GenBitmapTextButton):
|
||||
""" A themed generic bitmapped button with text label. """
|
||||
pass
|
||||
|
||||
|
||||
class ThemedGenToggleButton(__ThemedMixin, GenToggleButton):
|
||||
""" A themed generic toggle button. """
|
||||
pass
|
||||
|
||||
@@ -124,7 +124,7 @@ def GetMonthList():
|
||||
|
||||
rtype: `list`
|
||||
"""
|
||||
|
||||
|
||||
monthlist = []
|
||||
for i in range(13):
|
||||
name = Month[i]
|
||||
|
||||
@@ -54,7 +54,7 @@ Sample usage::
|
||||
import wx.lib.colourselect as csel
|
||||
|
||||
class MyFrame(wx.Frame):
|
||||
|
||||
|
||||
def __init__(self, parent, title):
|
||||
|
||||
wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(400, 300))
|
||||
@@ -65,8 +65,8 @@ Sample usage::
|
||||
|
||||
def OnChooseBackground(self, event):
|
||||
|
||||
col1 = event.GetValue()
|
||||
self.panel.SetBackgroundColour(col1)
|
||||
col1 = event.GetValue()
|
||||
self.panel.SetBackgroundColour(col1)
|
||||
event.Skip()
|
||||
|
||||
app = wx.App()
|
||||
@@ -111,7 +111,7 @@ class ColourSelectEvent(wx.PyCommandEvent):
|
||||
|
||||
:rtype: :class:`wx.Colour`
|
||||
"""
|
||||
|
||||
|
||||
return self.value
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ class ColourSelect(wx.lib.buttons.GenBitmapButton):
|
||||
h += 8
|
||||
else:
|
||||
w, h = 22, 22
|
||||
|
||||
|
||||
size.width = size.width if size.width != -1 else w
|
||||
size.height = size.height if size.height != -1 else h
|
||||
super(ColourSelect, self).__init__(parent, id, wx.Bitmap(w,h),
|
||||
@@ -234,7 +234,7 @@ class ColourSelect(wx.lib.buttons.GenBitmapButton):
|
||||
"""
|
||||
|
||||
self.SetColour(colour)
|
||||
|
||||
|
||||
|
||||
def SetColour(self, colour):
|
||||
"""
|
||||
@@ -302,14 +302,14 @@ class ColourSelect(wx.lib.buttons.GenBitmapButton):
|
||||
|
||||
def MakeBitmap(self):
|
||||
""" Creates a bitmap representation of the current selected colour. """
|
||||
|
||||
|
||||
bdr = 8
|
||||
width, height = self.GetSize()
|
||||
|
||||
# yes, this is weird, but it appears to work around a bug in wxMac
|
||||
if "wxMac" in wx.PlatformInfo and width == height:
|
||||
height -= 1
|
||||
|
||||
|
||||
bmp = wx.Bitmap(width-bdr, height-bdr)
|
||||
dc = wx.MemoryDC()
|
||||
dc.SelectObject(bmp)
|
||||
@@ -326,7 +326,7 @@ class ColourSelect(wx.lib.buttons.GenBitmapButton):
|
||||
dc.SetTextForeground(fcolour)
|
||||
dc.DrawLabel(label, (0,0, width-bdr, height-bdr),
|
||||
wx.ALIGN_CENTER)
|
||||
|
||||
|
||||
dc.SelectObject(wx.NullBitmap)
|
||||
return bmp
|
||||
|
||||
@@ -340,11 +340,11 @@ class ColourSelect(wx.lib.buttons.GenBitmapButton):
|
||||
|
||||
self.SetBitmapLabel(bmp)
|
||||
self.Refresh()
|
||||
|
||||
|
||||
|
||||
def OnChange(self):
|
||||
""" Fires the ``EVT_COLOURSELECT`` event, as the user has changed the current colour. """
|
||||
|
||||
|
||||
evt = ColourSelectEvent(self.GetId(), self.GetValue())
|
||||
evt.SetEventObject(self)
|
||||
wx.PostEvent(self, evt)
|
||||
@@ -381,5 +381,5 @@ class ColourSelect(wx.lib.buttons.GenBitmapButton):
|
||||
|
||||
# moved after dlg.Destroy, since who knows what the callback will do...
|
||||
if changed:
|
||||
self.OnChange()
|
||||
self.OnChange()
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ def AdjustAlpha(colour, alpha):
|
||||
:rtype: :class:`wx.Colour`
|
||||
:returns: A new :class:`wx.Colour` with the alpha channel specified as input
|
||||
"""
|
||||
|
||||
|
||||
return wx.Colour(colour.Red(), colour.Green(), colour.Blue(), alpha)
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ def AdjustColour(color, percent, alpha=wx.ALPHA_OPAQUE):
|
||||
"""
|
||||
Brighten/darken input colour by `percent` and adjust alpha
|
||||
channel if needed. Returns the modified color.
|
||||
|
||||
|
||||
:param wx.Colour `color`: color object to adjust;
|
||||
:param integer `percent`: percent to adjust +(brighten) or -(darken);
|
||||
:param integer `alpha`: amount to adjust alpha channel.
|
||||
@@ -75,13 +75,13 @@ def BestLabelColour(color, bw=False):
|
||||
"""
|
||||
Get the best color to use for the label that will be drawn on
|
||||
top of the given color.
|
||||
|
||||
|
||||
:param wx.Colour `color`: background color that text will be drawn on;
|
||||
:param bool `bw`: If ``True``, only return black or white.
|
||||
|
||||
:rtype: :class:`wx.Colour`
|
||||
"""
|
||||
|
||||
|
||||
avg = sum(color.Get()) / 3
|
||||
if avg > 192:
|
||||
txt_color = wx.BLACK
|
||||
@@ -99,10 +99,10 @@ def BestLabelColour(color, bw=False):
|
||||
def GetHighlightColour():
|
||||
"""
|
||||
Gets the default highlight color.
|
||||
|
||||
|
||||
:rtype: :class:`wx.Colour`
|
||||
"""
|
||||
|
||||
|
||||
if wx.Platform == '__WXMAC__':
|
||||
if CARBON:
|
||||
if wx.VERSION < (2, 9, 0, 0, ''):
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
# Licence: wxWidgets license
|
||||
# Tags: phoenix-port
|
||||
#----------------------------------------------------------------------------
|
||||
"""
|
||||
ComboTreeBox provides a ComboBox that pops up a tree instead of a list.
|
||||
"""
|
||||
ComboTreeBox provides a ComboBox that pops up a tree instead of a list.
|
||||
|
||||
ComboTreeBox tries to provide the same interface as :class:`wx.ComboBox` as much as
|
||||
possible. However, whereas the ComboBox widget uses indices to access
|
||||
possible. However, whereas the ComboBox widget uses indices to access
|
||||
items in the list of choices, ComboTreeBox uses TreeItemId's instead. If
|
||||
you add an item to the ComboTreeBox (using Append or Insert), the
|
||||
you add an item to the ComboTreeBox (using Append or Insert), the
|
||||
:class:`wx.TreeItemId` associated with the added item is returned. You can then use
|
||||
that `wx.TreeItemId` to add items as children of that first item. For
|
||||
example::
|
||||
@@ -30,7 +30,7 @@ example::
|
||||
You can also add client data to each of the items like this::
|
||||
|
||||
item1 = combo.Append('Item 1', clientData=somePythonObject)
|
||||
item1a = combo.Append('Item 1a', parent=item1,
|
||||
item1a = combo.Append('Item 1a', parent=item1,
|
||||
clientData=someOtherPythonObject)
|
||||
|
||||
|
||||
@@ -73,20 +73,20 @@ __all__ = ['ComboTreeBox'] # Export only the ComboTreeBox widget
|
||||
|
||||
|
||||
class IterableTreeCtrl(wx.TreeCtrl):
|
||||
"""
|
||||
TreeCtrl is the same as :class:`TreeCtrl`, with a few convenience methods
|
||||
"""
|
||||
TreeCtrl is the same as :class:`TreeCtrl`, with a few convenience methods
|
||||
added for easier navigation of items. """
|
||||
|
||||
def GetPreviousItem(self, item):
|
||||
"""
|
||||
Returns the item that is on the line immediately above item
|
||||
(as is displayed when the tree is fully expanded). The returned
|
||||
"""
|
||||
Returns the item that is on the line immediately above item
|
||||
(as is displayed when the tree is fully expanded). The returned
|
||||
item is invalid if item is the first item in the tree.
|
||||
|
||||
|
||||
:param TreeItemId `item`: a :class:`TreeItemId`
|
||||
:return: the :class:`TreeItemId` previous to the one passed in or an invalid item
|
||||
:rtype: :class:`TreeItemId`
|
||||
|
||||
|
||||
"""
|
||||
previousSibling = self.GetPrevSibling(item)
|
||||
if previousSibling:
|
||||
@@ -105,11 +105,11 @@ class IterableTreeCtrl(wx.TreeCtrl):
|
||||
Returns the item that is on the line immediately below item
|
||||
(as is displayed when the tree is fully expanded). The returned
|
||||
item is invalid if item is the last item in the tree.
|
||||
|
||||
|
||||
:param TreeItemId `item`: a :class:`TreeItemId`
|
||||
:return: :class:`TreeItemId` of the next item or an invalid item
|
||||
:rtype: :class:`TreeItemId`
|
||||
|
||||
|
||||
"""
|
||||
if self.ItemHasChildren(item):
|
||||
firstChild, cookie = self.GetFirstChild(item)
|
||||
@@ -123,10 +123,10 @@ class IterableTreeCtrl(wx.TreeCtrl):
|
||||
unless the root item is hidden. In that case the first child of
|
||||
the root item is returned, if any. If the tree is empty, an
|
||||
invalid tree item is returned.
|
||||
|
||||
|
||||
:return: :class:`TreeItemId`
|
||||
:rtype: :class:`TreeItemId`
|
||||
|
||||
|
||||
"""
|
||||
rootItem = self.GetRootItem()
|
||||
if rootItem and (self.GetWindowStyle() & wx.TR_HIDE_ROOT):
|
||||
@@ -144,7 +144,7 @@ class IterableTreeCtrl(wx.TreeCtrl):
|
||||
:param TreeItemId `item`: a :class:`TreeItemId`
|
||||
:return: :class:`TreeItemId` of the last item or an invalid item
|
||||
:rtype: :class:`TreeItemId`
|
||||
|
||||
|
||||
"""
|
||||
lastChild = item
|
||||
while self.ItemHasChildren(lastChild):
|
||||
@@ -152,17 +152,17 @@ class IterableTreeCtrl(wx.TreeCtrl):
|
||||
return lastChild
|
||||
|
||||
def GetNextSiblingRecursively(self, item):
|
||||
"""
|
||||
"""
|
||||
Returns the next sibling of item if it has one. If item has no
|
||||
next sibling the next sibling of the parent of item is returned.
|
||||
If the parent has no next sibling the next sibling of the parent
|
||||
next sibling the next sibling of the parent of item is returned.
|
||||
If the parent has no next sibling the next sibling of the parent
|
||||
of the parent is returned, etc. If none of the ancestors of item
|
||||
has a next sibling, an invalid item is returned.
|
||||
|
||||
|
||||
:param TreeItemId `item`: a :class:`TreeItemId`
|
||||
:return: :class:`TreeItemId` of the next item or an invalid item
|
||||
:rtype: :class:`TreeItemId`
|
||||
|
||||
|
||||
"""
|
||||
if item == self.GetRootItem():
|
||||
return wx.TreeItemId() # Return an invalid TreeItemId
|
||||
@@ -190,7 +190,7 @@ class IterableTreeCtrl(wx.TreeCtrl):
|
||||
|
||||
|
||||
class BasePopupFrame(wx.Frame):
|
||||
"""
|
||||
"""
|
||||
BasePopupFrame is the base class for platform specific versions of the
|
||||
PopupFrame. The PopupFrame is the frame that is popped up by ComboTreeBox.
|
||||
It contains the tree of items that the user can select one item from. Upon
|
||||
@@ -200,13 +200,13 @@ class BasePopupFrame(wx.Frame):
|
||||
def __init__(self, parent):
|
||||
super(BasePopupFrame, self).__init__(parent,
|
||||
style=wx.DEFAULT_FRAME_STYLE & wx.FRAME_FLOAT_ON_PARENT &
|
||||
~(wx.RESIZE_BORDER | wx.CAPTION))
|
||||
~(wx.RESIZE_BORDER | wx.CAPTION))
|
||||
self._createInterior()
|
||||
self._layoutInterior()
|
||||
self._bindEventHandlers()
|
||||
|
||||
def _createInterior(self):
|
||||
self._tree = IterableTreeCtrl(self,
|
||||
self._tree = IterableTreeCtrl(self,
|
||||
style=wx.TR_HIDE_ROOT|wx.TR_LINES_AT_ROOT|wx.TR_HAS_BUTTONS)
|
||||
self._tree.AddRoot('Hidden root node')
|
||||
|
||||
@@ -227,9 +227,9 @@ class BasePopupFrame(wx.Frame):
|
||||
self._tree.Unbind(wx.EVT_KILL_FOCUS)
|
||||
|
||||
def OnKillFocus(self, event):
|
||||
# We hide the frame rather than destroy it, so it can be
|
||||
# We hide the frame rather than destroy it, so it can be
|
||||
# popped up again later. Use CallAfter so that clicking the combobox
|
||||
# button doesn't immediately popup the frame again.
|
||||
# button doesn't immediately popup the frame again.
|
||||
wx.CallAfter(self.Hide)
|
||||
self.GetParent().NotifyNoItemSelected()
|
||||
event.Skip()
|
||||
@@ -271,7 +271,7 @@ class BasePopupFrame(wx.Frame):
|
||||
|
||||
|
||||
class MSWPopupFrame(BasePopupFrame):
|
||||
"""MSWPopupFrame is the base class Windows PopupFrame."""
|
||||
"""MSWPopupFrame is the base class Windows PopupFrame."""
|
||||
def Show(self):
|
||||
# Comply with the MS Windows Combobox behaviour: if the text in
|
||||
# the text field is not in the tree, the first item in the tree
|
||||
@@ -282,7 +282,7 @@ class MSWPopupFrame(BasePopupFrame):
|
||||
|
||||
|
||||
class MACPopupFrame(BasePopupFrame):
|
||||
"""MacPopupFrame is the base class Mac PopupFrame."""
|
||||
"""MacPopupFrame is the base class Mac PopupFrame."""
|
||||
def _bindKillFocus(self):
|
||||
# On wxMac, the kill focus event doesn't work, but the
|
||||
# deactivate event does:
|
||||
@@ -299,7 +299,7 @@ class MACPopupFrame(BasePopupFrame):
|
||||
|
||||
|
||||
class GTKPopupFrame(BasePopupFrame):
|
||||
"""GTKPopupFrame is the base class GTK PopupFrame."""
|
||||
"""GTKPopupFrame is the base class GTK PopupFrame."""
|
||||
def _keyShouldHidePopup(self, keyEvent):
|
||||
# On wxGTK, Alt-Up also closes the popup:
|
||||
return super(GTKPopupFrame, self)._keyShouldHidePopup(keyEvent) or \
|
||||
@@ -347,9 +347,9 @@ class BaseComboTreeBox(object):
|
||||
return self # By default, the dropdown button is the control itself.
|
||||
|
||||
def _createPopupFrame(self):
|
||||
# It is a subclass responsibility to provide the right PopupFrame,
|
||||
# It is a subclass responsibility to provide the right PopupFrame,
|
||||
# depending on platform:
|
||||
raise NotImplementedError
|
||||
raise NotImplementedError
|
||||
|
||||
def _layoutInterior(self):
|
||||
pass # By default, there is no layout to be done.
|
||||
@@ -359,15 +359,15 @@ class BaseComboTreeBox(object):
|
||||
eventSource.Bind(eventType, eventHandler)
|
||||
|
||||
def _eventsToBind(self):
|
||||
"""
|
||||
"""
|
||||
_eventsToBind returns a list of eventSource, eventType,
|
||||
eventHandlers tuples that will be bound. This method can be
|
||||
extended to bind additional events. In that case, don't
|
||||
eventHandlers tuples that will be bound. This method can be
|
||||
extended to bind additional events. In that case, don't
|
||||
forget to call _eventsToBind on the super class.
|
||||
|
||||
|
||||
:return: [(eventSource, eventType, eventHandlers), ]
|
||||
:rtype: list
|
||||
|
||||
|
||||
"""
|
||||
return [(self._text, wx.EVT_KEY_DOWN, self.OnKeyDown),
|
||||
(self._text, wx.EVT_TEXT, self.OnText),
|
||||
@@ -402,7 +402,7 @@ class BaseComboTreeBox(object):
|
||||
def _navigateUpOrDown(self, keyEvent):
|
||||
item = self.GetSelection()
|
||||
if item:
|
||||
navigationMethods = {wx.WXK_DOWN: self._tree.GetNextItem,
|
||||
navigationMethods = {wx.WXK_DOWN: self._tree.GetNextItem,
|
||||
wx.WXK_UP: self._tree.GetPreviousItem}
|
||||
getNextItem = navigationMethods[keyEvent.GetKeyCode()]
|
||||
nextItem = getNextItem(item)
|
||||
@@ -429,7 +429,7 @@ class BaseComboTreeBox(object):
|
||||
|
||||
def NotifyItemSelected(self, text):
|
||||
"""
|
||||
Simulate selection of an item by the user. This is meant to
|
||||
Simulate selection of an item by the user. This is meant to
|
||||
be called by the PopupFrame when the user selects an item.
|
||||
"""
|
||||
self._text.SetValue(text)
|
||||
@@ -437,15 +437,15 @@ class BaseComboTreeBox(object):
|
||||
self.SetFocus()
|
||||
|
||||
def _postComboBoxSelectedEvent(self, text):
|
||||
"""Simulate a selection event. """
|
||||
event = wx.CommandEvent(wx.wxEVT_COMMAND_COMBOBOX_SELECTED,
|
||||
"""Simulate a selection event. """
|
||||
event = wx.CommandEvent(wx.wxEVT_COMMAND_COMBOBOX_SELECTED,
|
||||
self.GetId())
|
||||
event.SetString(text)
|
||||
self.GetEventHandler().ProcessEvent(event)
|
||||
|
||||
def NotifyNoItemSelected(self):
|
||||
"""
|
||||
This is called by the PopupFrame when the user closes the
|
||||
This is called by the PopupFrame when the user closes the
|
||||
PopupFrame, without selecting an item.
|
||||
"""
|
||||
self.SetFocus()
|
||||
@@ -460,30 +460,30 @@ class BaseComboTreeBox(object):
|
||||
width = comboBoxSize[0]
|
||||
height = 300
|
||||
self._popupFrame.SetSize(x, y, width, height)
|
||||
# On wxGTK, when the Combobox width has been increased a call
|
||||
# to SetMinSize is needed to force a resize of the popupFrame:
|
||||
self._popupFrame.SetMinSize((width, height))
|
||||
# On wxGTK, when the Combobox width has been increased a call
|
||||
# to SetMinSize is needed to force a resize of the popupFrame:
|
||||
self._popupFrame.SetMinSize((width, height))
|
||||
self._popupFrame.Show()
|
||||
|
||||
|
||||
def Hide(self):
|
||||
"""Hide the popped up frame with the tree."""
|
||||
self._popupFrame.Hide()
|
||||
|
||||
|
||||
def GetTree(self):
|
||||
"""Returns the tree control that is popped up."""
|
||||
return self._popupFrame.GetTree()
|
||||
|
||||
def FindClientData(self, clientData, parent=None):
|
||||
"""
|
||||
"""
|
||||
Finds the *first* item in the tree with client data equal to the
|
||||
given clientData. If no such item exists, an invalid item is
|
||||
returned.
|
||||
|
||||
returned.
|
||||
|
||||
:param PyObject `clientData`: the client data to find
|
||||
:keyword TreeItemId `parent`: :class:`TreeItemId` parent or None
|
||||
:return: :class:`TreeItemId`
|
||||
:rtype: :class:`TreeItemId`
|
||||
|
||||
|
||||
"""
|
||||
parent = parent or self._tree.GetRootItem()
|
||||
child, cookie = self._tree.GetFirstChild(parent)
|
||||
@@ -499,14 +499,14 @@ class BaseComboTreeBox(object):
|
||||
|
||||
def SetClientDataSelection(self, clientData):
|
||||
"""
|
||||
Selects the item with the provided clientData in the control.
|
||||
Returns True if the item belonging to the clientData has been
|
||||
Selects the item with the provided clientData in the control.
|
||||
Returns True if the item belonging to the clientData has been
|
||||
selected, False if it wasn't found in the control.
|
||||
|
||||
|
||||
:param PyObject `clientData`: the client data to find
|
||||
:return: True if an item has been selected, otherwise False
|
||||
:rtype: bool
|
||||
|
||||
|
||||
"""
|
||||
item = self.FindClientData(clientData)
|
||||
if item:
|
||||
@@ -519,12 +519,12 @@ class BaseComboTreeBox(object):
|
||||
return False
|
||||
|
||||
# The following methods are all part of the ComboBox API (actually
|
||||
# the ControlWithItems API) and have been adapted to take TreeItemIds
|
||||
# the ControlWithItems API) and have been adapted to take TreeItemIds
|
||||
# as parameter and return :class:`TreeItemId`s, rather than indices.
|
||||
|
||||
def Append(self, itemText, parent=None, clientData=None):
|
||||
"""
|
||||
Adds the itemText to the control, associating the given clientData
|
||||
"""
|
||||
Adds the itemText to the control, associating the given clientData
|
||||
with the item if not None. If parent is None, itemText is added
|
||||
as a root item, else itemText is added as a child item of
|
||||
parent. The return value is the :class:`TreeItemId` of the newly added
|
||||
@@ -536,11 +536,11 @@ class BaseComboTreeBox(object):
|
||||
:keyword PyObject `clientData`: the client data to find
|
||||
:return: :class:`TreeItemId` of newly added item
|
||||
:rtype: :class:`TreeItemId`
|
||||
|
||||
"""
|
||||
|
||||
"""
|
||||
if parent is None:
|
||||
parent = self._tree.GetRootItem()
|
||||
item = self._tree.AppendItem(parent, itemText,
|
||||
item = self._tree.AppendItem(parent, itemText,
|
||||
data=clientData)
|
||||
if self._sort:
|
||||
self._tree.SortChildren(parent)
|
||||
@@ -549,22 +549,22 @@ class BaseComboTreeBox(object):
|
||||
def Clear(self):
|
||||
"""Removes all items from the control."""
|
||||
return self._tree.DeleteAllItems()
|
||||
|
||||
|
||||
def Delete(self, item):
|
||||
"""Deletes the item from the control."""
|
||||
return self._tree.Delete(item)
|
||||
|
||||
def FindString(self, string, parent=None):
|
||||
"""
|
||||
"""
|
||||
Finds the *first* item in the tree with a label equal to the
|
||||
given string. If no such item exists, an invalid item is
|
||||
returned.
|
||||
|
||||
|
||||
:param string `string`: string to be found in label
|
||||
:keyword TreeItemId `parent`: :class:`TreeItemId` parent or None
|
||||
:return: :class:`TreeItemId`
|
||||
:rtype: :class:`TreeItemId`
|
||||
|
||||
|
||||
"""
|
||||
parent = parent or self._tree.GetRootItem()
|
||||
child, cookie = self._tree.GetFirstChild(parent)
|
||||
@@ -582,10 +582,10 @@ class BaseComboTreeBox(object):
|
||||
"""
|
||||
Returns the :class:`TreeItemId` of the selected item or an invalid item
|
||||
if no item is selected.
|
||||
|
||||
|
||||
:return: a TreeItemId
|
||||
:rtype: :class:`TreeItemId`
|
||||
|
||||
|
||||
"""
|
||||
selectedItem = self._tree.GetSelection()
|
||||
if selectedItem and selectedItem != self._tree.GetRootItem():
|
||||
@@ -596,11 +596,11 @@ class BaseComboTreeBox(object):
|
||||
def GetString(self, item):
|
||||
"""
|
||||
Returns the label of the given item.
|
||||
|
||||
|
||||
:param TreeItemId `item`: :class:`TreeItemId` for which to get the label
|
||||
:return: label
|
||||
:rtype: string
|
||||
|
||||
|
||||
"""
|
||||
if item:
|
||||
return self._tree.GetItemText(item)
|
||||
@@ -609,28 +609,28 @@ class BaseComboTreeBox(object):
|
||||
|
||||
def GetStringSelection(self):
|
||||
"""
|
||||
Returns the label of the selected item or an empty string if no item
|
||||
Returns the label of the selected item or an empty string if no item
|
||||
is selected.
|
||||
|
||||
|
||||
:return: the label of the selected item or an empty string
|
||||
:rtype: string
|
||||
|
||||
|
||||
"""
|
||||
return self.GetValue()
|
||||
|
||||
def Insert(self, itemText, previous=None, parent=None, clientData=None):
|
||||
"""
|
||||
Insert an item into the control before the ``previous`` item
|
||||
and/or as child of the ``parent`` item. The itemText is associated
|
||||
Insert an item into the control before the ``previous`` item
|
||||
and/or as child of the ``parent`` item. The itemText is associated
|
||||
with clientData when not None.
|
||||
|
||||
|
||||
:param string `itemText`: the items label
|
||||
:keyword TreeItemId `previous`: the previous item
|
||||
:keyword TreeItemId `parent`: the parent item
|
||||
:keyword PyObject `clientData`: the data to associate
|
||||
:return: the create :class:`TreeItemId`
|
||||
:rtype: :class:`TreeItemId`
|
||||
|
||||
|
||||
"""
|
||||
data = wx.TreeItemData(clientData)
|
||||
if parent is None:
|
||||
@@ -646,44 +646,44 @@ class BaseComboTreeBox(object):
|
||||
def IsEmpty(self):
|
||||
"""
|
||||
Returns True if the control is empty or False if it has some items.
|
||||
|
||||
|
||||
:return: True if control is empty
|
||||
:rtype: boolean
|
||||
|
||||
|
||||
"""
|
||||
return self.GetCount() == 0
|
||||
|
||||
def GetCount(self):
|
||||
"""
|
||||
Returns the number of items in the control.
|
||||
|
||||
|
||||
:return: items in control
|
||||
:rtype: integer
|
||||
|
||||
|
||||
"""
|
||||
# Note: We don't need to substract 1 for the hidden root item,
|
||||
# Note: We don't need to substract 1 for the hidden root item,
|
||||
# because the TreeCtrl does that for us
|
||||
return self._tree.GetCount()
|
||||
return self._tree.GetCount()
|
||||
|
||||
def SetSelection(self, item):
|
||||
"""
|
||||
"""
|
||||
Sets the provided item to be the selected item.
|
||||
|
||||
|
||||
:param TreeItemId `item`: Select this item
|
||||
|
||||
|
||||
"""
|
||||
self._tree.SelectItem(item)
|
||||
self._text.SetValue(self._tree.GetItemText(item))
|
||||
|
||||
|
||||
Select = SetSelection
|
||||
|
||||
def SetString(self, item, string):
|
||||
"""
|
||||
Sets the label for the provided item.
|
||||
|
||||
|
||||
:param TreeItemId `item`: item on which to set the label
|
||||
:param string `string`: the label to set
|
||||
|
||||
|
||||
"""
|
||||
self._tree.SetItemText(item, string)
|
||||
if self._sort:
|
||||
@@ -691,14 +691,14 @@ class BaseComboTreeBox(object):
|
||||
|
||||
def SetStringSelection(self, string):
|
||||
"""
|
||||
Selects the item with the provided string in the control.
|
||||
Selects the item with the provided string in the control.
|
||||
Returns True if the provided string has been selected, False if
|
||||
it wasn't found in the control.
|
||||
|
||||
|
||||
:param string `string`: try to select the item with this string
|
||||
:return: True if an item has been selected
|
||||
:rtype: boolean
|
||||
|
||||
|
||||
"""
|
||||
item = self.FindString(string)
|
||||
if item:
|
||||
@@ -712,31 +712,31 @@ class BaseComboTreeBox(object):
|
||||
def GetClientData(self, item):
|
||||
"""
|
||||
Returns the client data associated with the given item, if any.
|
||||
|
||||
|
||||
:param TreeItemId `item`: item for which to get clientData
|
||||
:return: the client data
|
||||
:rtype: PyObject
|
||||
|
||||
|
||||
"""
|
||||
return self._tree.GetItemPyData(item)
|
||||
|
||||
def SetClientData(self, item, clientData):
|
||||
"""
|
||||
Associate the given client data with the provided item.
|
||||
|
||||
|
||||
:param TreeItemId `item`: item for which to set the clientData
|
||||
:param PyObject `clientData`: the data to set
|
||||
|
||||
|
||||
"""
|
||||
self._tree.SetItemPyData(item, clientData)
|
||||
|
||||
def GetValue(self):
|
||||
"""
|
||||
Returns the current value in the combobox text field.
|
||||
|
||||
|
||||
:return: the current value in the combobox text field
|
||||
:rtype: string
|
||||
|
||||
|
||||
"""
|
||||
if self._text == self:
|
||||
return super(BaseComboTreeBox, self).GetValue()
|
||||
@@ -750,9 +750,9 @@ class BaseComboTreeBox(object):
|
||||
NB: For a combobox with wxCB_READONLY style the string must be
|
||||
in the combobox choices list, otherwise the call to SetValue()
|
||||
is ignored.
|
||||
|
||||
|
||||
:param string `value`: set the combobox text field
|
||||
|
||||
|
||||
"""
|
||||
item = self._tree.GetSelection()
|
||||
if not item or self._tree.GetItemText(item) != value:
|
||||
@@ -778,21 +778,21 @@ class NativeComboTreeBox(BaseComboTreeBox, wx.ComboBox):
|
||||
"""
|
||||
|
||||
def _eventsToBind(self):
|
||||
events = super(NativeComboTreeBox, self)._eventsToBind()
|
||||
events = super(NativeComboTreeBox, self)._eventsToBind()
|
||||
# Bind all mouse click events to self.OnMouseClick so we can
|
||||
# intercept those events and prevent the native Combobox from
|
||||
# popping up its list of choices.
|
||||
for eventType in (wx.EVT_LEFT_DOWN, wx.EVT_LEFT_DCLICK,
|
||||
wx.EVT_MIDDLE_DOWN, wx.EVT_MIDDLE_DCLICK,
|
||||
for eventType in (wx.EVT_LEFT_DOWN, wx.EVT_LEFT_DCLICK,
|
||||
wx.EVT_MIDDLE_DOWN, wx.EVT_MIDDLE_DCLICK,
|
||||
wx.EVT_RIGHT_DOWN, wx.EVT_RIGHT_DCLICK):
|
||||
events.append((self._button, eventType, self.OnMouseClick))
|
||||
if self._readOnly:
|
||||
events.append((self, wx.EVT_CHAR, self.OnChar))
|
||||
return events
|
||||
return events
|
||||
|
||||
def OnChar(self, event):
|
||||
# OnChar is only called when in read only mode. We don't call
|
||||
# event.Skip() on purpose, to prevent the characters from being
|
||||
# OnChar is only called when in read only mode. We don't call
|
||||
# event.Skip() on purpose, to prevent the characters from being
|
||||
# displayed in the text field.
|
||||
pass
|
||||
|
||||
@@ -837,15 +837,15 @@ class MSWComboTreeBox(NativeComboTreeBox):
|
||||
"""
|
||||
Extend SetValue to also select the text in the
|
||||
ComboTreeBox's text field.
|
||||
|
||||
|
||||
:param string `value`: set the value and select it
|
||||
|
||||
|
||||
"""
|
||||
super(MSWComboTreeBox, self).SetValue(value)
|
||||
# We select the text in the ComboTreeBox's text field.
|
||||
# There is a slight complication, however. When the control is
|
||||
# deleted, SetValue is called. But if we call SetMark at that
|
||||
# time, wxPython will crash. We can prevent this by comparing the
|
||||
# There is a slight complication, however. When the control is
|
||||
# deleted, SetValue is called. But if we call SetMark at that
|
||||
# time, wxPython will crash. We can prevent this by comparing the
|
||||
# result of GetLastPosition and the length of the value. If they
|
||||
# match, all is fine. If they don't match, we don't call SetMark.
|
||||
if self._text.GetLastPosition() == len(value):
|
||||
@@ -873,8 +873,8 @@ class MSWComboTreeBox(NativeComboTreeBox):
|
||||
class GTKComboTreeBox(BaseComboTreeBox, wx.Panel):
|
||||
"""
|
||||
The ComboTreeBox widget for wxGTK. This is actually a work
|
||||
around because on wxGTK, there doesn't seem to be a way to intercept
|
||||
mouse events sent to the Combobox. Intercepting those events is
|
||||
around because on wxGTK, there doesn't seem to be a way to intercept
|
||||
mouse events sent to the Combobox. Intercepting those events is
|
||||
necessary to prevent the Combobox from popping up the list and pop up
|
||||
the tree instead. So, until wxPython makes intercepting those events
|
||||
possible we build a poor man's Combobox ourselves using a TextCtrl and
|
||||
@@ -929,12 +929,12 @@ def ComboTreeBox(*args, **kwargs):
|
||||
"""
|
||||
Factory function to create the right ComboTreeBox depending on
|
||||
platform. You may force a specific class, e.g. for testing
|
||||
purposes, by setting the keyword argument 'platform', e.g.
|
||||
purposes, by setting the keyword argument 'platform', e.g.
|
||||
'platform=GTK' or 'platform=MSW' or 'platform=MAC'.
|
||||
|
||||
|
||||
:keyword string `platform`: 'GTK'|'MSW'|'MAC' can be used to override the
|
||||
actual platform for testing
|
||||
|
||||
|
||||
"""
|
||||
|
||||
platform = kwargs.pop('platform', None) or wx.PlatformInfo[0][4:7]
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
"""
|
||||
This module supports the thread-safe, asynchronous transmission of data
|
||||
('delayed results') from a worker (non-GUI) thread to the main thread. Ie you don't
|
||||
need to mutex lock any data, the worker thread doesn't wait (or even check)
|
||||
for the result to be received, and the main thread doesn't wait for the
|
||||
worker thread to send the result. Instead, the consumer will be called
|
||||
automatically by the wx app when the worker thread result is available.
|
||||
This module supports the thread-safe, asynchronous transmission of data
|
||||
('delayed results') from a worker (non-GUI) thread to the main thread. Ie you don't
|
||||
need to mutex lock any data, the worker thread doesn't wait (or even check)
|
||||
for the result to be received, and the main thread doesn't wait for the
|
||||
worker thread to send the result. Instead, the consumer will be called
|
||||
automatically by the wx app when the worker thread result is available.
|
||||
|
||||
In most cases you just need to use startWorker() with the correct parameters
|
||||
(your worker function and your 'consumer' in the simplest of cases). The
|
||||
only requirement on consumer is that it must accept a DelayedResult instance
|
||||
as first arg.
|
||||
(your worker function and your 'consumer' in the simplest of cases). The
|
||||
only requirement on consumer is that it must accept a DelayedResult instance
|
||||
as first arg.
|
||||
|
||||
In the following example, this will call consumer(delayedResult) with the
|
||||
In the following example, this will call consumer(delayedResult) with the
|
||||
return value from workerFn::
|
||||
|
||||
from delayedresult import startWorker
|
||||
startWorker(consumer, workerFn)
|
||||
|
||||
More advanced uses:
|
||||
More advanced uses:
|
||||
|
||||
- The other parameters to startWorker()
|
||||
- Derive from Producer to override _extraInfo (e.g. to provide traceback info)
|
||||
- Create your own worker-function-thread wrapper instead of using Producer
|
||||
- Create your own Handler-like wrapper to pre- or post-process the result
|
||||
- Create your own Handler-like wrapper to pre- or post-process the result
|
||||
(see PreProcessChain)
|
||||
- Derive from Sender to use your own way of making result hop over the
|
||||
- Derive from Sender to use your own way of making result hop over the
|
||||
"thread boundary" (from non-main thread to main thread), e.g. using Queue
|
||||
|
||||
Thanks to Josiah Carlson for critical feedback/ideas that helped me
|
||||
improve this module.
|
||||
Thanks to Josiah Carlson for critical feedback/ideas that helped me
|
||||
improve this module.
|
||||
|
||||
:Copyright: (c) 2006 by Oliver Schoenborn
|
||||
:License: wxWidgets license
|
||||
@@ -39,7 +39,7 @@ improve this module.
|
||||
__author__ = 'Oliver Schoenborn at utoronto dot ca'
|
||||
__version__ = '1.0'
|
||||
|
||||
__all__ = ('Sender', 'SenderNoWx', 'SenderWxEvent', 'SenderCallAfter',
|
||||
__all__ = ('Sender', 'SenderNoWx', 'SenderWxEvent', 'SenderCallAfter',
|
||||
'Handler', 'DelayedResult', 'Producer', 'startWorker', 'PreProcessChain')
|
||||
|
||||
|
||||
@@ -50,20 +50,20 @@ import traceback
|
||||
|
||||
class Struct:
|
||||
"""
|
||||
An object that has attributes built from the dictionary given in
|
||||
An object that has attributes built from the dictionary given in
|
||||
constructor. So ss=Struct(a=1, b='b') will satisfy assert ss.a == 1
|
||||
and assert ss.b == 'b'.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.__dict__.update( kwargs )
|
||||
|
||||
|
||||
class Handler:
|
||||
"""
|
||||
Bind some of the arguments and keyword arguments of a callable ('listener').
|
||||
Bind some of the arguments and keyword arguments of a callable ('listener').
|
||||
Then when the Handler instance is called (e.g. `handler(result, **kwargs)`)
|
||||
the result is passed as first argument to callable, the kwargs is
|
||||
the result is passed as first argument to callable, the kwargs is
|
||||
combined with those given at construction, and the args are those
|
||||
given at construction. Its return value is returned.
|
||||
"""
|
||||
@@ -72,9 +72,9 @@ class Handler:
|
||||
self.__listener = listener
|
||||
self.__args = args
|
||||
self.__kwargs = kwargs
|
||||
|
||||
|
||||
def __call__(self, result, **moreKwargs):
|
||||
"""Listener is assumed to take result as first `arg`, then `*args`,
|
||||
"""Listener is assumed to take result as first `arg`, then `*args`,
|
||||
then the combination of moreKwargs and the kwargs given at construction."""
|
||||
if moreKwargs:
|
||||
moreKwargs.update(self.__kwargs)
|
||||
@@ -82,32 +82,32 @@ class Handler:
|
||||
moreKwargs = self.__kwargs
|
||||
return self.__listener(result, *self.__args, **moreKwargs)
|
||||
|
||||
|
||||
|
||||
class Sender:
|
||||
"""
|
||||
Base class for various kinds of senders. A sender sends a result
|
||||
produced by a worker funtion to a result handler (listener). Note
|
||||
that each sender can be given a "job id". This can be anything
|
||||
(number, string, id, and object, etc) and is not used, it is
|
||||
simply added as attribute whenever a DelayedResult is created.
|
||||
This allows you to know, if desired, what result corresponds to
|
||||
which sender. Note that uniqueness is not necessary.
|
||||
|
||||
(number, string, id, and object, etc) and is not used, it is
|
||||
simply added as attribute whenever a DelayedResult is created.
|
||||
This allows you to know, if desired, what result corresponds to
|
||||
which sender. Note that uniqueness is not necessary.
|
||||
|
||||
Derive from this class if none of the existing derived classes
|
||||
are adequate, and override _sendImpl().
|
||||
are adequate, and override _sendImpl().
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, jobID=None):
|
||||
"""The optional jobID can be anything that you want to use to
|
||||
"""The optional jobID can be anything that you want to use to
|
||||
track which sender particular results come from. """
|
||||
self.__jobID = jobID
|
||||
|
||||
def getJobID(self):
|
||||
"""Return the jobID given at construction"""
|
||||
return self.__jobID
|
||||
|
||||
|
||||
def sendResult(self, result):
|
||||
"""This will send the result to handler, using whatever
|
||||
"""This will send the result to handler, using whatever
|
||||
technique the derived class uses. """
|
||||
delayedResult = DelayedResult(result, jobID=self.__jobID)
|
||||
self._sendImpl(delayedResult)
|
||||
@@ -115,63 +115,63 @@ class Sender:
|
||||
def sendException(self, exception, extraInfo = None, originalTb = None):
|
||||
"""Use this when the worker function raised an exception.
|
||||
The *exception* is the instance of Exception caught. The extraInfo
|
||||
could be anything you want (e.g. locals or traceback etc),
|
||||
could be anything you want (e.g. locals or traceback etc),
|
||||
it will be added to the exception as attribute 'extraInfo'. The
|
||||
exception will be raised when DelayedResult.get() is called."""
|
||||
assert exception is not None
|
||||
delayedResult = DelayedResult(extraInfo,
|
||||
delayedResult = DelayedResult(extraInfo,
|
||||
exception=exception, jobID=self.__jobID, originalTb=originalTb)
|
||||
self._sendImpl(delayedResult)
|
||||
|
||||
def _sendImpl(self, delayedResult):
|
||||
msg = '_sendImpl() must be implemented in %s' % self.__class__
|
||||
raise NotImplementedError(msg)
|
||||
|
||||
|
||||
|
||||
|
||||
class SenderNoWx( Sender ):
|
||||
"""
|
||||
Sender that works without wx. The results are sent directly, ie
|
||||
the consumer will get them "in the worker thread". So it should
|
||||
only be used for testing.
|
||||
the consumer will get them "in the worker thread". So it should
|
||||
only be used for testing.
|
||||
"""
|
||||
def __init__(self, consumer, jobID=None, args=(), kwargs={}):
|
||||
"""The consumer can be any callable of the form
|
||||
"""The consumer can be any callable of the form
|
||||
`callable(result, *args, **kwargs)`"""
|
||||
Sender.__init__(self, jobID)
|
||||
if args or kwargs:
|
||||
self.__consumer = Handler(consumer, *args, **kwargs)
|
||||
else:
|
||||
else:
|
||||
self.__consumer = consumer
|
||||
|
||||
|
||||
def _sendImpl(self, delayedResult):
|
||||
self.__consumer(delayedResult)
|
||||
|
||||
|
||||
|
||||
class SenderWxEvent( Sender ):
|
||||
"""
|
||||
This sender sends the delayed result produced in the worker thread
|
||||
to an event handler in the main thread, via a wx event of class
|
||||
*eventClass*. The result is an attribute of the event (default:
|
||||
"delayedResult".
|
||||
to an event handler in the main thread, via a wx event of class
|
||||
*eventClass*. The result is an attribute of the event (default:
|
||||
"delayedResult".
|
||||
"""
|
||||
def __init__(self, handler, eventClass, resultAttr="delayedResult",
|
||||
def __init__(self, handler, eventClass, resultAttr="delayedResult",
|
||||
jobID=None, **kwargs):
|
||||
"""The handler must derive from wx.EvtHandler. The event class
|
||||
is typically the first item in the pair returned by
|
||||
wx.lib.newevent.NewEvent(). You can use the *resultAttr*
|
||||
to change the attribute name of the generated event's
|
||||
"""The handler must derive from wx.EvtHandler. The event class
|
||||
is typically the first item in the pair returned by
|
||||
wx.lib.newevent.NewEvent(). You can use the *resultAttr*
|
||||
to change the attribute name of the generated event's
|
||||
delayed result. """
|
||||
Sender.__init__(self, jobID)
|
||||
if not isinstance(handler, wx.EvtHandler):
|
||||
msg = 'SenderWxEvent(handler=%s, ...) not allowed,' % type(handler)
|
||||
msg = '%s handler must derive from wx.EvtHandler' % msg
|
||||
raise ValueError(msg)
|
||||
self.__consumer = Struct(handler=handler, eventClass=eventClass,
|
||||
self.__consumer = Struct(handler=handler, eventClass=eventClass,
|
||||
resultAttr=resultAttr, kwargs=kwargs)
|
||||
|
||||
|
||||
def _sendImpl(self, delayedResult):
|
||||
"""Must not modify the consumer (that was created at construction)
|
||||
since might be shared by several senders, each sending from
|
||||
"""Must not modify the consumer (that was created at construction)
|
||||
since might be shared by several senders, each sending from
|
||||
separate threads."""
|
||||
consumer = self.__consumer
|
||||
kwargs = consumer.kwargs.copy()
|
||||
@@ -183,7 +183,7 @@ class SenderWxEvent( Sender ):
|
||||
class SenderCallAfter( Sender ):
|
||||
"""
|
||||
This sender sends the delayed result produced in the worker thread
|
||||
to a callable in the main thread, via wx.CallAfter.
|
||||
to a callable in the main thread, via wx.CallAfter.
|
||||
"""
|
||||
def __init__(self, listener, jobID=None, args=(), kwargs={}):
|
||||
Sender.__init__(self, jobID)
|
||||
@@ -191,22 +191,22 @@ class SenderCallAfter( Sender ):
|
||||
self.__consumer = Handler(listener, *args, **kwargs)
|
||||
else:
|
||||
self.__consumer = listener
|
||||
|
||||
|
||||
def _sendImpl(self, delayedResult):
|
||||
wx.CallAfter(self.__consumer, delayedResult)
|
||||
|
||||
|
||||
|
||||
class DelayedResult:
|
||||
"""
|
||||
Represent the actual delayed result coming from the non-main thread.
|
||||
An instance of this is given to the result handler. This result is
|
||||
either a (reference to a) the value sent, or an exception.
|
||||
Represent the actual delayed result coming from the non-main thread.
|
||||
An instance of this is given to the result handler. This result is
|
||||
either a (reference to a) the value sent, or an exception.
|
||||
If the latter, the exception is raised when the get() method gets
|
||||
called.
|
||||
called.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, result, jobID=None, exception = None, originalTb = None):
|
||||
"""You should never have to call this yourself. A DelayedResult
|
||||
"""You should never have to call this yourself. A DelayedResult
|
||||
is created by a concrete Sender for you."""
|
||||
self.__result = result
|
||||
self.__exception = exception
|
||||
@@ -214,56 +214,56 @@ class DelayedResult:
|
||||
self.__jobID = jobID
|
||||
|
||||
def getJobID(self):
|
||||
"""Return the jobID given when Sender initialized,
|
||||
"""Return the jobID given when Sender initialized,
|
||||
or None if none given. """
|
||||
return self.__jobID
|
||||
|
||||
return self.__jobID
|
||||
|
||||
def get(self):
|
||||
"""Get the result. If an exception was sent instead of a result,
|
||||
"""Get the result. If an exception was sent instead of a result,
|
||||
(via Sender's sendExcept()), that **exception is raised**, and
|
||||
the original traceback is available as the 'originalTraceback'
|
||||
variable in the exception object.
|
||||
|
||||
Otherwise, the result is simply returned.
|
||||
Otherwise, the result is simply returned.
|
||||
"""
|
||||
if self.__exception: # exception was raised!
|
||||
self.__exception.extraInfo = self.__result
|
||||
self.__exception.originalTraceback = self.__original_traceback
|
||||
raise self.__exception
|
||||
|
||||
|
||||
return self.__result
|
||||
|
||||
|
||||
class AbortedException(Exception):
|
||||
"""Raise this in your worker function so that the sender knows
|
||||
"""Raise this in your worker function so that the sender knows
|
||||
not to send a result to handler."""
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class Producer(threading.Thread):
|
||||
"""
|
||||
Represent the worker thread that produces delayed results.
|
||||
It causes the given function to run in a separate thread,
|
||||
Represent the worker thread that produces delayed results.
|
||||
It causes the given function to run in a separate thread,
|
||||
and a sender to be used to send the return value of the function.
|
||||
As with any threading.Thread, instantiate and call start().
|
||||
Note that if the workerFn raises AbortedException, the result is not
|
||||
Note that if the workerFn raises AbortedException, the result is not
|
||||
sent and the thread terminates gracefully.
|
||||
"""
|
||||
|
||||
def __init__(self, sender, workerFn, args=(), kwargs={},
|
||||
name=None, group=None, daemon=False,
|
||||
|
||||
def __init__(self, sender, workerFn, args=(), kwargs={},
|
||||
name=None, group=None, daemon=False,
|
||||
sendReturn=True, senderArg=None):
|
||||
"""The sender will send the return value of
|
||||
`workerFn(*args, **kwargs)` to the main thread. The name and group
|
||||
are same as threading.Thread constructor parameters. Daemon causes
|
||||
setDaemon() to be called. If sendReturn is False, then the return
|
||||
value of workerFn() will not be sent. If senderArg is given, it
|
||||
must be the name of the keyword arg to use to pass the sender into
|
||||
"""The sender will send the return value of
|
||||
`workerFn(*args, **kwargs)` to the main thread. The name and group
|
||||
are same as threading.Thread constructor parameters. Daemon causes
|
||||
setDaemon() to be called. If sendReturn is False, then the return
|
||||
value of workerFn() will not be sent. If senderArg is given, it
|
||||
must be the name of the keyword arg to use to pass the sender into
|
||||
the workerFn, so the function can send (typically many) results."""
|
||||
if senderArg:
|
||||
kwargs[senderArg] = sender
|
||||
def wrapper():
|
||||
try:
|
||||
try:
|
||||
result = workerFn(*args, **kwargs)
|
||||
except AbortedException:
|
||||
pass
|
||||
@@ -274,14 +274,14 @@ class Producer(threading.Thread):
|
||||
else:
|
||||
if sendReturn:
|
||||
sender.sendResult(result)
|
||||
|
||||
|
||||
threading.Thread.__init__(self, name=name, group=group, target=wrapper)
|
||||
if daemon:
|
||||
self.setDaemon(daemon)
|
||||
|
||||
|
||||
def _extraInfo(self, exception):
|
||||
"""This method could be overridden in a derived class to provide
|
||||
extra information when an exception is being sent instead of a
|
||||
"""This method could be overridden in a derived class to provide
|
||||
extra information when an exception is being sent instead of a
|
||||
result. """
|
||||
return None
|
||||
|
||||
@@ -292,21 +292,21 @@ class AbortEvent:
|
||||
raises AbortedException when called (see the __call__ method, everything
|
||||
else is just to make it look like threading.Event).
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.__ev = threading.Event()
|
||||
|
||||
def __call__(self, timeout=None):
|
||||
"""See if event has been set (wait at most timeout if given). If so,
|
||||
"""See if event has been set (wait at most timeout if given). If so,
|
||||
raise AbortedException. Otherwise return None. Allows you to do
|
||||
'while not event():' which will always succeed unless the event
|
||||
'while not event():' which will always succeed unless the event
|
||||
has been set (then AbortedException will cause while to exit)."""
|
||||
if timeout:
|
||||
self.__ev.wait(timeout)
|
||||
if self.__ev.isSet():
|
||||
raise AbortedException()
|
||||
return None
|
||||
|
||||
|
||||
def __getattr__(self, name):
|
||||
"""This allows us to be a kind of threading.Event."""
|
||||
if name in ('set','clear','wait','isSet'):
|
||||
@@ -314,10 +314,10 @@ class AbortEvent:
|
||||
|
||||
|
||||
def startWorker(
|
||||
consumer, workerFn,
|
||||
cargs=(), ckwargs={},
|
||||
consumer, workerFn,
|
||||
cargs=(), ckwargs={},
|
||||
wargs=(), wkwargs={},
|
||||
jobID=None, group=None, daemon=False,
|
||||
jobID=None, group=None, daemon=False,
|
||||
sendReturn=True, senderArg=None):
|
||||
"""
|
||||
Convenience function to send data produced by `workerFn(*wargs, **wkwargs)`
|
||||
@@ -325,35 +325,35 @@ def startWorker(
|
||||
the main thread. This function merely creates a SenderCallAfter (or a
|
||||
SenderWxEvent, if consumer derives from wx.EvtHandler), and a Producer,
|
||||
and returns immediately after starting the Producer thread. The jobID
|
||||
is used for the Sender and as name for the Producer thread. Returns the
|
||||
is used for the Sender and as name for the Producer thread. Returns the
|
||||
thread created, in case caller needs join/etc.
|
||||
"""
|
||||
|
||||
|
||||
if isinstance(consumer, wx.EvtHandler):
|
||||
eventClass = cargs[0]
|
||||
sender = SenderWxEvent(consumer, eventClass, jobID=jobID, **ckwargs)
|
||||
else:
|
||||
sender = SenderCallAfter(consumer, jobID, args=cargs, kwargs=ckwargs)
|
||||
|
||||
|
||||
thread = Producer(
|
||||
sender, workerFn, args=wargs, kwargs=wkwargs,
|
||||
name=jobID, group=group, daemon=daemon,
|
||||
sender, workerFn, args=wargs, kwargs=wkwargs,
|
||||
name=jobID, group=group, daemon=daemon,
|
||||
senderArg=senderArg, sendReturn=sendReturn)
|
||||
|
||||
thread.start()
|
||||
|
||||
thread.start()
|
||||
return thread
|
||||
|
||||
|
||||
class PreProcessChain:
|
||||
"""
|
||||
Represent a 'delayed result pre-processing chain', a kind of Handler.
|
||||
Useful when lower-level objects need to apply a sequence of transformations
|
||||
to the delayed result before handing it over to a final handler.
|
||||
This allows the starter of the worker function to not know
|
||||
anything about the lower-level objects.
|
||||
Represent a 'delayed result pre-processing chain', a kind of Handler.
|
||||
Useful when lower-level objects need to apply a sequence of transformations
|
||||
to the delayed result before handing it over to a final handler.
|
||||
This allows the starter of the worker function to not know
|
||||
anything about the lower-level objects.
|
||||
"""
|
||||
def __init__(self, handler, *args, **kwargs):
|
||||
"""Wrap `handler(result, *args, **kwargs)` so that the result
|
||||
"""Wrap `handler(result, *args, **kwargs)` so that the result
|
||||
it receives has been transformed by us. """
|
||||
if handler is None:# assume rhs is a chain
|
||||
self.__chain = args[0]
|
||||
@@ -365,45 +365,45 @@ class PreProcessChain:
|
||||
def addSub(self, callable, *args, **kwargs):
|
||||
"""Add a sub-callable, ie a `callable(result, *args, **kwargs)`
|
||||
that returns a transformed result to the previously added
|
||||
sub-callable (or the handler given at construction, if this is
|
||||
sub-callable (or the handler given at construction, if this is
|
||||
the first call to addSub). """
|
||||
self.__chain.append( Handler(callable, *args, **kwargs) )
|
||||
|
||||
|
||||
def clone(self):
|
||||
"""Clone the chain. Shallow only. Useful when several threads
|
||||
"""Clone the chain. Shallow only. Useful when several threads
|
||||
must be started but have different sub-callables. """
|
||||
return PreProcessChain(None, self.__chain[:] )
|
||||
|
||||
|
||||
def cloneAddSub(self, callable, *args, **kwargs):
|
||||
"""Convenience method that first clones self, then calls addSub()
|
||||
"""Convenience method that first clones self, then calls addSub()
|
||||
on that clone with given arguments. """
|
||||
cc = self.clone()
|
||||
cc.addSub(callable, *args, **kwargs)
|
||||
|
||||
|
||||
def count(self):
|
||||
"""How many pre-processors in the chain"""
|
||||
return len(self.__chain)
|
||||
|
||||
|
||||
class Traverser:
|
||||
"""
|
||||
Traverses the chain of pre-processors it is given, transforming
|
||||
the original delayedResult along the way. The return value of each
|
||||
the original delayedResult along the way. The return value of each
|
||||
callable added via addSub() is given to the previous addSub() callable,
|
||||
until the handler is reached.
|
||||
until the handler is reached.
|
||||
"""
|
||||
def __init__(self, delayedResult, chain):
|
||||
self.__dr = delayedResult
|
||||
self.__chain = chain
|
||||
|
||||
|
||||
def get(self):
|
||||
"""This makes handler think we are a delayedResult."""
|
||||
if not self.__chain:
|
||||
return self.__dr.get()
|
||||
|
||||
|
||||
handler = self.__chain[0]
|
||||
del self.__chain[0]
|
||||
return handler(self)
|
||||
|
||||
|
||||
def getJobID(self):
|
||||
"""Return the job id for the delayedResult we transform."""
|
||||
return self.__dr.getJobID()
|
||||
@@ -411,10 +411,10 @@ class PreProcessChain:
|
||||
|
||||
def __call__(self, delayedResult):
|
||||
"""This makes us a Handler. We just call handler(Traverser). The
|
||||
handler will think it is getting a delayed result, but in fact
|
||||
handler will think it is getting a delayed result, but in fact
|
||||
will be getting an instance of Traverser, which will take care
|
||||
of properly applying the chain of transformations to delayedResult."""
|
||||
chainTrav = self.Traverser(delayedResult, self.__chain[1:])
|
||||
handler = self.__chain[0]
|
||||
handler( chainTrav )
|
||||
|
||||
|
||||
|
||||
@@ -34,12 +34,12 @@ class ScrolledMessageDialog(wx.Dialog):
|
||||
if x == -1 and y == -1:
|
||||
self.CenterOnScreen(wx.BOTH)
|
||||
|
||||
self.text = text = wx.TextCtrl(self, -1, msg,
|
||||
self.text = text = wx.TextCtrl(self, -1, msg,
|
||||
style=wx.TE_MULTILINE | wx.TE_READONLY)
|
||||
|
||||
ok = wx.Button(self, wx.ID_OK, "OK")
|
||||
ok.SetDefault()
|
||||
lc = layoutf.Layoutf('t=t5#1;b=t5#2;l=l5#1;r=r5#1', (self,ok))
|
||||
lc = layoutf.Layoutf('t=t5#1;b=t5#2;l=l5#1;r=r5#1', (self,ok))
|
||||
text.SetConstraints(lc)
|
||||
|
||||
lc = layoutf.Layoutf('b=b5#1;x%w50#1;w!80;h*', (self,))
|
||||
@@ -52,32 +52,32 @@ class MultipleChoiceDialog(wx.Dialog):
|
||||
def __init__(self, parent, msg, title, lst, pos = wx.DefaultPosition,
|
||||
size = (200,200), style = wx.DEFAULT_DIALOG_STYLE):
|
||||
wx.Dialog.__init__(self, parent, -1, title, pos, size, style)
|
||||
|
||||
|
||||
x, y = pos
|
||||
if x == -1 and y == -1:
|
||||
self.CenterOnScreen(wx.BOTH)
|
||||
|
||||
stat = wx.StaticText(self, -1, msg)
|
||||
self.lbox = wx.ListBox(self, 100, wx.DefaultPosition, wx.DefaultSize,
|
||||
self.lbox = wx.ListBox(self, 100, wx.DefaultPosition, wx.DefaultSize,
|
||||
lst, wx.LB_MULTIPLE)
|
||||
|
||||
ok = wx.Button(self, wx.ID_OK, "OK")
|
||||
ok.SetDefault()
|
||||
cancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
|
||||
|
||||
|
||||
dlgsizer = wx.BoxSizer(wx.VERTICAL)
|
||||
dlgsizer.Add(stat, 0, wx.ALL, 4)
|
||||
dlgsizer.Add(self.lbox, 1, wx.EXPAND | wx.ALL, 4)
|
||||
|
||||
|
||||
btnsizer = wx.StdDialogButtonSizer()
|
||||
btnsizer.AddButton(ok)
|
||||
btnsizer.AddButton(cancel)
|
||||
btnsizer.Realize()
|
||||
|
||||
|
||||
dlgsizer.Add(btnsizer, 0, wx.ALL | wx.ALIGN_RIGHT, 4)
|
||||
|
||||
|
||||
self.SetSizer(dlgsizer)
|
||||
|
||||
|
||||
self.lst = lst
|
||||
self.Layout()
|
||||
|
||||
@@ -315,7 +315,7 @@ def dirDialog(parent=None, message='Choose a directory', path='', style=0,
|
||||
directoryDialog = dirDialog
|
||||
|
||||
|
||||
def singleChoiceDialog(parent=None, message='', title='', lst=[],
|
||||
def singleChoiceDialog(parent=None, message='', title='', lst=[],
|
||||
style=wx.OK | wx.CANCEL | wx.CENTRE):
|
||||
dialog = wx.SingleChoiceDialog(parent, message, title, list(lst), style | wx.DEFAULT_DIALOG_STYLE)
|
||||
result = DialogResults(dialog.ShowModal())
|
||||
@@ -344,8 +344,8 @@ try:
|
||||
except AttributeError:
|
||||
wx.CANCEL_DEFAULT = 0
|
||||
wx.OK_DEFAULT = 0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class MultiMessageDialog(wx.Dialog):
|
||||
"""
|
||||
@@ -357,7 +357,7 @@ class MultiMessageDialog(wx.Dialog):
|
||||
"""
|
||||
CONTENT_MAX_W = 550
|
||||
CONTENT_MAX_H = 350
|
||||
|
||||
|
||||
def __init__(self, parent, message, caption = "Message Box", msg2="",
|
||||
style = wx.OK | wx.CANCEL, pos = wx.DefaultPosition, icon=None,
|
||||
btnLabels=None):
|
||||
@@ -365,13 +365,13 @@ class MultiMessageDialog(wx.Dialog):
|
||||
title = caption # the caption will be displayed inside the dialog on Macs
|
||||
else:
|
||||
title = ""
|
||||
|
||||
wx.Dialog.__init__(self, parent, -1, title, pos,
|
||||
|
||||
wx.Dialog.__init__(self, parent, -1, title, pos,
|
||||
style = wx.DEFAULT_DIALOG_STYLE | style & (wx.STAY_ON_TOP | wx.DIALOG_NO_PARENT))
|
||||
|
||||
|
||||
bitmap = None
|
||||
isize = (32,32)
|
||||
|
||||
|
||||
# was an icon passed to us?
|
||||
if icon is not None:
|
||||
if isinstance(icon, wx.Icon):
|
||||
@@ -382,7 +382,7 @@ class MultiMessageDialog(wx.Dialog):
|
||||
else:
|
||||
assert isinstance(icon, wx.Bitmap)
|
||||
bitmap = icon
|
||||
|
||||
|
||||
else:
|
||||
# check for icons in the style flags
|
||||
artid = None
|
||||
@@ -397,17 +397,17 @@ class MultiMessageDialog(wx.Dialog):
|
||||
|
||||
if artid is not None:
|
||||
bitmap = wx.ArtProvider.GetBitmap(artid, wx.ART_MESSAGE_BOX, isize)
|
||||
|
||||
|
||||
if bitmap:
|
||||
bitmap = wx.StaticBitmap(self, -1, bitmap)
|
||||
else:
|
||||
bitmap = isize # will be a spacer when added to the sizer
|
||||
|
||||
|
||||
# Sizer to contain the icon, text area and buttons
|
||||
sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
sizer.Add(bitmap, 0, wx.TOP|wx.LEFT, 12)
|
||||
sizer.Add((10,10))
|
||||
|
||||
|
||||
# Make the text area
|
||||
messageSizer = wx.BoxSizer(wx.VERTICAL)
|
||||
if 'wxMac' in wx.PlatformInfo and caption:
|
||||
@@ -415,7 +415,7 @@ class MultiMessageDialog(wx.Dialog):
|
||||
caption.SetFont(wx.Font(18, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
|
||||
messageSizer.Add(caption)
|
||||
messageSizer.Add((10,10))
|
||||
|
||||
|
||||
stext = wx.StaticText(self, -1, message)
|
||||
#stext.SetLabelMarkup(message) Wrap() causes all markup to be lost, so don't try to use it yet...
|
||||
stext.Wrap(self.CONTENT_MAX_W)
|
||||
@@ -425,7 +425,7 @@ class MultiMessageDialog(wx.Dialog):
|
||||
messageSizer.Add((15,15))
|
||||
t = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_RICH|wx.TE_DONTWRAP)
|
||||
t.SetValue(msg2)
|
||||
|
||||
|
||||
# Set size to be used by the sizer based on the message content,
|
||||
# with good maximums
|
||||
dc = wx.ClientDC(t)
|
||||
@@ -435,10 +435,10 @@ class MultiMessageDialog(wx.Dialog):
|
||||
h = min(self.CONTENT_MAX_H, 10 + h)
|
||||
t.SetMinSize((w,h))
|
||||
messageSizer.Add(t, 0, wx.EXPAND)
|
||||
|
||||
|
||||
# Make the buttons
|
||||
buttonSizer = self.CreateStdDialogButtonSizer(
|
||||
style & (wx.OK | wx.CANCEL | wx.YES_NO | wx.NO_DEFAULT
|
||||
style & (wx.OK | wx.CANCEL | wx.YES_NO | wx.NO_DEFAULT
|
||||
| wx.CANCEL_DEFAULT | wx.YES_DEFAULT | wx.OK_DEFAULT
|
||||
))
|
||||
self.Bind(wx.EVT_BUTTON, self.OnButton)
|
||||
@@ -449,7 +449,7 @@ class MultiMessageDialog(wx.Dialog):
|
||||
btn.SetLabel(label)
|
||||
messageSizer.Add(wx.Size(1, 15))
|
||||
messageSizer.Add(buttonSizer, 0, wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, 12)
|
||||
|
||||
|
||||
sizer.Add(messageSizer, 0, wx.LEFT | wx.RIGHT | wx.TOP, 12)
|
||||
self.SetSizer(sizer)
|
||||
self.Fit()
|
||||
@@ -457,23 +457,23 @@ class MultiMessageDialog(wx.Dialog):
|
||||
self.CenterOnParent()
|
||||
else:
|
||||
self.CenterOnScreen()
|
||||
|
||||
|
||||
for c in self.Children:
|
||||
if isinstance(c, wx.Button):
|
||||
wx.CallAfter(c.SetFocus)
|
||||
break
|
||||
|
||||
|
||||
|
||||
def OnButton(self, evt):
|
||||
if self.IsModal():
|
||||
self.EndModal(evt.EventObject.Id)
|
||||
else:
|
||||
self.Close()
|
||||
|
||||
|
||||
|
||||
|
||||
def MultiMessageBox(message, caption, msg2="", style=wx.OK, parent=None,
|
||||
|
||||
|
||||
|
||||
|
||||
def MultiMessageBox(message, caption, msg2="", style=wx.OK, parent=None,
|
||||
icon=None, btnLabels=None):
|
||||
"""
|
||||
A function like :class:`wx.MessageBox` which uses :class:`MultiMessageDialog`.
|
||||
@@ -485,11 +485,11 @@ def MultiMessageBox(message, caption, msg2="", style=wx.OK, parent=None,
|
||||
else:
|
||||
style |= wx.ICON_INFORMATION
|
||||
|
||||
dlg = MultiMessageDialog(parent, message, caption, msg2, style,
|
||||
dlg = MultiMessageDialog(parent, message, caption, msg2, style,
|
||||
icon=icon, btnLabels=btnLabels)
|
||||
ans = dlg.ShowModal()
|
||||
dlg.Destroy()
|
||||
|
||||
|
||||
if ans == wx.ID_OK:
|
||||
return wx.OK
|
||||
elif ans == wx.ID_YES:
|
||||
@@ -501,8 +501,8 @@ def MultiMessageBox(message, caption, msg2="", style=wx.OK, parent=None,
|
||||
|
||||
print("unexpected return code from MultiMessageDialog??")
|
||||
return wx.CANCEL
|
||||
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -79,7 +79,7 @@ class Document(wx.EvtHandler):
|
||||
The document class can be used to model an application's file-based data. It
|
||||
is part of the document/view framework supported by wxWindows, and cooperates
|
||||
with the :class:`View`, :class:`DocTemplate` and :class:`DocManager` classes.
|
||||
|
||||
|
||||
Note this wxPython version also keeps track of the modification date of the
|
||||
document and if it changes on disk outside of the application, we will warn the
|
||||
user before saving to avoid clobbering the file.
|
||||
@@ -169,14 +169,14 @@ class Document(wx.EvtHandler):
|
||||
|
||||
def GetDocumentSaved(self):
|
||||
"""
|
||||
Returns True if the document has been saved.
|
||||
Returns True if the document has been saved.
|
||||
"""
|
||||
return self._savedYet
|
||||
|
||||
|
||||
def SetDocumentSaved(self, saved=True):
|
||||
"""
|
||||
Sets whether the document has been saved.
|
||||
Sets whether the document has been saved.
|
||||
"""
|
||||
self._savedYet = saved
|
||||
|
||||
@@ -232,7 +232,7 @@ class Document(wx.EvtHandler):
|
||||
def GetDocumentModificationDate(self):
|
||||
"""
|
||||
Returns the file's modification date when it was loaded from disk.
|
||||
This is used to check if the file has been modified outside of the application.
|
||||
This is used to check if the file has been modified outside of the application.
|
||||
"""
|
||||
return self._documentModificationDate
|
||||
|
||||
@@ -383,14 +383,14 @@ class Document(wx.EvtHandler):
|
||||
msgTitle,
|
||||
wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION,
|
||||
self.GetDocumentWindow())
|
||||
|
||||
|
||||
if res == wx.NO:
|
||||
return True
|
||||
elif res == wx.YES:
|
||||
pass
|
||||
else: # elif res == wx.CANCEL:
|
||||
return False
|
||||
|
||||
|
||||
if not self._documentFile or not self._savedYet:
|
||||
return self.SaveAs()
|
||||
return self.OnSaveDocument(self._documentFile)
|
||||
@@ -430,7 +430,7 @@ class Document(wx.EvtHandler):
|
||||
|
||||
if docTemplate.FileMatchesTemplate(filename):
|
||||
self.GetDocumentManager().AddFileToHistory(filename)
|
||||
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -475,7 +475,7 @@ class Document(wx.EvtHandler):
|
||||
self.SaveObject(fileObject)
|
||||
fileObject.close()
|
||||
fileObject = None
|
||||
|
||||
|
||||
if backupFilename:
|
||||
os.remove(backupFilename)
|
||||
except:
|
||||
@@ -484,7 +484,7 @@ class Document(wx.EvtHandler):
|
||||
traceback.print_exc()
|
||||
|
||||
if fileObject:
|
||||
fileObject.close() # file is still open, close it, need to do this before removal
|
||||
fileObject.close() # file is still open, close it, need to do this before removal
|
||||
|
||||
# save failed, remove copied file
|
||||
if backupFilename and copied:
|
||||
@@ -532,7 +532,7 @@ class Document(wx.EvtHandler):
|
||||
traceback.print_exc()
|
||||
|
||||
if fileObject:
|
||||
fileObject.close() # file is still open, close it
|
||||
fileObject.close() # file is still open, close it
|
||||
|
||||
wx.MessageBox("Could not open '%s'. %s" % (FileNameFromPath(filename), sys.exc_value),
|
||||
msgTitle,
|
||||
@@ -633,7 +633,7 @@ class Document(wx.EvtHandler):
|
||||
msgTitle,
|
||||
wx.YES_NO | wx.CANCEL | wx.ICON_QUESTION,
|
||||
self.GetDocumentWindow())
|
||||
|
||||
|
||||
if res == wx.NO:
|
||||
self.Modify(False)
|
||||
return True
|
||||
@@ -747,7 +747,7 @@ class Document(wx.EvtHandler):
|
||||
Returns true if the document can be written to its accociated file path.
|
||||
"""
|
||||
if not self._writeable:
|
||||
return False
|
||||
return False
|
||||
if not self._documentFile: # Doesn't exist, do a save as
|
||||
return True
|
||||
else:
|
||||
@@ -805,7 +805,7 @@ class View(wx.EvtHandler):
|
||||
def ProcessUpdateUIEvent(self, event):
|
||||
"""
|
||||
Processes a UI event, searching event tables and calling zero or more
|
||||
suitable event handler function(s).
|
||||
suitable event handler function(s).
|
||||
"""
|
||||
return False
|
||||
|
||||
@@ -857,7 +857,7 @@ class View(wx.EvtHandler):
|
||||
frame.OnTitleIsModified()
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def OnChangeFilename(self):
|
||||
"""
|
||||
@@ -1172,14 +1172,14 @@ class DocTemplate(wx.Object):
|
||||
def GetIcon(self):
|
||||
"""
|
||||
Returns the icon, as passed to the document template
|
||||
constructor.
|
||||
constructor.
|
||||
"""
|
||||
return self._icon
|
||||
|
||||
|
||||
def SetIcon(self, flags):
|
||||
"""
|
||||
Sets the icon.
|
||||
Sets the icon.
|
||||
"""
|
||||
self._icon = icon
|
||||
|
||||
@@ -1214,7 +1214,7 @@ class DocTemplate(wx.Object):
|
||||
false otherwise.
|
||||
"""
|
||||
return (self._flags & TEMPLATE_NO_CREATE) != TEMPLATE_NO_CREATE
|
||||
|
||||
|
||||
|
||||
def GetDocumentName(self):
|
||||
"""
|
||||
@@ -1273,7 +1273,7 @@ class DocTemplate(wx.Object):
|
||||
"""
|
||||
ext = FindExtension(path)
|
||||
if not ext: return False
|
||||
|
||||
|
||||
extList = self.GetFileFilter().replace('*','').split(';')
|
||||
return ext in extList
|
||||
|
||||
@@ -1352,7 +1352,7 @@ class DocManager(wx.EvtHandler):
|
||||
|
||||
def GetFlags(self):
|
||||
"""
|
||||
Returns the document manager's flags.
|
||||
Returns the document manager's flags.
|
||||
"""
|
||||
return self._flags
|
||||
|
||||
@@ -1434,7 +1434,7 @@ class DocManager(wx.EvtHandler):
|
||||
"""
|
||||
return self.CloseDocuments(force = False)
|
||||
|
||||
|
||||
|
||||
def OnFileNew(self, event):
|
||||
"""
|
||||
Creates a new document and reads in the selected file.
|
||||
@@ -1497,7 +1497,7 @@ class DocManager(wx.EvtHandler):
|
||||
self.printData = wx.PrintData()
|
||||
self.printData.SetPaperId(wx.PAPER_LETTER)
|
||||
self.printData.SetPrintMode(wx.PRINT_MODE_PRINTER)
|
||||
|
||||
|
||||
pdd = wx.PrintDialogData(self.printData)
|
||||
printer = wx.Printer(pdd)
|
||||
printer.Print(view.GetFrame(), printout)
|
||||
@@ -1516,17 +1516,17 @@ class DocManager(wx.EvtHandler):
|
||||
if not hasattr(self, "printData"):
|
||||
self.printData = wx.PrintData()
|
||||
self.printData.SetPaperId(wx.PAPER_LETTER)
|
||||
|
||||
|
||||
data = wx.PrintDialogData(self.printData)
|
||||
printDialog = wx.PrintDialog(parentWin, data)
|
||||
printDialog.GetPrintDialogData().SetSetupDialog(True)
|
||||
printDialog.ShowModal()
|
||||
|
||||
|
||||
# this makes a copy of the wx.PrintData instead of just saving
|
||||
# a reference to the one inside the PrintDialogData that will
|
||||
# be destroyed when the dialog is destroyed
|
||||
self.printData = wx.PrintData(printDialog.GetPrintDialogData().GetPrintData())
|
||||
|
||||
|
||||
printDialog.Destroy()
|
||||
|
||||
|
||||
@@ -1545,7 +1545,7 @@ class DocManager(wx.EvtHandler):
|
||||
self.printData = wx.PrintData()
|
||||
self.printData.SetPaperId(wx.PAPER_LETTER)
|
||||
self.printData.SetPrintMode(wx.PRINT_MODE_PREVIEW)
|
||||
|
||||
|
||||
data = wx.PrintDialogData(self.printData)
|
||||
# Pass two printout objects: for preview, and possible printing.
|
||||
preview = wx.PrintPreview(printout, view.OnCreatePrintout(), data)
|
||||
@@ -1756,7 +1756,7 @@ class DocManager(wx.EvtHandler):
|
||||
def ProcessUpdateUIEvent(self, event):
|
||||
"""
|
||||
Processes a UI event, searching event tables and calling zero or more
|
||||
suitable event handler function(s).
|
||||
suitable event handler function(s).
|
||||
"""
|
||||
id = event.GetId()
|
||||
view = self.GetCurrentView()
|
||||
@@ -1827,7 +1827,7 @@ class DocManager(wx.EvtHandler):
|
||||
wxPython version supports the document manager's
|
||||
``wx.lib.docview.DOC_OPEN_ONCE`` and ``wx.lib.docview.DOC_NO_VIEW``
|
||||
flag.
|
||||
|
||||
|
||||
if ``wx.lib.docview.DOC_OPEN_ONCE`` is present, trying to open the
|
||||
same file multiple times will just return the same document. if
|
||||
``wx.lib.docview.DOC_NO_VIEW`` is present, opening a file will
|
||||
@@ -1895,7 +1895,7 @@ class DocManager(wx.EvtHandler):
|
||||
document.GetDocumentTemplate().CreateView(document, flags)
|
||||
document.UpdateAllViews()
|
||||
firstView = document.GetFirstView()
|
||||
|
||||
|
||||
if firstView and firstView.GetFrame() and not (flags & DOC_NO_VIEW):
|
||||
firstView.GetFrame().SetFocus() # Not in wxWindows code but useful nonetheless
|
||||
if hasattr(firstView.GetFrame(), "IsIconized") and firstView.GetFrame().IsIconized(): # Not in wxWindows code but useful nonetheless
|
||||
@@ -2110,7 +2110,7 @@ class DocManager(wx.EvtHandler):
|
||||
Given a path, try to find template that matches the extension. This is
|
||||
only an approximate method of finding a template for creating a
|
||||
document.
|
||||
|
||||
|
||||
Note this wxPython verson looks for and returns a default template
|
||||
if no specific template is found.
|
||||
"""
|
||||
@@ -2118,7 +2118,7 @@ class DocManager(wx.EvtHandler):
|
||||
for temp in self._templates:
|
||||
if temp.FileMatchesTemplate(path):
|
||||
return temp
|
||||
|
||||
|
||||
if "*.*" in temp.GetFileFilter():
|
||||
default = temp
|
||||
return default
|
||||
@@ -2171,12 +2171,12 @@ class DocManager(wx.EvtHandler):
|
||||
else:
|
||||
path = None
|
||||
dlg.Destroy()
|
||||
|
||||
if path:
|
||||
|
||||
if path:
|
||||
theTemplate = self.FindTemplateForPath(path)
|
||||
return (theTemplate, path)
|
||||
|
||||
return (None, None)
|
||||
|
||||
return (None, None)
|
||||
|
||||
|
||||
def OnOpenFileFailure(self):
|
||||
@@ -2400,7 +2400,7 @@ class DocParentFrame(wx.Frame):
|
||||
def ProcessEvent(self, event):
|
||||
"""
|
||||
Processes an event, searching event tables and calling zero or more
|
||||
suitable event handler function(s).
|
||||
suitable event handler function(s).
|
||||
"""
|
||||
return self._docManager and self._docManager.ProcessEvent(event)
|
||||
|
||||
@@ -2408,7 +2408,7 @@ class DocParentFrame(wx.Frame):
|
||||
def ProcessUpdateUIEvent(self, event):
|
||||
"""
|
||||
Processes a UI event, searching event tables and calling zero or more
|
||||
suitable event handler function(s).
|
||||
suitable event handler function(s).
|
||||
"""
|
||||
return self._docManager and self._docManager.ProcessUpdateUIEvent(event)
|
||||
|
||||
@@ -2465,7 +2465,7 @@ class DocChildFrame(wx.Frame):
|
||||
|
||||
def __init__(self, doc, view, frame, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, name="frame"):
|
||||
"""
|
||||
Constructor.
|
||||
Constructor.
|
||||
"""
|
||||
wx.Frame.__init__(self, frame, id, title, pos, size, style, name)
|
||||
wx.EVT_ACTIVATE(self, self.OnActivate)
|
||||
@@ -2505,7 +2505,7 @@ class DocChildFrame(wx.Frame):
|
||||
def ProcessEvent(self, event):
|
||||
"""
|
||||
Processes an event, searching event tables and calling zero or more
|
||||
suitable event handler function(s).
|
||||
suitable event handler function(s).
|
||||
"""
|
||||
if self._childView:
|
||||
self._childView.Activate(True)
|
||||
@@ -2523,7 +2523,7 @@ class DocChildFrame(wx.Frame):
|
||||
def ProcessUpdateUIEvent(self, event):
|
||||
"""
|
||||
Processes a UI event, searching event tables and calling zero or more
|
||||
suitable event handler function(s).
|
||||
suitable event handler function(s).
|
||||
"""
|
||||
if self.GetParent():
|
||||
self.GetParent().ProcessUpdateUIEvent(event)
|
||||
@@ -2538,7 +2538,7 @@ class DocChildFrame(wx.Frame):
|
||||
event.Skip()
|
||||
if self._childView:
|
||||
self._childView.Activate(event.GetActive())
|
||||
|
||||
|
||||
|
||||
def OnCloseWindow(self, event):
|
||||
"""
|
||||
@@ -2606,7 +2606,7 @@ class DocMDIParentFrame(wx.MDIParentFrame):
|
||||
|
||||
def __init__(self, manager, frame, id, title, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE, name="frame"):
|
||||
"""
|
||||
Constructor.
|
||||
Constructor.
|
||||
"""
|
||||
wx.MDIParentFrame.__init__(self, frame, id, title, pos, size, style, name)
|
||||
self._docManager = manager
|
||||
@@ -2646,7 +2646,7 @@ class DocMDIParentFrame(wx.MDIParentFrame):
|
||||
def ProcessEvent(self, event):
|
||||
"""
|
||||
Processes an event, searching event tables and calling zero or more
|
||||
suitable event handler function(s).
|
||||
suitable event handler function(s).
|
||||
"""
|
||||
return self._docManager and self._docManager.ProcessEvent(event)
|
||||
|
||||
@@ -2654,7 +2654,7 @@ class DocMDIParentFrame(wx.MDIParentFrame):
|
||||
def ProcessUpdateUIEvent(self, event):
|
||||
"""
|
||||
Processes a UI event, searching event tables and calling zero or more
|
||||
suitable event handler function(s).
|
||||
suitable event handler function(s).
|
||||
"""
|
||||
return self._docManager and self._docManager.ProcessUpdateUIEvent(event)
|
||||
|
||||
@@ -2754,7 +2754,7 @@ class DocMDIChildFrame(wx.MDIChildFrame):
|
||||
def ProcessEvent(event):
|
||||
"""
|
||||
Processes an event, searching event tables and calling zero or more
|
||||
suitable event handler function(s).
|
||||
suitable event handler function(s).
|
||||
"""
|
||||
if self._activeEvent == event:
|
||||
return False
|
||||
@@ -2863,7 +2863,7 @@ class DocMDIChildFrame(wx.MDIChildFrame):
|
||||
else:
|
||||
if title.endswith("*"):
|
||||
title = title[:-1]
|
||||
self.SetTitle(title)
|
||||
self.SetTitle(title)
|
||||
else:
|
||||
return
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import wx
|
||||
|
||||
class DragScroller:
|
||||
""" Scrolls a wx.ScrollWindow in the direction and speed of a mouse drag.
|
||||
|
||||
|
||||
Call Start with the position of the drag start.
|
||||
Call Stop on the drag release. """
|
||||
|
||||
@@ -24,12 +24,12 @@ class DragScroller:
|
||||
|
||||
self.pos = None
|
||||
self.timer = None
|
||||
|
||||
|
||||
def GetScrollWindow(self):
|
||||
return self.scrollwin
|
||||
def SetScrollWindow(self, scrollwin):
|
||||
self.scrollwin = scrollwin
|
||||
|
||||
|
||||
def GetUpdateRate(self):
|
||||
return self.rate
|
||||
def SetUpdateRate(self, rate):
|
||||
@@ -44,7 +44,7 @@ class DragScroller:
|
||||
""" Start a drag scroll operation """
|
||||
if not self.scrollwin:
|
||||
raise Exception('No ScrollWindow defined')
|
||||
|
||||
|
||||
self.pos = pos
|
||||
self.scrollwin.SetCursor(wx.Cursor(wx.CURSOR_SIZING))
|
||||
if not self.scrollwin.HasCapture():
|
||||
@@ -53,7 +53,7 @@ class DragScroller:
|
||||
self.timer = wx.Timer(self.scrollwin)
|
||||
self.scrollwin.Bind(wx.EVT_TIMER, self.OnTimerDoScroll, id=self.timer.GetId())
|
||||
self.timer.Start(self.rate)
|
||||
|
||||
|
||||
def Stop(self):
|
||||
""" Stops a drag scroll operation """
|
||||
if self.timer and self.scrollwin:
|
||||
@@ -67,9 +67,9 @@ class DragScroller:
|
||||
self.scrollwin.ReleaseMouse()
|
||||
|
||||
def OnTimerDoScroll(self, event):
|
||||
if self.pos is None or not self.timer or not self.scrollwin:
|
||||
if self.pos is None or not self.timer or not self.scrollwin:
|
||||
return
|
||||
|
||||
|
||||
new = self.scrollwin.ScreenToClient(wx.GetMousePosition())
|
||||
dx = int((new.x-self.pos.x)*self.sensitivity)
|
||||
dy = int((new.y-self.pos.y)*self.sensitivity)
|
||||
|
||||
@@ -21,7 +21,7 @@ try:
|
||||
b64decode = base64.b64decode
|
||||
except AttributeError:
|
||||
b64decode = base64.decodestring
|
||||
|
||||
|
||||
|
||||
class PyEmbeddedImage(object):
|
||||
"""
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#----------------------------------------------------------------------
|
||||
# Name: wx.lib.eventStack
|
||||
# Purpose: These mixins implement a push and pop menu/UI update event
|
||||
# Purpose: These mixins implement a push and pop menu/UI update event
|
||||
# handler system at the wx.App level. This is useful for resolving
|
||||
# cases where multiple views may want to respond to an event
|
||||
# (say, wx.ID_COPY) and where you also want a "default" handler
|
||||
# cases where multiple views may want to respond to an event
|
||||
# (say, wx.ID_COPY) and where you also want a "default" handler
|
||||
# for the event (and UI update status) when there is no active
|
||||
# view which wishes to handle the event.
|
||||
#
|
||||
@@ -55,7 +55,7 @@ class AppEventHandlerMixin:
|
||||
|
||||
AddUIHandlerForID(ID, handlerFunc)
|
||||
|
||||
|
||||
|
||||
in their EVT_SET_FOCUS handler, and call Remove(UI)HandlerForID(ID) in their
|
||||
EVT_KILL_FOCUS handler.
|
||||
"""
|
||||
|
||||
@@ -61,19 +61,19 @@ def addModuleEvents(module):
|
||||
if _eventBinders is None:
|
||||
buildWxEventMap()
|
||||
return _buildModuleEventMap(module)
|
||||
|
||||
|
||||
|
||||
# Events that should not be watched by default
|
||||
_noWatchList = [
|
||||
wx.EVT_PAINT,
|
||||
wx.EVT_PAINT,
|
||||
wx.EVT_NC_PAINT,
|
||||
wx.EVT_ERASE_BACKGROUND,
|
||||
wx.EVT_IDLE,
|
||||
wx.EVT_IDLE,
|
||||
wx.EVT_UPDATE_UI,
|
||||
wx.EVT_UPDATE_UI_RANGE,
|
||||
]
|
||||
OTHER_WIDTH = 250
|
||||
|
||||
|
||||
|
||||
def _makeSourceString(wdgt):
|
||||
if wdgt is None:
|
||||
@@ -105,7 +105,7 @@ def _makeAttribString(evt):
|
||||
attribs += "%s : %s\n" % (name, value)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
return attribs.rstrip()
|
||||
|
||||
def cmp(a, b):
|
||||
@@ -121,19 +121,19 @@ class EventLog(wx.ListCtrl):
|
||||
kw['style'] = wx.LC_REPORT|wx.LC_SINGLE_SEL|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES
|
||||
wx.ListCtrl.__init__(self, *args, **kw)
|
||||
self.clear()
|
||||
|
||||
|
||||
if 'wxMac' in wx.PlatformInfo:
|
||||
self.SetWindowVariant(wx.WINDOW_VARIANT_SMALL)
|
||||
|
||||
|
||||
self.InsertColumn(0, "#", format=wx.LIST_FORMAT_RIGHT, width=50)
|
||||
self.InsertColumn(1, "Event", width=200)
|
||||
self.InsertColumn(2, "Source", width=200)
|
||||
|
||||
|
||||
self.SetMinSize((450+wx.SystemSettings.GetMetric(wx.SYS_VSCROLL_X), 450))
|
||||
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onItemSelected)
|
||||
self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.onItemActivated)
|
||||
self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onItemActivated)
|
||||
|
||||
|
||||
def append(self, evt):
|
||||
evtName = _eventIdMap.get(evt.GetEventType(), None)
|
||||
if evtName is None:
|
||||
@@ -143,30 +143,30 @@ class EventLog(wx.ListCtrl):
|
||||
|
||||
lastIsSelected = self.currItem == len(self.data)-1
|
||||
self.data.append( (evtName, source, attribs) )
|
||||
|
||||
|
||||
count = len(self.data)
|
||||
self.SetItemCount(count)
|
||||
self.RefreshItem(count-1)
|
||||
if lastIsSelected:
|
||||
self.Select(count-1)
|
||||
self.EnsureVisible(count-1)
|
||||
|
||||
|
||||
def clear(self):
|
||||
self.data = []
|
||||
self.SetItemCount(0)
|
||||
self.currItem = -1
|
||||
self.Refresh()
|
||||
|
||||
|
||||
def OnGetItemText(self, item, col):
|
||||
if col == 0:
|
||||
val = str(item+1)
|
||||
else:
|
||||
val = self.data[item][col-1]
|
||||
return val
|
||||
|
||||
|
||||
def OnGetItemAttr(self, item): return None
|
||||
def OnGetItemImage(self, item): return -1
|
||||
|
||||
|
||||
def onItemSelected(self, evt):
|
||||
self.currItem = evt.GetIndex()
|
||||
|
||||
@@ -182,20 +182,20 @@ class EventChooser(wx.Panel):
|
||||
"""
|
||||
Panel with CheckListCtrl for selecting which events will be watched.
|
||||
"""
|
||||
|
||||
|
||||
class EventChooserLC(wx.ListCtrl, CheckListCtrlMixin):
|
||||
def __init__(self, parent):
|
||||
wx.ListCtrl.__init__(self, parent,
|
||||
wx.ListCtrl.__init__(self, parent,
|
||||
style=wx.LC_REPORT|wx.LC_SINGLE_SEL|wx.LC_HRULES|wx.LC_VRULES)
|
||||
CheckListCtrlMixin.__init__(self)
|
||||
if 'wxMac' in wx.PlatformInfo:
|
||||
self.SetWindowVariant(wx.WINDOW_VARIANT_SMALL)
|
||||
|
||||
|
||||
# this is called by the base class when an item is checked/unchecked
|
||||
def OnCheckItem(self, index, flag):
|
||||
self.Parent.OnCheckItem(index, flag)
|
||||
|
||||
|
||||
|
||||
|
||||
def __init__(self, *args, **kw):
|
||||
wx.Panel.__init__(self, *args, **kw)
|
||||
self.updateCallback = lambda: None
|
||||
@@ -211,25 +211,25 @@ class EventChooser(wx.Panel):
|
||||
btn2.SetToolTip("Uncheck all events")
|
||||
|
||||
self.Bind(wx.EVT_BUTTON, self.onCheckAll, btn1)
|
||||
self.Bind(wx.EVT_BUTTON, self.onUncheckAll, btn2)
|
||||
|
||||
self.Bind(wx.EVT_BUTTON, self.onUncheckAll, btn2)
|
||||
|
||||
self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.onItemActivated, self.lc)
|
||||
self.lc.InsertColumn(0, "Binder", width=OTHER_WIDTH)
|
||||
|
||||
self.lc.InsertColumn(0, "Binder", width=OTHER_WIDTH)
|
||||
|
||||
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
btnSizer.Add(btn1, 0, wx.ALL, 5)
|
||||
btnSizer.Add(btn2, 0, wx.ALL, 5)
|
||||
|
||||
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
sizer.Add(self._event_name_filter, 0, wx.EXPAND|wx.ALL, 5)
|
||||
sizer.Add(self.lc, 1, wx.EXPAND)
|
||||
sizer.Add(btnSizer)
|
||||
self.SetSizer(sizer)
|
||||
|
||||
|
||||
|
||||
|
||||
def setUpdateCallback(self, func):
|
||||
self.updateCallback = func
|
||||
|
||||
|
||||
def setWatchList(self, watchList):
|
||||
self.doUpdate = False
|
||||
searched = self._event_name_filter.GetValue().lower()
|
||||
@@ -250,15 +250,15 @@ class EventChooser(wx.Panel):
|
||||
self.doUpdate = True
|
||||
self.updateCallback()
|
||||
|
||||
|
||||
|
||||
def OnCheckItem(self, index, flag):
|
||||
index = self.lc.GetItemData(index)
|
||||
item, f = self.watchList[index]
|
||||
self.watchList[index] = (item, flag)
|
||||
if self.doUpdate:
|
||||
self.updateCallback()
|
||||
|
||||
|
||||
|
||||
|
||||
def onItemActivated(self, evt):
|
||||
self.lc.ToggleItem(evt.m_itemIndex)
|
||||
|
||||
@@ -268,7 +268,7 @@ class EventChooser(wx.Panel):
|
||||
self.lc.CheckItem(idx, True)
|
||||
self.doUpdate = True
|
||||
self.updateCallback()
|
||||
|
||||
|
||||
def onUncheckAll(self, evt):
|
||||
self.doUpdate = False
|
||||
for idx in range(self.lc.GetItemCount()):
|
||||
@@ -300,7 +300,7 @@ class EventWatcher(wx.Frame):
|
||||
|
||||
buildWxEventMap()
|
||||
self.buildWatchList(_noWatchList)
|
||||
|
||||
|
||||
# Make the widgets
|
||||
self.splitter = wx.SplitterWindow(self)
|
||||
panel = wx.Panel(self.splitter)
|
||||
@@ -312,12 +312,12 @@ class EventWatcher(wx.Frame):
|
||||
watchBtn.SetValue(True)
|
||||
selectBtn = wx.ToggleButton(panel, -1, ">>>")
|
||||
self.selectBtn = selectBtn
|
||||
|
||||
|
||||
clearBtn.SetToolTip("Clear the event log")
|
||||
addBtn.SetToolTip("Add the event binders in an additional package or module to the watcher")
|
||||
watchBtn.SetToolTip("Toggle the watching of events")
|
||||
selectBtn.SetToolTip("Show/hide the list of events to be logged")
|
||||
|
||||
|
||||
# Do the layout
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
@@ -333,16 +333,16 @@ class EventWatcher(wx.Frame):
|
||||
self.Sizer = wx.BoxSizer()
|
||||
self.Sizer.Add(self.splitter, 1, wx.EXPAND)
|
||||
self.Fit()
|
||||
|
||||
|
||||
# Bind events
|
||||
self.Bind(wx.EVT_CLOSE, self.onCloseWindow)
|
||||
self.Bind(wx.EVT_BUTTON, self.onClear, clearBtn)
|
||||
self.Bind(wx.EVT_BUTTON, self.onAddModule, addBtn)
|
||||
self.Bind(wx.EVT_TOGGLEBUTTON, self.onToggleWatch, watchBtn)
|
||||
self.Bind(wx.EVT_TOGGLEBUTTON, self.onToggleSelectEvents, selectBtn)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def watch(self, widget):
|
||||
assert self._watchedWidget is None, "Can only watch one widget at a time"
|
||||
self.SetTitle("EventWatcher for " + _makeSourceString(widget))
|
||||
@@ -350,27 +350,27 @@ class EventWatcher(wx.Frame):
|
||||
if flag:
|
||||
widget.Bind(evtBinder, self.onWatchedEvent)
|
||||
self._watchedWidget = widget
|
||||
|
||||
|
||||
|
||||
|
||||
def unwatch(self):
|
||||
self.SetTitle("EventWatcher")
|
||||
if self._watchedWidget:
|
||||
for evtBinder, flag in self._watchedEvents:
|
||||
self._watchedWidget.Unbind(evtBinder, handler=self.onWatchedEvent)
|
||||
self._watchedWidget = None
|
||||
|
||||
|
||||
|
||||
|
||||
def updateBindings(self):
|
||||
widget = self._watchedWidget
|
||||
self.unwatch()
|
||||
self.watch(widget)
|
||||
|
||||
|
||||
def onWatchedEvent(self, evt):
|
||||
|
||||
|
||||
def onWatchedEvent(self, evt):
|
||||
if self:
|
||||
self.log.append(evt)
|
||||
evt.Skip()
|
||||
|
||||
|
||||
def buildWatchList(self, exclusions):
|
||||
# This is a list of (PyEventBinder, flag) tuples where the flag indicates
|
||||
# whether to bind that event or not. By default all execpt those in
|
||||
@@ -378,18 +378,18 @@ class EventWatcher(wx.Frame):
|
||||
self._watchedEvents = list()
|
||||
for item in _eventBinders:
|
||||
self._watchedEvents.append( (item, item not in exclusions) )
|
||||
|
||||
|
||||
def onCloseWindow(self, evt):
|
||||
self.unwatch()
|
||||
evt.Skip()
|
||||
|
||||
|
||||
def onClear(self, evt):
|
||||
self.log.clear()
|
||||
|
||||
|
||||
def onAddModule(self, evt):
|
||||
try:
|
||||
dlg = wx.TextEntryDialog(
|
||||
self,
|
||||
self,
|
||||
"Enter the package or module name to be scanned for \"EVT_\" event binders.",
|
||||
"Add Module")
|
||||
if dlg.ShowModal() == wx.ID_OK:
|
||||
@@ -405,13 +405,13 @@ class EventWatcher(wx.Frame):
|
||||
count = addModuleEvents(module)
|
||||
wx.MessageBox("%d new event binders found" % count,
|
||||
"Success")
|
||||
|
||||
|
||||
# Now unwatch and re-watch so we can get the new events bound
|
||||
self.updateBindings()
|
||||
finally:
|
||||
finally:
|
||||
dlg.Destroy()
|
||||
|
||||
|
||||
|
||||
|
||||
def onToggleWatch(self, evt):
|
||||
if evt.IsChecked():
|
||||
self.watch(self._unwatchedWidget)
|
||||
@@ -420,16 +420,16 @@ class EventWatcher(wx.Frame):
|
||||
self._unwatchedWidget = self._watchedWidget
|
||||
self.unwatch()
|
||||
|
||||
|
||||
|
||||
def onToggleSelectEvents(self, evt):
|
||||
if evt.IsChecked():
|
||||
self.selectBtn.SetLabel("<<<")
|
||||
self._selectList = EventChooser(self.splitter)
|
||||
self._selectList.setUpdateCallback(self.updateBindings)
|
||||
self._selectList.setWatchList(self._watchedEvents)
|
||||
|
||||
|
||||
self.SetSize(self.GetSize() + (OTHER_WIDTH,0))
|
||||
self.splitter.SplitVertically(self.splitter.GetWindow1(),
|
||||
self.splitter.SplitVertically(self.splitter.GetWindow1(),
|
||||
self._selectList,
|
||||
-OTHER_WIDTH)
|
||||
else:
|
||||
@@ -441,7 +441,7 @@ class EventWatcher(wx.Frame):
|
||||
self.SetClientSize((sashPos, cs.height))
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = wx.App(redirect=False)
|
||||
frm = wx.Frame(None, title="Test Frame")
|
||||
@@ -449,13 +449,13 @@ if __name__ == '__main__':
|
||||
txt = wx.TextCtrl(pnl, -1, "text", pos=(20,20))
|
||||
btn = wx.Button(pnl, -1, "button", pos=(20,50))
|
||||
frm.Show()
|
||||
|
||||
|
||||
ewf=EventWatcher(frm)
|
||||
ewf.watch(frm)
|
||||
ewf.Show()
|
||||
|
||||
|
||||
#import wx.lib.inspection
|
||||
#wx.lib.inspection.InspectionTool().Show()
|
||||
|
||||
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ Sample usage::
|
||||
class MyFrame(wx.Frame):
|
||||
|
||||
def __init__(self):
|
||||
|
||||
|
||||
wx.Frame.__init__(self, None, title="Test ExpandoTextCtrl")
|
||||
self.pnl = p = wx.Panel(self)
|
||||
self.eom = ExpandoTextCtrl(p, size=(250,-1),
|
||||
@@ -77,7 +77,7 @@ Sample usage::
|
||||
frameSizer = wx.BoxSizer()
|
||||
frameSizer.Add(p, 1, wx.EXPAND)
|
||||
self.SetSizer(frameSizer)
|
||||
|
||||
|
||||
self.Fit()
|
||||
|
||||
|
||||
@@ -89,12 +89,12 @@ Sample usage::
|
||||
# just resize the frame to fit the new needs of the sizer.
|
||||
self.Fit()
|
||||
|
||||
|
||||
|
||||
def OnWriteText(self, evt):
|
||||
self.eom.WriteText("This is a test... Only a test. If this had "
|
||||
"been a real emergency you would have seen the "
|
||||
"quick brown fox jump over the lazy dog.")
|
||||
|
||||
|
||||
def OnAppendText(self, evt):
|
||||
self.eom.AppendText("Appended text.")
|
||||
|
||||
@@ -134,10 +134,10 @@ class ExpandoTextCtrl(wx.TextCtrl):
|
||||
the EVT_ETC_LAYOUT_NEEDED event in the container and make any
|
||||
other layout adjustments that may be needed.
|
||||
"""
|
||||
|
||||
|
||||
_defaultHeight = -1
|
||||
_leading = 1 # TODO: find a way to calculate this, it may vary by platform
|
||||
|
||||
|
||||
def __init__(self, parent, id=-1, value="",
|
||||
pos=wx.DefaultPosition, size=wx.DefaultSize,
|
||||
style=0, validator=wx.DefaultValidator, name="expando"):
|
||||
@@ -177,7 +177,7 @@ class ExpandoTextCtrl(wx.TextCtrl):
|
||||
self.maxHeight = -1
|
||||
if value:
|
||||
wx.CallAfter(self._adjustCtrl)
|
||||
|
||||
|
||||
self.Bind(wx.EVT_TEXT, self.OnTextChanged)
|
||||
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||
|
||||
@@ -201,7 +201,7 @@ class ExpandoTextCtrl(wx.TextCtrl):
|
||||
|
||||
:rtype: int
|
||||
"""
|
||||
|
||||
|
||||
return self.maxHeight
|
||||
|
||||
|
||||
@@ -216,13 +216,13 @@ class ExpandoTextCtrl(wx.TextCtrl):
|
||||
:returns: ``True`` if the font was really changed, ``False`` if it was already
|
||||
set to this font and nothing was done.
|
||||
"""
|
||||
|
||||
|
||||
retVal = wx.TextCtrl.SetFont(self, font)
|
||||
self.numLines = -1
|
||||
self._adjustCtrl()
|
||||
|
||||
return retVal
|
||||
|
||||
|
||||
|
||||
def WriteText(self, text):
|
||||
"""
|
||||
@@ -238,9 +238,9 @@ class ExpandoTextCtrl(wx.TextCtrl):
|
||||
will be at the end of the inserted text, so subsequent write operations will
|
||||
be appended. To append text after the user may have interacted with the control,
|
||||
call :meth:`TextCtrl.SetInsertionPointEnd` before writing.
|
||||
|
||||
|
||||
"""
|
||||
|
||||
|
||||
# work around a bug of a lack of a EVT_TEXT when calling
|
||||
# WriteText on wxMac
|
||||
wx.TextCtrl.WriteText(self, text)
|
||||
@@ -255,7 +255,7 @@ class ExpandoTextCtrl(wx.TextCtrl):
|
||||
|
||||
.. seealso:: :meth:`WriteText`
|
||||
"""
|
||||
|
||||
|
||||
# Instead of using wx.TextCtrl.AppendText append and set the
|
||||
# insertion point ourselves. This works around a bug on wxMSW
|
||||
# where it scrolls the old text out of view, and since there
|
||||
@@ -274,7 +274,7 @@ class ExpandoTextCtrl(wx.TextCtrl):
|
||||
# check if any adjustments are needed on every text update
|
||||
self._adjustCtrl()
|
||||
evt.Skip()
|
||||
|
||||
|
||||
|
||||
def OnSize(self, evt):
|
||||
"""
|
||||
@@ -320,7 +320,7 @@ class ExpandoTextCtrl(wx.TextCtrl):
|
||||
evt.height = height
|
||||
evt.numLines = numLines
|
||||
self.GetEventHandler().ProcessEvent(evt)
|
||||
|
||||
|
||||
|
||||
def _getDefaultHeight(self, parent):
|
||||
# checked for cached value
|
||||
@@ -334,7 +334,7 @@ class ExpandoTextCtrl(wx.TextCtrl):
|
||||
return sz.height
|
||||
|
||||
|
||||
if 'wxGTK' in wx.PlatformInfo or 'wxOSX-cocoa' in wx.PlatformInfo:
|
||||
if 'wxGTK' in wx.PlatformInfo or 'wxOSX-cocoa' in wx.PlatformInfo:
|
||||
# GetNumberOfLines in some ports doesn't count wrapped lines, so we
|
||||
# need to implement our own.
|
||||
def GetNumberOfLines(self):
|
||||
@@ -342,7 +342,7 @@ class ExpandoTextCtrl(wx.TextCtrl):
|
||||
width = self.GetClientSize().width
|
||||
dc = wx.ClientDC(self)
|
||||
dc.SetFont(self.GetFont())
|
||||
count = 0
|
||||
count = 0
|
||||
for line in text.split('\n'):
|
||||
count += 1
|
||||
w, h = dc.GetTextExtent(line)
|
||||
@@ -350,7 +350,7 @@ class ExpandoTextCtrl(wx.TextCtrl):
|
||||
# the width of the text is wider than the control,
|
||||
# calc how many lines it will be wrapped to
|
||||
count += self._wrapLine(line, dc, width)
|
||||
|
||||
|
||||
if not count:
|
||||
count = 1
|
||||
return count
|
||||
@@ -360,11 +360,11 @@ class ExpandoTextCtrl(wx.TextCtrl):
|
||||
return wx.SystemSettings.GetMetric(wx.SYS_VSCROLL_X)
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
def _wrapLine(self, line, dc, width):
|
||||
# Estimate where the control will wrap the lines and
|
||||
# return the count of extra lines needed.
|
||||
pte = dc.GetPartialTextExtents(line)
|
||||
pte = dc.GetPartialTextExtents(line)
|
||||
width -= wx.SystemSettings.GetMetric(wx.SYS_VSCROLL_X)
|
||||
if not pte or width < pte[0]:
|
||||
return 1
|
||||
|
||||
@@ -69,16 +69,16 @@ if sys.platform == "win32":
|
||||
else:
|
||||
_greekEncoding = str(wx.FONTENCODING_ISO8859_7)
|
||||
|
||||
_families = {"fixed" : wx.FONTFAMILY_TELETYPE, "default" : wx.FONTFAMILY_DEFAULT,
|
||||
_families = {"fixed" : wx.FONTFAMILY_TELETYPE, "default" : wx.FONTFAMILY_DEFAULT,
|
||||
"decorative" : wx.FONTFAMILY_DECORATIVE, "roman" : wx.FONTFAMILY_ROMAN,
|
||||
"script" : wx.FONTFAMILY_SCRIPT, "swiss" : wx.FONTFAMILY_SWISS,
|
||||
"script" : wx.FONTFAMILY_SCRIPT, "swiss" : wx.FONTFAMILY_SWISS,
|
||||
"modern" : wx.FONTFAMILY_MODERN}
|
||||
_styles = {"normal" : wx.FONTSTYLE_NORMAL, "slant" : wx.FONTSTYLE_SLANT, "italic" : wx.FONTSTYLE_ITALIC}
|
||||
_weights = {"normal" : wx.FONTWEIGHT_NORMAL, "light" : wx.FONTWEIGHT_LIGHT, "bold" : wx.FONTWEIGHT_BOLD}
|
||||
|
||||
# The next three classes: Renderer, SizeRenderer and DCRenderer are
|
||||
# what you will need to override to extend the XML language. All of
|
||||
# the font stuff as well as the subscript and superscript stuff are in
|
||||
# the font stuff as well as the subscript and superscript stuff are in
|
||||
# Renderer.
|
||||
|
||||
_greek_letters = ("alpha", "beta", "gamma", "delta", "epsilon", "zeta",
|
||||
@@ -88,7 +88,7 @@ _greek_letters = ("alpha", "beta", "gamma", "delta", "epsilon", "zeta",
|
||||
|
||||
def iround(number):
|
||||
return int(round(number))
|
||||
|
||||
|
||||
def iceil(number):
|
||||
return int(math.ceil(number))
|
||||
|
||||
@@ -121,7 +121,7 @@ class Renderer:
|
||||
Renderer.defaultSize = wx.NORMAL_FONT.GetPointSize()
|
||||
if Renderer.defaultEncoding is None:
|
||||
Renderer.defaultEncoding = wx.Font.GetDefaultEncoding()
|
||||
|
||||
|
||||
def getY(self):
|
||||
if self._y is None:
|
||||
self.minY = self.maxY = self._y = self.dc.GetTextExtent("M")[1]
|
||||
@@ -129,7 +129,7 @@ class Renderer:
|
||||
def setY(self, value):
|
||||
self._y = y
|
||||
y = property(getY, setY)
|
||||
|
||||
|
||||
def startElement(self, name, attrs):
|
||||
method = "start_" + name
|
||||
if not hasattr(self, method):
|
||||
@@ -144,7 +144,7 @@ class Renderer:
|
||||
pass
|
||||
else:
|
||||
raise ValueError("XML tag '%s' not supported" % methname)
|
||||
|
||||
|
||||
def characterData(self, data):
|
||||
self.dc.SetFont(self.getCurrentFont())
|
||||
for i, chunk in enumerate(data.split('\n')):
|
||||
@@ -213,7 +213,7 @@ class Renderer:
|
||||
|
||||
def end_sup(self):
|
||||
self.fonts.pop()
|
||||
self.offsets.pop()
|
||||
self.offsets.pop()
|
||||
|
||||
def getCurrentFont(self):
|
||||
font = self.fonts[-1]
|
||||
@@ -227,10 +227,10 @@ class Renderer:
|
||||
def getCurrentColor(self):
|
||||
font = self.fonts[-1]
|
||||
return wx.TheColourDatabase.FindColour(font.get("color", self.defaultColor))
|
||||
|
||||
|
||||
def getCurrentPen(self):
|
||||
return wx.Pen(self.getCurrentColor(), 1, wx.PENSTYLE_SOLID)
|
||||
|
||||
|
||||
def renderCharacterData(self, data, x, y):
|
||||
raise NotImplementedError()
|
||||
|
||||
@@ -262,19 +262,19 @@ def _addGreek():
|
||||
self.end_font()
|
||||
setattr(Renderer, "start_%s" % name.capitalize(), start)
|
||||
setattr(Renderer, "end_%s" % name.capitalize(), end)
|
||||
_addGreek()
|
||||
_addGreek()
|
||||
|
||||
|
||||
|
||||
class SizeRenderer(Renderer):
|
||||
"""Processes text as if rendering it, but just computes the size."""
|
||||
|
||||
|
||||
def __init__(self, dc=None):
|
||||
Renderer.__init__(self, dc, 0, 0)
|
||||
|
||||
|
||||
def renderCharacterData(self, data, x, y):
|
||||
pass
|
||||
|
||||
|
||||
def start_angle(self, attrs):
|
||||
self.characterData("M")
|
||||
|
||||
@@ -291,9 +291,9 @@ class SizeRenderer(Renderer):
|
||||
self.characterData("M")
|
||||
|
||||
def start_times(self, attrs):
|
||||
self.characterData("M")
|
||||
self.characterData("M")
|
||||
|
||||
|
||||
|
||||
class DCRenderer(Renderer):
|
||||
"""Renders text to a wxPython device context DC."""
|
||||
|
||||
@@ -309,7 +309,7 @@ class DCRenderer(Renderer):
|
||||
self.dc.DrawLine(iround(self.x), iround(y), iround( self.x+width), iround(y))
|
||||
self.dc.DrawLine(iround(self.x), iround(y), iround(self.x+width), iround(y-width))
|
||||
self.updateDims(width, height, descent, leading)
|
||||
|
||||
|
||||
|
||||
def start_infinity(self, attrs):
|
||||
self.dc.SetFont(self.getCurrentFont())
|
||||
@@ -352,7 +352,7 @@ def RenderToRenderer(str, renderer, enclose=True):
|
||||
p.CharacterDataHandler = renderer.characterData
|
||||
p.Parse(str, 1)
|
||||
except xml.parsers.expat.error as err:
|
||||
raise ValueError('error parsing text text "%s": %s' % (str, err))
|
||||
raise ValueError('error parsing text text "%s": %s' % (str, err))
|
||||
|
||||
|
||||
# Public interface
|
||||
@@ -383,7 +383,7 @@ def RenderToBitmap(str, background=None, enclose=1):
|
||||
if background is None:
|
||||
dc.SetBackground(wx.WHITE_BRUSH)
|
||||
else:
|
||||
dc.SetBackground(background)
|
||||
dc.SetBackground(background)
|
||||
dc.Clear()
|
||||
renderer = DCRenderer(dc, y=dy)
|
||||
RenderToRenderer(str, renderer, enclose)
|
||||
@@ -401,8 +401,8 @@ def RenderToDC(str, dc, x, y, enclose=1):
|
||||
width, height, dy = GetFullExtent(str, dc)
|
||||
renderer = DCRenderer(dc, x, y+dy)
|
||||
RenderToRenderer(str, renderer, enclose)
|
||||
|
||||
|
||||
|
||||
|
||||
class StaticFancyText(wx.StaticBitmap):
|
||||
def __init__(self, window, id, text, *args, **kargs):
|
||||
args = list(args)
|
||||
@@ -413,7 +413,7 @@ class StaticFancyText(wx.StaticBitmap):
|
||||
background = args.pop(0)
|
||||
else:
|
||||
background = wx.Brush(window.GetBackgroundColour(), wx.BRUSHSTYLE_SOLID)
|
||||
|
||||
|
||||
bmp = RenderToBitmap(text, background)
|
||||
wx.StaticBitmap.__init__(self, window, id, bmp, *args, **kargs)
|
||||
|
||||
@@ -438,14 +438,14 @@ This module exports four main methods::
|
||||
def RenderToDC(str, dc, x, y, enclose=True)
|
||||
</font>
|
||||
In all cases, 'str' is an XML string. Note that start and end tags
|
||||
are only required if *enclose* is set to False. In this case the
|
||||
are only required if *enclose* is set to False. In this case the
|
||||
text should be wrapped in FancyText tags.
|
||||
|
||||
In addition, the module exports one class::
|
||||
<font family="fixed" style="slant">
|
||||
class StaticFancyText(self, window, id, text, background, ...)
|
||||
</font>
|
||||
This class works similar to StaticText except it interprets its text
|
||||
This class works similar to StaticText except it interprets its text
|
||||
as FancyText.
|
||||
|
||||
The text can support<sup>superscripts</sup> and <sub>subscripts</sub>, text
|
||||
@@ -478,7 +478,7 @@ The End"""
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
|
||||
if __name__ == "__main__":
|
||||
if __name__ == "__main__":
|
||||
test()
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class FlashWindow(wx.lib.activex.ActiveXCtrl):
|
||||
size=wx.DefaultSize, style=0, name='FlashWindow'):
|
||||
wx.lib.activex.ActiveXCtrl.__init__(self, parent, progID,
|
||||
id, pos, size, style, name)
|
||||
|
||||
|
||||
def SetZoomRect(self, left, top, right, bottom):
|
||||
return self.ctrl.SetZoomRect(left, top, right, bottom)
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
wx.activex.ActiveXWindow.__init__(self, parent,
|
||||
wx.activex.CLSID('{D27CDB6E-AE6D-11CF-96B8-444553540000}'),
|
||||
ID, pos, size, style, name)
|
||||
|
||||
|
||||
# Methods exported by the ActiveX object
|
||||
def QueryInterface(self, riid):
|
||||
return self.CallAXMethod('QueryInterface', riid)
|
||||
@@ -293,76 +293,76 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# --------------------
|
||||
# readystate
|
||||
# type:int arg:VT_EMPTY canGet:True canSet:False
|
||||
#
|
||||
#
|
||||
# totalframes
|
||||
# type:int arg:VT_EMPTY canGet:True canSet:False
|
||||
#
|
||||
#
|
||||
# playing
|
||||
# type:bool arg:bool canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# quality
|
||||
# type:int arg:int canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# scalemode
|
||||
# type:int arg:int canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# alignmode
|
||||
# type:int arg:int canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# backgroundcolor
|
||||
# type:int arg:int canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# loop
|
||||
# type:bool arg:bool canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# movie
|
||||
# type:string arg:string canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# framenum
|
||||
# type:int arg:int canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# wmode
|
||||
# type:string arg:string canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# salign
|
||||
# type:string arg:string canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# menu
|
||||
# type:bool arg:bool canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# base
|
||||
# type:string arg:string canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# scale
|
||||
# type:string arg:string canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# devicefont
|
||||
# type:bool arg:bool canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# embedmovie
|
||||
# type:bool arg:bool canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# bgcolor
|
||||
# type:string arg:string canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# quality2
|
||||
# type:string arg:string canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# swremote
|
||||
# type:string arg:string canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# flashvars
|
||||
# type:string arg:string canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# allowscriptaccess
|
||||
# type:string arg:string canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# moviedata
|
||||
# type:string arg:string canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# METHODS
|
||||
# --------------------
|
||||
# QueryInterface
|
||||
@@ -372,19 +372,19 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# in:True out:False optional:False type:unsupported type 29
|
||||
# ppvObj
|
||||
# in:False out:True optional:False type:unsupported type 26
|
||||
#
|
||||
#
|
||||
# AddRef
|
||||
# retType: int
|
||||
#
|
||||
#
|
||||
# Release
|
||||
# retType: int
|
||||
#
|
||||
#
|
||||
# GetTypeInfoCount
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# pctinfo
|
||||
# in:False out:True optional:False type:int
|
||||
#
|
||||
#
|
||||
# GetTypeInfo
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -394,7 +394,7 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# in:True out:False optional:False type:int
|
||||
# pptinfo
|
||||
# in:False out:True optional:False type:unsupported type 26
|
||||
#
|
||||
#
|
||||
# GetIDsOfNames
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -408,7 +408,7 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# in:True out:False optional:False type:int
|
||||
# rgdispid
|
||||
# in:False out:True optional:False type:int
|
||||
#
|
||||
#
|
||||
# Invoke
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -428,7 +428,7 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# in:False out:True optional:False type:unsupported type 29
|
||||
# puArgErr
|
||||
# in:False out:True optional:False type:int
|
||||
#
|
||||
#
|
||||
# SetZoomRect
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -440,13 +440,13 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# in:True out:False optional:False type:int
|
||||
# bottom
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# Zoom
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# factor
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# Pan
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -456,49 +456,49 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# in:True out:False optional:False type:int
|
||||
# mode
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# Play
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# Stop
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# Back
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# Forward
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# Rewind
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# StopPlay
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# GotoFrame
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# FrameNum
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# CurrentFrame
|
||||
# retType: int
|
||||
#
|
||||
#
|
||||
# IsPlaying
|
||||
# retType: bool
|
||||
#
|
||||
#
|
||||
# PercentLoaded
|
||||
# retType: int
|
||||
#
|
||||
#
|
||||
# FrameLoaded
|
||||
# retType: bool
|
||||
# params:
|
||||
# FrameNum
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# FlashVersion
|
||||
# retType: int
|
||||
#
|
||||
#
|
||||
# LoadMovie
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -506,7 +506,7 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# in:True out:False optional:False type:int
|
||||
# url
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# TGotoFrame
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -514,7 +514,7 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# in:True out:False optional:False type:string
|
||||
# FrameNum
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# TGotoLabel
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -522,31 +522,31 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# in:True out:False optional:False type:string
|
||||
# label
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# TCurrentFrame
|
||||
# retType: int
|
||||
# params:
|
||||
# target
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# TCurrentLabel
|
||||
# retType: string
|
||||
# params:
|
||||
# target
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# TPlay
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# target
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# TStopPlay
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# target
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# SetVariable
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -554,13 +554,13 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# in:True out:False optional:False type:string
|
||||
# value
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# GetVariable
|
||||
# retType: string
|
||||
# params:
|
||||
# name
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# TSetProperty
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -570,7 +570,7 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# in:True out:False optional:False type:int
|
||||
# value
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# TGetProperty
|
||||
# retType: string
|
||||
# params:
|
||||
@@ -578,7 +578,7 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# in:True out:False optional:False type:string
|
||||
# property
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# TCallFrame
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -586,7 +586,7 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# in:True out:False optional:False type:string
|
||||
# FrameNum
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# TCallLabel
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -594,7 +594,7 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# in:True out:False optional:False type:string
|
||||
# label
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# TSetPropertyNum
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -604,7 +604,7 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# in:True out:False optional:False type:int
|
||||
# value
|
||||
# in:True out:False optional:False type:double
|
||||
#
|
||||
#
|
||||
# TGetPropertyNum
|
||||
# retType: double
|
||||
# params:
|
||||
@@ -612,7 +612,7 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# in:True out:False optional:False type:string
|
||||
# property
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# TGetPropertyAsNumber
|
||||
# retType: double
|
||||
# params:
|
||||
@@ -620,10 +620,10 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# in:True out:False optional:False type:string
|
||||
# property
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# EVENTS
|
||||
# --------------------
|
||||
# ReadyStateChange
|
||||
@@ -631,13 +631,13 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# params:
|
||||
# newState
|
||||
# in:False out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# Progress
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# percentDone
|
||||
# in:False out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# FSCommand
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -645,7 +645,7 @@ class FlashWindow(wx.activex.ActiveXWindow):
|
||||
# in:True out:False optional:False type:string
|
||||
# args
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
@@ -42,7 +42,7 @@ warningmsg = r"""\
|
||||
"""
|
||||
|
||||
warnings.warn(warningmsg, DeprecationWarning, stacklevel=2)
|
||||
|
||||
|
||||
if wx.Platform == '__WXGTK__':
|
||||
#
|
||||
# For wxGTK all we have to do is set the wxTB_DOCKABLE flag
|
||||
|
||||
@@ -17,7 +17,7 @@ class FoldOutWindow(wx.PopupWindow):
|
||||
self.inWindow=False
|
||||
self.Bind(wx.EVT_ENTER_WINDOW, self.evEnter)
|
||||
self.Bind(wx.EVT_LEAVE_WINDOW, self.evLeave)
|
||||
|
||||
|
||||
def InitColors(self):
|
||||
faceClr = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW)
|
||||
self.SetBackgroundColour(faceClr)
|
||||
@@ -53,7 +53,7 @@ class FoldOutWindow(wx.PopupWindow):
|
||||
self.inWindow=True
|
||||
self.rect=self.GetRect()
|
||||
event.Skip()
|
||||
|
||||
|
||||
def evLeave(self,event):
|
||||
if self.inWindow:
|
||||
if not self.rect.Inside(self.ClientToScreen(event.GetPosition())):
|
||||
@@ -62,9 +62,9 @@ class FoldOutWindow(wx.PopupWindow):
|
||||
event.Skip()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class FoldOutMenu(wx.BitmapButton):
|
||||
def __init__(self,parent,id,bitmap,pos = wx.DefaultPosition,
|
||||
size = wx.DefaultSize, style = wx.BU_AUTODRAW,
|
||||
|
||||
@@ -66,8 +66,8 @@ This allows the user to change the mouse button/modifiers at runtime.
|
||||
Changelog:
|
||||
0.0.1: Treats a mouse leaving event as mouse up.
|
||||
(Bug Report, Thanks Peter Damoc).
|
||||
|
||||
|
||||
|
||||
|
||||
0.0.0: Initial Release.
|
||||
'''
|
||||
|
||||
@@ -89,31 +89,31 @@ import wx
|
||||
class MouseGestures:
|
||||
def __init__(self, parent, Auto=True, MouseButton=wx.MOUSE_BTN_MIDDLE):
|
||||
self.parent = parent
|
||||
|
||||
|
||||
self.gestures = []
|
||||
self.actions = []
|
||||
self.actionarguments = []
|
||||
|
||||
|
||||
self.mousebutton = MouseButton
|
||||
self.modifiers = []
|
||||
|
||||
|
||||
self.recording = False
|
||||
|
||||
|
||||
self.lastposition = (-1, -1)
|
||||
|
||||
|
||||
self.pen = wx.Pen(wx.Colour(0, 144, 255), 5)
|
||||
|
||||
self.dc = wx.ScreenDC()
|
||||
self.dc.SetPen(self.pen)
|
||||
|
||||
|
||||
self.showgesture = False
|
||||
|
||||
|
||||
self.wobbletolerance = 7
|
||||
|
||||
|
||||
self.rawgesture = ''
|
||||
|
||||
|
||||
self.SetAuto(Auto)
|
||||
|
||||
|
||||
def _check_modifiers(self, event):
|
||||
'''Internal: Returns True if all needed modifiers are down
|
||||
for the given event.'''
|
||||
@@ -127,12 +127,12 @@ class MouseGestures:
|
||||
good = good and event.AltDown()
|
||||
return good
|
||||
return True
|
||||
|
||||
|
||||
def AddGesture(self, gesture, action, *args):
|
||||
'''Registers a gesture, and an associated function, with any arguments needed.'''
|
||||
#Make Sure not a duplicate:
|
||||
self.RemoveGesture(gesture)
|
||||
|
||||
|
||||
self.gestures.append(gesture)
|
||||
self.actions.append(action)
|
||||
self.actionarguments.append(args)
|
||||
@@ -147,14 +147,14 @@ class MouseGestures:
|
||||
'''Stops recording the points to create the mouse gesture from,
|
||||
and creates the mouse gesture, returns the result as a string.'''
|
||||
self.recording = False
|
||||
|
||||
|
||||
#Figure out the gestures (Look for occurances of 5 in a row or more):
|
||||
|
||||
|
||||
tempstring = '0'
|
||||
possiblechange = '0'
|
||||
|
||||
|
||||
directions = ''
|
||||
|
||||
|
||||
for g in self.rawgesture:
|
||||
l = len(tempstring)
|
||||
if g != tempstring[l - 1]:
|
||||
@@ -172,29 +172,29 @@ class MouseGestures:
|
||||
else:
|
||||
directions += g
|
||||
tempstring = '0'
|
||||
|
||||
|
||||
if self.showgesture:
|
||||
self.parent.Refresh()
|
||||
|
||||
|
||||
return directions
|
||||
|
||||
|
||||
def GetDirection(self, point1, point2):
|
||||
'''Gets the direction between two points.'''
|
||||
#point1 is the old point
|
||||
#point2 is current
|
||||
|
||||
|
||||
x1, y1 = point1
|
||||
x2, y2 = point2
|
||||
|
||||
|
||||
#(Negative = Left, Up)
|
||||
#(Positive = Right, Down)
|
||||
|
||||
|
||||
horizontal = x2 - x1
|
||||
vertical = y2 - y1
|
||||
|
||||
|
||||
horizontalchange = abs(horizontal) > 0
|
||||
verticalchange = abs(vertical) > 0
|
||||
|
||||
|
||||
if horizontalchange and verticalchange:
|
||||
ah = abs(horizontal)
|
||||
av = abs(vertical)
|
||||
@@ -206,7 +206,7 @@ class MouseGestures:
|
||||
if (av / ah) > 2:
|
||||
horizontal = 0
|
||||
horizontalchange = False
|
||||
|
||||
|
||||
if horizontalchange and verticalchange:
|
||||
#Diagonal
|
||||
if (horizontal > 0) and (vertical > 0):
|
||||
@@ -229,11 +229,11 @@ class MouseGestures:
|
||||
return 'D'
|
||||
else:
|
||||
return 'U'
|
||||
|
||||
|
||||
def GetRecording(self):
|
||||
'''Returns whether or not Gesture Recording has started.'''
|
||||
return self.recording
|
||||
|
||||
|
||||
def OnMotion(self, event):
|
||||
'''Internal. Used if Start() has been run'''
|
||||
if self.recording:
|
||||
@@ -245,11 +245,11 @@ class MouseGestures:
|
||||
px1, py1 = self.parent.ClientToScreen(self.lastposition)
|
||||
px2, py2 = self.parent.ClientToScreen(currentposition)
|
||||
self.dc.DrawLine(px1, py1, px2, py2)
|
||||
|
||||
|
||||
self.lastposition = currentposition
|
||||
|
||||
|
||||
event.Skip()
|
||||
|
||||
|
||||
def OnMouseEvent(self, event):
|
||||
'''Internal. Used in Auto Mode.'''
|
||||
if event.ButtonDown(self.mousebutton) and self._check_modifiers(event):
|
||||
@@ -258,49 +258,49 @@ class MouseGestures:
|
||||
result = self.End()
|
||||
self.DoAction(result)
|
||||
event.Skip()
|
||||
|
||||
|
||||
def RemoveGesture(self, gesture):
|
||||
'''Removes a gesture, and its associated action'''
|
||||
if gesture in self.gestures:
|
||||
i = self.gestures.index(gesture)
|
||||
|
||||
|
||||
del self.gestures[i]
|
||||
del self.actions[i]
|
||||
del self.actionarguments[i]
|
||||
|
||||
|
||||
def SetAuto(self, auto):
|
||||
'''Warning: Once auto is set, it stays set, unless you manually use UnBind'''
|
||||
if auto:
|
||||
self.parent.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouseEvent)
|
||||
self.parent.Bind(wx.EVT_MOTION, self.OnMotion)
|
||||
|
||||
|
||||
def SetGesturePen(self, pen):
|
||||
'''Sets the wx pen used to visually represent each gesture'''
|
||||
self.pen = pen
|
||||
self.dc.SetPen(self.pen)
|
||||
|
||||
|
||||
def SetGesturePen(self, colour, width):
|
||||
'''Sets the colour and width of the line drawn to visually represent each gesture'''
|
||||
self.pen = wx.Pen(colour, width)
|
||||
self.dc.SetPen(self.pen)
|
||||
|
||||
|
||||
def SetGesturesVisible(self, vis):
|
||||
'''Sets whether a line is drawn to visually represent each gesture'''
|
||||
self.showgesture = vis
|
||||
|
||||
|
||||
def SetModifiers(self, modifiers=[]):
|
||||
'''Takes an array of wx Key constants (Control, Shift, and/or Alt).
|
||||
Leave empty to unset all modifiers.'''
|
||||
self.modifiers = modifiers
|
||||
|
||||
|
||||
def SetMouseButton(self, mousebutton):
|
||||
'''Takes the wx constant for the target mousebutton'''
|
||||
self.mousebutton = mousebutton
|
||||
|
||||
|
||||
def SetWobbleTolerance(self, wobbletolerance):
|
||||
'''Sets just how much wobble this class can take!'''
|
||||
self.WobbleTolerance = wobbletolerance
|
||||
|
||||
|
||||
def Start(self):
|
||||
'''Starts recording the points to create the mouse gesture from'''
|
||||
self.recording = True
|
||||
|
||||
@@ -64,46 +64,46 @@ FORMAT_A1 = cairo.FORMAT_A1
|
||||
# Compositing operators. See http://cairographics.org/operators
|
||||
|
||||
# clear destination layer (bounded)
|
||||
OPERATOR_CLEAR = cairo.OPERATOR_CLEAR
|
||||
OPERATOR_CLEAR = cairo.OPERATOR_CLEAR
|
||||
|
||||
# replace destination layer (bounded)
|
||||
OPERATOR_SOURCE = cairo.OPERATOR_SOURCE
|
||||
OPERATOR_SOURCE = cairo.OPERATOR_SOURCE
|
||||
|
||||
# draw source layer on top of destination layer (bounded)
|
||||
OPERATOR_OVER = cairo.OPERATOR_OVER
|
||||
OPERATOR_OVER = cairo.OPERATOR_OVER
|
||||
|
||||
# draw source where there was destination content (unbounded)
|
||||
OPERATOR_IN = cairo.OPERATOR_IN
|
||||
OPERATOR_IN = cairo.OPERATOR_IN
|
||||
|
||||
# draw source where there was no destination content (unbounded)
|
||||
OPERATOR_OUT = cairo.OPERATOR_OUT
|
||||
OPERATOR_OUT = cairo.OPERATOR_OUT
|
||||
|
||||
# draw source on top of destination content and only there
|
||||
OPERATOR_ATOP = cairo.OPERATOR_ATOP
|
||||
OPERATOR_ATOP = cairo.OPERATOR_ATOP
|
||||
|
||||
# ignore the source
|
||||
OPERATOR_DEST = cairo.OPERATOR_DEST
|
||||
OPERATOR_DEST = cairo.OPERATOR_DEST
|
||||
|
||||
# draw destination on top of source
|
||||
OPERATOR_DEST_OVER = cairo.OPERATOR_DEST_OVER
|
||||
OPERATOR_DEST_OVER = cairo.OPERATOR_DEST_OVER
|
||||
|
||||
# leave destination only where there was source content (unbounded)
|
||||
OPERATOR_DEST_IN = cairo.OPERATOR_DEST_IN
|
||||
OPERATOR_DEST_IN = cairo.OPERATOR_DEST_IN
|
||||
|
||||
# leave destination only where there was no source content
|
||||
OPERATOR_DEST_OUT = cairo.OPERATOR_DEST_OUT
|
||||
OPERATOR_DEST_OUT = cairo.OPERATOR_DEST_OUT
|
||||
|
||||
# leave destination on top of source content and only there (unbounded)
|
||||
OPERATOR_DEST_ATOP = cairo.OPERATOR_DEST_ATOP
|
||||
OPERATOR_DEST_ATOP = cairo.OPERATOR_DEST_ATOP
|
||||
|
||||
# source and destination are shown where there is only one of them
|
||||
OPERATOR_XOR = cairo.OPERATOR_XOR
|
||||
OPERATOR_XOR = cairo.OPERATOR_XOR
|
||||
|
||||
# source and destination layers are accumulated
|
||||
OPERATOR_ADD = cairo.OPERATOR_ADD
|
||||
OPERATOR_ADD = cairo.OPERATOR_ADD
|
||||
|
||||
# like over, but assuming source and dest are disjoint geometries
|
||||
OPERATOR_SATURATE = cairo.OPERATOR_SATURATE
|
||||
OPERATOR_SATURATE = cairo.OPERATOR_SATURATE
|
||||
|
||||
|
||||
|
||||
@@ -112,18 +112,18 @@ OPERATOR_SATURATE = cairo.OPERATOR_SATURATE
|
||||
# current backends support the the SUBPIXEL mode.
|
||||
|
||||
# Use the default antialiasing for the subsystem and target device
|
||||
ANTIALIAS_DEFAULT = cairo.ANTIALIAS_DEFAULT
|
||||
ANTIALIAS_DEFAULT = cairo.ANTIALIAS_DEFAULT
|
||||
|
||||
# Use a bilevel alpha mask
|
||||
ANTIALIAS_NONE = cairo.ANTIALIAS_NONE
|
||||
ANTIALIAS_NONE = cairo.ANTIALIAS_NONE
|
||||
|
||||
# Perform single-color antialiasing (using shades of gray for black
|
||||
# text on a white background, for example).
|
||||
ANTIALIAS_GRAY = cairo.ANTIALIAS_GRAY
|
||||
ANTIALIAS_GRAY = cairo.ANTIALIAS_GRAY
|
||||
|
||||
# Perform antialiasing by taking advantage of the order of subpixel
|
||||
# elements on devices such as LCD panels
|
||||
ANTIALIAS_SUBPIXEL = cairo.ANTIALIAS_SUBPIXEL
|
||||
ANTIALIAS_SUBPIXEL = cairo.ANTIALIAS_SUBPIXEL
|
||||
|
||||
|
||||
|
||||
@@ -174,12 +174,12 @@ class GraphicsPen(GraphicsObject):
|
||||
_capMap = { wx.CAP_BUTT : cairo.LINE_CAP_BUTT,
|
||||
wx.CAP_ROUND : cairo.LINE_CAP_ROUND,
|
||||
wx.CAP_PROJECTING : cairo.LINE_CAP_SQUARE }
|
||||
|
||||
|
||||
_joinMap = { wx.JOIN_BEVEL : cairo.LINE_JOIN_BEVEL,
|
||||
wx.JOIN_MITER : cairo.LINE_JOIN_MITER,
|
||||
wx.JOIN_ROUND : cairo.LINE_JOIN_ROUND }
|
||||
|
||||
|
||||
|
||||
|
||||
def __init__(self, colour=wx.BLACK, width=1, style=wx.SOLID):
|
||||
"""
|
||||
Create a new ``GraphicsPen``
|
||||
@@ -193,7 +193,7 @@ class GraphicsPen(GraphicsObject):
|
||||
self._join = wx.JOIN_ROUND
|
||||
self._stipple = None
|
||||
self._pattern = None
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def CreateFromPen(pen):
|
||||
@@ -327,7 +327,7 @@ class GraphicsPen(GraphicsObject):
|
||||
self._pattern = value
|
||||
return locals()
|
||||
|
||||
|
||||
|
||||
def Apply(self, ctx):
|
||||
"""
|
||||
Apply this pen's properties to the given context.
|
||||
@@ -340,10 +340,10 @@ class GraphicsPen(GraphicsObject):
|
||||
ctx.set_line_cap(self._capMap[self._cap])
|
||||
ctx.set_line_join(self._joinMap[self._join])
|
||||
ctx.set_dash([])
|
||||
|
||||
|
||||
if self._style == wx.SOLID:
|
||||
ctx.set_source_rgba( *_colourToValues(self._colour) )
|
||||
|
||||
|
||||
elif self._style == wx.STIPPLE:
|
||||
if not self._pattern and self._stipple:
|
||||
# make a pattern from the stipple bitmap
|
||||
@@ -351,20 +351,20 @@ class GraphicsPen(GraphicsObject):
|
||||
self._pattern = cairo.SurfacePattern(img)
|
||||
self._pattern.set_extend(cairo.EXTEND_REPEAT)
|
||||
ctx.set_source(self._pattern)
|
||||
|
||||
|
||||
elif self._style == wx.USER_DASH:
|
||||
ctx.set_source_rgba( *_colourToValues(self._colour) )
|
||||
ctx.set_dash(self._dashes)
|
||||
|
||||
|
||||
elif self._style in [wx.DOT, wx.DOT_DASH, wx.LONG_DASH, wx.SHORT_DASH]:
|
||||
ctx.set_source_rgba( *_colourToValues(self._colour) )
|
||||
ctx.set_dash( _stdDashes(self._style, self._width) )
|
||||
|
||||
|
||||
elif self._style in [wx.BDIAGONAL_HATCH, wx.CROSSDIAG_HATCH, wx.FDIAGONAL_HATCH,
|
||||
wx.CROSS_HATCH, wx.HORIZONTAL_HATCH, wx.VERTICAL_HATCH]:
|
||||
pass # TODO make a stock pattern...
|
||||
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class GraphicsBrush(GraphicsObject):
|
||||
@@ -374,7 +374,7 @@ class GraphicsBrush(GraphicsObject):
|
||||
stipple created from a :class:`wx.Bitmap`, or a Cairo ``Pattern``
|
||||
object.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, colour=wx.BLACK, style=wx.BRUSHSTYLE_SOLID):
|
||||
"""
|
||||
Create a new ``GraphicsBrush``.
|
||||
@@ -383,7 +383,7 @@ class GraphicsBrush(GraphicsObject):
|
||||
self._style = style
|
||||
self._stipple = None
|
||||
self._pattern = None
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def CreateFromBrush(brush):
|
||||
@@ -477,7 +477,7 @@ class GraphicsBrush(GraphicsObject):
|
||||
Called by :class:`GraphicsContext` as needed.
|
||||
"""
|
||||
ctx = ctx.GetNativeContext()
|
||||
|
||||
|
||||
if self._style == wx.BRUSHSTYLE_SOLID:
|
||||
ctx.set_source_rgba( *_colourToValues(self._colour) )
|
||||
|
||||
@@ -488,7 +488,7 @@ class GraphicsBrush(GraphicsObject):
|
||||
self._pattern = cairo.SurfacePattern(img)
|
||||
self._pattern.set_extend(cairo.EXTEND_REPEAT)
|
||||
ctx.set_source(self._pattern)
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class GraphicsFont(GraphicsObject):
|
||||
@@ -519,7 +519,7 @@ class GraphicsFont(GraphicsObject):
|
||||
|
||||
def IsNull(self):
|
||||
return self._font is None
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def CreateFromFont(font, colour=None):
|
||||
@@ -597,7 +597,7 @@ class GraphicsFont(GraphicsObject):
|
||||
nctx.set_font_face(self._fontface)
|
||||
nctx.set_font_size(self._pointSize)
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class GraphicsBitmap(GraphicsObject):
|
||||
@@ -616,7 +616,7 @@ class GraphicsBitmap(GraphicsObject):
|
||||
def IsNull(self):
|
||||
return self._surface is None
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def CreateFromBitmap(bitmap):
|
||||
"""Create a GraphicsBitmap from a wx.Bitmap"""
|
||||
@@ -664,7 +664,7 @@ class GraphicsBitmap(GraphicsObject):
|
||||
# long as this object does
|
||||
b._buffer = buffer
|
||||
return b
|
||||
|
||||
|
||||
|
||||
@Property
|
||||
def Width():
|
||||
@@ -768,12 +768,12 @@ class GraphicsMatrix(GraphicsObject):
|
||||
"""Inverts the matrix."""
|
||||
self._matrix.invert()
|
||||
return self
|
||||
|
||||
|
||||
|
||||
def IsEqual(self, matrix):
|
||||
"""Returns True if the elements of the transformation matrices are equal."""
|
||||
return self._matrix == matrix._matrix
|
||||
|
||||
|
||||
|
||||
def IsIdentity(self):
|
||||
"""Returns True if this is the identity matrix."""
|
||||
@@ -815,7 +815,7 @@ class GraphicsMatrix(GraphicsObject):
|
||||
m = GraphicsMatrix()
|
||||
m.Set(*self.Get())
|
||||
return m
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class GraphicsPath(GraphicsObject):
|
||||
@@ -839,7 +839,7 @@ class GraphicsPath(GraphicsObject):
|
||||
Adds an arc of a circle centering at (x,y) with radius, from
|
||||
startAngle to endAngle.
|
||||
"""
|
||||
# clockwise means positive in our system (y pointing downwards)
|
||||
# clockwise means positive in our system (y pointing downwards)
|
||||
if clockwise or endAngle-startAngle >= 2*math.pi:
|
||||
self._pathContext.arc(x, y, radius, startAngle, endAngle)
|
||||
else:
|
||||
@@ -868,7 +868,7 @@ class GraphicsPath(GraphicsObject):
|
||||
alpha = math.radians(alpha)
|
||||
|
||||
dist = radius / math.sin(alpha/2) * math.cos(alpha/2)
|
||||
|
||||
|
||||
# calculate tangential points
|
||||
t1 = (v1 * dist) + p1
|
||||
t2 = (v2 * dist) + p1
|
||||
@@ -884,7 +884,7 @@ class GraphicsPath(GraphicsObject):
|
||||
self.AddArc(c.x, c.y, radius, math.radians(a1), math.radians(a2), True)
|
||||
self.AddLineToPoint(p2.x, p2.y)
|
||||
return self
|
||||
|
||||
|
||||
|
||||
def AddCircle(self, x, y, radius):
|
||||
"""
|
||||
@@ -921,7 +921,7 @@ class GraphicsPath(GraphicsObject):
|
||||
p.Transform(m)
|
||||
self.AddPath(p)
|
||||
return self
|
||||
|
||||
|
||||
|
||||
def AddLineToPoint(self, x, y):
|
||||
"""
|
||||
@@ -953,7 +953,7 @@ class GraphicsPath(GraphicsObject):
|
||||
c2 = c * (2/3.0) + end * (1/3.0)
|
||||
self.AddCurveToPoint(c1.x, c1.y, c2.x, c2.y, x, y);
|
||||
return self
|
||||
|
||||
|
||||
|
||||
def AddRectangle(self, x, y, w, h):
|
||||
"""
|
||||
@@ -977,7 +977,7 @@ class GraphicsPath(GraphicsObject):
|
||||
self.AddArcToPoint(x + w, y, x + w, y + h / 2.0, radius)
|
||||
self.CloseSubpath()
|
||||
return self
|
||||
|
||||
|
||||
|
||||
def CloseSubpath(self):
|
||||
"""
|
||||
@@ -997,7 +997,7 @@ class GraphicsPath(GraphicsObject):
|
||||
rule = d[fillStyle]
|
||||
self._pathContext.set_fill_rule(rule)
|
||||
return self._pathContext.in_stroke(x,y) or self._pathContext.in_fill(x,y)
|
||||
|
||||
|
||||
|
||||
def GetCurrentPoint(self):
|
||||
"""
|
||||
@@ -1064,7 +1064,7 @@ class GraphicsPath(GraphicsObject):
|
||||
h = y2 - y1
|
||||
return (x, y, w, h)
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class GraphicsGradientStop(object):
|
||||
@@ -1076,7 +1076,7 @@ class GraphicsGradientStop(object):
|
||||
def __init__(self, colour=wx.TransparentColour, pos=0.0):
|
||||
self.SetColour(colour)
|
||||
self.SetPosition(pos)
|
||||
|
||||
|
||||
def GetColour(self):
|
||||
return self._colour
|
||||
def SetColour(self, value):
|
||||
@@ -1084,17 +1084,17 @@ class GraphicsGradientStop(object):
|
||||
assert isinstance(value, wx.Colour)
|
||||
self._colour = value
|
||||
Colour = property(GetColour, SetColour)
|
||||
|
||||
|
||||
|
||||
|
||||
def GetPosition(self):
|
||||
return self._pos
|
||||
def SetPosition(self, value):
|
||||
assert value >= 0.0 and value <= 1.0
|
||||
self._pos = value
|
||||
Position = property(GetPosition, SetPosition)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class GraphicsGradientStops(object):
|
||||
"""
|
||||
An ordered collection of gradient color stops
|
||||
@@ -1107,7 +1107,7 @@ class GraphicsGradientStops(object):
|
||||
self.Add(startColour, 0.0)
|
||||
self.Add(endColour, 1.0)
|
||||
|
||||
|
||||
|
||||
def Add(self, *args):
|
||||
"""
|
||||
Add a new color to the collection. ``args`` may be either a gradient stop,
|
||||
@@ -1121,38 +1121,38 @@ class GraphicsGradientStops(object):
|
||||
else:
|
||||
raise ValueError("Invalid parameters passed to Add")
|
||||
assert isinstance(stop, GraphicsGradientStop)
|
||||
|
||||
|
||||
self._stops.append(stop)
|
||||
self._stops.sort(key=lambda x: x.Position)
|
||||
|
||||
|
||||
|
||||
def GetCount(self):
|
||||
return len(self._stops)
|
||||
Count = property(GetCount)
|
||||
def __len__(self):
|
||||
return self.GetCount()
|
||||
|
||||
|
||||
|
||||
def Item(self, n):
|
||||
return self._stops[n]
|
||||
def __getitem__(self, n):
|
||||
return self._stops[n]
|
||||
|
||||
|
||||
|
||||
def GetStartColour(self):
|
||||
return self._stops[0].Colour
|
||||
def SetStartColour(self, col):
|
||||
self._stops[0].Colour = col
|
||||
StartColour = property(GetStartColour, SetStartColour)
|
||||
|
||||
|
||||
|
||||
def GetEndColour(self):
|
||||
return self._stops[-1].Colour
|
||||
def SetEndColour(self, col):
|
||||
self._stops[-1].Colour = col
|
||||
EndColour = property(GetEndColour, SetEndColour)
|
||||
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
class GraphicsContext(GraphicsObject):
|
||||
@@ -1174,12 +1174,12 @@ class GraphicsContext(GraphicsObject):
|
||||
self._height = 10000.0
|
||||
if size is not None:
|
||||
self._width, self._height = size
|
||||
|
||||
|
||||
|
||||
def IsNull(self):
|
||||
return self._context is None
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def Create(dc=None):
|
||||
"""
|
||||
@@ -1212,7 +1212,7 @@ class GraphicsContext(GraphicsObject):
|
||||
"""
|
||||
surface = cairo.ImageSurface(FORMAT_ARGB32, 1, 1)
|
||||
ctx = cairo.Context(surface)
|
||||
return GraphicsContext(ctx,
|
||||
return GraphicsContext(ctx,
|
||||
(surface.get_width(), surface.get_height()))
|
||||
|
||||
|
||||
@@ -1252,7 +1252,7 @@ class GraphicsContext(GraphicsObject):
|
||||
|
||||
# Our implementation is able to create these things directly, but
|
||||
# we'll keep them here too for compatibility with wx.GraphicsContext.
|
||||
|
||||
|
||||
def CreateBrush(self, brush):
|
||||
"""
|
||||
Create a brush from a :class:`wx.Brush`.
|
||||
@@ -1282,20 +1282,20 @@ class GraphicsContext(GraphicsObject):
|
||||
stops = GraphicsGradientStops(c1, c2)
|
||||
else:
|
||||
raise ValueError("Invalid args passed to CreateLinearGradientBrush")
|
||||
|
||||
|
||||
pattern = cairo.LinearGradient(x1, y1, x2, y2)
|
||||
for stop in stops:
|
||||
pattern.add_color_stop_rgba(stop.Position, *_colourToValues(stop.Colour))
|
||||
return GraphicsBrush.CreateFromPattern(pattern)
|
||||
|
||||
|
||||
|
||||
def CreateRadialGradientBrush(self, xo, yo, xc, yc, radius, *args):
|
||||
"""
|
||||
Creates a native brush, having a radial gradient originating at point
|
||||
(xo,yo) and ending on a circle around (xc,yc) with the given radius;
|
||||
the colours may be specified by just the two extremes or the full
|
||||
array of gradient stops.
|
||||
|
||||
|
||||
The `*args` can be either a :class:`GraphicsGradientStops` or just two
|
||||
colours to be used as the starting and ending gradient colours.
|
||||
"""
|
||||
@@ -1307,13 +1307,13 @@ class GraphicsContext(GraphicsObject):
|
||||
stops = GraphicsGradientStops(oColour, cColour)
|
||||
else:
|
||||
raise ValueError("Invalid args passed to CreateLinearGradientBrush")
|
||||
|
||||
|
||||
pattern = cairo.RadialGradient(xo, yo, 0.0, xc, yc, radius)
|
||||
for stop in stops:
|
||||
pattern.add_color_stop_rgba(stop.Position, *_colourToValues(stop.Colour))
|
||||
return GraphicsBrush.CreateFromPattern(pattern)
|
||||
|
||||
|
||||
|
||||
def CreateMatrix(self, a=1.0, b=0, c=0, d=1.0, tx=0, ty=0):
|
||||
"""
|
||||
Create a new matrix object.
|
||||
@@ -1321,7 +1321,7 @@ class GraphicsContext(GraphicsObject):
|
||||
m = GraphicsMatrix()
|
||||
m.Set(a, b, c, d, tx, ty)
|
||||
return m
|
||||
|
||||
|
||||
def CreatePath(self):
|
||||
"""
|
||||
Create a new path obejct.
|
||||
@@ -1351,7 +1351,7 @@ class GraphicsContext(GraphicsObject):
|
||||
:meth:`PushState`.
|
||||
"""
|
||||
self._context.restore()
|
||||
|
||||
|
||||
|
||||
def Clip(self, x, y, w, h):
|
||||
"""
|
||||
@@ -1363,7 +1363,7 @@ class GraphicsContext(GraphicsObject):
|
||||
p.AddRectangle(x, y, w, h)
|
||||
self._context.append_path(p.GetNativePath())
|
||||
self._context.clip()
|
||||
|
||||
|
||||
|
||||
def ClipRegion(self, region):
|
||||
"""
|
||||
@@ -1377,14 +1377,14 @@ class GraphicsContext(GraphicsObject):
|
||||
ri.Next()
|
||||
self._context.append_path(p.GetNativePath())
|
||||
self._context.clip()
|
||||
|
||||
|
||||
|
||||
def ResetClip(self):
|
||||
"""
|
||||
Resets the clipping region to the original shape of the context.
|
||||
"""
|
||||
self._context.reset_clip()
|
||||
|
||||
|
||||
|
||||
def GetNativeContext(self):
|
||||
return self._context
|
||||
@@ -1410,7 +1410,7 @@ class GraphicsContext(GraphicsObject):
|
||||
user-space origin by (dx, dy).
|
||||
"""
|
||||
self._context.translate(dx, dy)
|
||||
|
||||
|
||||
|
||||
def Scale(self, xScale, yScale):
|
||||
"""
|
||||
@@ -1418,7 +1418,7 @@ class GraphicsContext(GraphicsObject):
|
||||
user-space axes by xScale and yScale.
|
||||
"""
|
||||
self._context.scale(xScale, yScale)
|
||||
|
||||
|
||||
|
||||
def Rotate(self, angle):
|
||||
"""
|
||||
@@ -1434,14 +1434,14 @@ class GraphicsContext(GraphicsObject):
|
||||
as an additional transformation.
|
||||
"""
|
||||
self._context.transform(matrix.GetNativeMatrix())
|
||||
|
||||
|
||||
|
||||
def SetTransform(self, matrix):
|
||||
"""
|
||||
Set the context's current transformation matrix to matrix.
|
||||
"""
|
||||
self._context.set_matrix(matrix.GetNativeMatrix())
|
||||
|
||||
|
||||
|
||||
def GetTransform(self):
|
||||
"""
|
||||
@@ -1489,7 +1489,7 @@ class GraphicsContext(GraphicsObject):
|
||||
"""Returns the current brush"""
|
||||
return self._brush
|
||||
Brush = property(GetBrush, SetBrush)
|
||||
|
||||
|
||||
|
||||
def SetFont(self, font, colour=None):
|
||||
"""
|
||||
@@ -1507,7 +1507,7 @@ class GraphicsContext(GraphicsObject):
|
||||
def GetFont(self): return (self._font, self._fontColour)
|
||||
def _SetFont(self, *both): self.SetFont(*both)
|
||||
Font = property(GetFont, _SetFont)
|
||||
|
||||
|
||||
|
||||
def StrokePath(self, path):
|
||||
"""
|
||||
@@ -1518,8 +1518,8 @@ class GraphicsContext(GraphicsObject):
|
||||
self._context.append_path(path.GetNativePath())
|
||||
self._pen.Apply(self)
|
||||
self._context.stroke()
|
||||
|
||||
|
||||
|
||||
|
||||
def FillPath(self, path, fillStyle=wx.ODDEVEN_RULE):
|
||||
"""
|
||||
Fills the path using the current brush.
|
||||
@@ -1533,7 +1533,7 @@ class GraphicsContext(GraphicsObject):
|
||||
rule = d[fillStyle]
|
||||
self._context.set_fill_rule(rule)
|
||||
self._context.fill()
|
||||
|
||||
|
||||
|
||||
def DrawPath(self, path, fillStyle=wx.ODDEVEN_RULE):
|
||||
"""
|
||||
@@ -1543,7 +1543,7 @@ class GraphicsContext(GraphicsObject):
|
||||
# code here and only loading the path once.
|
||||
self.FillPath(path, fillStyle)
|
||||
self.StrokePath(path)
|
||||
|
||||
|
||||
|
||||
def DrawText(self, text, x, y, backgroundBrush=None):
|
||||
"""
|
||||
@@ -1566,8 +1566,8 @@ class GraphicsContext(GraphicsObject):
|
||||
|
||||
else:
|
||||
self._DrawText(text, x, y)
|
||||
|
||||
|
||||
|
||||
|
||||
def _DrawText(self, text, x, y, angle=None):
|
||||
"""helper used by DrawText and DrawRotatedText"""
|
||||
if angle is not None:
|
||||
@@ -1575,7 +1575,7 @@ class GraphicsContext(GraphicsObject):
|
||||
self.Translate(x, y)
|
||||
self.Rotate(-angle)
|
||||
x = y = 0
|
||||
|
||||
|
||||
self._font.Apply(self, self._fontColour)
|
||||
# Cairo's x,y for drawing text is at the baseline, so we need to adjust
|
||||
# the position we move to by the ascent.
|
||||
@@ -1586,7 +1586,7 @@ class GraphicsContext(GraphicsObject):
|
||||
|
||||
if angle is not None:
|
||||
self.PopState()
|
||||
|
||||
|
||||
|
||||
def DrawRotatedText(self, text, x, y, angle, backgroundBrush=None):
|
||||
"""
|
||||
@@ -1613,7 +1613,7 @@ class GraphicsContext(GraphicsObject):
|
||||
|
||||
else:
|
||||
self._DrawText(text, x, y, angle)
|
||||
|
||||
|
||||
|
||||
def GetFullTextExtent(self, text):
|
||||
"""
|
||||
@@ -1635,7 +1635,7 @@ class GraphicsContext(GraphicsObject):
|
||||
externalLeading = max(0, height - (ascent + descent))
|
||||
|
||||
return (width, height, descent, externalLeading)
|
||||
|
||||
|
||||
|
||||
def GetTextExtent(self, text):
|
||||
"""
|
||||
@@ -1645,10 +1645,10 @@ class GraphicsContext(GraphicsObject):
|
||||
(width, height, descent, externalLeading) = self.GetFullTextExtent(text)
|
||||
return (width, height)
|
||||
|
||||
|
||||
|
||||
def GetPartialTextExtents(self, text):
|
||||
raise NotImplementedError("TODO")
|
||||
|
||||
|
||||
|
||||
def DrawBitmap(self, bmp, x, y, w=-1, h=-1):
|
||||
"""
|
||||
@@ -1680,10 +1680,10 @@ class GraphicsContext(GraphicsObject):
|
||||
self._context.rectangle(0, 0, bw, bh)
|
||||
# fill the rectangle with the pattern
|
||||
self._context.fill()
|
||||
|
||||
|
||||
self.PopState()
|
||||
|
||||
|
||||
|
||||
def DrawIcon(self, icon, x, y, w=-1, h=-1):
|
||||
raise NotImplementedError("TODO")
|
||||
|
||||
@@ -1696,7 +1696,7 @@ class GraphicsContext(GraphicsObject):
|
||||
path.MoveToPoint(x1, y1)
|
||||
path.AddLineToPoint(x2, y2)
|
||||
self.StrokePath(path)
|
||||
|
||||
|
||||
|
||||
def StrokeLines(self, points):
|
||||
"""
|
||||
@@ -1711,7 +1711,7 @@ class GraphicsContext(GraphicsObject):
|
||||
x, y = point
|
||||
path.AddLineToPoint(x, y)
|
||||
self.StrokePath(path)
|
||||
|
||||
|
||||
|
||||
def StrokeLineSegments(self, beginPoints, endPoints):
|
||||
"""
|
||||
@@ -1724,7 +1724,7 @@ class GraphicsContext(GraphicsObject):
|
||||
path.MoveToPoint(begin[0], begin[1])
|
||||
path.AddLineToPoint(end[0], end[1])
|
||||
self.StrokePath(path)
|
||||
|
||||
|
||||
|
||||
def DrawLines(self, points, fillStyle=wx.ODDEVEN_RULE):
|
||||
"""
|
||||
@@ -1759,7 +1759,7 @@ class GraphicsContext(GraphicsObject):
|
||||
path.AddEllipse(x, y, w, h)
|
||||
self.DrawPath(path)
|
||||
|
||||
|
||||
|
||||
def DrawRoundedRectangle(self, x, y, w, h, radius):
|
||||
"""
|
||||
Stroke and fill a rounded rectangle using the current pen and
|
||||
@@ -1768,7 +1768,7 @@ class GraphicsContext(GraphicsObject):
|
||||
path = GraphicsPath()
|
||||
path.AddRoundedRectangle(x, y, w, h, radius)
|
||||
self.DrawPath(path)
|
||||
|
||||
|
||||
|
||||
|
||||
def GetCompositingOperator(self):
|
||||
@@ -1811,7 +1811,7 @@ class GraphicsContext(GraphicsObject):
|
||||
"""
|
||||
self._layerOpacities.append(opacity)
|
||||
self._context.push_group()
|
||||
|
||||
|
||||
|
||||
def EndLayer(self):
|
||||
"""
|
||||
@@ -1823,12 +1823,12 @@ class GraphicsContext(GraphicsObject):
|
||||
self._context.pop_group_to_source()
|
||||
self._context.paint_with_alpha(opacity)
|
||||
|
||||
|
||||
|
||||
def GetSize(self):
|
||||
return (self._width, self._height)
|
||||
Size = property(GetSize)
|
||||
|
||||
|
||||
|
||||
|
||||
# Some things not in wx.GraphicsContext (yet)
|
||||
|
||||
def DrawCircle(self, x, y, radius):
|
||||
@@ -1839,7 +1839,7 @@ class GraphicsContext(GraphicsObject):
|
||||
path = GraphicsPath()
|
||||
path.AddCircle(x, y, radius)
|
||||
self.DrawPath(path)
|
||||
|
||||
|
||||
|
||||
def ClipPath(self, path):
|
||||
"""
|
||||
@@ -1848,7 +1848,7 @@ class GraphicsContext(GraphicsObject):
|
||||
self._context.append_path(path.GetNativePath())
|
||||
self._context.clip()
|
||||
|
||||
|
||||
|
||||
def Clear(self, colour=None):
|
||||
"""
|
||||
Clear the context using the given color or the currently set brush.
|
||||
@@ -1867,7 +1867,7 @@ class GraphicsContext(GraphicsObject):
|
||||
|
||||
brush.Apply(self)
|
||||
self._context.paint()
|
||||
|
||||
|
||||
self._context.set_operator(op)
|
||||
self.PopState()
|
||||
|
||||
@@ -1885,13 +1885,13 @@ def _makeColour(colour):
|
||||
else:
|
||||
return colour
|
||||
|
||||
|
||||
def _colourToValues(c):
|
||||
|
||||
def _colourToValues(c):
|
||||
"""
|
||||
Helper which converts wx.Colour components to a set of values between 0 and 1
|
||||
"""
|
||||
return tuple( [x/255.0 for x in c.Get(True)] )
|
||||
|
||||
|
||||
|
||||
class _OffsetHelper(object):
|
||||
"""A helper used by the context class."""
|
||||
@@ -1917,7 +1917,7 @@ def _stdDashes(style, width):
|
||||
"""
|
||||
if width < 1.0:
|
||||
width = 1.0
|
||||
|
||||
|
||||
if style == wx.DOT:
|
||||
dashes = [ width, width + 2.0]
|
||||
elif style == wx.DOT_DASH:
|
||||
@@ -1929,5 +1929,5 @@ def _stdDashes(style, width):
|
||||
|
||||
return dashes
|
||||
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
@@ -27,7 +27,7 @@ import wx.grid
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# event class and macros
|
||||
#
|
||||
#
|
||||
# New style 12/7/03
|
||||
#
|
||||
|
||||
@@ -263,7 +263,7 @@ class GridColMover(wx.EvtHandler):
|
||||
_rlSize = self.grid.GetRowLabelSize()
|
||||
if abs(self.startX - evt.X) >= 3 \
|
||||
and abs(evt.X - self.lastX) >= 3:
|
||||
self.lastX = evt.X
|
||||
self.lastX = evt.X
|
||||
self.didMove = True
|
||||
sx,y = self.grid.GetViewStart()
|
||||
w,h = self.lwin.GetClientSize()
|
||||
@@ -406,9 +406,9 @@ class GridRowMover(wx.EvtHandler):
|
||||
elif evt.Y > h:
|
||||
y += evt.Y - h
|
||||
|
||||
if y < 1:
|
||||
if y < 1:
|
||||
y = 0
|
||||
else:
|
||||
else:
|
||||
y /= self.uy
|
||||
|
||||
if y != sy:
|
||||
@@ -425,7 +425,7 @@ class GridRowMover(wx.EvtHandler):
|
||||
|
||||
py = y - self.cellY
|
||||
|
||||
if py < 0 + _clSize:
|
||||
if py < 0 + _clSize:
|
||||
py = 0 + _clSize
|
||||
|
||||
if py > h - self.rowWin.GetSize()[1] + _clSize:
|
||||
@@ -448,14 +448,14 @@ class GridRowMover(wx.EvtHandler):
|
||||
return
|
||||
|
||||
row = self.grid.YToRow(py + sy)
|
||||
|
||||
|
||||
if row == wx.NOT_FOUND:
|
||||
evt.Skip()
|
||||
return
|
||||
|
||||
|
||||
self.isDragging = True
|
||||
self.didMove = False
|
||||
|
||||
|
||||
rect = self.grid.RowToRect(row)
|
||||
self.cellY = py + sy - rect.y
|
||||
size = self.lwin.GetSize()
|
||||
|
||||
@@ -57,7 +57,7 @@ class IEHtmlWindow(wx.lib.activex.ActiveXCtrl):
|
||||
|
||||
self._canGoBack = False
|
||||
self._canGoForward = False
|
||||
|
||||
|
||||
|
||||
def LoadString(self, html):
|
||||
"""Load the html document from a string"""
|
||||
@@ -78,7 +78,7 @@ class IEHtmlWindow(wx.lib.activex.ActiveXCtrl):
|
||||
for line in stream:
|
||||
doc.write(line)
|
||||
doc.close()
|
||||
|
||||
|
||||
|
||||
def LoadUrl(self, URL, Flags=0):
|
||||
"""Load the document from url."""
|
||||
@@ -101,8 +101,8 @@ class IEHtmlWindow(wx.lib.activex.ActiveXCtrl):
|
||||
return range.htmlText
|
||||
else:
|
||||
return range.text
|
||||
|
||||
|
||||
|
||||
|
||||
def GetText(self, asHTML=True):
|
||||
"""
|
||||
Returns the contents of the the html document as either html or plain text.
|
||||
@@ -115,7 +115,7 @@ class IEHtmlWindow(wx.lib.activex.ActiveXCtrl):
|
||||
if not asHTML:
|
||||
# if just fetching the text then get it from the body property
|
||||
return doc.body.innerText
|
||||
|
||||
|
||||
# otherwise look in the all property
|
||||
for idx in range(doc.all.length):
|
||||
# the first item with content should be the <html> tag and all its
|
||||
@@ -138,9 +138,9 @@ class IEHtmlWindow(wx.lib.activex.ActiveXCtrl):
|
||||
def PrintPreview(self):
|
||||
self.ctrl.ExecWB( SHDocVw.OLECMDID_PRINTPREVIEW,
|
||||
SHDocVw.OLECMDEXECOPT_DODEFAULT)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def GoBack(self):
|
||||
if self.CanGoBack():
|
||||
return self.ctrl.GoBack()
|
||||
@@ -182,7 +182,7 @@ class IEHtmlWindow(wx.lib.activex.ActiveXCtrl):
|
||||
self._canGoForward = enable
|
||||
if command == SHDocVw.CSC_NAVIGATEBACK:
|
||||
self._canGoBack = enable
|
||||
|
||||
|
||||
|
||||
# Getters, Setters and properties
|
||||
def _get_Busy(self):
|
||||
@@ -238,12 +238,12 @@ class IEHtmlWindow(wx.lib.activex.ActiveXCtrl):
|
||||
if __name__ == '__main__':
|
||||
app = wx.App(False)
|
||||
frm = wx.Frame(None, title="AX Test Window")
|
||||
|
||||
|
||||
ie = IEHtmlWindow(frm)
|
||||
|
||||
|
||||
frm.Show()
|
||||
import wx.lib.inspection
|
||||
wx.lib.inspection.InspectionTool().Show()
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in case the old 'ID' param is used as a keyword
|
||||
if ID != -1:
|
||||
id = ID
|
||||
|
||||
|
||||
wx.activex.IEHtmlWindowBase.__init__(self, parent,
|
||||
wx.activex.CLSID('{8856F961-340A-11D0-A96B-00C04FD705A2}'),
|
||||
id, pos, size, style, name)
|
||||
@@ -153,13 +153,13 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
Returns the contents of the the html document as either html or plain text.
|
||||
"""
|
||||
return wx.activex.IEHtmlWindowBase.GetText(self, asHTML)
|
||||
|
||||
|
||||
|
||||
|
||||
def SetCharset(self, charset):
|
||||
""""""
|
||||
return wx.activex.IEHtmlWindowBase.SetCharset(self, charset)
|
||||
|
||||
|
||||
|
||||
# Methods exported by the ActiveX object
|
||||
def QueryInterface(self, riid):
|
||||
return self.CallAXMethod('QueryInterface', riid)
|
||||
@@ -398,100 +398,100 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# --------------------
|
||||
# application
|
||||
# type:VT_DISPATCH arg:VT_EMPTY canGet:True canSet:False
|
||||
#
|
||||
#
|
||||
# parent
|
||||
# type:VT_DISPATCH arg:VT_EMPTY canGet:True canSet:False
|
||||
#
|
||||
#
|
||||
# container
|
||||
# type:VT_DISPATCH arg:VT_EMPTY canGet:True canSet:False
|
||||
#
|
||||
#
|
||||
# document
|
||||
# type:VT_DISPATCH arg:VT_EMPTY canGet:True canSet:False
|
||||
#
|
||||
#
|
||||
# toplevelcontainer
|
||||
# type:bool arg:VT_EMPTY canGet:True canSet:False
|
||||
#
|
||||
#
|
||||
# type
|
||||
# type:string arg:VT_EMPTY canGet:True canSet:False
|
||||
#
|
||||
#
|
||||
# left
|
||||
# type:int arg:int canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# top
|
||||
# type:int arg:int canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# width
|
||||
# type:int arg:int canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# height
|
||||
# type:int arg:int canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# locationname
|
||||
# type:string arg:VT_EMPTY canGet:True canSet:False
|
||||
#
|
||||
#
|
||||
# locationurl
|
||||
# type:string arg:VT_EMPTY canGet:True canSet:False
|
||||
#
|
||||
#
|
||||
# busy
|
||||
# type:bool arg:VT_EMPTY canGet:True canSet:False
|
||||
#
|
||||
#
|
||||
# name
|
||||
# type:string arg:VT_EMPTY canGet:True canSet:False
|
||||
#
|
||||
#
|
||||
# hwnd
|
||||
# type:int arg:VT_EMPTY canGet:True canSet:False
|
||||
#
|
||||
#
|
||||
# fullname
|
||||
# type:string arg:VT_EMPTY canGet:True canSet:False
|
||||
#
|
||||
#
|
||||
# path
|
||||
# type:string arg:VT_EMPTY canGet:True canSet:False
|
||||
#
|
||||
#
|
||||
# visible
|
||||
# type:bool arg:bool canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# statusbar
|
||||
# type:bool arg:bool canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# statustext
|
||||
# type:string arg:string canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# toolbar
|
||||
# type:int arg:int canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# menubar
|
||||
# type:bool arg:bool canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# fullscreen
|
||||
# type:bool arg:bool canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# readystate
|
||||
# type:unsupported type 29 arg:VT_EMPTY canGet:True canSet:False
|
||||
#
|
||||
#
|
||||
# offline
|
||||
# type:bool arg:bool canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# silent
|
||||
# type:bool arg:bool canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# registerasbrowser
|
||||
# type:bool arg:bool canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# registerasdroptarget
|
||||
# type:bool arg:bool canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# theatermode
|
||||
# type:bool arg:bool canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# addressbar
|
||||
# type:bool arg:bool canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# resizable
|
||||
# type:bool arg:bool canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# METHODS
|
||||
# --------------------
|
||||
# QueryInterface
|
||||
@@ -501,19 +501,19 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:False optional:False type:unsupported type 29
|
||||
# ppvObj
|
||||
# in:False out:True optional:False type:unsupported type 26
|
||||
#
|
||||
#
|
||||
# AddRef
|
||||
# retType: int
|
||||
#
|
||||
#
|
||||
# Release
|
||||
# retType: int
|
||||
#
|
||||
#
|
||||
# GetTypeInfoCount
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# pctinfo
|
||||
# in:False out:True optional:False type:int
|
||||
#
|
||||
#
|
||||
# GetTypeInfo
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -523,7 +523,7 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:False optional:False type:int
|
||||
# pptinfo
|
||||
# in:False out:True optional:False type:unsupported type 26
|
||||
#
|
||||
#
|
||||
# GetIDsOfNames
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -537,7 +537,7 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:False optional:False type:int
|
||||
# rgdispid
|
||||
# in:False out:True optional:False type:int
|
||||
#
|
||||
#
|
||||
# Invoke
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -557,19 +557,19 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:False out:True optional:False type:unsupported type 29
|
||||
# puArgErr
|
||||
# in:False out:True optional:False type:int
|
||||
#
|
||||
#
|
||||
# GoBack
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# GoForward
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# GoHome
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# GoSearch
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# Navigate
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -583,22 +583,22 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:False optional:True type:VT_VARIANT
|
||||
# Headers
|
||||
# in:True out:False optional:True type:VT_VARIANT
|
||||
#
|
||||
#
|
||||
# Refresh
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# Refresh2
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# Level
|
||||
# in:True out:False optional:False type:VT_VARIANT
|
||||
#
|
||||
#
|
||||
# Stop
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# Quit
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# ClientToWindow
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -606,7 +606,7 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:True optional:False type:int
|
||||
# pcy
|
||||
# in:True out:True optional:False type:int
|
||||
#
|
||||
#
|
||||
# PutProperty
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -614,13 +614,13 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:False optional:False type:string
|
||||
# vtValue
|
||||
# in:True out:False optional:False type:VT_VARIANT
|
||||
#
|
||||
#
|
||||
# GetProperty
|
||||
# retType: VT_VARIANT
|
||||
# params:
|
||||
# Property
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# Navigate2
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -634,13 +634,13 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:False optional:True type:VT_VARIANT
|
||||
# Headers
|
||||
# in:True out:False optional:True type:VT_VARIANT
|
||||
#
|
||||
#
|
||||
# QueryStatusWB
|
||||
# retType: unsupported type 29
|
||||
# params:
|
||||
# cmdID
|
||||
# in:True out:False optional:False type:unsupported type 29
|
||||
#
|
||||
#
|
||||
# ExecWB
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -652,7 +652,7 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:False optional:False type:VT_VARIANT
|
||||
# pvaOut
|
||||
# in:True out:True optional:True type:VT_VARIANT
|
||||
#
|
||||
#
|
||||
# ShowBrowserBar
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -662,10 +662,10 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:False optional:False type:VT_VARIANT
|
||||
# pvarSize
|
||||
# in:True out:False optional:True type:VT_VARIANT
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# EVENTS
|
||||
# --------------------
|
||||
# StatusTextChange
|
||||
@@ -673,7 +673,7 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# params:
|
||||
# Text
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# ProgressChange
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -681,7 +681,7 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:False optional:False type:int
|
||||
# ProgressMax
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# CommandStateChange
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -689,25 +689,25 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:False optional:False type:int
|
||||
# Enable
|
||||
# in:True out:False optional:False type:bool
|
||||
#
|
||||
#
|
||||
# DownloadBegin
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# DownloadComplete
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# TitleChange
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# Text
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# PropertyChange
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# szProperty
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# BeforeNavigate2
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -725,7 +725,7 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:False optional:False type:VT_VARIANT
|
||||
# Cancel
|
||||
# in:True out:True optional:False type:bool
|
||||
#
|
||||
#
|
||||
# NewWindow2
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -733,7 +733,7 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:True optional:False type:VT_DISPATCH
|
||||
# Cancel
|
||||
# in:True out:True optional:False type:bool
|
||||
#
|
||||
#
|
||||
# NavigateComplete2
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -741,7 +741,7 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:False optional:False type:VT_DISPATCH
|
||||
# URL
|
||||
# in:True out:False optional:False type:VT_VARIANT
|
||||
#
|
||||
#
|
||||
# DocumentComplete
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -749,76 +749,76 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:False optional:False type:VT_DISPATCH
|
||||
# URL
|
||||
# in:True out:False optional:False type:VT_VARIANT
|
||||
#
|
||||
#
|
||||
# Quit
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# Visible
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# Visible
|
||||
# in:True out:False optional:False type:bool
|
||||
#
|
||||
#
|
||||
# ToolBar
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# ToolBar
|
||||
# in:True out:False optional:False type:bool
|
||||
#
|
||||
#
|
||||
# MenuBar
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# MenuBar
|
||||
# in:True out:False optional:False type:bool
|
||||
#
|
||||
#
|
||||
# StatusBar
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# StatusBar
|
||||
# in:True out:False optional:False type:bool
|
||||
#
|
||||
#
|
||||
# FullScreen
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# FullScreen
|
||||
# in:True out:False optional:False type:bool
|
||||
#
|
||||
#
|
||||
# TheaterMode
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# TheaterMode
|
||||
# in:True out:False optional:False type:bool
|
||||
#
|
||||
#
|
||||
# WindowSetResizable
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# Resizable
|
||||
# in:True out:False optional:False type:bool
|
||||
#
|
||||
#
|
||||
# WindowSetLeft
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# Left
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# WindowSetTop
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# Top
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# WindowSetWidth
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# Width
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# WindowSetHeight
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# Height
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# WindowClosing
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -826,7 +826,7 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:False optional:False type:bool
|
||||
# Cancel
|
||||
# in:True out:True optional:False type:bool
|
||||
#
|
||||
#
|
||||
# ClientToHostWindow
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -834,19 +834,19 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:True optional:False type:int
|
||||
# CY
|
||||
# in:True out:True optional:False type:int
|
||||
#
|
||||
#
|
||||
# SetSecureLockIcon
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# SecureLockIcon
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# FileDownload
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# Cancel
|
||||
# in:True out:True optional:False type:bool
|
||||
#
|
||||
#
|
||||
# NavigateError
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -860,19 +860,19 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:False optional:False type:VT_VARIANT
|
||||
# Cancel
|
||||
# in:True out:True optional:False type:bool
|
||||
#
|
||||
#
|
||||
# PrintTemplateInstantiation
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# pDisp
|
||||
# in:True out:False optional:False type:VT_DISPATCH
|
||||
#
|
||||
#
|
||||
# PrintTemplateTeardown
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# pDisp
|
||||
# in:True out:False optional:False type:VT_DISPATCH
|
||||
#
|
||||
#
|
||||
# UpdatePageStatus
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -882,13 +882,13 @@ class IEHtmlWindow(wx.activex.IEHtmlWindowBase):
|
||||
# in:True out:False optional:False type:VT_VARIANT
|
||||
# fDone
|
||||
# in:True out:False optional:False type:VT_VARIANT
|
||||
#
|
||||
#
|
||||
# PrivacyImpactedStateChange
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# bImpacted
|
||||
# in:True out:False optional:False type:bool
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
@@ -127,7 +127,7 @@ def GetCheckeredBitmap(blocksize=8, ntiles=4, rgb0='\xFF', rgb1='\xCC'):
|
||||
:param int `ntiles1`: the number of tiles along width and height. Each tile is 2x2 blocks.
|
||||
:param `rbg0`: the first color, as 3-byte strings.
|
||||
:param `rgb1`: the second color, as 3-byte strings. If only 1 byte is provided, it is treated as a grey value.
|
||||
|
||||
|
||||
:return: :class:`wx.BitmapFromBuffer`
|
||||
|
||||
"""
|
||||
|
||||
@@ -43,7 +43,7 @@ Sample usage::
|
||||
|
||||
# Lighter
|
||||
light_colour = stepColour(colour, 120)
|
||||
|
||||
|
||||
app.MainLoop()
|
||||
|
||||
"""
|
||||
@@ -60,10 +60,10 @@ def grayOut(anImage):
|
||||
|
||||
:rtype: :class:`wx.Image`
|
||||
:returns: The modified (greyed out) image.
|
||||
|
||||
|
||||
.. note:: the image is converted in place, i.e. the input image will
|
||||
be modified to a greyed out version.
|
||||
|
||||
|
||||
"""
|
||||
|
||||
factor = 0.7 # 0 < f < 1. Higher is grayer.
|
||||
@@ -75,7 +75,7 @@ def grayOut(anImage):
|
||||
alpha = anImage.GetAlpha()
|
||||
else:
|
||||
alpha = None
|
||||
|
||||
|
||||
data = anImage.GetData()
|
||||
|
||||
for i in range(0, len(data), 3):
|
||||
@@ -86,7 +86,7 @@ def grayOut(anImage):
|
||||
anImage.SetData(data) # ''.join(map(chr, data)))
|
||||
if alpha:
|
||||
anImage.SetAlpha(alpha)
|
||||
|
||||
|
||||
|
||||
def makeGray(rgb, factor, maskColor):
|
||||
"""
|
||||
@@ -98,11 +98,11 @@ def makeGray(rgb, factor, maskColor):
|
||||
:param `maskColor`: the mask colour.
|
||||
|
||||
:type `maskColor`: tuple or :class:`wx.Colour`.
|
||||
|
||||
|
||||
:rtype: tuple
|
||||
:returns: An RGB tuple with the greyed out pixel colour.
|
||||
"""
|
||||
|
||||
|
||||
if rgb != maskColor:
|
||||
return tuple([int((230 - x)*factor) + x for x in rgb])
|
||||
else:
|
||||
@@ -123,7 +123,7 @@ def stepColour(c, step):
|
||||
:rtype: :class:`wx.Colour`
|
||||
:returns: A new colour, darkened or lightened depending on the input `step` value.
|
||||
"""
|
||||
|
||||
|
||||
def _blendColour(fg, bg, dstep):
|
||||
result = bg + (dstep * (fg - bg))
|
||||
if result < 0:
|
||||
@@ -134,18 +134,18 @@ def stepColour(c, step):
|
||||
|
||||
if step == 100:
|
||||
return c
|
||||
|
||||
|
||||
r = c.Red()
|
||||
g = c.Green()
|
||||
b = c.Blue()
|
||||
|
||||
|
||||
# step is 0..200 where 0 is completely black
|
||||
# and 200 is completely white and 100 is the same
|
||||
# convert that to a range of -1.0 .. 1.0
|
||||
step = min(step, 200)
|
||||
step = max(step, 0)
|
||||
dstep = (step - 100.0)/100.0
|
||||
|
||||
|
||||
if step > 100:
|
||||
# blend with white
|
||||
bg = 255.0
|
||||
@@ -154,10 +154,10 @@ def stepColour(c, step):
|
||||
# blend with black
|
||||
bg = 0.0
|
||||
dstep = 1.0 + dstep; # 0 = transparent fg; 1 = opaque fg
|
||||
|
||||
|
||||
r = _blendColour(r, bg, dstep)
|
||||
g = _blendColour(g, bg, dstep)
|
||||
b = _blendColour(b, bg, dstep)
|
||||
|
||||
|
||||
return wx.Colour(int(r), int(g), int(b))
|
||||
|
||||
|
||||
@@ -51,10 +51,10 @@ it this way::
|
||||
InformationalMessagesFrame = PyInformationalMessagesFrame( \
|
||||
options_from_progname, # (default = "")
|
||||
txt), # (default = "informational messages")
|
||||
|
||||
|
||||
#^^^^ early in the program
|
||||
# ...
|
||||
|
||||
|
||||
InformationalMessagesFrame(list_of_items)
|
||||
|
||||
# where list_of_items:
|
||||
@@ -62,7 +62,7 @@ it this way::
|
||||
# comma-separated list of items to display.
|
||||
# Note that these will never be separated by spaces as they may
|
||||
# be when used in the Python 'print' command
|
||||
|
||||
|
||||
|
||||
The latter statement, of course, may be repeated arbitrarily often.
|
||||
The window will not appear until it is written to, and it may be
|
||||
@@ -131,7 +131,7 @@ write() which displays it's argument.
|
||||
All (well, most) of this is made clear by the example code at the end
|
||||
of this file, which is run if the file is run by itself; otherwise,
|
||||
see the appropriate "stub" file in the wxPython demo.
|
||||
|
||||
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
@@ -89,11 +89,11 @@ class InspectionTool:
|
||||
"""
|
||||
Creates the inspection frame if it hasn't been already, and
|
||||
raises it if neccessary.
|
||||
|
||||
|
||||
:param `selectObj`: Pass a widget or sizer to have that object be
|
||||
preselected in widget tree.
|
||||
:param boolean `refreshTree`: rebuild the widget tree, default False
|
||||
|
||||
|
||||
"""
|
||||
if not self.initialized:
|
||||
self.Init()
|
||||
@@ -215,7 +215,7 @@ class InspectionFrame(wx.Frame):
|
||||
collapseTreeBmp = CollapseTree.GetBitmap()
|
||||
highlightItemBmp = HighlightItem.GetBitmap()
|
||||
evtWatcherBmp = EvtWatcher.GetBitmap()
|
||||
|
||||
|
||||
toggleFillingBmp = ShowFilling.GetBitmap()
|
||||
|
||||
refreshTool = tbar.AddTool(-1, 'Refresh', refreshBmp,
|
||||
@@ -233,7 +233,7 @@ class InspectionFrame(wx.Frame):
|
||||
shortHelp='Attempt to highlight live item (F6)')
|
||||
evtWatcherTool = tbar.AddTool(-1, 'Events', evtWatcherBmp,
|
||||
shortHelp='Watch the events of the selected item (F7)')
|
||||
|
||||
|
||||
toggleFillingTool = tbar.AddTool(-1, 'Filling', toggleFillingBmp,
|
||||
shortHelp='Show PyCrust \'filling\' (F8)',
|
||||
kind=wx.ITEM_CHECK)
|
||||
@@ -361,7 +361,7 @@ class InspectionFrame(wx.Frame):
|
||||
def OnHighlightItem(self, evt):
|
||||
self.HighlightCurrentItem()
|
||||
|
||||
|
||||
|
||||
def OnWatchEvents(self, evt):
|
||||
item = self.tree.GetSelection()
|
||||
obj = self.tree.GetItemData(item)
|
||||
@@ -370,7 +370,7 @@ class InspectionFrame(wx.Frame):
|
||||
watcher = ew.EventWatcher(self)
|
||||
watcher.watch(obj)
|
||||
watcher.Show()
|
||||
|
||||
|
||||
def OnWatchEventsUI(self, evt):
|
||||
item = self.tree.GetSelection()
|
||||
if item:
|
||||
@@ -404,7 +404,7 @@ class InspectionFrame(wx.Frame):
|
||||
self.Move(pos)
|
||||
rect = utils.AdjustRectToScreen(self.GetRect())
|
||||
self.SetRect(rect)
|
||||
|
||||
|
||||
perspective = config.Read('perspective', '')
|
||||
if perspective:
|
||||
try:
|
||||
@@ -427,7 +427,7 @@ class InspectionFrame(wx.Frame):
|
||||
px, py = self.GetPosition()
|
||||
config.WriteInt('Window/PosX', px)
|
||||
config.WriteInt('Window/PosY', py)
|
||||
|
||||
|
||||
if hasattr(self, "mgr"):
|
||||
perspective = self.mgr.SavePerspective()
|
||||
config.Write('perspective', perspective)
|
||||
@@ -561,8 +561,8 @@ class InspectionTree(TreeBaseClass):
|
||||
if hasattr(widget, 'GetName'):
|
||||
return "%s (\"%s\")" % (widget.__class__.__name__, widget.GetName())
|
||||
return widget.__class__.__name__
|
||||
|
||||
|
||||
|
||||
|
||||
def GetTextForSizer(self, sizer):
|
||||
"""
|
||||
Returns the string to be used in the tree for a sizer
|
||||
@@ -678,7 +678,7 @@ class InspectionInfoPanel(wx.stc.StyledTextCtrl):
|
||||
st.append(self.Fmt('virtual size',obj.GetVirtualSize()))
|
||||
st.append(self.Fmt('IsEnabled', obj.IsEnabled()))
|
||||
st.append(self.Fmt('IsShown', obj.IsShown()))
|
||||
st.append(self.Fmt('IsFrozen', obj.IsFrozen()))
|
||||
st.append(self.Fmt('IsFrozen', obj.IsFrozen()))
|
||||
st.append(self.Fmt('fg color', obj.GetForegroundColour()))
|
||||
st.append(self.Fmt('bg color', obj.GetBackgroundColour()))
|
||||
st.append(self.Fmt('label', obj.GetLabel()))
|
||||
@@ -751,7 +751,7 @@ class InspectionInfoPanel(wx.stc.StyledTextCtrl):
|
||||
if hasattr(obj, '_parentSizer'):
|
||||
st.append('')
|
||||
st += self.FmtSizerItem(obj._parentSizer.GetItem(obj))
|
||||
|
||||
|
||||
return st
|
||||
|
||||
|
||||
@@ -821,16 +821,16 @@ class _InspectionHighlighter(object):
|
||||
color3 = '#00008B' # for items in sizers
|
||||
|
||||
highlightTime = 3000 # how long to display the highlights
|
||||
|
||||
|
||||
# how to draw it
|
||||
useOverlay = 'wxMac' in wx.PlatformInfo
|
||||
|
||||
|
||||
|
||||
|
||||
def __init__(self):
|
||||
if self.useOverlay:
|
||||
self.overlay = wx.Overlay()
|
||||
|
||||
|
||||
|
||||
|
||||
def HighlightCurrentItem(self, tree):
|
||||
"""
|
||||
Draw a highlight rectangle around the item represented by the
|
||||
@@ -904,7 +904,7 @@ class _InspectionHighlighter(object):
|
||||
continue
|
||||
r = self.AdjustRect(tlw, win, r)
|
||||
dc.DrawRectangle(r)
|
||||
|
||||
|
||||
# Next highlight the area allocated to each item in the sizer.
|
||||
# Each kind of sizer will need to be done a little
|
||||
# differently.
|
||||
@@ -914,7 +914,7 @@ class _InspectionHighlighter(object):
|
||||
for item in sizer.GetChildren():
|
||||
ir = self.AdjustRect(tlw, win, item.Rect)
|
||||
dc.DrawRectangle(ir)
|
||||
|
||||
|
||||
# wx.BoxSizer, wx.StaticBoxSizer
|
||||
elif isinstance(sizer, wx.BoxSizer):
|
||||
# NOTE: we have to do some reverse-engineering here for
|
||||
@@ -1019,7 +1019,7 @@ class _InspectionHighlighter(object):
|
||||
else:
|
||||
dc = wx.ScreenDC()
|
||||
dco = None
|
||||
|
||||
|
||||
dc.SetPen(wx.Pen(colour, penWidth))
|
||||
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
||||
|
||||
@@ -1034,7 +1034,7 @@ class _InspectionHighlighter(object):
|
||||
|
||||
return dc, dco
|
||||
|
||||
|
||||
|
||||
def DoUnhighlight(self, tlw, rect):
|
||||
if not tlw:
|
||||
return
|
||||
@@ -1048,7 +1048,7 @@ class _InspectionHighlighter(object):
|
||||
self.overlay.Reset()
|
||||
else:
|
||||
tlw.RefreshRect(rect)
|
||||
|
||||
|
||||
|
||||
def FlickerTLW(self, tlw):
|
||||
"""
|
||||
@@ -1060,7 +1060,7 @@ class _InspectionHighlighter(object):
|
||||
tlw.Hide()
|
||||
self.cl = wx.CallLater(300, self._Toggle, tlw)
|
||||
|
||||
|
||||
|
||||
def _Toggle(self, tlw):
|
||||
if tlw.IsShown():
|
||||
tlw.Hide()
|
||||
|
||||
@@ -73,15 +73,15 @@ WXK_CTRL_V = (ord('V')+1) - ord('A')
|
||||
|
||||
class IntUpdatedEvent(wx.PyCommandEvent):
|
||||
"""Event sent from the :class:`~lib.intctrl.IntCtrl` when control is updated."""
|
||||
|
||||
|
||||
def __init__(self, id, value = 0, object=None):
|
||||
"""
|
||||
Default class constructor.
|
||||
|
||||
|
||||
:param int `id`: the object id
|
||||
:param int `value`: the value
|
||||
:param `object`: the object of the event
|
||||
|
||||
|
||||
"""
|
||||
wx.PyCommandEvent.__init__(self, wxEVT_COMMAND_INT_UPDATED, id)
|
||||
|
||||
@@ -110,10 +110,10 @@ class IntValidator(wx.Validator):
|
||||
def Clone (self):
|
||||
"""
|
||||
Standard cloner
|
||||
|
||||
|
||||
..note::
|
||||
Every validator must implement the Clone() method.
|
||||
|
||||
|
||||
"""
|
||||
return self.__class__()
|
||||
|
||||
@@ -360,11 +360,11 @@ class IntValidator(wx.Validator):
|
||||
def TransferToWindow(self):
|
||||
"""
|
||||
Transfer data from validator to window.
|
||||
|
||||
|
||||
The default implementation returns False, indicating that an error
|
||||
occurred. We simply return True, to indicate to e.g. :class:`Dialog`
|
||||
that all is well.
|
||||
|
||||
|
||||
If data comes e.g. from a database then you need to override this.
|
||||
"""
|
||||
return True
|
||||
@@ -373,11 +373,11 @@ class IntValidator(wx.Validator):
|
||||
def TransferFromWindow(self):
|
||||
"""
|
||||
Transfer data from window to validator.
|
||||
|
||||
|
||||
The default implementation returns False, indicating that an error
|
||||
occurred. We simply return True, to indicate to e.g. :class:`Dialog`
|
||||
that all is well.
|
||||
|
||||
|
||||
If data comes e.g. from a database then you need to override this.
|
||||
"""
|
||||
return True
|
||||
@@ -407,12 +407,12 @@ class IntCtrl(wx.TextCtrl):
|
||||
|
||||
:param int `id`: window identifier. A value of -1 indicates a
|
||||
default value
|
||||
|
||||
:param `value`: If no initial value is set, the default will be zero,
|
||||
|
||||
:param `value`: If no initial value is set, the default will be zero,
|
||||
or the minimum value, if specified. If an illegal string is
|
||||
specified, a ValueError will result. (You can always later set the
|
||||
initial value with ChangeValue() after instantiation of the control.)
|
||||
|
||||
|
||||
:param tuple `pos`: the control position. A value of (-1, -1) indicates
|
||||
a default position, chosen by either the windowing system or
|
||||
wxPython, depending on platform
|
||||
@@ -420,9 +420,9 @@ class IntCtrl(wx.TextCtrl):
|
||||
:param wx.Size `size`: the control size. A value of (-1, -1) indicates a
|
||||
default size, chosen by either the windowing system or wxPython,
|
||||
depending on platform
|
||||
|
||||
|
||||
:param int `style`: the underlying :class:`TextCtrl` style
|
||||
|
||||
|
||||
:param wx.Validator `validator`: Normally None, IntCtrl uses its own
|
||||
validator to do value validation and input control. However, a
|
||||
validator derived from :class:`~lib.intctrl.IntValidator` can be
|
||||
@@ -435,7 +435,7 @@ class IntCtrl(wx.TextCtrl):
|
||||
color. If min < -sys.maxsize-1 and the control is configured to not
|
||||
allow long values, the minimum bound will still be set to the long
|
||||
value, but the implicit bound will be -sys.maxsize-1.
|
||||
|
||||
|
||||
:param int `max`: The maximum value that the control should allow. This
|
||||
can be adjusted with SetMax(). If the control is not limited, any
|
||||
value above this bound will be colored with the current out-of-bounds
|
||||
@@ -534,9 +534,9 @@ class IntCtrl(wx.TextCtrl):
|
||||
or colored if not limited but the value is out-of-bounds.
|
||||
A ValueError exception will be raised if an invalid value
|
||||
is specified.
|
||||
|
||||
|
||||
:param int `value`: The value to be set
|
||||
|
||||
|
||||
"""
|
||||
wx.TextCtrl.SetValue( self, self._toGUI(value) )
|
||||
self._colorValue()
|
||||
@@ -547,7 +547,7 @@ class IntCtrl(wx.TextCtrl):
|
||||
Change the value without sending an EVT_TEXT event.
|
||||
|
||||
:param int `value`: The value to be set
|
||||
|
||||
|
||||
"""
|
||||
wx.TextCtrl.ChangeValue(self, self._toGUI(value))
|
||||
self.__oldvalue = self.GetValue() # record for next event
|
||||
@@ -569,7 +569,7 @@ class IntCtrl(wx.TextCtrl):
|
||||
|
||||
If min > -sys.maxsize-1 and the control is configured to not allow longs,
|
||||
the function will return 0, and the min will not be set.
|
||||
|
||||
|
||||
:param int `min`: The value to be set as minimum
|
||||
|
||||
"""
|
||||
@@ -610,7 +610,7 @@ class IntCtrl(wx.TextCtrl):
|
||||
|
||||
If max > sys.maxsize and the control is configured to not allow longs,
|
||||
the function will return 0, and the max will not be set.
|
||||
|
||||
|
||||
:param int `max`: The value to be set as maximum
|
||||
"""
|
||||
if( self.__min is None
|
||||
@@ -643,9 +643,9 @@ class IntCtrl(wx.TextCtrl):
|
||||
only if both operations succeed.
|
||||
..note::
|
||||
Leaving out an argument will remove the corresponding bound.
|
||||
|
||||
:param int `min`: The value to be set as minimum
|
||||
|
||||
|
||||
:param int `min`: The value to be set as minimum
|
||||
|
||||
:param int `max`: The value to be set as maximum
|
||||
|
||||
"""
|
||||
@@ -672,9 +672,9 @@ class IntCtrl(wx.TextCtrl):
|
||||
If called with a value of 0, this function will disable value
|
||||
limiting, but coloring of out-of-bounds values will still take
|
||||
place if bounds have been set for the control.
|
||||
|
||||
|
||||
:param bool `limited`: If True set to control to be limited.
|
||||
|
||||
|
||||
"""
|
||||
self.__limited = limited
|
||||
if limited:
|
||||
@@ -702,9 +702,9 @@ class IntCtrl(wx.TextCtrl):
|
||||
of the control falls within the current bounds. This function can
|
||||
also be called with a value to see if that value would fall within
|
||||
the current bounds of the given control.
|
||||
|
||||
|
||||
:param int `value`: value to check or None
|
||||
|
||||
|
||||
"""
|
||||
if value is None:
|
||||
value = self.GetValue()
|
||||
@@ -733,9 +733,9 @@ class IntCtrl(wx.TextCtrl):
|
||||
of the control is currently None, and allow_none is 0, the
|
||||
value of the control will be set to the minimum value of the
|
||||
control, or 0 if no lower bound is set.
|
||||
|
||||
|
||||
:param bool `allow_none`: If True a None value is allowed
|
||||
|
||||
|
||||
"""
|
||||
self.__allow_none = allow_none
|
||||
if not allow_none and self.GetValue() is None:
|
||||
@@ -757,9 +757,9 @@ class IntCtrl(wx.TextCtrl):
|
||||
value of the control will be adjusted to fall within the
|
||||
size of an integer type, at either the sys.maxsize or -sys.maxsize-1,
|
||||
for positive and negative values, respectively.
|
||||
|
||||
|
||||
:param bool `allow_long`: If True allow long values for control
|
||||
|
||||
|
||||
"""
|
||||
current_value = self.GetValue()
|
||||
if not allow_long and type(current_value) is LONGTYPE:
|
||||
@@ -781,10 +781,10 @@ class IntCtrl(wx.TextCtrl):
|
||||
Tells the control what colors to use for normal and out-of-bounds
|
||||
values. If the value currently exceeds the bounds, it will be
|
||||
recolored accordingly.
|
||||
|
||||
|
||||
:param Color `default_color`: default color to be used
|
||||
:param Color `oob_color`: out of bound color to be used
|
||||
|
||||
|
||||
"""
|
||||
self.__default_color = default_color
|
||||
self.__oob_color = oob_color
|
||||
|
||||
@@ -70,33 +70,33 @@ class ItemsPicker(wx.Panel):
|
||||
sizer.Add(self._CreateDestList(selectedLabel), 1,
|
||||
wx.EXPAND|wx.ALL, 5)
|
||||
self.SetSizer(sizer)
|
||||
|
||||
|
||||
|
||||
|
||||
def SetItems(self, items):
|
||||
"""SetItems(self, items)=> None
|
||||
items - Sequence of strings that the user can pick from"""
|
||||
return self._source.SetItems(items)
|
||||
|
||||
|
||||
def GetItems(self):
|
||||
return self._source.SetItems(items)
|
||||
|
||||
|
||||
def GetItems(self):
|
||||
"""GetItems(self)=> items
|
||||
returns list of strings that the user can pick from"""
|
||||
return self._source.GetItems()
|
||||
|
||||
|
||||
|
||||
|
||||
Items = property(fget = GetItems,
|
||||
fset = SetItems,
|
||||
doc = 'See GetItems/SetItems')
|
||||
|
||||
|
||||
|
||||
|
||||
def GetSelections(self):
|
||||
"""GetSelections(self)=>items
|
||||
returns list of strings that were selected
|
||||
"""
|
||||
return self._dest.GetItems()
|
||||
|
||||
|
||||
def SetSelections(self, items):
|
||||
|
||||
|
||||
def SetSelections(self, items):
|
||||
"""SetSelections(self, items)=>None
|
||||
items - Sequence of strings to be selected
|
||||
The items are displayed in the selection part of the widget"""
|
||||
@@ -104,13 +104,13 @@ class ItemsPicker(wx.Panel):
|
||||
if items != self._dest.GetItems():
|
||||
self._dest.SetItems(items)
|
||||
self._FireIpSelectionChanged()
|
||||
|
||||
|
||||
|
||||
|
||||
Selections = property(fget = GetSelections,
|
||||
fset = SetSelections,
|
||||
doc = 'See GetSelections/SetSelections')
|
||||
|
||||
|
||||
|
||||
|
||||
def _CreateButtons(self):
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.bAdd = wx.Button(self, -1, label = 'Add ->')
|
||||
@@ -120,30 +120,30 @@ class ItemsPicker(wx.Panel):
|
||||
sizer.Add(self.bAdd, 0, wx.EXPAND|wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
|
||||
sizer.Add(self.bRemove, 0, wx.EXPAND|wx.ALL, 5)
|
||||
return sizer
|
||||
|
||||
|
||||
|
||||
|
||||
def _set_add_button_label(self, label=None):
|
||||
if label is None:
|
||||
return
|
||||
self.bAdd.SetLabel(label)
|
||||
|
||||
|
||||
add_button_label = property(fset = _set_add_button_label, fget = lambda x:x)
|
||||
|
||||
|
||||
|
||||
|
||||
def _set_remove_button_label(self, label=None):
|
||||
if label is None:
|
||||
return
|
||||
self.bRemove.SetLabel(label)
|
||||
|
||||
|
||||
remove_button_label = property(fset = _set_remove_button_label, fget = lambda x:x)
|
||||
|
||||
|
||||
|
||||
|
||||
def _OnAdd(self, e):
|
||||
if self._ipStyle & IP_REMOVE_FROM_CHOICES:
|
||||
self._MoveItems(self._source,self._dest)
|
||||
else:
|
||||
self._AddSelectedItems()
|
||||
|
||||
|
||||
def _MoveItems(self,source,dest):
|
||||
selections = source.GetSelections()
|
||||
selectedItems = list(map(source.GetString, selections))
|
||||
@@ -152,30 +152,30 @@ class ItemsPicker(wx.Panel):
|
||||
source.SetItems([item for i, item in enumerate(source.GetItems())\
|
||||
if i not in selections])
|
||||
self._FireIpSelectionChanged()
|
||||
|
||||
|
||||
def _AddSelectedItems(self):
|
||||
newItems = list(map(self._source.GetString, self._source.GetSelections()))
|
||||
items = self._dest.GetItems()
|
||||
oldItems = set(items)
|
||||
for newItem in newItems:
|
||||
if newItem not in oldItems:
|
||||
items.append(newItem)
|
||||
items.append(newItem)
|
||||
self.SetSelections(items)
|
||||
|
||||
|
||||
|
||||
|
||||
def _FireIpSelectionChanged(self):
|
||||
self.GetEventHandler().ProcessEvent(
|
||||
IpSelectionChanged(self.GetId(),
|
||||
IpSelectionChanged(self.GetId(),
|
||||
self._dest.GetItems(),
|
||||
self ))
|
||||
|
||||
|
||||
|
||||
|
||||
def _OnRemove(self, e):
|
||||
if self._ipStyle & IP_REMOVE_FROM_CHOICES:
|
||||
self._MoveItems(self._dest, self._source)
|
||||
else:
|
||||
self._RemoveSelected()
|
||||
|
||||
|
||||
def _RemoveSelected(self):
|
||||
selections = self._dest.GetSelections()
|
||||
if selections:
|
||||
@@ -184,8 +184,8 @@ class ItemsPicker(wx.Panel):
|
||||
if i not in selections]
|
||||
self.SetSelections(items)
|
||||
self._FireIpSelectionChanged()
|
||||
|
||||
|
||||
|
||||
|
||||
def _CreateSourceList(self, items, label):
|
||||
style = LB_STYLE
|
||||
if self._ipStyle & IP_SORT_CHOICES:
|
||||
@@ -199,8 +199,8 @@ class ItemsPicker(wx.Panel):
|
||||
self._source.SetItems(items)
|
||||
sizer.Add(self._source, 1, wx.EXPAND|wx.ALL, 5)
|
||||
return sizer
|
||||
|
||||
|
||||
|
||||
|
||||
def _CreateDestList(self, label):
|
||||
style = LB_STYLE
|
||||
if self._ipStyle & IP_SORT_SELECTED:
|
||||
@@ -210,11 +210,11 @@ class ItemsPicker(wx.Panel):
|
||||
sizer.Add(wx.StaticText(self, label = label), 0,
|
||||
wx.ALIGN_LEFT|wx.ALL, 5)
|
||||
self._dest = wx.ListBox(self, -1, style = style)
|
||||
self._dest.Bind(wx.EVT_LISTBOX_DCLICK, self._OnDClick)
|
||||
self._dest.Bind(wx.EVT_LISTBOX_DCLICK, self._OnDClick)
|
||||
sizer.Add(self._dest, 1, wx.EXPAND|wx.ALL, 5)
|
||||
return sizer
|
||||
|
||||
|
||||
|
||||
|
||||
def _OnDClick(self, e):
|
||||
lb = e.GetEventObject()
|
||||
selections = lb.GetSelections()
|
||||
@@ -223,19 +223,19 @@ class ItemsPicker(wx.Panel):
|
||||
if e.GetSelection() != selections[0]:
|
||||
#this can happen using ^DCLICK when two items are selected
|
||||
return
|
||||
if lb == self._source:
|
||||
if lb == self._source:
|
||||
self._OnAdd(e)
|
||||
else:
|
||||
self._OnRemove(e)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test = wx.App(0)
|
||||
frame = wx.Frame(None, -1)
|
||||
d = wx.Dialog(frame, style = wx.RESIZE_BORDER|wx.DEFAULT_DIALOG_STYLE)
|
||||
|
||||
|
||||
d.sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
d.sizer.Add(wx.StaticText(d, -1, label = 'Example of the ItemsPicker'),
|
||||
0, wx.ALL, 10)
|
||||
@@ -252,5 +252,5 @@ if __name__ == '__main__':
|
||||
d.ShowModal()
|
||||
d.Destroy()
|
||||
frame.Close()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#-----------------------------------------------------------------------------
|
||||
# Name: languagectrls.py
|
||||
# Purpose:
|
||||
# Purpose:
|
||||
#
|
||||
# Author: Riaan Booysen
|
||||
#
|
||||
@@ -193,7 +193,7 @@ langIdCountryMap = {
|
||||
wx.LANGUAGE_AMHARIC: 'ET',
|
||||
wx.LANGUAGE_ASSAMESE: 'IN',
|
||||
wx.LANGUAGE_AYMARA: 'BO',
|
||||
wx.LANGUAGE_ARABIC: 'SA',
|
||||
wx.LANGUAGE_ARABIC: 'SA',
|
||||
wx.LANGUAGE_BASHKIR: 'RU',
|
||||
wx.LANGUAGE_BHUTANI: 'BT',
|
||||
wx.LANGUAGE_BIHARI: 'IN',
|
||||
@@ -205,7 +205,7 @@ langIdCountryMap = {
|
||||
wx.LANGUAGE_FIJI: 'FJ',
|
||||
wx.LANGUAGE_GUARANI: 'PY',
|
||||
wx.LANGUAGE_HAUSA: 'NG',
|
||||
wx.LANGUAGE_INTERLINGUA: 'US',
|
||||
wx.LANGUAGE_INTERLINGUA: 'US',
|
||||
wx.LANGUAGE_INTERLINGUE: 'US',
|
||||
wx.LANGUAGE_INUPIAK: 'US',
|
||||
wx.LANGUAGE_JAVANESE: 'IN',
|
||||
@@ -282,20 +282,20 @@ def CreateLanguagesResourceLists(filter=LC_AVAILABLE, only=()):
|
||||
(filter == LC_AVAILABLE and wx.Locale.IsAvailable(wxLI)) or \
|
||||
(filter == LC_ALL):
|
||||
wxLangIds.append(wxLI)
|
||||
except wx.PyAssertionError:
|
||||
except wx.PyAssertionError:
|
||||
# invalid language assertions
|
||||
pass
|
||||
except AttributeError:
|
||||
# wx 2.6
|
||||
wxLangIds.append(wxLI)
|
||||
|
||||
langCodes = [(langIdNameMap[wxLangId], wxLangId)
|
||||
for wxLangId in wxLangIds
|
||||
|
||||
langCodes = [(langIdNameMap[wxLangId], wxLangId)
|
||||
for wxLangId in wxLangIds
|
||||
if wxLangId in langIdNameMap]
|
||||
|
||||
|
||||
for lc, wxli in langCodes:
|
||||
l, cnt = lc.split('_')
|
||||
|
||||
|
||||
if cnt in flagart.catalog:
|
||||
bmp = flagart.catalog[cnt].GetBitmap()
|
||||
else:
|
||||
@@ -306,10 +306,10 @@ def CreateLanguagesResourceLists(filter=LC_AVAILABLE, only=()):
|
||||
if wxli == wx.LANGUAGE_DEFAULT:
|
||||
#print(cnt, name, lc, wxli)
|
||||
name = 'Default: '+name
|
||||
|
||||
|
||||
names.append(name)
|
||||
langs.append(wxli)
|
||||
|
||||
|
||||
return icons, names, langs
|
||||
|
||||
|
||||
@@ -340,9 +340,9 @@ def BuildLanguageCountryMapping():
|
||||
for name in _wxLangIds:
|
||||
n = 'wx.'+name
|
||||
wn = getattr(wx, name)
|
||||
|
||||
|
||||
li = wx.Locale.GetLanguageInfo(wn)
|
||||
if li:
|
||||
if li:
|
||||
code = li.CanonicalName
|
||||
|
||||
if wn in langIdCountryMap:
|
||||
@@ -354,7 +354,7 @@ def BuildLanguageCountryMapping():
|
||||
# map unhandled to blank images
|
||||
elif '_' not in code:
|
||||
code += '_BLANK'
|
||||
|
||||
|
||||
res[wn] = code
|
||||
return res
|
||||
|
||||
@@ -362,8 +362,8 @@ def GetWxIdentifierForLanguage(lang):
|
||||
"""
|
||||
Get the wx identifier for a language.
|
||||
|
||||
:returns: The language id as a string
|
||||
"""
|
||||
:returns: The language id as a string
|
||||
"""
|
||||
for n in dir(wx):
|
||||
if n.startswith('LANGUAGE_') and getattr(wx, n) == lang:
|
||||
return n
|
||||
@@ -373,22 +373,22 @@ def GetWxIdentifierForLanguage(lang):
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
class LanguageListCtrl(wx.ListCtrl):
|
||||
"""
|
||||
"""
|
||||
:class:`wx.ListCtrl` derived control that displays languages and flags
|
||||
"""
|
||||
def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
|
||||
size=wx.DefaultSize, style=wx.LC_REPORT | wx.LC_NO_HEADER | wx.LC_SINGLE_SEL,
|
||||
size=wx.DefaultSize, style=wx.LC_REPORT | wx.LC_NO_HEADER | wx.LC_SINGLE_SEL,
|
||||
filter=LC_AVAILABLE, only=(), select=None, name='languagelistctrl'):
|
||||
"""
|
||||
Default class constructor.
|
||||
|
||||
:param `parent`: Parent window. Must not be ``None``.
|
||||
:param `parent`: Parent window. Must not be ``None``.
|
||||
:type `parent`: wx.Window
|
||||
:param `id`: Window identifier. The value ``ID_ANY`` indicates a default value.
|
||||
:param `id`: Window identifier. The value ``ID_ANY`` indicates a default value.
|
||||
:type `id`: int
|
||||
:param `pos`: Window position. If ``DefaultPosition`` is specified then a default position is chosen.
|
||||
:param `pos`: Window position. If ``DefaultPosition`` is specified then a default position is chosen.
|
||||
:type `pos`: wx.Point
|
||||
:param `size`: Window size. If ``DefaultSize`` is specified then the window is sized appropriately.
|
||||
:param `size`: Window size. If ``DefaultSize`` is specified then the window is sized appropriately.
|
||||
:type `size`: wx.Size
|
||||
:param `style`: Window style. See :ref:`wx.ListCtrl`.
|
||||
:type `style`: long
|
||||
@@ -398,36 +398,36 @@ class LanguageListCtrl(wx.ListCtrl):
|
||||
"""
|
||||
|
||||
wx.ListCtrl.__init__(self, parent, id, pos, size, style, name=name)
|
||||
|
||||
|
||||
self.SetUpFilter(filter, only)
|
||||
self.Language = select
|
||||
|
||||
def SetUpFilter(self, filter=LC_AVAILABLE, only=()):
|
||||
"""
|
||||
Filters the languages displayed in the control.
|
||||
|
||||
|
||||
|
||||
|
||||
:param `filter`: Filter the list of languages (LC_AVAILABLE, LC_ALL or LC_ONLY)
|
||||
:param `only`: a tuple of language ids
|
||||
"""
|
||||
lang = self.GetLanguage()
|
||||
|
||||
|
||||
self.filter, self.only = filter, only
|
||||
self.icons, self.choices, self.langs = CreateLanguagesResourceLists(filter, only)
|
||||
|
||||
|
||||
self.AssignImageList(self.icons, wx.IMAGE_LIST_SMALL)
|
||||
|
||||
|
||||
self.ClearAll()
|
||||
self.InsertColumn(0, '', width=175)
|
||||
for i in range(len(self.choices)):
|
||||
self.InsertItem(i, self.choices[i], i)
|
||||
|
||||
|
||||
self.SetLanguage(lang)
|
||||
|
||||
def GetLanguage(self):
|
||||
"""
|
||||
Get the currently selected language in the control.
|
||||
|
||||
|
||||
:returns: The currently selected language
|
||||
"""
|
||||
idx = self.GetFirstSelected()
|
||||
@@ -435,11 +435,11 @@ class LanguageListCtrl(wx.ListCtrl):
|
||||
return self.langs[idx]
|
||||
else:
|
||||
None
|
||||
|
||||
|
||||
def SetLanguage(self, lang):
|
||||
"""
|
||||
Selects the given language ids item in the control.
|
||||
|
||||
|
||||
:param `lang`: a 'wx.LANGUAGE_*' id
|
||||
"""
|
||||
if lang is not None:
|
||||
@@ -448,16 +448,16 @@ class LanguageListCtrl(wx.ListCtrl):
|
||||
self.Select(idx)
|
||||
self.Focus(idx)
|
||||
|
||||
Language = property(GetLanguage, SetLanguage, doc="See `GetLanguage` and `SetLanguage`")
|
||||
|
||||
Language = property(GetLanguage, SetLanguage, doc="See `GetLanguage` and `SetLanguage`")
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
a = wx.App()
|
||||
|
||||
|
||||
print(GetLanguageFlag(wx.LANGUAGE_AFRIKAANS))
|
||||
|
||||
|
||||
f=wx.Frame(None, -1)
|
||||
f.p=wx.Panel(f, -1)
|
||||
s=wx.BoxSizer(wx.VERTICAL)
|
||||
@@ -467,14 +467,14 @@ if __name__ == '__main__':
|
||||
s.Add(f.lc, 0, wx.GROW)
|
||||
except:
|
||||
pass
|
||||
f.llc=LanguageListCtrl(f.p, pos = (10, 10), size = (200, 200),
|
||||
filter=LC_ONLY,
|
||||
only=(wx.LANGUAGE_AFRIKAANS, wx.LANGUAGE_ENGLISH,
|
||||
wx.LANGUAGE_FRENCH, wx.LANGUAGE_GERMAN, wx.LANGUAGE_ITALIAN,
|
||||
wx.LANGUAGE_PORTUGUESE_BRAZILIAN, wx.LANGUAGE_SPANISH),
|
||||
f.llc=LanguageListCtrl(f.p, pos = (10, 10), size = (200, 200),
|
||||
filter=LC_ONLY,
|
||||
only=(wx.LANGUAGE_AFRIKAANS, wx.LANGUAGE_ENGLISH,
|
||||
wx.LANGUAGE_FRENCH, wx.LANGUAGE_GERMAN, wx.LANGUAGE_ITALIAN,
|
||||
wx.LANGUAGE_PORTUGUESE_BRAZILIAN, wx.LANGUAGE_SPANISH),
|
||||
select=wx.LANGUAGE_ENGLISH)
|
||||
## filter=LC_ALL)
|
||||
s.Add(f.llc, 1, wx.GROW)
|
||||
f.Show()
|
||||
|
||||
|
||||
a.MainLoop()
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
# 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o Updated for wx namespace
|
||||
#
|
||||
#
|
||||
# 12/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
||||
#
|
||||
# o wxScrolledMessageDialog -> ScrolledMessageDialog
|
||||
#
|
||||
# Tags:
|
||||
#
|
||||
# Tags:
|
||||
|
||||
import re
|
||||
import wx
|
||||
@@ -178,10 +178,10 @@ class Layoutf(wx.LayoutConstraints):
|
||||
attr = getattr(self, self.attr_d[g[0]])
|
||||
func = getattr(attr, self.op_d[g[1]])
|
||||
if g[1] == '!':
|
||||
print("%s.%s.%s(%s)" %
|
||||
print("%s.%s.%s(%s)" %
|
||||
('self',self.attr_d[g[0]],self.op_d[g[1]],g[2]))
|
||||
else:
|
||||
print("%s.%s.%s()" %
|
||||
print("%s.%s.%s()" %
|
||||
('self',self.attr_d[g[0]],self.op_d[g[1]]))
|
||||
continue
|
||||
m = self.rexp2.match(item)
|
||||
@@ -191,13 +191,13 @@ class Layoutf(wx.LayoutConstraints):
|
||||
else: g[3] = 0;
|
||||
g[4] = int(g[4]) - 1
|
||||
if g[1] in '<>^_':
|
||||
if g[3]: print("%s.%s.%s(%s,%d)" %
|
||||
if g[3]: print("%s.%s.%s(%s,%d)" %
|
||||
('self',self.attr_d[g[0]],self.op_d[g[1]],winlist[g[4]],
|
||||
g[3]))
|
||||
else: print("%s.%s.%s(%s)" % \
|
||||
('self',self.attr_d[g[0]],self.op_d[g[1]],winlist[g[4]]))
|
||||
else:
|
||||
if g[3]: print("%s.%s.%s(%s,%s,%d)" %
|
||||
if g[3]: print("%s.%s.%s(%s,%s,%d)" %
|
||||
('self',self.attr_d[g[0]],self.op_d[g[1]],winlist[g[4]],
|
||||
self.cmp_d[g[2]],g[3]))
|
||||
else: print("%s.%s.%s(%s,%s)" % \
|
||||
|
||||
@@ -28,7 +28,7 @@ class MessagePanel(wx.Panel):
|
||||
if flags:
|
||||
artid = None
|
||||
if flags & wx.ICON_EXCLAMATION:
|
||||
artid = wx.ART_WARNING
|
||||
artid = wx.ART_WARNING
|
||||
elif flags & wx.ICON_ERROR:
|
||||
artid = wx.ART_ERROR
|
||||
elif flags & wx.ICON_QUESTION:
|
||||
@@ -55,7 +55,7 @@ class MessagePanel(wx.Panel):
|
||||
tbox.Add(caption)
|
||||
tbox.Add((10,10))
|
||||
tbox.Add(message)
|
||||
|
||||
|
||||
hbox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
hbox.Add((10,10), 1)
|
||||
hbox.Add(icon)
|
||||
@@ -71,7 +71,7 @@ class MessagePanel(wx.Panel):
|
||||
self.SetSizer(box)
|
||||
self.Fit()
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -92,4 +92,4 @@ This is only a test...""")
|
||||
frm.Fit()
|
||||
frm.Show()
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ Sample usage::
|
||||
|
||||
def on_cmd2(self, e):
|
||||
self.show("goo = %s" % e.goo, "Got Goo (cmd2)")
|
||||
|
||||
|
||||
|
||||
app = wx.App(0)
|
||||
f = Frame()
|
||||
@@ -114,13 +114,13 @@ def NewEvent():
|
||||
Generates a new `(event, binder)` tuple.
|
||||
|
||||
::
|
||||
|
||||
|
||||
MooEvent, EVT_MOO = NewEvent()
|
||||
|
||||
|
||||
"""
|
||||
|
||||
evttype = wx.NewEventType()
|
||||
|
||||
|
||||
class _Event(wx.PyEvent):
|
||||
def __init__(self, **kw):
|
||||
wx.PyEvent.__init__(self)
|
||||
@@ -135,9 +135,9 @@ def NewCommandEvent():
|
||||
Generates a new `(command_event, binder)` tuple.
|
||||
|
||||
::
|
||||
|
||||
|
||||
MooCmdEvent, EVT_MOO = NewCommandEvent()
|
||||
|
||||
|
||||
"""
|
||||
|
||||
evttype = wx.NewEventType()
|
||||
@@ -146,7 +146,7 @@ def NewCommandEvent():
|
||||
def __init__(self, id, **kw):
|
||||
wx.PyCommandEvent.__init__(self, evttype, id)
|
||||
self._getAttrDict().update(kw)
|
||||
|
||||
|
||||
return _Event, wx.PyEventBinder(evttype, 1)
|
||||
|
||||
|
||||
@@ -218,7 +218,7 @@ def _test():
|
||||
|
||||
def on_cmd2(self, e):
|
||||
self.show("goo = %s" % e.goo, "Got Goo (cmd2)")
|
||||
|
||||
|
||||
|
||||
app = wx.App(0)
|
||||
f = Frame()
|
||||
|
||||
@@ -26,8 +26,8 @@ import wx
|
||||
|
||||
MARGIN = 4
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class SimpleNameValueDialog(wx.Dialog):
|
||||
def __init__(self, parent, id=-1, title="", pos=wx.DefaultPosition,
|
||||
size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE,
|
||||
@@ -39,7 +39,7 @@ class SimpleNameValueDialog(wx.Dialog):
|
||||
self.Sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self._contentSizer = wx.FlexGridSizer(cols=2, hgap=MARGIN, vgap=MARGIN)
|
||||
self._contentSizer.AddGrowableCol(1)
|
||||
|
||||
|
||||
if captionTitle:
|
||||
titleTxt = wx.StaticText(self, -1, captionTitle)
|
||||
titleTxt.SetFont(wx.FFont(18, wx.FONTFAMILY_SWISS, wx.FONTFLAG_BOLD))
|
||||
@@ -49,13 +49,13 @@ class SimpleNameValueDialog(wx.Dialog):
|
||||
self.Sizer.Add(descTxt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, MARGIN)
|
||||
if captionTitle or captionDescr:
|
||||
self.Sizer.Add(wx.StaticLine(self), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, MARGIN)
|
||||
|
||||
|
||||
self.createFields(fields)
|
||||
self.loadValues(initialValues)
|
||||
|
||||
|
||||
self.Sizer.Add(self._contentSizer, 1, wx.EXPAND|wx.ALL, MARGIN)
|
||||
self.Sizer.Add(wx.StaticLine(self), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, MARGIN)
|
||||
|
||||
|
||||
# TODO: add ability to specify which stock or custom buttons are used
|
||||
btnSizer = wx.StdDialogButtonSizer()
|
||||
btnSizer.AddButton(wx.Button(self, wx.ID_OK))
|
||||
@@ -65,8 +65,8 @@ class SimpleNameValueDialog(wx.Dialog):
|
||||
self.FindWindowById(wx.ID_OK).SetDefault()
|
||||
|
||||
self.Fit()
|
||||
|
||||
|
||||
|
||||
|
||||
def createFields(self, fields):
|
||||
self.destroyFields()
|
||||
for name, label, args in fields:
|
||||
@@ -75,33 +75,33 @@ class SimpleNameValueDialog(wx.Dialog):
|
||||
kwargs.update(args)
|
||||
stxt = wx.StaticText(self, -1, label)
|
||||
txt = wx.TextCtrl(self, **kwargs)
|
||||
|
||||
|
||||
self._contentSizer.Add(stxt, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT)
|
||||
self._contentSizer.Add(txt, 0, wx.EXPAND)
|
||||
|
||||
|
||||
self.__dict__[name] = ""
|
||||
self._fields[name] = (stxt, txt)
|
||||
|
||||
|
||||
|
||||
|
||||
def destroyFields(self):
|
||||
for name, widgets in self._fields.iteritems():
|
||||
for w in widgets:
|
||||
w.Destroy()
|
||||
del self.__dict__[name]
|
||||
|
||||
|
||||
|
||||
|
||||
def loadValues(self, values):
|
||||
self.clearValues()
|
||||
for name, value in values.iteritems():
|
||||
if name in self._fields.keys():
|
||||
setattr(self, name, value)
|
||||
|
||||
|
||||
def clearValues(self):
|
||||
for name in self._fields.keys():
|
||||
setattr(self, name, "")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class _TransferValidator(wx.PyValidator):
|
||||
"""
|
||||
This validator is used to transfer values to/from the widgets and
|
||||
@@ -113,17 +113,17 @@ class _TransferValidator(wx.PyValidator):
|
||||
|
||||
def Clone(self):
|
||||
return _TransferValidator(self.name)
|
||||
|
||||
|
||||
|
||||
|
||||
def Validate(self, win):
|
||||
return True
|
||||
|
||||
|
||||
def TransferFromWindow(self):
|
||||
dlg = self.Window.Parent
|
||||
value = dlg._fields[self.name][1].GetValue()
|
||||
setattr(dlg, self.name, value)
|
||||
return True
|
||||
|
||||
|
||||
def TransferToWindow(self):
|
||||
dlg = self.Window.Parent
|
||||
value = getattr(dlg, self.name)
|
||||
@@ -131,19 +131,19 @@ class _TransferValidator(wx.PyValidator):
|
||||
return True
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from wx.lib.mixins.inspection import InspectableApp
|
||||
app = InspectableApp(redirect=False)
|
||||
#app = wx.App(redirect=False)
|
||||
|
||||
|
||||
fields = [ ('username', 'Login ID:', None),
|
||||
('passwd', 'Password:', dict(size=(150,-1), style=wx.TE_PASSWORD)),
|
||||
]
|
||||
|
||||
dlg = SimpleNameValueDialog(None, title="This is the title",
|
||||
fields=fields,
|
||||
|
||||
dlg = SimpleNameValueDialog(None, title="This is the title",
|
||||
fields=fields,
|
||||
initialValues=dict(username='rdunn'),
|
||||
captionTitle="Login",
|
||||
captionDescr="Enter your testing credentials")
|
||||
@@ -151,5 +151,5 @@ if __name__ == '__main__':
|
||||
print(dlg.username, dlg.passwd)
|
||||
dlg.Destroy()
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ def get_acroversion():
|
||||
return _min_adobe_version
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
if wx.PlatformInfo[1] == 'wxMSW':
|
||||
import wx.lib.activex
|
||||
import comtypes.client as cc
|
||||
@@ -40,7 +40,7 @@ if wx.PlatformInfo[1] == 'wxMSW':
|
||||
_min_adobe_version = 5.0
|
||||
except:
|
||||
pass # Adobe Reader not installed (progID is not defined)
|
||||
# Use get_min_adobe_version() before instantiating PDFWindow
|
||||
# Use get_min_adobe_version() before instantiating PDFWindow
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
@@ -54,7 +54,7 @@ if wx.PlatformInfo[1] == 'wxMSW':
|
||||
def OnDestroyWindow(self, event):
|
||||
wx.CallAfter(self.FreeDlls)
|
||||
|
||||
def FreeDlls(self):
|
||||
def FreeDlls(self):
|
||||
"""
|
||||
Unloads any DLLs that are no longer in use when all COM object instances are
|
||||
released. This prevents the error 'The instruction at "0x0700609c" referenced
|
||||
@@ -85,37 +85,37 @@ if wx.PlatformInfo[1] == 'wxMSW':
|
||||
Goes to the previous view on the view stack, if it exists.
|
||||
"""
|
||||
return self.ctrl.goBackwardStack()
|
||||
|
||||
|
||||
def goForwardStack(self):
|
||||
"""
|
||||
Goes to the next view on the view stack, if it exists.
|
||||
"""
|
||||
return self.ctrl.goForwardStack()
|
||||
|
||||
|
||||
def gotoFirstPage(self):
|
||||
"""
|
||||
Goes to the first page in the document.
|
||||
"""
|
||||
return self.ctrl.gotoFirstPage()
|
||||
|
||||
|
||||
def gotoLastPage(self):
|
||||
"""
|
||||
Goes to the last page in the document.
|
||||
"""
|
||||
return self.ctrl.gotoLastPage()
|
||||
|
||||
|
||||
def gotoNextPage(self):
|
||||
"""
|
||||
Goes to the next page in the document, if it exists
|
||||
"""
|
||||
return self.ctrl.gotoNextPage()
|
||||
|
||||
|
||||
def gotoPreviousPage(self):
|
||||
"""
|
||||
Goes to the previous page in the document, if it exists.
|
||||
"""
|
||||
return self.ctrl.gotoPreviousPage()
|
||||
|
||||
|
||||
def printAll(self):
|
||||
"""
|
||||
Prints the entire document without displaying a user
|
||||
@@ -124,7 +124,7 @@ if wx.PlatformInfo[1] == 'wxMSW':
|
||||
if the printing has not completed.
|
||||
"""
|
||||
return self.ctrl.printAll()
|
||||
|
||||
|
||||
def printAllFit(self, shrinkToFit):
|
||||
"""
|
||||
Prints the entire document without a user dialog box, and
|
||||
@@ -132,13 +132,13 @@ if wx.PlatformInfo[1] == 'wxMSW':
|
||||
imageable area of a page in the printer.
|
||||
"""
|
||||
return self.ctrl.printAllFit(shrinkToFit)
|
||||
|
||||
|
||||
def printPages(self, from_, to):
|
||||
"""
|
||||
Prints the specified pages without displaying a user dialog box.
|
||||
"""
|
||||
return self.ctrl.printPages(from_, to)
|
||||
|
||||
|
||||
def printPagesFit(self, from_, to, shrinkToFit):
|
||||
"""
|
||||
Prints the specified pages without displaying a user
|
||||
@@ -146,7 +146,7 @@ if wx.PlatformInfo[1] == 'wxMSW':
|
||||
to fit the imageable area of a page in the printer.
|
||||
"""
|
||||
return self.ctrl.printPagesFit( from_, to, shrinkToFit)
|
||||
|
||||
|
||||
def printWithDialog(self):
|
||||
"""
|
||||
Prints the document according to the specified options in
|
||||
@@ -154,13 +154,13 @@ if wx.PlatformInfo[1] == 'wxMSW':
|
||||
printing and specifying which printer is to be used.
|
||||
|
||||
NB. The page range in the dialog defaults to
|
||||
'From Page 1 to 1' - Use Print() above instead. (dfh)
|
||||
'From Page 1 to 1' - Use Print() above instead. (dfh)
|
||||
"""
|
||||
return self.ctrl.printWithDialog()
|
||||
|
||||
|
||||
def setCurrentHighlight(self, a, b, c, d):
|
||||
return self.ctrl.setCurrentHighlight(a, b, c, d)
|
||||
|
||||
|
||||
def setCurrentPage(self, npage):
|
||||
"""
|
||||
Goes to the specified page in the document. Maintains the
|
||||
@@ -171,7 +171,7 @@ if wx.PlatformInfo[1] == 'wxMSW':
|
||||
## Oh no it isn't! The first page is 1 (dfh)
|
||||
"""
|
||||
return self.ctrl.setCurrentPage(npage)
|
||||
|
||||
|
||||
def setLayoutMode(self, layoutMode):
|
||||
"""
|
||||
LayoutMode possible values:
|
||||
@@ -185,13 +185,13 @@ if wx.PlatformInfo[1] == 'wxMSW':
|
||||
================= ====================================
|
||||
"""
|
||||
return self.ctrl.setLayoutMode(layoutMode)
|
||||
|
||||
|
||||
def setNamedDest(self, namedDest):
|
||||
"""
|
||||
Changes the page view to the named destination in the specified string.
|
||||
"""
|
||||
return self.ctrl.setNamedDest(namedDest)
|
||||
|
||||
|
||||
def setPageMode(self, pageMode):
|
||||
"""
|
||||
Sets the page mode to display the document only, or to
|
||||
@@ -199,9 +199,9 @@ if wx.PlatformInfo[1] == 'wxMSW':
|
||||
'none' or 'bookmarks' or 'thumbs'.
|
||||
|
||||
## NB.'thumbs' is case-sensitive, the other are not (dfh)
|
||||
"""
|
||||
"""
|
||||
return self.ctrl.setPageMode(pageMode)
|
||||
|
||||
|
||||
def setShowScrollbars(self, On):
|
||||
"""
|
||||
Determines whether scrollbars will appear in the document
|
||||
@@ -210,13 +210,13 @@ if wx.PlatformInfo[1] == 'wxMSW':
|
||||
## NB. If scrollbars are off, the navigation tools disappear as well (dfh)
|
||||
"""
|
||||
return self.ctrl.setShowScrollbars(On)
|
||||
|
||||
|
||||
def setShowToolbar(self, On):
|
||||
"""
|
||||
Determines whether a toolbar will appear in the application.
|
||||
"""
|
||||
return self.ctrl.setShowToolbar(On)
|
||||
|
||||
|
||||
def setView(self, viewMode):
|
||||
"""
|
||||
Determines how the page will fit in the current view.
|
||||
@@ -232,7 +232,7 @@ if wx.PlatformInfo[1] == 'wxMSW':
|
||||
======== ==============================================
|
||||
"""
|
||||
return self.ctrl.setView(viewMode)
|
||||
|
||||
|
||||
def setViewRect(self, left, top, width, height):
|
||||
"""
|
||||
Sets the view rectangle according to the specified coordinates.
|
||||
@@ -243,7 +243,7 @@ if wx.PlatformInfo[1] == 'wxMSW':
|
||||
:param height: The vertical height of the rectangle.
|
||||
"""
|
||||
return self.ctrl.setViewRect(left, top, width, height)
|
||||
|
||||
|
||||
def setViewScroll(self, viewMode, offset):
|
||||
"""
|
||||
Sets the view of a page according to the specified string.
|
||||
@@ -252,16 +252,16 @@ if wx.PlatformInfo[1] == 'wxMSW':
|
||||
offset. Possible values of viewMode are as in setView
|
||||
above. offset is the horizontal or vertical coordinate
|
||||
positioned either at the left or top edge.
|
||||
"""
|
||||
"""
|
||||
return self.ctrl.setViewScroll(viewMode, offset)
|
||||
|
||||
|
||||
def setZoom(self, percent):
|
||||
"""
|
||||
Sets the magnification according to the specified value
|
||||
expressed as a percentage (float)
|
||||
"""
|
||||
return self.ctrl.setZoom(percent)
|
||||
|
||||
|
||||
def setZoomScroll(self, percent, left, top):
|
||||
"""
|
||||
Sets the magnification according to the specified value,
|
||||
@@ -282,14 +282,14 @@ if wx.PlatformInfo[1] == 'wxMSW':
|
||||
if __name__ == '__main__':
|
||||
app = wx.App(False)
|
||||
frm = wx.Frame(None, title="AX Test Window")
|
||||
|
||||
|
||||
pdf = PDFWindow(frm)
|
||||
|
||||
|
||||
frm.Show()
|
||||
import wx.lib.inspection
|
||||
wx.lib.inspection.InspectionTool().Show()
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ def get_acroversion():
|
||||
except WindowsError:
|
||||
regKey = _winreg.HKEY_CURRENT_USER
|
||||
adobesoft = _winreg.OpenKey(regKey, r'Software\Adobe')
|
||||
|
||||
|
||||
for index in range(_winreg.QueryInfoKey(adobesoft)[0]):
|
||||
key = _winreg.EnumKey(adobesoft, index)
|
||||
if "acrobat" in key.lower():
|
||||
@@ -44,7 +44,7 @@ def get_acroversion():
|
||||
if acroversions:
|
||||
_acroversion = acroversions[0]
|
||||
return _acroversion
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
@@ -74,12 +74,12 @@ if get_acroversion() >= 7.0:
|
||||
class PDFWindowError(RuntimeError):
|
||||
def __init__(self):
|
||||
RuntimeError.__init__(self, "A PDF must be loaded before calling this method.")
|
||||
|
||||
|
||||
|
||||
class PDFWindow(wx.Panel):
|
||||
def __init__(self, *args, **kw):
|
||||
wx.Panel.__init__(self, *args, **kw)
|
||||
|
||||
|
||||
# Make a new class that derives from the WebBrowser class
|
||||
# in the COM module imported above. This class also
|
||||
# derives from wxWindow and implements the machinery
|
||||
@@ -90,7 +90,7 @@ if get_acroversion() >= 7.0:
|
||||
sizer.Add(self.ie, 1, wx.EXPAND)
|
||||
self.SetSizer(sizer)
|
||||
|
||||
|
||||
|
||||
def LoadFile(self, fileName):
|
||||
"""
|
||||
Opens and displays the specified document within the browser.
|
||||
@@ -100,7 +100,7 @@ if get_acroversion() >= 7.0:
|
||||
else:
|
||||
self.ie.Navigate2(fileName)
|
||||
return True # can we sense failure at this point?
|
||||
|
||||
|
||||
def GetVersions(self):
|
||||
"""
|
||||
Deprecated: No longer available - do not use.
|
||||
@@ -109,7 +109,7 @@ if get_acroversion() >= 7.0:
|
||||
return self.ie.Document.GetVersions()
|
||||
else:
|
||||
raise PDFWindowError()
|
||||
|
||||
|
||||
def Print(self):
|
||||
"""
|
||||
Prints the document according to the specified options in a user dialog box.
|
||||
@@ -118,7 +118,7 @@ if get_acroversion() >= 7.0:
|
||||
return self.ie.Document.Print()
|
||||
else:
|
||||
raise PDFWindowError()
|
||||
|
||||
|
||||
def goBackwardStack(self):
|
||||
"""
|
||||
Goes to the previous view on the view stack, if it exists.
|
||||
@@ -221,9 +221,9 @@ if get_acroversion() >= 7.0:
|
||||
Prints the document according to the specified options in
|
||||
a user dialog box. These options may include embedded
|
||||
printing and specifying which printer is to be used.
|
||||
|
||||
|
||||
NB. The page range in the dialog defaults to
|
||||
'From Page 1 to 1' - Use Print() above instead. (dfh)
|
||||
'From Page 1 to 1' - Use Print() above instead. (dfh)
|
||||
"""
|
||||
if self.ie.Document:
|
||||
return self.ie.Document.printWithDialog()
|
||||
@@ -242,7 +242,7 @@ if get_acroversion() >= 7.0:
|
||||
current location within the page and zoom level. npage is
|
||||
the page number of the destination page. The first page
|
||||
in a document is page 0.
|
||||
|
||||
|
||||
## Oh no it isn't! The first page is 1 (dfh)
|
||||
"""
|
||||
if self.ie.Document:
|
||||
@@ -253,7 +253,7 @@ if get_acroversion() >= 7.0:
|
||||
def setLayoutMode(self, layoutMode):
|
||||
"""
|
||||
LayoutMode possible values:
|
||||
|
||||
|
||||
================= ====================================
|
||||
'DontCare' use the current user preference
|
||||
'SinglePage' use single page mode (as in pre-Acrobat
|
||||
@@ -284,9 +284,9 @@ if get_acroversion() >= 7.0:
|
||||
Sets the page mode to display the document only, or to
|
||||
additionally display bookmarks or thumbnails. pageMode =
|
||||
'none' or 'bookmarks' or 'thumbs'.
|
||||
|
||||
|
||||
## NB.'thumbs' is case-sensitive, the other are not (dfh)
|
||||
"""
|
||||
"""
|
||||
if self.ie.Document:
|
||||
return self.ie.Document.setPageMode(pageMode)
|
||||
else:
|
||||
@@ -356,7 +356,7 @@ if get_acroversion() >= 7.0:
|
||||
offset. Possible values of viewMode are as in setView
|
||||
above. offset is the horizontal or vertical coordinate
|
||||
positioned either at the left or top edge.
|
||||
"""
|
||||
"""
|
||||
if self.ie.Document:
|
||||
return self.ie.Document.setViewScroll(viewMode, offset)
|
||||
else:
|
||||
@@ -377,7 +377,7 @@ if get_acroversion() >= 7.0:
|
||||
Sets the magnification according to the specified value,
|
||||
and scrolls the page view both horizontally and vertically
|
||||
according to the specified amounts.
|
||||
|
||||
|
||||
:param left: the horizontal coordinate positioned at the left edge.
|
||||
:param top: the vertical coordinate positioned at the top edge.
|
||||
"""
|
||||
@@ -386,7 +386,7 @@ if get_acroversion() >= 7.0:
|
||||
else:
|
||||
raise PDFWindowError()
|
||||
|
||||
|
||||
|
||||
|
||||
elif get_acroversion() is not None:
|
||||
import wx.activex
|
||||
@@ -532,13 +532,13 @@ elif get_acroversion() is not None:
|
||||
# --------------------
|
||||
# src
|
||||
# type:string arg:string canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
# messagehandler
|
||||
# type:VT_VARIANT arg:VT_VARIANT canGet:True canSet:True
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# METHODS
|
||||
# --------------------
|
||||
# QueryInterface
|
||||
@@ -548,19 +548,19 @@ elif get_acroversion() is not None:
|
||||
# in:True out:False optional:False type:unsupported type 29
|
||||
# ppvObj
|
||||
# in:False out:True optional:False type:unsupported type 26
|
||||
#
|
||||
#
|
||||
# AddRef
|
||||
# retType: int
|
||||
#
|
||||
#
|
||||
# Release
|
||||
# retType: int
|
||||
#
|
||||
#
|
||||
# GetTypeInfoCount
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# pctinfo
|
||||
# in:False out:True optional:False type:int
|
||||
#
|
||||
#
|
||||
# GetTypeInfo
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -570,7 +570,7 @@ elif get_acroversion() is not None:
|
||||
# in:True out:False optional:False type:int
|
||||
# pptinfo
|
||||
# in:False out:True optional:False type:unsupported type 26
|
||||
#
|
||||
#
|
||||
# GetIDsOfNames
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -584,7 +584,7 @@ elif get_acroversion() is not None:
|
||||
# in:True out:False optional:False type:int
|
||||
# rgdispid
|
||||
# in:False out:True optional:False type:int
|
||||
#
|
||||
#
|
||||
# Invoke
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -604,73 +604,73 @@ elif get_acroversion() is not None:
|
||||
# in:False out:True optional:False type:unsupported type 29
|
||||
# puArgErr
|
||||
# in:False out:True optional:False type:int
|
||||
#
|
||||
#
|
||||
# LoadFile
|
||||
# retType: bool
|
||||
# params:
|
||||
# fileName
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# setShowToolbar
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# On
|
||||
# in:True out:False optional:False type:bool
|
||||
#
|
||||
#
|
||||
# gotoFirstPage
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# gotoLastPage
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# gotoNextPage
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# gotoPreviousPage
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# setCurrentPage
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# n
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# goForwardStack
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# goBackwardStack
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# setPageMode
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# pageMode
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# setLayoutMode
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# layoutMode
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# setNamedDest
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# namedDest
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# Print
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# printWithDialog
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# setZoom
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# percent
|
||||
# in:True out:False optional:False type:double
|
||||
#
|
||||
#
|
||||
# setZoomScroll
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -680,13 +680,13 @@ elif get_acroversion() is not None:
|
||||
# in:True out:False optional:False type:double
|
||||
# top
|
||||
# in:True out:False optional:False type:double
|
||||
#
|
||||
#
|
||||
# setView
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# viewMode
|
||||
# in:True out:False optional:False type:string
|
||||
#
|
||||
#
|
||||
# setViewScroll
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -694,7 +694,7 @@ elif get_acroversion() is not None:
|
||||
# in:True out:False optional:False type:string
|
||||
# offset
|
||||
# in:True out:False optional:False type:double
|
||||
#
|
||||
#
|
||||
# setViewRect
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -706,7 +706,7 @@ elif get_acroversion() is not None:
|
||||
# in:True out:False optional:False type:double
|
||||
# height
|
||||
# in:True out:False optional:False type:double
|
||||
#
|
||||
#
|
||||
# printPages
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -714,7 +714,7 @@ elif get_acroversion() is not None:
|
||||
# in:True out:False optional:False type:int
|
||||
# to
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# printPagesFit
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -724,25 +724,25 @@ elif get_acroversion() is not None:
|
||||
# in:True out:False optional:False type:int
|
||||
# shrinkToFit
|
||||
# in:True out:False optional:False type:bool
|
||||
#
|
||||
#
|
||||
# printAll
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# printAllFit
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# shrinkToFit
|
||||
# in:True out:False optional:False type:bool
|
||||
#
|
||||
#
|
||||
# setShowScrollbars
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# On
|
||||
# in:True out:False optional:False type:bool
|
||||
#
|
||||
#
|
||||
# GetVersions
|
||||
# retType: VT_VARIANT
|
||||
#
|
||||
#
|
||||
# setCurrentHightlight
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -754,7 +754,7 @@ elif get_acroversion() is not None:
|
||||
# in:True out:False optional:False type:int
|
||||
# d
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# setCurrentHighlight
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
@@ -766,24 +766,24 @@ elif get_acroversion() is not None:
|
||||
# in:True out:False optional:False type:int
|
||||
# d
|
||||
# in:True out:False optional:False type:int
|
||||
#
|
||||
#
|
||||
# postMessage
|
||||
# retType: VT_VOID
|
||||
# params:
|
||||
# strArray
|
||||
# in:True out:False optional:False type:VT_VARIANT
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
# EVENTS
|
||||
# --------------------
|
||||
# Error
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
# Message
|
||||
# retType: VT_VOID
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
Editra Control Library: PlateButton
|
||||
|
||||
The PlateButton is a custom owner drawn flat button, that in many ways emulates
|
||||
the buttons found the bookmark bar of the Safari browser. It can be used as a
|
||||
drop in replacement for wx.Button/wx.BitmapButton under most circumstances. It
|
||||
also offers a wide range of options for customizing its appearance, a
|
||||
the buttons found the bookmark bar of the Safari browser. It can be used as a
|
||||
drop in replacement for wx.Button/wx.BitmapButton under most circumstances. It
|
||||
also offers a wide range of options for customizing its appearance, a
|
||||
description of each of the main style settings is listed below.
|
||||
|
||||
Main Button Styles:
|
||||
@@ -76,7 +76,7 @@ Requirements:
|
||||
__author__ = "Cody Precord <cprecord@editra.org>"
|
||||
|
||||
__all__ = ["PlateButton",
|
||||
"PLATE_NORMAL", "PLATE_PRESSED", "PLATE_HIGHLIGHT",
|
||||
"PLATE_NORMAL", "PLATE_PRESSED", "PLATE_HIGHLIGHT",
|
||||
|
||||
"PB_STYLE_DEFAULT", "PB_STYLE_GRADIENT", "PB_STYLE_SQUARE",
|
||||
"PB_STYLE_NOBG", "PB_STYLE_DROPARROW", "PB_STYLE_TOGGLE",
|
||||
@@ -119,11 +119,11 @@ class PlateButton(wx.Control):
|
||||
displaying bitmaps and having an attached dropdown menu.
|
||||
|
||||
"""
|
||||
def __init__(self, parent, id=wx.ID_ANY, label='', bmp=None,
|
||||
def __init__(self, parent, id=wx.ID_ANY, label='', bmp=None,
|
||||
pos=wx.DefaultPosition, size=wx.DefaultSize,
|
||||
style=PB_STYLE_DEFAULT, name=wx.ButtonNameStr):
|
||||
"""Create a PlateButton
|
||||
|
||||
|
||||
:keyword string `label`: Buttons label text
|
||||
:keyword wx.Bitmap `bmp`: Buttons bitmap
|
||||
:keyword `style`: Button style
|
||||
@@ -336,7 +336,7 @@ class PlateButton(wx.Control):
|
||||
color = GetHighlightColour()
|
||||
pcolor = AdjustColour(color, -12)
|
||||
colors = dict(default=True,
|
||||
hlight=color,
|
||||
hlight=color,
|
||||
press=pcolor,
|
||||
htxt=BestLabelColour(self.GetForegroundColour()))
|
||||
return colors
|
||||
@@ -345,7 +345,7 @@ class PlateButton(wx.Control):
|
||||
def __LeaveWindow(self):
|
||||
"""Handle updating the buttons state when the mouse cursor leaves"""
|
||||
if (self._style & PB_STYLE_TOGGLE) and self._pressed:
|
||||
self._SetState(PLATE_PRESSED)
|
||||
self._SetState(PLATE_PRESSED)
|
||||
else:
|
||||
self._SetState(PLATE_NORMAL)
|
||||
self._pressed = False
|
||||
@@ -358,7 +358,7 @@ class PlateButton(wx.Control):
|
||||
|
||||
.. note::
|
||||
the state may be altered by mouse actions
|
||||
|
||||
|
||||
.. note::
|
||||
Internal use only!
|
||||
|
||||
@@ -373,7 +373,7 @@ class PlateButton(wx.Control):
|
||||
|
||||
def _ToggleState(self):
|
||||
"""Toggle button state
|
||||
|
||||
|
||||
..note::
|
||||
Internal Use Only!
|
||||
|
||||
@@ -414,7 +414,7 @@ class PlateButton(wx.Control):
|
||||
|
||||
def DoGetBestSize(self):
|
||||
"""Calculate the best size of the button
|
||||
|
||||
|
||||
:return: :class:`wx.Size`
|
||||
|
||||
"""
|
||||
@@ -427,7 +427,7 @@ class PlateButton(wx.Control):
|
||||
lsize = self.GetFullTextExtent(self.Label)
|
||||
width += lsize[0]
|
||||
height += lsize[1]
|
||||
|
||||
|
||||
if self._bmp['enable'] is not None:
|
||||
bsize = self._bmp['enable'].Size
|
||||
width += (bsize[0] + 10)
|
||||
@@ -454,9 +454,9 @@ class PlateButton(wx.Control):
|
||||
|
||||
def GetBackgroundBrush(self, dc):
|
||||
"""Get the brush for drawing the background of the button
|
||||
|
||||
|
||||
:return: :class:`wx.Brush`
|
||||
|
||||
|
||||
..note::
|
||||
used internally when on gtk
|
||||
|
||||
@@ -487,7 +487,7 @@ class PlateButton(wx.Control):
|
||||
|
||||
def GetBitmapLabel(self):
|
||||
"""Get the label bitmap
|
||||
|
||||
|
||||
:return: :class:`wx.Bitmap` or None
|
||||
|
||||
"""
|
||||
@@ -496,7 +496,7 @@ class PlateButton(wx.Control):
|
||||
# GetBitmap Aliases for BitmapButton api
|
||||
GetBitmapFocus = GetBitmapLabel
|
||||
GetBitmapHover = GetBitmapLabel
|
||||
|
||||
|
||||
# Alias for GetLabel
|
||||
GetLabelText = wx.Control.GetLabel
|
||||
|
||||
@@ -511,9 +511,9 @@ class PlateButton(wx.Control):
|
||||
|
||||
def GetState(self):
|
||||
"""Get the current state of the button
|
||||
|
||||
|
||||
:return: int
|
||||
|
||||
|
||||
.. seeAlso::
|
||||
PLATE_NORMAL, PLATE_HIGHLIGHT, PLATE_PRESSED
|
||||
|
||||
@@ -528,7 +528,7 @@ class PlateButton(wx.Control):
|
||||
|
||||
def IsPressed(self):
|
||||
"""Return if button is pressed (PB_STYLE_TOGGLE)
|
||||
|
||||
|
||||
:return: bool
|
||||
|
||||
"""
|
||||
@@ -540,7 +540,7 @@ class PlateButton(wx.Control):
|
||||
def OnErase(self, evt):
|
||||
"""Trap the erase event to keep the background transparent
|
||||
on windows.
|
||||
|
||||
|
||||
:param `evt`: wx.EVT_ERASE_BACKGROUND
|
||||
|
||||
"""
|
||||
@@ -556,7 +556,7 @@ class PlateButton(wx.Control):
|
||||
def OnKeyUp(self, evt):
|
||||
"""Execute a single button press action when the Return key is pressed
|
||||
and this control has the focus.
|
||||
|
||||
|
||||
:param `evt`: wx.EVT_KEY_UP
|
||||
|
||||
"""
|
||||
@@ -598,7 +598,7 @@ class PlateButton(wx.Control):
|
||||
event = PlateBtnDropArrowPressed()
|
||||
event.SetEventObject(self)
|
||||
self.EventHandler.ProcessEvent(event)
|
||||
|
||||
|
||||
self.SetFocus()
|
||||
|
||||
|
||||
@@ -624,7 +624,7 @@ class PlateButton(wx.Control):
|
||||
def OnMenuClose(self, evt):
|
||||
"""Refresh the control to a proper state after the menu has been
|
||||
dismissed.
|
||||
|
||||
|
||||
:param `evt`: wx.EVT_MENU_CLOSE
|
||||
|
||||
"""
|
||||
@@ -640,7 +640,7 @@ class PlateButton(wx.Control):
|
||||
|
||||
def SetBitmap(self, bmp):
|
||||
"""Set the bitmap displayed in the button
|
||||
|
||||
|
||||
:param `bmp`: :class:`wx.Bitmap`
|
||||
|
||||
"""
|
||||
@@ -693,7 +693,7 @@ class PlateButton(wx.Control):
|
||||
"""Set the color of the label. The optimal label color is usually
|
||||
automatically selected depending on the button color. In some
|
||||
cases the colors that are chosen may not be optimal.
|
||||
|
||||
|
||||
The normal state must be specified, if the other two params are left
|
||||
Null they will be automatically guessed based on the normal color. To
|
||||
prevent this automatic color choices from happening either specify
|
||||
@@ -724,7 +724,7 @@ class PlateButton(wx.Control):
|
||||
drop arrow of the button.
|
||||
|
||||
:param wx.Menu `menu`: :class:`wx.Menu` to use as a PopupMenu
|
||||
|
||||
|
||||
.. note::
|
||||
Arrow is not drawn unless a menu is set
|
||||
|
||||
@@ -741,7 +741,7 @@ class PlateButton(wx.Control):
|
||||
"""Set the color used for highlighting the pressed state
|
||||
|
||||
:param wx.Colour `color`: :class:`wx.Colour`
|
||||
|
||||
|
||||
.. note::
|
||||
also resets all text colours as necessary
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#----------------------------------------------------------------------
|
||||
# Name: wx.lib.progressindicator
|
||||
# Purpose:
|
||||
# Purpose:
|
||||
#
|
||||
# Author: Robin Dunn
|
||||
#
|
||||
@@ -45,22 +45,22 @@ class ProgressIndicator(wx.Panel):
|
||||
size = kw['size']
|
||||
elif len(args) >= 4:
|
||||
size=args[3] # parent, id, pos, size, style, name
|
||||
|
||||
|
||||
self.SetInitialSize(size)
|
||||
|
||||
|
||||
if self.HasFlag(PI_PULSEMODE):
|
||||
self.timer = wx.Timer(self)
|
||||
self.Bind(wx.EVT_TIMER, self.onTimer)
|
||||
if self.HasFlag(PI_HIDEINACTIVE):
|
||||
self.Hide()
|
||||
|
||||
|
||||
|
||||
def __del__(self):
|
||||
if hasattr(self, 'timer'):
|
||||
self.timer.Stop()
|
||||
del self.timer
|
||||
|
||||
|
||||
|
||||
def Start(self, label=None):
|
||||
"""
|
||||
Show (if necessary) and begin displaying progress
|
||||
@@ -70,14 +70,14 @@ class ProgressIndicator(wx.Panel):
|
||||
self.SetLabel(label)
|
||||
if self.HasFlag(PI_HIDEINACTIVE):
|
||||
self.Show()
|
||||
self.Layout()
|
||||
self.Layout()
|
||||
if self.HasFlag(PI_PULSEMODE):
|
||||
self.gauge.Pulse()
|
||||
self.timer.Start(250)
|
||||
else:
|
||||
self.gauge.SetValue(0)
|
||||
|
||||
|
||||
|
||||
def Stop(self, clearLabel=False):
|
||||
"""
|
||||
Stop showing progress
|
||||
@@ -89,25 +89,25 @@ class ProgressIndicator(wx.Panel):
|
||||
self._startCount -= 1
|
||||
if self._startCount:
|
||||
return # there's still more starts than stops...
|
||||
|
||||
|
||||
if self.HasFlag(PI_HIDEINACTIVE):
|
||||
self.Hide()
|
||||
|
||||
|
||||
if self.HasFlag(PI_PULSEMODE):
|
||||
self.timer.Stop()
|
||||
|
||||
|
||||
if clearLabel:
|
||||
self.label.SetLabel("")
|
||||
|
||||
|
||||
|
||||
|
||||
def SetLabel(self, text):
|
||||
"""
|
||||
Set the text displayed in the label.
|
||||
"""
|
||||
self.label.SetLabel(text)
|
||||
self.Layout()
|
||||
|
||||
|
||||
|
||||
|
||||
def SetValue(self, value, label=None):
|
||||
"""
|
||||
For determinante mode (non-pulse) update the progress indicator to the
|
||||
@@ -118,15 +118,15 @@ class ProgressIndicator(wx.Panel):
|
||||
self.SetLabel(label)
|
||||
self.gauge.SetValue(value)
|
||||
|
||||
|
||||
|
||||
def SetRange(self, maxval):
|
||||
"""
|
||||
For determinante mode (non-pulse) set the max value that the gauge can
|
||||
be set to. Defaults to 100.
|
||||
"""
|
||||
self.gauge.SetRange(maxval)
|
||||
|
||||
|
||||
|
||||
|
||||
def onTimer(self, evt):
|
||||
self.gauge.Pulse()
|
||||
|
||||
@@ -139,13 +139,13 @@ if __name__ == '__main__':
|
||||
pnl = wx.Panel(frm)
|
||||
pi1 = ProgressIndicator(pnl, pos=(20,20), size=(150,-1),
|
||||
style=PI_HIDEINACTIVE|PI_PULSEMODE)
|
||||
|
||||
|
||||
pi2 = ProgressIndicator(pnl, pos=(20,60), size=(150,-1),
|
||||
style=PI_HIDEINACTIVE)
|
||||
|
||||
import wx.lib.inspection
|
||||
wx.lib.inspection.InspectionTool().Show()
|
||||
|
||||
|
||||
frm.Show()
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
@@ -679,7 +679,7 @@ class DocTabbedChildFrame(wx.Panel):
|
||||
if title.endswith("*"):
|
||||
title = title[:-1]
|
||||
self.SetTitle(title)
|
||||
|
||||
|
||||
|
||||
def ProcessEvent(event):
|
||||
"""
|
||||
@@ -1174,7 +1174,7 @@ class DocMDIChildFrame(wx.MDIChildFrame):
|
||||
else:
|
||||
if title.endswith("*"):
|
||||
title = title[:-1]
|
||||
self.SetTitle(title)
|
||||
self.SetTitle(title)
|
||||
else:
|
||||
return
|
||||
|
||||
@@ -2880,11 +2880,11 @@ class WindowMenuService(DocService):
|
||||
windowMenu = wx.Menu()
|
||||
else:
|
||||
needWindowMenu = False
|
||||
|
||||
|
||||
if self.GetDocumentManager().GetFlags() & wx.lib.docview.DOC_SDI:
|
||||
if not _WINDOWS: # Arrange All and window navigation doesn't work on Linux
|
||||
return
|
||||
|
||||
|
||||
item = windowMenu.Append(self.ARRANGE_WINDOWS_ID, _("&Arrange All"), _("Arrange the open windows"))
|
||||
wx.EVT_MENU(frame, self.ARRANGE_WINDOWS_ID, frame.ProcessEvent)
|
||||
wx.EVT_UPDATE_UI(frame, self.ARRANGE_WINDOWS_ID, frame.ProcessUpdateUIEvent)
|
||||
@@ -2972,7 +2972,7 @@ class WindowMenuService(DocService):
|
||||
elif wx.GetApp().GetUseTabbedMDI():
|
||||
if id == self.SELECT_NEXT_WINDOW_ID:
|
||||
self.BuildWindowMenu(event.GetEventObject()) # build file list only when we are updating the windows menu
|
||||
|
||||
|
||||
notebook = wx.GetApp().GetTopWindow()._notebook
|
||||
i = notebook.GetSelection()
|
||||
if i == -1:
|
||||
@@ -3056,8 +3056,8 @@ class WindowMenuService(DocService):
|
||||
if numPages > len(self._selectWinIds):
|
||||
for i in range(len(self._selectWinIds), numPages):
|
||||
self._selectWinIds.append(wx.NewId())
|
||||
wx.EVT_MENU(currentFrame, self._selectWinIds[i], self.OnCtrlKeySelect)
|
||||
|
||||
wx.EVT_MENU(currentFrame, self._selectWinIds[i], self.OnCtrlKeySelect)
|
||||
|
||||
for i in range(0, numPages):
|
||||
if i == 0 and not self._sep:
|
||||
self._sep = windowMenu.AppendSeparator()
|
||||
|
||||
@@ -48,12 +48,12 @@ class ResizeWidget(wx.Panel):
|
||||
"""
|
||||
Reparents a given widget into a specialized panel that provides a resize
|
||||
handle for the widget.
|
||||
|
||||
|
||||
"""
|
||||
def __init__(self, *args, **kw):
|
||||
"""
|
||||
Default class constructor.
|
||||
|
||||
|
||||
:param `args`: arguments will be passed on to the wx.Panel
|
||||
:param `kw`: key words will be passed on to the wx.Panel
|
||||
|
||||
@@ -85,10 +85,10 @@ class ResizeWidget(wx.Panel):
|
||||
def SetDimensions(self, thickness=RW_THICKNESS, length=RW_LENGTH):
|
||||
"""
|
||||
Set the dimensions of handles.
|
||||
|
||||
|
||||
:param `thickness`: the thickness of the handles
|
||||
:param `length`: the length of the handles
|
||||
|
||||
|
||||
"""
|
||||
self.RW_THICKNESS = thickness
|
||||
self.RW_LENGTH = length
|
||||
@@ -96,11 +96,11 @@ class ResizeWidget(wx.Panel):
|
||||
def SetColors(self, pen=RW_PEN, fill=RW_FILL, fill2=RW_FILL2):
|
||||
"""
|
||||
Set the colors of handles.
|
||||
|
||||
|
||||
:param `pen`: the pen color
|
||||
:param `fill`: the fill color
|
||||
:param `fill2`: the secondary fill color
|
||||
|
||||
|
||||
"""
|
||||
self.RW_PEN = pen
|
||||
self.RW_FILL = fill
|
||||
@@ -109,9 +109,9 @@ class ResizeWidget(wx.Panel):
|
||||
def SetManagedChild(self, child):
|
||||
"""
|
||||
Set a managed child.
|
||||
|
||||
|
||||
:param `child`: child to manage
|
||||
|
||||
|
||||
"""
|
||||
self._reparenting = True
|
||||
child.Reparent(self) # This calls AddChild, so do the rest of the init there
|
||||
@@ -133,9 +133,9 @@ class ResizeWidget(wx.Panel):
|
||||
def AdjustToSize(self, size):
|
||||
"""
|
||||
Adjust to given size.
|
||||
|
||||
|
||||
:param `size`: size to adjust to.
|
||||
|
||||
|
||||
"""
|
||||
size = wx.Size(*size)
|
||||
self._bestSize = size + (self.RW_THICKNESS, self.RW_THICKNESS)
|
||||
@@ -146,9 +146,9 @@ class ResizeWidget(wx.Panel):
|
||||
def EnableResize(self, enable=True):
|
||||
"""
|
||||
Enable resizing.
|
||||
|
||||
|
||||
:param boolean `enable`: enable or disable resizing.
|
||||
|
||||
|
||||
"""
|
||||
self._resizeEnabled = enable
|
||||
self.Refresh(False)
|
||||
@@ -163,9 +163,9 @@ class ResizeWidget(wx.Panel):
|
||||
def OnLeftDown(self, evt):
|
||||
"""
|
||||
Handles the ``wx.EVT_LEFT_DOWN`` event for :class:`ResizeWidget`.
|
||||
|
||||
|
||||
:param `evt`: a :class:`MouseEvent` event to be processed.
|
||||
|
||||
|
||||
"""
|
||||
if self._hitTest(evt.GetPosition()) and self._resizeEnabled:
|
||||
self.CaptureMouse()
|
||||
@@ -175,9 +175,9 @@ class ResizeWidget(wx.Panel):
|
||||
def OnLeftUp(self, evt):
|
||||
"""
|
||||
Handles the ``wx.EVT_LEFT_UP`` event for :class:`ResizeWidget`.
|
||||
|
||||
|
||||
:param `evt`: a :class:`MouseEvent` event to be processed.
|
||||
|
||||
|
||||
"""
|
||||
if self.HasCapture():
|
||||
self.ReleaseMouse()
|
||||
@@ -187,9 +187,9 @@ class ResizeWidget(wx.Panel):
|
||||
def OnMouseMove(self, evt):
|
||||
"""
|
||||
Handles the ``wx.EVT_MOTION`` event for :class:`ResizeWidget`.
|
||||
|
||||
|
||||
:param `evt`: a :class:`MouseEvent` event to be processed.
|
||||
|
||||
|
||||
"""
|
||||
# set or reset the drag cursor
|
||||
pos = evt.GetPosition()
|
||||
@@ -243,9 +243,9 @@ class ResizeWidget(wx.Panel):
|
||||
def OnMouseLeave(self, evt):
|
||||
"""
|
||||
Handles the ``wx.EVT_LEAVE_WINDOW`` event for :class:`ResizeWidget`.
|
||||
|
||||
|
||||
:param `evt`: a :class:`MouseEvent` event to be processed.
|
||||
|
||||
|
||||
"""
|
||||
if self._resizeCursor:
|
||||
self.SetCursor(wx.Cursor(wx.CURSOR_ARROW))
|
||||
@@ -255,9 +255,9 @@ class ResizeWidget(wx.Panel):
|
||||
def OnSize(self, evt):
|
||||
"""
|
||||
Handles the ``wx.EVT_SIZE`` event for :class:`ResizeWidget`.
|
||||
|
||||
|
||||
:param `evt`: a :class:`wx.SizeEvent` event to be processed.
|
||||
|
||||
|
||||
"""
|
||||
if not self._managedChild:
|
||||
return
|
||||
@@ -273,9 +273,9 @@ class ResizeWidget(wx.Panel):
|
||||
def OnPaint(self, evt):
|
||||
"""
|
||||
Handles the ``wx.EVT_PAINT`` event for :class:`ResizeWidget`.
|
||||
|
||||
|
||||
:param `evt`: a :class:`PaintEvent` event to be processed.
|
||||
|
||||
|
||||
"""
|
||||
# draw the resize handle
|
||||
dc = wx.PaintDC(self)
|
||||
@@ -313,9 +313,9 @@ class ResizeWidget(wx.Panel):
|
||||
def AddChild(self, child):
|
||||
"""
|
||||
Add the child to manage.
|
||||
|
||||
|
||||
:param `child`: the child to manage.
|
||||
|
||||
|
||||
"""
|
||||
assert self._managedChild is None, "Already managing a child widget, can only do one"
|
||||
self._managedChild = child
|
||||
@@ -341,9 +341,9 @@ class ResizeWidget(wx.Panel):
|
||||
def RemoveChild(self, child):
|
||||
"""
|
||||
Remove the managed child.
|
||||
|
||||
|
||||
:param `child`: child to remove.
|
||||
|
||||
|
||||
"""
|
||||
self._init()
|
||||
wx.Panel.RemoveChild(self, child)
|
||||
|
||||
@@ -44,10 +44,10 @@ Usage example::
|
||||
|
||||
text = '''
|
||||
ScrolledPanel extends wx.ScrolledWindow, adding all
|
||||
the necessary bits to set up scroll handling for you.
|
||||
the necessary bits to set up scroll handling for you.
|
||||
|
||||
Here are three fixed size examples of its use. The
|
||||
demo panel for this sample is also using it -- the
|
||||
demo panel for this sample is also using it -- the
|
||||
wx.StaticLine below is intentionally made too long so a scrollbar will be
|
||||
activated.'''
|
||||
|
||||
@@ -63,7 +63,7 @@ Usage example::
|
||||
vbox = wx.BoxSizer(wx.VERTICAL)
|
||||
|
||||
desc = wx.StaticText(self, -1, text)
|
||||
|
||||
|
||||
desc.SetForegroundColour("Blue")
|
||||
vbox.Add(desc, 0, wx.ALIGN_LEFT | wx.ALL, 5)
|
||||
vbox.Add(wx.StaticLine(self, -1, size=(1024, -1)), 0, wx.ALL, 5)
|
||||
@@ -90,7 +90,7 @@ class ScrolledPanel(wx.ScrolledWindow):
|
||||
:class:`ScrolledWindow`, providing automatic scrollbar and scrolling
|
||||
behavior and the tab traversal management that :class:`ScrolledWindow` lacks.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, parent, id=-1, pos=wx.DefaultPosition,
|
||||
size=wx.DefaultSize, style=wx.TAB_TRAVERSAL,
|
||||
name="scrolledpanel"):
|
||||
@@ -117,7 +117,7 @@ class ScrolledPanel(wx.ScrolledWindow):
|
||||
self.Bind(wx.EVT_CHILD_FOCUS, self.OnChildFocus)
|
||||
|
||||
|
||||
def SetupScrolling(self, scroll_x=True, scroll_y=True, rate_x=20, rate_y=20,
|
||||
def SetupScrolling(self, scroll_x=True, scroll_y=True, rate_x=20, rate_y=20,
|
||||
scrollToTop=True, scrollIntoView=True):
|
||||
"""
|
||||
This function sets up the event handling necessary to handle
|
||||
@@ -130,10 +130,10 @@ class ScrolledPanel(wx.ScrolledWindow):
|
||||
:param bool `scroll_y`: ``True`` to allow vertical scrolling, ``False`` otherwise;
|
||||
:param int `rate_x`: the horizontal scroll increment;
|
||||
:param int `rate_y`: the vertical scroll increment;
|
||||
:param bool `scrollToTop`: ``True`` to scroll all way to the top, ``False`` otherwise;
|
||||
:param bool `scrollToTop`: ``True`` to scroll all way to the top, ``False`` otherwise;
|
||||
:param bool `scrollIntoView`: ``True`` to scroll a focused child into view, ``False`` otherwise.
|
||||
"""
|
||||
|
||||
|
||||
self.scrollIntoView = scrollIntoView
|
||||
|
||||
# The following is all that is needed to integrate the sizer and the scrolled window
|
||||
@@ -149,7 +149,7 @@ class ScrolledPanel(wx.ScrolledWindow):
|
||||
if rate_y:
|
||||
h += rate_y - (h % rate_y)
|
||||
self.SetVirtualSize( (w, h) )
|
||||
self.SetScrollRate(rate_x, rate_y)
|
||||
self.SetScrollRate(rate_x, rate_y)
|
||||
wx.CallAfter(self._SetupAfter, scrollToTop) # scroll back to top after initial events
|
||||
|
||||
|
||||
@@ -166,25 +166,25 @@ class ScrolledPanel(wx.ScrolledWindow):
|
||||
|
||||
:param `evt`: a :class:`ChildFocusEvent` event to be processed.
|
||||
"""
|
||||
|
||||
|
||||
child = evt.GetWindow()
|
||||
if self.scrollIntoView:
|
||||
self.ScrollChildIntoView(child)
|
||||
evt.Skip()
|
||||
|
||||
|
||||
|
||||
def ScrollChildIntoView(self, child):
|
||||
"""
|
||||
Scroll the panel so that the specified child window is in view.
|
||||
|
||||
:param wx.Window `child`: any :class:`wx.Window` - derived control.
|
||||
|
||||
|
||||
.. note:: This method looks redundant if `evt.Skip()` is
|
||||
called as well - the base :class:`ScrolledWindow` widget now seems
|
||||
to be doing the same thing anyway.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
sppu_x, sppu_y = self.GetScrollPixelsPerUnit()
|
||||
vs_x, vs_y = self.GetViewStart()
|
||||
cr = child.GetRect()
|
||||
@@ -210,7 +210,7 @@ class ScrolledPanel(wx.ScrolledWindow):
|
||||
new_vs_x = vs_x + diff
|
||||
else:
|
||||
new_vs_x = vs_x + (cr.x / sppu_x)
|
||||
|
||||
|
||||
# is it below the bottom ?
|
||||
if cr.bottom > clntsz.height and sppu_y > 0:
|
||||
diff = math.ceil(1.0 * (cr.bottom - clntsz.height + 1) / sppu_y)
|
||||
|
||||
@@ -127,8 +127,8 @@ class CCellEditor(wx.grid.PyGridCellEditor):
|
||||
"""
|
||||
key = evt.GetKeyCode() # Get the key code
|
||||
ch = None # Handle num pad keys
|
||||
if key in [ wx.WXK_NUMPAD0, wx.WXK_NUMPAD1, wx.WXK_NUMPAD2, wx.WXK_NUMPAD3,
|
||||
wx.WXK_NUMPAD4, wx.WXK_NUMPAD5, wx.WXK_NUMPAD6, wx.WXK_NUMPAD7,
|
||||
if key in [ wx.WXK_NUMPAD0, wx.WXK_NUMPAD1, wx.WXK_NUMPAD2, wx.WXK_NUMPAD3,
|
||||
wx.WXK_NUMPAD4, wx.WXK_NUMPAD5, wx.WXK_NUMPAD6, wx.WXK_NUMPAD7,
|
||||
wx.WXK_NUMPAD8, wx.WXK_NUMPAD9]:
|
||||
ch = chr(ord('0') + key - wx.WXK_NUMPAD0)
|
||||
|
||||
@@ -154,7 +154,7 @@ class CCellEditor(wx.grid.PyGridCellEditor):
|
||||
|
||||
def Destroy(self):
|
||||
""" Final cleanup
|
||||
|
||||
|
||||
NOTE: There is no need to everride this if you don't need
|
||||
to do something out of the ordinary.
|
||||
"""
|
||||
|
||||
@@ -41,10 +41,10 @@ Sample usage::
|
||||
app = wx.App(0)
|
||||
|
||||
frame = sc.SizedFrame(None, -1, "A sized frame")
|
||||
|
||||
|
||||
pane = frame.GetContentsPane()
|
||||
pane.SetSizerType("horizontal")
|
||||
|
||||
|
||||
b1 = wx.Button(pane, wx.ID_ANY)
|
||||
t1 = wx.TextCtrl(pane, -1)
|
||||
t1.SetSizerProps(expand=True)
|
||||
@@ -58,7 +58,7 @@ Sample usage::
|
||||
import wx
|
||||
import wx.lib.scrolledpanel as sp
|
||||
|
||||
# For HIG info: links to all the HIGs can be found here:
|
||||
# For HIG info: links to all the HIGs can be found here:
|
||||
# http://en.wikipedia.org/wiki/Human_Interface_Guidelines
|
||||
|
||||
|
||||
@@ -69,27 +69,27 @@ halign = { "left": wx.ALIGN_LEFT,
|
||||
"centre": wx.ALIGN_CENTRE_HORIZONTAL,
|
||||
"right": wx.ALIGN_RIGHT,
|
||||
}
|
||||
|
||||
|
||||
valign = { "top": wx.ALIGN_TOP,
|
||||
"bottom": wx.ALIGN_BOTTOM,
|
||||
"center": wx.ALIGN_CENTER_VERTICAL,
|
||||
"centre": wx.ALIGN_CENTRE_VERTICAL,
|
||||
}
|
||||
|
||||
|
||||
align = { "center": wx.ALIGN_CENTER,
|
||||
"centre": wx.ALIGN_CENTRE,
|
||||
"centre": wx.ALIGN_CENTRE,
|
||||
}
|
||||
|
||||
|
||||
border = { "left": wx.LEFT,
|
||||
"right": wx.RIGHT,
|
||||
"top": wx.TOP,
|
||||
"bottom": wx.BOTTOM,
|
||||
"all": wx.ALL,
|
||||
}
|
||||
|
||||
|
||||
minsize = { "fixed": wx.FIXED_MINSIZE,
|
||||
}
|
||||
|
||||
|
||||
misc_flags = { "expand": wx.EXPAND, }
|
||||
|
||||
|
||||
@@ -105,14 +105,14 @@ class TableSizer(wx.Sizer):
|
||||
self.fixed_height = 0
|
||||
self.hgrow = 0
|
||||
self.vgrow = 0
|
||||
|
||||
|
||||
self.row_widths = []
|
||||
self.col_heights = []
|
||||
|
||||
|
||||
# allow us to use 'old-style' proportions when emulating box sizers
|
||||
self.isHorizontal = (self.rows == 1 and self.cols == 0)
|
||||
self.isVertical = (self.cols == 1 and self.rows == 0)
|
||||
|
||||
|
||||
def CalcNumRowsCols(self):
|
||||
"""
|
||||
Calculate the number of rows and columns needed.
|
||||
@@ -123,41 +123,41 @@ class TableSizer(wx.Sizer):
|
||||
numrows = self.rows
|
||||
numcols = self.cols
|
||||
numchild = len(self.GetChildren())
|
||||
|
||||
|
||||
if numrows == 0 and numcols == 0:
|
||||
return 0, 0
|
||||
|
||||
|
||||
if numrows == 0:
|
||||
rows, mod = divmod(numchild, self.cols)
|
||||
if mod > 0:
|
||||
rows += 1
|
||||
numrows = rows
|
||||
|
||||
|
||||
if numcols == 0:
|
||||
cols, mod = divmod(numchild, self.rows)
|
||||
if mod > 0:
|
||||
cols += 1
|
||||
numcols = cols
|
||||
|
||||
|
||||
return numrows, numcols
|
||||
|
||||
|
||||
def CalcMin(self):
|
||||
"""
|
||||
Calculate the minimum size.
|
||||
|
||||
|
||||
:rtype: :ref:`wx.Size`
|
||||
|
||||
|
||||
"""
|
||||
numrows, numcols = self.CalcNumRowsCols()
|
||||
numrows, numcols = self.CalcNumRowsCols()
|
||||
numchild = len(self.GetChildren())
|
||||
|
||||
|
||||
if numchild == 0:
|
||||
return wx.Size(10, 10)
|
||||
|
||||
|
||||
if numrows == 0 and numcols == 0:
|
||||
print("TableSizer must have the number of rows or columns set. Cannot continue.")
|
||||
return wx.Size(10, 10)
|
||||
|
||||
|
||||
self.row_widths = [0 for x in range(0, numrows)]
|
||||
self.col_heights = [0 for x in range(0, numcols)]
|
||||
currentRow = 0
|
||||
@@ -167,72 +167,72 @@ class TableSizer(wx.Sizer):
|
||||
self.vgrow = 0
|
||||
|
||||
# get the max row width and max column height
|
||||
for item in self.GetChildren():
|
||||
for item in self.GetChildren():
|
||||
if self.cols != 0:
|
||||
currentRow, currentCol = divmod(counter, numcols)
|
||||
else:
|
||||
currentCol, currentRow = divmod(counter, numrows)
|
||||
|
||||
|
||||
if item.IsShown():
|
||||
width, height = item.CalcMin()
|
||||
|
||||
|
||||
if self.isVertical and item.GetProportion() > 0:
|
||||
self.hgrow += item.GetProportion()
|
||||
elif self.isHorizontal and item.GetProportion() > 0:
|
||||
self.vgrow += item.GetProportion()
|
||||
|
||||
|
||||
if width > self.row_widths[currentRow]:
|
||||
self.row_widths[currentRow] = width
|
||||
|
||||
|
||||
if height > self.col_heights[currentCol]:
|
||||
self.col_heights[currentCol] = height
|
||||
|
||||
|
||||
counter += 1
|
||||
|
||||
|
||||
minwidth = 0
|
||||
for row_width in self.row_widths:
|
||||
minwidth += row_width
|
||||
|
||||
|
||||
minheight = 0
|
||||
for col_height in self.col_heights:
|
||||
minheight += col_height
|
||||
|
||||
|
||||
self.fixed_width = minwidth
|
||||
self.fixed_height = minheight
|
||||
|
||||
|
||||
return wx.Size(minwidth, minheight)
|
||||
|
||||
|
||||
def RecalcSizes(self):
|
||||
"""
|
||||
Recalculate the sizes.
|
||||
"""
|
||||
|
||||
|
||||
numrows, numcols = self.CalcNumRowsCols()
|
||||
numchild = len(self.GetChildren())
|
||||
|
||||
|
||||
if numchild == 0:
|
||||
return
|
||||
currentRow = 0
|
||||
currentCol = 0
|
||||
counter = 0
|
||||
|
||||
|
||||
print("cols %d, rows %d" % (self.cols, self.rows))
|
||||
print("fixed_height %d, fixed_width %d" % (self.fixed_height, self.fixed_width))
|
||||
#print("self.GetSize() = " + `self.GetSize()`)
|
||||
|
||||
|
||||
row_widths = [0 for x in range(0, numrows)]
|
||||
col_heights = [0 for x in range(0, numcols)]
|
||||
item_sizes = [0 for x in range(0, len(self.GetChildren()))]
|
||||
grow_sizes = [0 for x in range(0, len(self.GetChildren()))]
|
||||
|
||||
|
||||
curHPos = 0
|
||||
curVPos = 0
|
||||
curCol = 0
|
||||
curRow = 0
|
||||
# first, we set sizes for all children, and while doing so, calc
|
||||
# the maximum row heights and col widths. Then, afterwards we handle
|
||||
# the positioning of the controls
|
||||
|
||||
# the positioning of the controls
|
||||
|
||||
for item in self.GetChildren():
|
||||
if self.cols != 0:
|
||||
currentRow, currentCol = divmod(counter, numcols)
|
||||
@@ -242,17 +242,17 @@ class TableSizer(wx.Sizer):
|
||||
item_minsize = item.GetMinSizeWithBorder()
|
||||
width = item_minsize[0]
|
||||
height = item_minsize[1]
|
||||
|
||||
|
||||
print("row_height %d, row_width %d" % (self.col_heights[currentCol], self.row_widths[currentRow]))
|
||||
growable_width = (self.GetSize()[0]) - width
|
||||
growable_height = (self.GetSize()[1]) - height
|
||||
|
||||
|
||||
#if not self.isVertical and not self.isHorizontal:
|
||||
# growable_width = self.GetSize()[0] - self.row_widths[currentRow]
|
||||
# growable_height = self.GetSize()[1] - self.col_heights[currentCol]
|
||||
|
||||
|
||||
#print("grow_height %d, grow_width %d" % (growable_height, growable_width))
|
||||
|
||||
|
||||
item_vgrow = 0
|
||||
item_hgrow = 0
|
||||
# support wx.EXPAND for box sizers to be compatible
|
||||
@@ -260,13 +260,13 @@ class TableSizer(wx.Sizer):
|
||||
if self.isVertical:
|
||||
if self.hgrow > 0 and item.GetProportion() > 0:
|
||||
item_hgrow = (growable_width * item.GetProportion()) / self.hgrow
|
||||
item_vgrow = growable_height
|
||||
item_vgrow = growable_height
|
||||
|
||||
elif self.isHorizontal:
|
||||
elif self.isHorizontal:
|
||||
if self.vgrow > 0 and item.GetProportion() > 0:
|
||||
item_vgrow = (growable_height * item.GetProportion()) / self.vgrow
|
||||
item_hgrow = growable_width
|
||||
|
||||
|
||||
if growable_width > 0 and item.GetHGrow() > 0:
|
||||
item_hgrow = (growable_width * item.GetHGrow()) / 100
|
||||
print("hgrow = %d" % (item_hgrow))
|
||||
@@ -274,60 +274,60 @@ class TableSizer(wx.Sizer):
|
||||
if growable_height > 0 and item.GetVGrow() > 0:
|
||||
item_vgrow = (growable_height * item.GetVGrow()) / 100
|
||||
print("vgrow = %d" % (item_vgrow))
|
||||
|
||||
|
||||
grow_size = wx.Size(item_hgrow, item_vgrow)
|
||||
size = item_minsize #wx.Size(item_minsize[0] + item_hgrow, item_minsize[1] + item_vgrow)
|
||||
size = item_minsize #wx.Size(item_minsize[0] + item_hgrow, item_minsize[1] + item_vgrow)
|
||||
if size[0] + grow_size[0] > row_widths[currentRow]:
|
||||
row_widths[currentRow] = size[0] + grow_size[0]
|
||||
if size[1] + grow_size[1] > col_heights[currentCol]:
|
||||
col_heights[currentCol] = size[1] + grow_size[1]
|
||||
|
||||
col_heights[currentCol] = size[1] + grow_size[1]
|
||||
|
||||
grow_sizes[counter] = grow_size
|
||||
item_sizes[counter] = size
|
||||
|
||||
|
||||
counter += 1
|
||||
|
||||
|
||||
counter = 0
|
||||
for item in self.GetChildren():
|
||||
if self.cols != 0:
|
||||
currentRow, currentCol = divmod(counter, numcols)
|
||||
else:
|
||||
currentCol, currentRow = divmod(counter, numrows)
|
||||
|
||||
|
||||
itempos = self.GetPosition()
|
||||
if item.IsShown():
|
||||
rowstart = itempos[0]
|
||||
rowstart = itempos[0]
|
||||
for row in range(0, currentRow):
|
||||
rowstart += row_widths[row]
|
||||
|
||||
|
||||
colstart = itempos[1]
|
||||
for col in range(0, currentCol):
|
||||
#print("numcols = %d, currentCol = %d, col = %d" % (numcols, currentCol, col))
|
||||
colstart += col_heights[col]
|
||||
|
||||
|
||||
itempos[0] += rowstart
|
||||
itempos[1] += colstart
|
||||
|
||||
|
||||
if item.GetFlag() & wx.ALIGN_RIGHT:
|
||||
itempos[0] += (row_widths[currentRow] - item_sizes[counter][0])
|
||||
elif item.GetFlag() & (wx.ALIGN_CENTER | wx.ALIGN_CENTER_HORIZONTAL):
|
||||
itempos[0] += (row_widths[currentRow] - item_sizes[counter][0]) / 2
|
||||
|
||||
|
||||
if item.GetFlag() & wx.ALIGN_BOTTOM:
|
||||
itempos[1] += (col_heights[currentCol] - item_sizes[counter][1])
|
||||
elif item.GetFlag() & (wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL):
|
||||
itempos[1] += (col_heights[currentCol] - item_sizes[counter][1]) / 2
|
||||
|
||||
|
||||
hgrowth = (grow_sizes[counter][0] - itempos[0])
|
||||
if hgrowth > 0:
|
||||
item_sizes[counter][0] += hgrowth
|
||||
|
||||
|
||||
vgrowth = (grow_sizes[counter][1] - itempos[1])
|
||||
if vgrowth > 0:
|
||||
item_sizes[counter][1] += vgrowth
|
||||
#item_sizes[counter][1] -= itempos[1]
|
||||
item.SetDimension(itempos, item_sizes[counter])
|
||||
|
||||
|
||||
counter += 1
|
||||
|
||||
def GetDefaultBorder(self):
|
||||
@@ -338,13 +338,13 @@ def GetDefaultBorder(self):
|
||||
"""
|
||||
border = 4
|
||||
if wx.Platform == "__WXMAC__":
|
||||
border = 6
|
||||
border = 6
|
||||
elif wx.Platform == "__WXMSW__":
|
||||
# MSW HIGs use dialog units, not pixels
|
||||
pnt = self.ConvertDialogToPixels(wx.Point(4, 4))
|
||||
border = pnt[0] // 2
|
||||
elif wx.Platform == "__WXGTK__":
|
||||
border = 3
|
||||
border = 3
|
||||
|
||||
return border
|
||||
|
||||
@@ -352,11 +352,11 @@ def SetDefaultSizerProps(self):
|
||||
"""
|
||||
Set default sizer properties.
|
||||
"""
|
||||
item = self.GetParent().GetSizer().GetItem(self)
|
||||
item = self.GetParent().GetSizer().GetItem(self)
|
||||
item.SetProportion(0)
|
||||
item.SetFlag(wx.ALL)
|
||||
item.SetBorder(self.GetDefaultHIGBorder())
|
||||
|
||||
|
||||
def GetSizerProps(self):
|
||||
"""
|
||||
Returns a dictionary of prop name + value.
|
||||
@@ -365,7 +365,7 @@ def GetSizerProps(self):
|
||||
item = self.GetParent().GetSizer().GetItem(self)
|
||||
if item is None:
|
||||
return None
|
||||
|
||||
|
||||
props['proportion'] = item.GetProportion()
|
||||
flags = item.GetFlag()
|
||||
|
||||
@@ -375,10 +375,10 @@ def GetSizerProps(self):
|
||||
borders = []
|
||||
for key in border:
|
||||
if flags & border[key]:
|
||||
borders.append(key)
|
||||
|
||||
borders.append(key)
|
||||
|
||||
props['border'] = (borders, item.GetBorder())
|
||||
|
||||
|
||||
if flags & align['center'] == align['center']:
|
||||
props['align'] = 'center'
|
||||
else:
|
||||
@@ -389,33 +389,33 @@ def GetSizerProps(self):
|
||||
for key in valign:
|
||||
if flags & valign[key]:
|
||||
props['valign'] = key
|
||||
|
||||
|
||||
for key in minsize:
|
||||
if flags & minsize[key]:
|
||||
props['minsize'] = key
|
||||
|
||||
props['minsize'] = key
|
||||
|
||||
for key in misc_flags:
|
||||
if flags & misc_flags[key]:
|
||||
props[key] = "true"
|
||||
|
||||
|
||||
return props
|
||||
|
||||
def SetSizerProp(self, prop, value):
|
||||
"""
|
||||
Sets a sizer property
|
||||
|
||||
|
||||
Sample usages::
|
||||
|
||||
|
||||
control.SetSizerProp('expand', True)
|
||||
|
||||
|
||||
:param string `prop`: valid strings are "proportion", "hgrow", "vgrow",
|
||||
"align", "halign", "valign", "border", "minsize" and "expand"
|
||||
:param `value`: corresponding value for the prop
|
||||
"""
|
||||
|
||||
|
||||
lprop = prop.lower()
|
||||
sizer = self.GetParent().GetSizer()
|
||||
item = sizer.GetItem(self)
|
||||
item = sizer.GetItem(self)
|
||||
flag = item.GetFlag()
|
||||
if lprop == "proportion":
|
||||
item.SetProportion(int(value))
|
||||
@@ -454,7 +454,7 @@ def SetSizerProp(self, prop, value):
|
||||
flag = flag &~ misc_flags[lprop]
|
||||
else:
|
||||
flag = flag | misc_flags[lprop]
|
||||
|
||||
|
||||
# auto-adjust growable rows/columns if expand or proportion is set
|
||||
# on a sizer item in a FlexGridSizer
|
||||
if lprop in ["expand", "proportion"] and isinstance(sizer, wx.FlexGridSizer):
|
||||
@@ -463,14 +463,14 @@ def SetSizerProp(self, prop, value):
|
||||
# FIXME: I'd like to get the item index in the sizer instead, but
|
||||
# doing sizer.GetChildren.index(item) always gives an error
|
||||
itemnum = self.GetParent().GetChildren().index(self)
|
||||
|
||||
|
||||
col = 0
|
||||
row = 0
|
||||
if cols == 0:
|
||||
col, row = divmod( itemnum, rows )
|
||||
else:
|
||||
row, col = divmod( itemnum, cols )
|
||||
|
||||
|
||||
if lprop == "expand" and not sizer.IsColGrowable(col):
|
||||
sizer.AddGrowableCol(col)
|
||||
elif lprop == "proportion" and int(value) != 0 and not sizer.IsRowGrowable(row):
|
||||
@@ -481,88 +481,88 @@ def SetSizerProp(self, prop, value):
|
||||
def SetSizerProps(self, props={}, **kwargs):
|
||||
"""
|
||||
Allows to set multiple sizer properties
|
||||
|
||||
|
||||
Sample usages::
|
||||
|
||||
|
||||
control.SetSizerProps(expand=True, proportion=1)
|
||||
|
||||
|
||||
control.SetSizerProps(expand=True, valign='center', border=(['top',
|
||||
'bottom'], 5))
|
||||
|
||||
|
||||
control.SetSizerProps({'growable_row': (1, 1),
|
||||
'growable_col': (0, 1),})
|
||||
|
||||
:param dict `props`: a dictionary of prop name + value
|
||||
:param `kwargs`: keywords can be used for properties, e.g. expand=True
|
||||
|
||||
|
||||
"""
|
||||
|
||||
allprops = {}
|
||||
allprops.update(props)
|
||||
allprops.update(kwargs)
|
||||
|
||||
|
||||
for prop in allprops:
|
||||
self.SetSizerProp(prop, allprops[prop])
|
||||
|
||||
|
||||
def GetDialogBorder(self):
|
||||
"""
|
||||
Get the platform specific dialog border.
|
||||
|
||||
:rtype: `int`
|
||||
"""
|
||||
|
||||
|
||||
border = 6
|
||||
if wx.Platform == "__WXMAC__" or wx.Platform == "__WXGTK__":
|
||||
border = 12
|
||||
elif wx.Platform == "__WXMSW__":
|
||||
pnt = self.ConvertDialogToPixels(wx.Point(7, 7))
|
||||
border = pnt[0]
|
||||
|
||||
|
||||
return border
|
||||
|
||||
def SetHGrow(self, proportion):
|
||||
"""
|
||||
Set horizontal grow proportion.
|
||||
|
||||
|
||||
:param int `proportion`: proportion to use
|
||||
"""
|
||||
|
||||
|
||||
data = self.GetUserData()
|
||||
if "HGrow" in data:
|
||||
data["HGrow"] = proportion
|
||||
self.SetUserData(data)
|
||||
|
||||
self.SetUserData(data)
|
||||
|
||||
def GetHGrow(self):
|
||||
"""
|
||||
Get the horizontal grow value.
|
||||
|
||||
:rtype: `int`
|
||||
"""
|
||||
|
||||
|
||||
if self.GetUserData() and "HGrow" in self.GetUserData():
|
||||
return self.GetUserData()["HGrow"]
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
def SetVGrow(self, proportion):
|
||||
"""
|
||||
Set vertical grow proportion.
|
||||
|
||||
|
||||
:param int `proportion`: proportion to use
|
||||
"""
|
||||
|
||||
|
||||
data = self.GetUserData()
|
||||
if "VGrow" in data:
|
||||
data["VGrow"] = proportion
|
||||
self.SetUserData(data)
|
||||
|
||||
self.SetUserData(data)
|
||||
|
||||
def GetVGrow(self):
|
||||
"""
|
||||
Get the vertical grow value.
|
||||
|
||||
:rtype: `int`
|
||||
"""
|
||||
|
||||
|
||||
if self.GetUserData() and "VGrow" in self.GetUserData():
|
||||
return self.GetUserData()["VGrow"]
|
||||
else:
|
||||
@@ -575,7 +575,7 @@ def GetDefaultPanelBorder(self):
|
||||
"""
|
||||
return 0
|
||||
|
||||
# Why, Python?! Why do you make it so easy?! ;-)
|
||||
# Why, Python?! Why do you make it so easy?! ;-)
|
||||
wx.Dialog.GetDialogBorder = GetDialogBorder
|
||||
wx.Panel.GetDefaultHIGBorder = GetDefaultPanelBorder
|
||||
wx.Notebook.GetDefaultHIGBorder = GetDefaultPanelBorder
|
||||
@@ -600,11 +600,11 @@ class SizedParent:
|
||||
def AddChild(self, child):
|
||||
"""
|
||||
Add a child to sizer
|
||||
|
||||
|
||||
:param `child`: child (window or another sizer) to be added to sizer.
|
||||
:type `child`: :class:`wx.Window` or :class:`wx.Sizer`
|
||||
"""
|
||||
|
||||
|
||||
# Note: The wx.LogNull is used here to suppress a log message
|
||||
# on wxMSW that happens because when AddChild is called the
|
||||
# widget's hwnd hasn't been set yet, so the GetWindowRect that
|
||||
@@ -616,46 +616,46 @@ class SizedParent:
|
||||
item = sizer.Add(child)
|
||||
del nolog
|
||||
item.SetUserData({"HGrow":0, "VGrow":0})
|
||||
|
||||
|
||||
# Note: One problem is that the child class given to AddChild
|
||||
# is the underlying wxWidgets control, not its Python subclass. So if
|
||||
# you derive your own class, and override that class' GetDefaultBorder(),
|
||||
# etc. methods, it will have no effect.
|
||||
# is the underlying wxWidgets control, not its Python subclass. So if
|
||||
# you derive your own class, and override that class' GetDefaultBorder(),
|
||||
# etc. methods, it will have no effect.
|
||||
child.SetDefaultSizerProps()
|
||||
|
||||
|
||||
def GetSizerType(self):
|
||||
"""
|
||||
Return the sizer type.
|
||||
|
||||
:rtype: `string`
|
||||
"""
|
||||
|
||||
|
||||
return self.sizerType
|
||||
|
||||
|
||||
def SetSizerType(self, type, options={}):
|
||||
"""
|
||||
Sets the sizer type and automatically re-assign any children
|
||||
to it.
|
||||
|
||||
|
||||
:param string `type`: sizer type, valid values are "horizontal", "vertical",
|
||||
"form", "table" and "grid";
|
||||
:param dict `options`: dictionary of options depending on type.
|
||||
|
||||
|
||||
"""
|
||||
|
||||
sizer = None
|
||||
self.sizerType = type
|
||||
if type == "horizontal":
|
||||
sizer = wx.BoxSizer(wx.HORIZONTAL) # TableSizer(0, 1)
|
||||
|
||||
sizer = wx.BoxSizer(wx.HORIZONTAL) # TableSizer(0, 1)
|
||||
|
||||
elif type == "vertical":
|
||||
sizer = wx.BoxSizer(wx.VERTICAL) # TableSizer(1, 0)
|
||||
|
||||
|
||||
elif type == "form":
|
||||
#sizer = TableSizer(2, 0)
|
||||
sizer = wx.FlexGridSizer(0, 2, 0, 0)
|
||||
#sizer.AddGrowableCol(1)
|
||||
|
||||
|
||||
elif type == "table":
|
||||
rows = cols = 0
|
||||
if 'rows' in options:
|
||||
@@ -663,9 +663,9 @@ class SizedParent:
|
||||
|
||||
if 'cols' in options:
|
||||
cols = int(options['cols'])
|
||||
|
||||
|
||||
sizer = TableSizer(rows, cols)
|
||||
|
||||
|
||||
elif type == "grid":
|
||||
sizer = wx.FlexGridSizer(0, 0, 0, 0)
|
||||
if 'rows' in options:
|
||||
@@ -676,30 +676,30 @@ class SizedParent:
|
||||
sizer.SetCols(int(options['cols']))
|
||||
else:
|
||||
sizer.SetCols(0)
|
||||
|
||||
|
||||
if 'growable_row' in options:
|
||||
row, proportion = options['growable_row']
|
||||
sizer.SetGrowableRow(row, proportion)
|
||||
|
||||
|
||||
if 'growable_col' in options:
|
||||
col, proportion = options['growable_col']
|
||||
sizer.SetGrowableCol(col, proportion)
|
||||
|
||||
|
||||
if 'hgap' in options:
|
||||
sizer.SetHGap(options['hgap'])
|
||||
|
||||
|
||||
if 'vgap' in options:
|
||||
sizer.SetVGap(options['vgap'])
|
||||
if sizer:
|
||||
self._SetNewSizer(sizer)
|
||||
|
||||
|
||||
def _DetachFromSizer(self, sizer):
|
||||
"""
|
||||
Detach children from sizer.
|
||||
|
||||
|
||||
:param wx.Sizer `sizer`: sizer to detach children from
|
||||
"""
|
||||
|
||||
|
||||
props = {}
|
||||
for child in self.GetChildren():
|
||||
# On the Mac the scrollbars and corner gripper of a
|
||||
@@ -717,10 +717,10 @@ class SizedParent:
|
||||
def _AddToNewSizer(self, sizer, props):
|
||||
"""
|
||||
Add children to new sizer.
|
||||
|
||||
|
||||
:param `sizer`: param is not used, remove it ???
|
||||
:param `props`: sizer properties
|
||||
|
||||
|
||||
"""
|
||||
for child in self.GetChildren():
|
||||
csp = props.get(child.GetId(), None)
|
||||
@@ -733,7 +733,7 @@ class SizedParent:
|
||||
class SizedPanel(wx.Panel, SizedParent):
|
||||
"""
|
||||
A sized panel.
|
||||
|
||||
|
||||
Controls added to it will automatically be added to its sizer.
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -741,13 +741,13 @@ class SizedPanel(wx.Panel, SizedParent):
|
||||
`self` in the following sample is a :class:`wx.SizedPanel` instance.
|
||||
|
||||
Sample usage::
|
||||
|
||||
|
||||
self.SetSizerType("horizontal")
|
||||
|
||||
|
||||
b1 = wx.Button(self, wx.ID_ANY)
|
||||
t1 = wx.TextCtrl(self, -1)
|
||||
t1.SetSizerProps(expand=True)
|
||||
|
||||
|
||||
"""
|
||||
|
||||
wx.Panel.__init__(self, *args, **kwargs)
|
||||
@@ -775,7 +775,7 @@ class SizedPanel(wx.Panel, SizedParent):
|
||||
class SizedScrolledPanel(sp.ScrolledPanel, SizedParent):
|
||||
"""
|
||||
A sized scrolled panel.
|
||||
|
||||
|
||||
Controls added to it will automatically be added to its sizer.
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -783,9 +783,9 @@ class SizedScrolledPanel(sp.ScrolledPanel, SizedParent):
|
||||
`self` in the following sample is a :class:`wx.SizedScrolledPanel` instance.
|
||||
|
||||
Sample usage::
|
||||
|
||||
|
||||
self.SetSizerType("horizontal")
|
||||
|
||||
|
||||
b1 = wx.Button(self, wx.ID_ANY)
|
||||
t1 = wx.TextCtrl(self, -1)
|
||||
t1.SetSizerProps(expand=True)
|
||||
@@ -819,92 +819,92 @@ class SizedScrolledPanel(sp.ScrolledPanel, SizedParent):
|
||||
|
||||
class SizedDialog(wx.Dialog):
|
||||
"""A sized dialog
|
||||
|
||||
Controls added to its content pane will automatically be added to
|
||||
|
||||
Controls added to its content pane will automatically be added to
|
||||
the panes sizer.
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""
|
||||
`self` in the following sample is a :class:`wx.SizedDialog` instance.
|
||||
|
||||
Sample usage::
|
||||
|
||||
|
||||
pane = self.GetContentsPane()
|
||||
pane.SetSizerType("horizontal")
|
||||
|
||||
|
||||
b1 = wx.Button(pane, wx.ID_ANY)
|
||||
t1 = wx.TextCtrl(pane, wx.ID_ANY)
|
||||
t1.SetSizerProps(expand=True)
|
||||
|
||||
|
||||
"""
|
||||
|
||||
|
||||
wx.Dialog.__init__(self, *args, **kwargs)
|
||||
|
||||
|
||||
self.SetExtraStyle(wx.WS_EX_VALIDATE_RECURSIVELY)
|
||||
|
||||
|
||||
self.borderLen = 12
|
||||
self.mainPanel = SizedPanel(self, -1)
|
||||
|
||||
|
||||
mysizer = wx.BoxSizer(wx.VERTICAL)
|
||||
mysizer.Add(self.mainPanel, 1, wx.EXPAND | wx.ALL, self.GetDialogBorder())
|
||||
self.SetSizer(mysizer)
|
||||
|
||||
|
||||
self.SetAutoLayout(True)
|
||||
|
||||
|
||||
def GetContentsPane(self):
|
||||
"""
|
||||
Return the pane to add controls too.
|
||||
"""
|
||||
return self.mainPanel
|
||||
|
||||
|
||||
def SetButtonSizer(self, sizer):
|
||||
"""
|
||||
Set a sizer for buttons and adjust the button order.
|
||||
"""
|
||||
self.GetSizer().Add(sizer, 0, wx.EXPAND | wx.BOTTOM | wx.RIGHT, self.GetDialogBorder())
|
||||
|
||||
|
||||
# Temporary hack to fix button ordering problems.
|
||||
cancel = self.FindWindowById(wx.ID_CANCEL, parent=self)
|
||||
no = self.FindWindowById(wx.ID_NO, parent=self)
|
||||
if no and cancel:
|
||||
cancel.MoveAfterInTabOrder(no)
|
||||
|
||||
|
||||
class SizedFrame(wx.Frame):
|
||||
"""
|
||||
A sized frame.
|
||||
|
||||
Controls added to its content pane will automatically be added to
|
||||
|
||||
Controls added to its content pane will automatically be added to
|
||||
the panes sizer.
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""
|
||||
`self` in the following sample is a :class:`wx.SizedFrame` instance
|
||||
|
||||
Sample usage::
|
||||
|
||||
|
||||
pane = self.GetContentsPane()
|
||||
pane.SetSizerType("horizontal")
|
||||
|
||||
|
||||
b1 = wx.Button(pane, wx.ID_ANY)
|
||||
t1 = wx.TextCtrl(pane, -1)
|
||||
t1.SetSizerProps(expand=True)
|
||||
|
||||
|
||||
"""
|
||||
|
||||
wx.Frame.__init__(self, *args, **kwargs)
|
||||
|
||||
|
||||
self.borderLen = 12
|
||||
# this probably isn't needed, but I thought it would help to make it consistent
|
||||
# with SizedDialog, and creating a panel to hold things is often good practice.
|
||||
self.mainPanel = SizedPanel(self, -1)
|
||||
|
||||
|
||||
mysizer = wx.BoxSizer(wx.VERTICAL)
|
||||
mysizer.Add(self.mainPanel, 1, wx.EXPAND)
|
||||
self.SetSizer(mysizer)
|
||||
|
||||
|
||||
self.SetAutoLayout(True)
|
||||
|
||||
|
||||
def GetContentsPane(self):
|
||||
"""
|
||||
Return the pane to add controls too
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#----------------------------------------------------------------------
|
||||
# Name: wx.lib.softwareupdate
|
||||
# Purpose: A mixin class using Esky that allows a frozen application
|
||||
# to update itself when new versions of the software become
|
||||
# Purpose: A mixin class using Esky that allows a frozen application
|
||||
# to update itself when new versions of the software become
|
||||
# available.
|
||||
#
|
||||
# Author: Robin Dunn
|
||||
@@ -52,12 +52,12 @@ try:
|
||||
except AttributeError:
|
||||
wx.App.GetAppDisplayName = wx.App.GetAppName
|
||||
wx.App.SetAppDisplayName = wx.App.SetAppName
|
||||
|
||||
|
||||
|
||||
|
||||
SOT = 0
|
||||
#if 'wxMac' in wx.PlatformInfo:
|
||||
# SOT = wx.STAY_ON_TOP
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -71,14 +71,14 @@ class SoftwareUpdate(object):
|
||||
OnInit method. Be sure that the :class:`App` has set a display name
|
||||
(self.SetAppDisplayName) as that value will be used in the update dialogs.
|
||||
"""
|
||||
|
||||
|
||||
_caption = "Software Update"
|
||||
_networkFailureMsg = (
|
||||
"Unable to connect to %s to check for updates.\n\n"
|
||||
"Perhaps your network is not enabled, the update server is down, or your"
|
||||
"firewall is blocking the connection.")
|
||||
|
||||
|
||||
|
||||
|
||||
def InitUpdates(self, updatesURL, changelogURL=None, icon=None):
|
||||
"""
|
||||
Set up the Esky object for doing software updates. Passing either the
|
||||
@@ -87,7 +87,7 @@ class SoftwareUpdate(object):
|
||||
esky.finder.VersionFinder class is required. A custom VersionFinder
|
||||
can be used to find and fetch the newer verison of the software in
|
||||
some other way, if desired.
|
||||
|
||||
|
||||
Call this method from the app's OnInit method.
|
||||
"""
|
||||
if isFrozenApp:
|
||||
@@ -104,7 +104,7 @@ class SoftwareUpdate(object):
|
||||
except:
|
||||
pass
|
||||
self._fixSysExecutable()
|
||||
|
||||
|
||||
|
||||
def AutoCheckForUpdate(self, frequencyInDays, parentWindow=None, cfg=None):
|
||||
"""
|
||||
@@ -123,13 +123,13 @@ class SoftwareUpdate(object):
|
||||
lastCheckVersion = cfg.Read('lastCheckVersion', '')
|
||||
today = int(wx.DateTime.Today().GetJulianDayNumber())
|
||||
active = self._esky.active_version
|
||||
|
||||
|
||||
if (today - lastCheck >= frequencyInDays
|
||||
or lastCheckVersion != active):
|
||||
self.CheckForUpdate(True, parentWindow, cfg)
|
||||
cfg.SetPath(oldPath)
|
||||
|
||||
|
||||
|
||||
|
||||
def CheckForUpdate(self, silentUnlessUpdate=False, parentWindow=None, cfg=None):
|
||||
"""
|
||||
This method will check for the availability of a new update, and will
|
||||
@@ -137,7 +137,7 @@ class SoftwareUpdate(object):
|
||||
also tell the user if there is not a new update, but you can pass
|
||||
silentUnlessUpdate=True to not bother the user if there isn't a new
|
||||
update available.
|
||||
|
||||
|
||||
This method should be called from an event handler for a "Check for
|
||||
updates" menu item, or something similar. The actual update check
|
||||
will be run in a background thread and this function will return
|
||||
@@ -160,7 +160,7 @@ class SoftwareUpdate(object):
|
||||
chLogTxt = req.read()
|
||||
req.close()
|
||||
return (newest, chLogTxt)
|
||||
|
||||
|
||||
except URLError:
|
||||
return 'URLError'
|
||||
|
||||
@@ -175,7 +175,7 @@ class SoftwareUpdate(object):
|
||||
self._caption, parent=parentWindow, icon=self._icon,
|
||||
style=wx.OK|SOT)
|
||||
return
|
||||
|
||||
|
||||
active = self._esky.active_version
|
||||
if cfg:
|
||||
oldPath = cfg.GetPath()
|
||||
@@ -185,28 +185,28 @@ class SoftwareUpdate(object):
|
||||
cfg.Write('lastCheckVersion', active)
|
||||
cfg.Flush()
|
||||
cfg.SetPath(oldPath)
|
||||
|
||||
|
||||
newest, chLogTxt = result
|
||||
if newest is None:
|
||||
if not silentUnlessUpdate:
|
||||
MultiMessageBox("You are already running the newest verison of %s." %
|
||||
MultiMessageBox("You are already running the newest verison of %s." %
|
||||
self.GetAppDisplayName(),
|
||||
self._caption, parent=parentWindow, icon=self._icon,
|
||||
style=wx.OK|SOT)
|
||||
return
|
||||
return
|
||||
self._parentWindow = parentWindow
|
||||
|
||||
|
||||
resp = MultiMessageBox("A new version of %s is available.\n\n"
|
||||
"You are currently running verison %s; version %s is now "
|
||||
"available for download. Do you wish to install it now?"
|
||||
% (self.GetAppDisplayName(), active, newest),
|
||||
self._caption, msg2=chLogTxt, style=wx.YES_NO|SOT,
|
||||
parent=parentWindow, icon=self._icon,
|
||||
btnLabels={wx.ID_YES:"Yes, install now",
|
||||
self._caption, msg2=chLogTxt, style=wx.YES_NO|SOT,
|
||||
parent=parentWindow, icon=self._icon,
|
||||
btnLabels={wx.ID_YES:"Yes, install now",
|
||||
wx.ID_NO:"No, maybe later"})
|
||||
if resp != wx.YES:
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
# Ok, there is a little trickery going on here. We don't know yet if
|
||||
# the user wants to restart the application after the update is
|
||||
# complete, but since atexit functions are executed in a LIFO order we
|
||||
@@ -224,7 +224,7 @@ class SoftwareUpdate(object):
|
||||
os.execv(self.exe, [self.exe] + sys.argv[1:])
|
||||
info = RestartInfo()
|
||||
atexit.register(info.restart)
|
||||
|
||||
|
||||
try:
|
||||
# Let Esky handle all the rest of the update process so we can
|
||||
# take advantage of the error checking and priviledge elevation
|
||||
@@ -232,27 +232,27 @@ class SoftwareUpdate(object):
|
||||
# about that ourselves like we would if we broke down the proccess
|
||||
# into component steps.
|
||||
self._esky.auto_update(self._updateProgress)
|
||||
|
||||
|
||||
except UpdateAbortedError:
|
||||
MultiMessageBox("Update canceled.", self._caption,
|
||||
MultiMessageBox("Update canceled.", self._caption,
|
||||
parent=parentWindow, icon=self._icon,
|
||||
style=wx.OK|SOT)
|
||||
if self._pd:
|
||||
self._pd.Destroy()
|
||||
|
||||
|
||||
self.InitUpdates(self._updatesURL, self._changelogURL, self._icon)
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
# Ask the user if they want the application to be restarted.
|
||||
resp = MultiMessageBox("The upgrade to %s %s is ready to use; the application will "
|
||||
"need to be restarted to begin using the new release.\n\n"
|
||||
"Restart %s now?"
|
||||
% (self.GetAppDisplayName(), newest, self.GetAppDisplayName()),
|
||||
self._caption, style=wx.YES_NO|SOT,
|
||||
self._caption, style=wx.YES_NO|SOT,
|
||||
parent=parentWindow, icon=self._icon,
|
||||
btnLabels={wx.ID_YES:"Yes, restart now",
|
||||
btnLabels={wx.ID_YES:"Yes, restart now",
|
||||
wx.ID_NO:"No, I'll restart later"})
|
||||
|
||||
|
||||
if resp == wx.YES:
|
||||
# Close all windows in this application...
|
||||
for w in wx.GetTopLevelWindows():
|
||||
@@ -261,43 +261,43 @@ class SoftwareUpdate(object):
|
||||
elif isinstance(w, wx.Frame):
|
||||
w.Close(True) # force close (can't be cancelled)
|
||||
wx.Yield()
|
||||
|
||||
|
||||
# ...find the path of the esky bootstrap/wrapper program...
|
||||
exe = esky.util.appexe_from_executable(sys.executable)
|
||||
|
||||
|
||||
# ...and tell our RestartInfo object about it.
|
||||
info.exe = exe
|
||||
|
||||
|
||||
# Make sure the CWD not in the current version's appdir, so it can
|
||||
# hopefully be cleaned up either as we exit or as the next verison
|
||||
# is starting.
|
||||
os.chdir(os.path.dirname(exe))
|
||||
|
||||
|
||||
# With all the top level windows closed the MainLoop should exit
|
||||
# automatically, but just in case tell it to exit so we can have a
|
||||
# normal-as-possible shutdown of this process. Hopefully there
|
||||
# isn't anything happening after we return from this function that
|
||||
# matters.
|
||||
self.ExitMainLoop()
|
||||
|
||||
|
||||
return
|
||||
|
||||
|
||||
# Start the worker thread that will check for an update, it will call
|
||||
# processResults when it is finished.
|
||||
import wx.lib.delayedresult as dr
|
||||
dr.startWorker(processResults, doFindUpdate)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def _updateProgress(self, status):
|
||||
# Show progress of the download and install. This function is passed to Esky
|
||||
# functions to use as a callback.
|
||||
if self._pd is None and status.get('status') != 'done':
|
||||
self._pd = wx.ProgressDialog('Software Update', ' '*40,
|
||||
self._pd = wx.ProgressDialog('Software Update', ' '*40,
|
||||
style=wx.PD_CAN_ABORT|wx.PD_APP_MODAL,
|
||||
parent=self._parentWindow)
|
||||
self._pd.Update(0, '')
|
||||
|
||||
|
||||
if self._parentWindow:
|
||||
self._pd.CenterOnParent()
|
||||
|
||||
@@ -309,10 +309,10 @@ class SoftwareUpdate(object):
|
||||
|
||||
if status.get('status') in simpleMsgMap:
|
||||
self._doUpdateProgress(True, simpleMsgMap[status.get('status')])
|
||||
|
||||
|
||||
elif status.get('status') == 'found':
|
||||
self._doUpdateProgress(True, 'Found version %s...' % status.get('new_version'))
|
||||
|
||||
|
||||
elif status.get('status') == 'downloading':
|
||||
received = status.get('received')
|
||||
size = status.get('size')
|
||||
@@ -321,15 +321,15 @@ class SoftwareUpdate(object):
|
||||
self._doUpdateProgress(False, "Unzipping...", int(currentPercentage))
|
||||
else:
|
||||
self._doUpdateProgress(False, "Downloading...", int(currentPercentage))
|
||||
|
||||
elif status.get('status') == 'done':
|
||||
|
||||
elif status.get('status') == 'done':
|
||||
if self._pd:
|
||||
self._pd.Destroy()
|
||||
self._pd = None
|
||||
|
||||
|
||||
wx.Yield()
|
||||
|
||||
|
||||
|
||||
|
||||
def _doUpdateProgress(self, pulse, message, value=0):
|
||||
if pulse:
|
||||
keepGoing, skip = self._pd.Pulse(message)
|
||||
@@ -340,7 +340,7 @@ class SoftwareUpdate(object):
|
||||
self._pd = None
|
||||
raise UpdateAbortedError()
|
||||
|
||||
|
||||
|
||||
def _fixSysExecutable(self):
|
||||
# It looks like at least some versions of py2app are setting
|
||||
# sys.executable to ApplicationName.app/Contents/MacOS/python instead
|
||||
@@ -352,11 +352,11 @@ class SoftwareUpdate(object):
|
||||
and sys.frozen == 'macosx_app' and sys.executable.endswith('MacOS/python'):
|
||||
names = os.listdir(os.path.dirname(sys.executable))
|
||||
assert len(names) == 2 # there should be only 2
|
||||
for name in names:
|
||||
for name in names:
|
||||
if name != 'python':
|
||||
sys.executable = os.path.join(os.path.dirname(sys.executable), name)
|
||||
break
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ class MultiSplitterWindow(wx.Panel):
|
||||
Set whether the windows managed by the splitter will be
|
||||
stacked vertically or horizontally. The default is
|
||||
horizontal.
|
||||
|
||||
|
||||
:param `orient`: either ``wx.VERTICAL`` or ``wx.HORIZONTAL``
|
||||
"""
|
||||
assert orient in [ wx.VERTICAL, wx.HORIZONTAL ]
|
||||
@@ -128,9 +128,9 @@ class MultiSplitterWindow(wx.Panel):
|
||||
def SetBackgroundColour(self,color):
|
||||
"""
|
||||
Sets the back ground colour.
|
||||
|
||||
|
||||
:param wx.Colour `color`: the colour to use.
|
||||
|
||||
|
||||
"""
|
||||
wx.Panel.SetBackgroundColour(self,color)
|
||||
self._drawSashInBackgroundColour = True
|
||||
@@ -142,9 +142,9 @@ class MultiSplitterWindow(wx.Panel):
|
||||
"""
|
||||
Set the smallest size that any pane will be allowed to be
|
||||
resized to.
|
||||
|
||||
|
||||
:param int `minSize`: the minimum size of pane
|
||||
|
||||
|
||||
"""
|
||||
self._minimumPaneSize = minSize
|
||||
|
||||
@@ -160,10 +160,10 @@ class MultiSplitterWindow(wx.Panel):
|
||||
"""
|
||||
Add a new window to the splitter at the right side or bottom
|
||||
of the window stack.
|
||||
|
||||
|
||||
:param `window`: the window to add to the splitter
|
||||
:param `sashPos`: if given it is used to size the new window
|
||||
|
||||
|
||||
"""
|
||||
self.InsertWindow(len(self._windows), window, sashPos)
|
||||
|
||||
@@ -171,11 +171,11 @@ class MultiSplitterWindow(wx.Panel):
|
||||
def InsertWindow(self, idx, window, sashPos=-1):
|
||||
"""
|
||||
Insert a new window into the splitter.
|
||||
|
||||
|
||||
:param int `idx`: the position to insert the window at.
|
||||
:param `window`: the window to add to the splitter
|
||||
:param `sashPos`: if given it is used to size the new window
|
||||
|
||||
|
||||
"""
|
||||
assert window not in self._windows, "A window can only be in the splitter once!"
|
||||
self._windows.insert(idx, window)
|
||||
@@ -193,9 +193,9 @@ class MultiSplitterWindow(wx.Panel):
|
||||
Removes the window from the stack of windows managed by the
|
||||
splitter. The window will still exist so you should `Hide` or
|
||||
`Destroy` it as needed.
|
||||
|
||||
|
||||
:param `window`: the window to be removed from the splitter
|
||||
|
||||
|
||||
"""
|
||||
assert window in self._windows, "Unknown window!"
|
||||
idx = self._windows.index(window)
|
||||
@@ -209,10 +209,10 @@ class MultiSplitterWindow(wx.Panel):
|
||||
Replaces oldWindow (which is currently being managed by the
|
||||
splitter) with newWindow. The oldWindow window will still
|
||||
exist so you should `Hide` or `Destroy` it as needed.
|
||||
|
||||
|
||||
:param `oldWindow`: the window to be replace
|
||||
:param `newWindow`: the window to replace the above window
|
||||
|
||||
|
||||
"""
|
||||
assert oldWindow in self._windows, "Unknown window!"
|
||||
idx = self._windows.index(oldWindow)
|
||||
@@ -225,10 +225,10 @@ class MultiSplitterWindow(wx.Panel):
|
||||
def ExchangeWindows(self, window1, window2):
|
||||
"""
|
||||
Trade the positions in the splitter of the two windows.
|
||||
|
||||
|
||||
:param `window1`: the first window to switch position
|
||||
:param `window2`: the second window to switch position
|
||||
|
||||
|
||||
"""
|
||||
assert window1 in self._windows, "Unknown window!"
|
||||
assert window2 in self._windows, "Unknown window!"
|
||||
@@ -242,9 +242,9 @@ class MultiSplitterWindow(wx.Panel):
|
||||
def GetWindow(self, idx):
|
||||
"""
|
||||
Returns the idx'th window being managed by the splitter.
|
||||
|
||||
|
||||
:param int `idx`: get the window at the given index
|
||||
|
||||
|
||||
"""
|
||||
assert idx < len(self._windows)
|
||||
return self._windows[idx]
|
||||
@@ -254,9 +254,9 @@ class MultiSplitterWindow(wx.Panel):
|
||||
"""
|
||||
Returns the position of the idx'th sash, measured from the
|
||||
left/top of the window preceding the sash.
|
||||
|
||||
|
||||
:param int `idx`: get the sash position of the given index
|
||||
|
||||
|
||||
"""
|
||||
assert idx < len(self._sashes)
|
||||
return self._sashes[idx]
|
||||
@@ -266,10 +266,10 @@ class MultiSplitterWindow(wx.Panel):
|
||||
"""
|
||||
Set the position of the idx'th sash, measured from the left/top
|
||||
of the window preceding the sash.
|
||||
|
||||
|
||||
:param int `idx`: set the sash position of the given index
|
||||
:param int `pos`: the sash position
|
||||
|
||||
:param int `pos`: the sash position
|
||||
|
||||
"""
|
||||
assert idx < len(self._sashes)
|
||||
self._sashes[idx] = pos
|
||||
@@ -804,15 +804,15 @@ class MultiSplitterEvent(wx.PyCommandEvent):
|
||||
"""
|
||||
def __init__(self, type=wx.wxEVT_NULL, splitter=None):
|
||||
"""
|
||||
Constructor.
|
||||
|
||||
Used internally by wxWidgets only.
|
||||
|
||||
:param `eventType`:
|
||||
Constructor.
|
||||
|
||||
Used internally by wxWidgets only.
|
||||
|
||||
:param `eventType`:
|
||||
:type `eventType`: EventType
|
||||
:param `splitter`:
|
||||
:param `splitter`:
|
||||
:type `splitter`: SplitterWindow
|
||||
|
||||
|
||||
"""
|
||||
wx.PyCommandEvent.__init__(self, type)
|
||||
if splitter:
|
||||
@@ -825,15 +825,15 @@ class MultiSplitterEvent(wx.PyCommandEvent):
|
||||
def SetSashIdx(self, idx):
|
||||
"""
|
||||
In the case of ``wxEVT_SPLITTER_SASH_POS_CHANGED`` events, sets the
|
||||
new sash index.
|
||||
new sash index.
|
||||
|
||||
In the case of ``wxEVT_SPLITTER_SASH_POS_CHANGING`` events, sets the
|
||||
new tracking bar position so visual feedback during dragging will
|
||||
represent that change that will actually take place. Set to -1 from
|
||||
the event handler code to prevent reindexing.
|
||||
the event handler code to prevent reindexing.
|
||||
|
||||
May only be called while processing ``wxEVT_SPLITTER_SASH_POS_CHANGING``
|
||||
and ``wxEVT_SPLITTER_SASH_POS_CHANGED`` events.
|
||||
and ``wxEVT_SPLITTER_SASH_POS_CHANGED`` events.
|
||||
|
||||
:param int `pos`: New sash index.
|
||||
|
||||
@@ -843,27 +843,27 @@ class MultiSplitterEvent(wx.PyCommandEvent):
|
||||
def SetSashPosition(self, pos):
|
||||
"""
|
||||
In the case of ``wxEVT_SPLITTER_SASH_POS_CHANGED`` events, sets the
|
||||
new sash position.
|
||||
|
||||
new sash position.
|
||||
|
||||
In the case of ``wxEVT_SPLITTER_SASH_POS_CHANGING`` events, sets the
|
||||
new tracking bar position so visual feedback during dragging will
|
||||
represent that change that will actually take place. Set to -1 from
|
||||
the event handler code to prevent repositioning.
|
||||
|
||||
the event handler code to prevent repositioning.
|
||||
|
||||
May only be called while processing ``wxEVT_SPLITTER_SASH_POS_CHANGING``
|
||||
and ``wxEVT_SPLITTER_SASH_POS_CHANGED`` events.
|
||||
|
||||
:param int `pos`: New sash position.
|
||||
|
||||
and ``wxEVT_SPLITTER_SASH_POS_CHANGED`` events.
|
||||
|
||||
:param int `pos`: New sash position.
|
||||
|
||||
"""
|
||||
self.sashPos = pos
|
||||
|
||||
def GetSashIdx(self):
|
||||
"""
|
||||
Returns the new sash index.
|
||||
Returns the new sash index.
|
||||
|
||||
May only be called while processing ``wxEVT_SPLITTER_SASH_POS_CHANGING``
|
||||
and ``wxEVT_SPLITTER_SASH_POS_CHANGED`` events.
|
||||
and ``wxEVT_SPLITTER_SASH_POS_CHANGED`` events.
|
||||
|
||||
:rtype: `int`
|
||||
|
||||
@@ -872,25 +872,25 @@ class MultiSplitterEvent(wx.PyCommandEvent):
|
||||
|
||||
def GetSashPosition(self):
|
||||
"""
|
||||
Returns the new sash position.
|
||||
|
||||
Returns the new sash position.
|
||||
|
||||
May only be called while processing ``wxEVT_SPLITTER_SASH_POS_CHANGING``
|
||||
and ``wxEVT_SPLITTER_SASH_POS_CHANGED`` events.
|
||||
|
||||
and ``wxEVT_SPLITTER_SASH_POS_CHANGED`` events.
|
||||
|
||||
:rtype: `int`
|
||||
|
||||
|
||||
"""
|
||||
return self.sashPos
|
||||
|
||||
# methods from wx.NotifyEvent
|
||||
def Veto(self):
|
||||
"""
|
||||
Prevents the change announced by this event from happening.
|
||||
|
||||
Prevents the change announced by this event from happening.
|
||||
|
||||
It is in general a good idea to notify the user about the reasons
|
||||
for vetoing the change because otherwise the applications behaviour
|
||||
(which just refuses to do what the user wants) might be quite
|
||||
surprising.
|
||||
surprising.
|
||||
|
||||
"""
|
||||
self.isAllowed = False
|
||||
@@ -898,22 +898,22 @@ class MultiSplitterEvent(wx.PyCommandEvent):
|
||||
def Allow(self):
|
||||
"""
|
||||
This is the opposite of :meth:`Veto` : it explicitly allows the
|
||||
event to be processed.
|
||||
|
||||
event to be processed.
|
||||
|
||||
For most events it is not necessary to call this method as the events
|
||||
are allowed anyhow but some are forbidden by default (this will be
|
||||
mentioned in the corresponding event description).
|
||||
|
||||
mentioned in the corresponding event description).
|
||||
|
||||
"""
|
||||
self.isAllowed = True
|
||||
|
||||
def IsAllowed(self):
|
||||
"""
|
||||
Returns ``True`` if the change is allowed (:meth:`Veto` hasn't been
|
||||
called) or ``False`` otherwise (if it was).
|
||||
|
||||
called) or ``False`` otherwise (if it was).
|
||||
|
||||
:rtype: `bool`
|
||||
|
||||
|
||||
"""
|
||||
return self.isAllowed
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#----------------------------------------------------------------------
|
||||
# Name: wx.lib.statbmp
|
||||
# Purpose: A generic StaticBitmap class.
|
||||
# Purpose: A generic StaticBitmap class.
|
||||
#
|
||||
# Author: Robin Dunn
|
||||
#
|
||||
@@ -41,7 +41,7 @@ Sample usage::
|
||||
app = wx.App(0)
|
||||
|
||||
frame = wx.Frame(None, -1, "wx.lib.statbmp Test")
|
||||
panel = wx.Panel(frame)
|
||||
panel = wx.Panel(frame)
|
||||
|
||||
bmp = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_OTHER, (16, 16))
|
||||
st1 = SB.GenStaticBitmap(panel, -1, bmp, (20, 10))
|
||||
@@ -51,7 +51,7 @@ Sample usage::
|
||||
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
"""
|
||||
|
||||
@@ -61,7 +61,7 @@ import wx
|
||||
|
||||
class GenStaticBitmap(wx.Control):
|
||||
""" :class:`GenStaticBitmap` is a generic implementation of :class:`wx.StaticBitmap`. """
|
||||
|
||||
|
||||
labelDelta = 1
|
||||
|
||||
def __init__(self, parent, ID, bitmap,
|
||||
@@ -88,7 +88,7 @@ class GenStaticBitmap(wx.Control):
|
||||
|
||||
if not style & wx.BORDER_MASK:
|
||||
style = style | wx.BORDER_NONE
|
||||
|
||||
|
||||
wx.Control.__init__(self, parent, ID, pos, size, style,
|
||||
wx.DefaultValidator, name)
|
||||
self._bitmap = bitmap
|
||||
@@ -104,10 +104,10 @@ class GenStaticBitmap(wx.Control):
|
||||
Sets the bitmap label.
|
||||
|
||||
:param wx.Bitmap `bitmap`: the new bitmap.
|
||||
|
||||
|
||||
.. seealso:: :meth:`GetBitmap`
|
||||
"""
|
||||
|
||||
|
||||
self._bitmap = bitmap
|
||||
self.SetInitialSize( (bitmap.GetWidth(), bitmap.GetHeight()) )
|
||||
self.Refresh()
|
||||
@@ -118,12 +118,12 @@ class GenStaticBitmap(wx.Control):
|
||||
Returns the bitmap currently used in the control.
|
||||
|
||||
:rtype: wx.Bitmap
|
||||
|
||||
|
||||
.. seealso:: :meth:`SetBitmap`
|
||||
"""
|
||||
|
||||
|
||||
return self._bitmap
|
||||
|
||||
|
||||
|
||||
def DoGetBestSize(self):
|
||||
"""
|
||||
@@ -155,7 +155,7 @@ class GenStaticBitmap(wx.Control):
|
||||
"""
|
||||
|
||||
return wx.StaticBitmap.GetClassDefaultAttributes()
|
||||
|
||||
|
||||
|
||||
def ShouldInheritColours(self):
|
||||
"""
|
||||
@@ -166,7 +166,7 @@ class GenStaticBitmap(wx.Control):
|
||||
"""
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
||||
def OnPaint(self, event):
|
||||
"""
|
||||
@@ -178,7 +178,7 @@ class GenStaticBitmap(wx.Control):
|
||||
dc = wx.PaintDC(self)
|
||||
if self._bitmap:
|
||||
dc.DrawBitmap(self._bitmap, 0, 0, True)
|
||||
|
||||
|
||||
|
||||
def OnEraseBackground(self, event):
|
||||
"""
|
||||
|
||||
@@ -50,7 +50,7 @@ Sample usage::
|
||||
app = wx.App(0)
|
||||
|
||||
frame = wx.Frame(None, -1, "wx.lib.stattext Test")
|
||||
panel = wx.Panel(frame)
|
||||
panel = wx.Panel(frame)
|
||||
|
||||
st1 = ST.GenStaticText(panel, -1, "This is an example of static text", (20, 10))
|
||||
|
||||
@@ -62,7 +62,7 @@ Sample usage::
|
||||
|
||||
frame.Show()
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
"""
|
||||
|
||||
@@ -76,7 +76,7 @@ if wx.Platform == "__WXMAC__":
|
||||
from Carbon.Appearance import kThemeBrushDialogBackgroundActive
|
||||
except ImportError:
|
||||
kThemeBrushDialogBackgroundActive = 1
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class GenStaticText(wx.Control):
|
||||
@@ -120,7 +120,7 @@ class GenStaticText(wx.Control):
|
||||
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
|
||||
else:
|
||||
self.SetBackgroundStyle(wx.BG_STYLE_SYSTEM)
|
||||
|
||||
|
||||
|
||||
|
||||
def SetLabel(self, label):
|
||||
@@ -130,7 +130,7 @@ class GenStaticText(wx.Control):
|
||||
|
||||
:param string `label`: the static text label (i.e., its text label).
|
||||
"""
|
||||
|
||||
|
||||
wx.Control.SetLabel(self, label)
|
||||
style = self.GetWindowStyleFlag()
|
||||
self.InvalidateBestSize()
|
||||
@@ -147,7 +147,7 @@ class GenStaticText(wx.Control):
|
||||
:param wx.Font `font`: a valid font instance, which will be the new font used
|
||||
to display the text.
|
||||
"""
|
||||
|
||||
|
||||
wx.Control.SetFont(self, font)
|
||||
style = self.GetWindowStyleFlag()
|
||||
self.InvalidateBestSize()
|
||||
@@ -163,14 +163,14 @@ class GenStaticText(wx.Control):
|
||||
|
||||
.. note:: Overridden from :class:`wx.Control`.
|
||||
"""
|
||||
|
||||
|
||||
label = self.GetLabel()
|
||||
font = self.GetFont()
|
||||
if not font:
|
||||
font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
|
||||
dc = wx.ClientDC(self)
|
||||
dc.SetFont(font)
|
||||
|
||||
|
||||
maxWidth = totalHeight = 0
|
||||
for line in label.split('\n'):
|
||||
if line == '':
|
||||
@@ -186,7 +186,7 @@ class GenStaticText(wx.Control):
|
||||
|
||||
def Enable(self, enable=True):
|
||||
"""
|
||||
Enable or disable the widget for user input.
|
||||
Enable or disable the widget for user input.
|
||||
|
||||
:param bool `enable`: If ``True``, enables the window for input. If
|
||||
``False``, disables the window.
|
||||
@@ -206,7 +206,7 @@ class GenStaticText(wx.Control):
|
||||
self.Refresh()
|
||||
|
||||
return retVal
|
||||
|
||||
|
||||
|
||||
def Disable(self):
|
||||
"""
|
||||
@@ -214,7 +214,7 @@ class GenStaticText(wx.Control):
|
||||
|
||||
:returns: ``True`` if the window has been disabled, ``False`` if it had been
|
||||
already disabled before the call to this function.
|
||||
|
||||
|
||||
.. note:: This is functionally equivalent of calling :meth:`~wx.Control.Enable`
|
||||
with a ``False`` flag.
|
||||
|
||||
@@ -244,7 +244,7 @@ class GenStaticText(wx.Control):
|
||||
|
||||
.. note:: Overridden from :class:`wx.Control`.
|
||||
"""
|
||||
|
||||
|
||||
return wx.StaticText.GetClassDefaultAttributes()
|
||||
|
||||
|
||||
@@ -258,14 +258,14 @@ class GenStaticText(wx.Control):
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
||||
def OnPaint(self, event):
|
||||
"""
|
||||
Handles the ``wx.EVT_PAINT`` for :class:`GenStaticText`.
|
||||
|
||||
:param `event`: a :class:`wx.PaintEvent` event to be processed.
|
||||
"""
|
||||
|
||||
|
||||
if BUFFERED:
|
||||
dc = wx.BufferedPaintDC(self)
|
||||
else:
|
||||
@@ -289,7 +289,7 @@ class GenStaticText(wx.Control):
|
||||
dc.SetTextForeground(self.GetForegroundColour())
|
||||
else:
|
||||
dc.SetTextForeground(wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
|
||||
|
||||
|
||||
dc.SetFont(self.GetFont())
|
||||
label = self.GetLabel()
|
||||
style = self.GetWindowStyleFlag()
|
||||
|
||||
@@ -89,7 +89,7 @@ class Throbber(wx.Panel):
|
||||
:param `sequence`: sequence of frames, defaults to range(self.frames)
|
||||
|
||||
"""
|
||||
|
||||
|
||||
super(Throbber, self).__init__(parent, id, pos, size, style, name)
|
||||
self.name = name
|
||||
self.label = label
|
||||
@@ -163,19 +163,19 @@ class Throbber(wx.Panel):
|
||||
def DoGetBestSize(self):
|
||||
"""
|
||||
Get the best size of the widget.
|
||||
|
||||
|
||||
:returns: the width and height
|
||||
|
||||
|
||||
"""
|
||||
return (self.width, self.height)
|
||||
|
||||
|
||||
|
||||
def OnTimer(self, event):
|
||||
"""
|
||||
Handles the ``wx.EVT_TIMER`` event for :class:`Throbber`.
|
||||
|
||||
|
||||
:param `event`: a :class:`TimerEvent` event to be processed.
|
||||
|
||||
|
||||
"""
|
||||
wx.PostEvent(self, UpdateThrobberEvent())
|
||||
|
||||
@@ -183,9 +183,9 @@ class Throbber(wx.Panel):
|
||||
def OnDestroyWindow(self, event):
|
||||
"""
|
||||
Handles the ``wx.EVT_WINDOW_DESTROY`` event for :class:`Throbber`.
|
||||
|
||||
|
||||
:param `event`: a :class:`wx.WindowDestroyEvent` event to be processed.
|
||||
|
||||
|
||||
"""
|
||||
self.Stop()
|
||||
event.Skip()
|
||||
@@ -194,9 +194,9 @@ class Throbber(wx.Panel):
|
||||
def Draw(self, dc):
|
||||
"""
|
||||
Draw the widget.
|
||||
|
||||
|
||||
:param `dc`: the :class:`wx.DC` to draw on
|
||||
|
||||
|
||||
"""
|
||||
dc.DrawBitmap(self.submaps[self.sequence[self.current]], 0, 0, True)
|
||||
if self.overlay and self.showOverlay:
|
||||
@@ -210,9 +210,9 @@ class Throbber(wx.Panel):
|
||||
def OnPaint(self, event):
|
||||
"""
|
||||
Handles the ``wx.EVT_PAINT`` event for :class:`Throbber`.
|
||||
|
||||
|
||||
:param `event`: a :class:`PaintEvent` event to be processed.
|
||||
|
||||
|
||||
"""
|
||||
self.Draw(wx.PaintDC(self))
|
||||
event.Skip()
|
||||
@@ -221,9 +221,9 @@ class Throbber(wx.Panel):
|
||||
def Update(self, event):
|
||||
"""
|
||||
Handles the ``EVT_UPDATE_THROBBER`` event for :class:`ResizeWidget`.
|
||||
|
||||
|
||||
:param `event`: a :class:`UpdateThrobberEvent` event to be processed.
|
||||
|
||||
|
||||
"""
|
||||
self.Next()
|
||||
|
||||
@@ -249,9 +249,9 @@ class Throbber(wx.Panel):
|
||||
def SetFont(self, font):
|
||||
"""
|
||||
Set the font for the label.
|
||||
|
||||
|
||||
:param `font`: the :class:`wx.Font` to use
|
||||
|
||||
|
||||
"""
|
||||
wx.Panel.SetFont(self, font)
|
||||
self.SetLabel(self.label)
|
||||
@@ -292,9 +292,9 @@ class Throbber(wx.Panel):
|
||||
def SetCurrent(self, current):
|
||||
"""
|
||||
Set current image.
|
||||
|
||||
|
||||
:param int `current`: the index to the current image
|
||||
|
||||
|
||||
"""
|
||||
running = self.Running()
|
||||
if not running:
|
||||
@@ -306,9 +306,9 @@ class Throbber(wx.Panel):
|
||||
def SetRest(self, rest):
|
||||
"""
|
||||
Set rest image.
|
||||
|
||||
|
||||
:param int `rest`: the index for the rest frame.
|
||||
|
||||
|
||||
"""
|
||||
self.rest = rest
|
||||
|
||||
@@ -316,9 +316,9 @@ class Throbber(wx.Panel):
|
||||
def SetSequence(self, sequence = None):
|
||||
"""
|
||||
Order to display images in.
|
||||
|
||||
|
||||
:param `sequence`: a sequence containing the order to display images in.
|
||||
|
||||
|
||||
"""
|
||||
|
||||
# self.sequence can be changed, but it's not recommended doing it
|
||||
@@ -337,7 +337,7 @@ class Throbber(wx.Panel):
|
||||
|
||||
if running:
|
||||
self.Start()
|
||||
|
||||
|
||||
|
||||
def Increment(self):
|
||||
"""Display next image in sequence."""
|
||||
@@ -366,9 +366,9 @@ class Throbber(wx.Panel):
|
||||
def SetFrameDelay(self, frameDelay = 0.05):
|
||||
"""
|
||||
Delay between each frame.
|
||||
|
||||
|
||||
:param float `frameDelay`: the delay between frames.
|
||||
|
||||
|
||||
"""
|
||||
self.frameDelay = frameDelay
|
||||
if self.running:
|
||||
@@ -379,9 +379,9 @@ class Throbber(wx.Panel):
|
||||
def ToggleOverlay(self, state = None):
|
||||
"""
|
||||
Toggle the overlay image.
|
||||
|
||||
|
||||
:param boolean `state`: set the overlay state or if None toggle state.
|
||||
|
||||
|
||||
"""
|
||||
if state is None:
|
||||
self.showOverlay = not self.showOverlay
|
||||
@@ -393,9 +393,9 @@ class Throbber(wx.Panel):
|
||||
def ToggleLabel(self, state = None):
|
||||
"""
|
||||
Toggle the label.
|
||||
|
||||
|
||||
:param boolean `state`: set the label state or if None toggle state.
|
||||
|
||||
|
||||
"""
|
||||
if state is None:
|
||||
self.showLabel = not self.showLabel
|
||||
@@ -407,9 +407,9 @@ class Throbber(wx.Panel):
|
||||
def SetLabel(self, label):
|
||||
"""
|
||||
Change the text of the label.
|
||||
|
||||
|
||||
:param string `label`: the label text.
|
||||
|
||||
|
||||
"""
|
||||
self.label = label
|
||||
if label:
|
||||
|
||||
@@ -58,7 +58,7 @@ class Ticker(wx.Control):
|
||||
:param wx.Point `pos`: the control position. A value of (-1, -1) indicates a default position,
|
||||
chosen by either the windowing system or wxPython, depending on platform
|
||||
:param `name`: the control name
|
||||
|
||||
|
||||
"""
|
||||
wx.Control.__init__(self, parent, id=id, pos=pos, size=size, style=style, name=name)
|
||||
self.timer = wx.Timer(owner=self)
|
||||
@@ -97,9 +97,9 @@ class Ticker(wx.Control):
|
||||
def SetFPS(self, fps):
|
||||
"""
|
||||
Adjust the update speed of the ticker.
|
||||
|
||||
|
||||
:param int `fps`: frames per second.
|
||||
|
||||
|
||||
"""
|
||||
self._fps = fps
|
||||
self.Stop()
|
||||
@@ -117,9 +117,9 @@ class Ticker(wx.Control):
|
||||
"""
|
||||
Set the number of pixels per frame the ticker moves - ie,
|
||||
how "jumpy" it is.
|
||||
|
||||
|
||||
:param int `ppf`: the pixels per frame setting.
|
||||
|
||||
|
||||
"""
|
||||
self._ppf = ppf
|
||||
|
||||
@@ -132,9 +132,9 @@ class Ticker(wx.Control):
|
||||
def SetFont(self, font):
|
||||
"""
|
||||
Set the font for the control.
|
||||
|
||||
|
||||
:param wx.Font `font`: the font to be used.
|
||||
|
||||
|
||||
"""
|
||||
self._extent = (-1, -1)
|
||||
wx.Control.SetFont(self, font)
|
||||
@@ -144,9 +144,9 @@ class Ticker(wx.Control):
|
||||
"""
|
||||
Sets the direction of the ticker: right to left (rtl) or
|
||||
left to right (ltr).
|
||||
|
||||
|
||||
:param `dir`: the direction 'rtl' or 'ltr'
|
||||
|
||||
|
||||
"""
|
||||
if dir == "ltr" or dir == "rtl":
|
||||
if self._offset != 0:
|
||||
@@ -165,9 +165,9 @@ class Ticker(wx.Control):
|
||||
def SetText(self, text):
|
||||
"""
|
||||
Set the ticker text.
|
||||
|
||||
|
||||
:param string `text`: the ticker text
|
||||
|
||||
|
||||
"""
|
||||
self._text = text
|
||||
self._extent = (-1, -1)
|
||||
@@ -183,9 +183,9 @@ class Ticker(wx.Control):
|
||||
def UpdateExtent(self, dc):
|
||||
"""
|
||||
Updates the cached text extent if needed.
|
||||
|
||||
|
||||
:param wx.DC `dc`: the dc to use.
|
||||
|
||||
|
||||
"""
|
||||
if not self._text:
|
||||
self._extent = (-1, -1)
|
||||
@@ -197,9 +197,9 @@ class Ticker(wx.Control):
|
||||
def DrawText(self, dc):
|
||||
"""
|
||||
Draws the ticker text at the current offset using the provided DC.
|
||||
|
||||
|
||||
:param wx.DC `dc`: the dc to use.
|
||||
|
||||
|
||||
"""
|
||||
dc.SetTextForeground(self.GetForegroundColour())
|
||||
dc.SetFont(self.GetFont())
|
||||
@@ -215,7 +215,7 @@ class Ticker(wx.Control):
|
||||
def OnTick(self, evt):
|
||||
"""
|
||||
Handles the ``wx.EVT_TIMER`` event for :class:`Ticker`.
|
||||
|
||||
|
||||
:param `evt`: a :class:`TimerEvent` event to be processed.
|
||||
|
||||
"""
|
||||
@@ -230,9 +230,9 @@ class Ticker(wx.Control):
|
||||
def OnPaint(self, evt):
|
||||
"""
|
||||
Handles the ``wx.EVT_PAINT`` event for :class:`Ticker`.
|
||||
|
||||
|
||||
:param `evt`: a :class:`PaintEvent` event to be processed.
|
||||
|
||||
|
||||
"""
|
||||
dc = wx.BufferedPaintDC(self)
|
||||
brush = wx.Brush(self.GetBackgroundColour())
|
||||
@@ -244,11 +244,11 @@ class Ticker(wx.Control):
|
||||
def OnErase(self, evt):
|
||||
"""
|
||||
Noop because of double buffering
|
||||
|
||||
|
||||
Handles the ``wx.EVT_ERASE_BACKGROUND`` event for :class:`Ticker`.
|
||||
|
||||
|
||||
:param `evt`: a :class:`EraseEvent` event to be processed.
|
||||
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@ class wxTickerXmlHandler(xrc.XmlResourceHandler):
|
||||
def __init__(self):
|
||||
xrc.XmlResourceHandler.__init__(self)
|
||||
self.AddWindowStyles()
|
||||
|
||||
|
||||
def CanHandle(self, node):
|
||||
return self.IsOfClass(node, "wxTicker")
|
||||
|
||||
|
||||
def DoCreateResource(self):
|
||||
t = Ticker(
|
||||
self.GetParentAsWindow(),
|
||||
@@ -42,7 +42,7 @@ class wxTickerXmlHandler(xrc.XmlResourceHandler):
|
||||
t.SetFPS(self.GetLong("fps"))
|
||||
if self.HasParam("direction"):
|
||||
t.SetDirection(self.GetText("direction"))
|
||||
|
||||
|
||||
self.SetupWindow(t) # handles font, bg/fg color
|
||||
return t
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ def AdjustRectToScreen(rect, adjust=(0,0)):
|
||||
|
||||
:rtype: `rect`
|
||||
"""
|
||||
|
||||
|
||||
assert isinstance(rect, wx.Rect)
|
||||
if -1 in rect.Get():
|
||||
# bail out if there are any -1's in the dimensions
|
||||
@@ -74,7 +74,7 @@ def AdjustRectToScreen(rect, adjust=(0,0)):
|
||||
if rect.top < ca.top:
|
||||
rect.height -= (ca.top - rect.top)
|
||||
rect.top = ca.top
|
||||
|
||||
|
||||
# make final adjustments if needed
|
||||
adjust = wx.Size(*adjust)
|
||||
if rect.width > (ca.width - adjust.width):
|
||||
|
||||
@@ -24,8 +24,8 @@ def wordwrap(text, width, dc, breakLongWords=True, margin=0):
|
||||
wrapped_lines = []
|
||||
text = text.split('\n')
|
||||
for line in text:
|
||||
pte = dc.GetPartialTextExtents(line)
|
||||
wid = ( width - (2*margin+1)*dc.GetTextExtent(' ')[0]
|
||||
pte = dc.GetPartialTextExtents(line)
|
||||
wid = ( width - (2*margin+1)*dc.GetTextExtent(' ')[0]
|
||||
- max([0] + [pte[i]-pte[i-1] for i in range(1,len(pte))]) )
|
||||
idx = 0
|
||||
start = 0
|
||||
@@ -62,12 +62,12 @@ if __name__ == '__main__':
|
||||
self.tc = wx.TextCtrl(self, -1, "", (20,20), (150,150), wx.TE_MULTILINE)
|
||||
self.Bind(wx.EVT_TEXT, self.OnDoUpdate, self.tc)
|
||||
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||
|
||||
|
||||
|
||||
def OnSize(self, evt):
|
||||
wx.CallAfter(self.OnDoUpdate, None)
|
||||
|
||||
|
||||
|
||||
|
||||
def OnDoUpdate(self, evt):
|
||||
WIDTH = self.GetSize().width - 220
|
||||
HEIGHT = 200
|
||||
|
||||
Reference in New Issue
Block a user