- Phoenix-port of another part of the AGW library, including `KnobCtrl`, `MultiDirDialog`, `PeakMeterCtrl`, `PyCollapsiblePane` and `PyGauge`. Unittests and documentation updated to Phoenix standards;
- Modified some methods names in the unittest for previously committed AGW widgets.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@72116 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Andrea Gavana
2012-07-16 21:05:36 +00:00
parent 6bfa39aff0
commit bb9bd6c9b8
20 changed files with 926 additions and 184 deletions

View File

@@ -41,7 +41,7 @@ class lib_agw_floatspin_Tests(wtc.WidgetTestCase):
self.assertEqual(floatspin.GetIncrement(), FS.FixedPoint(str(0.01), 20))
def test_lib_agw_floatspinConstantsExists(self):
def test_lib_agw_floatspinConstantsExist(self):
FS.DEFAULT_PRECISION
FS.FS_CENTRE
FS.FS_LEFT

View File

@@ -39,7 +39,7 @@ class lib_agw_foldpanelbar_Tests(wtc.WidgetTestCase):
self.assertTrue(not foldpanel.IsExpanded())
def test_lib_agw_foldpanelbarConstantsExists(self):
def test_lib_agw_foldpanelbarConstantsExist(self):
FPB.CAPTIONBAR_FILLED_RECTANGLE
FPB.CAPTIONBAR_GRADIENT_H
FPB.CAPTIONBAR_GRADIENT_V

View File

@@ -43,7 +43,7 @@ class lib_agw_fourwaysplitter_Tests(wtc.WidgetTestCase):
self.assertTrue(not splitter.GetWindow(index).IsShown())
def test_lib_agw_fourwaysplitterConstantsExists(self):
def test_lib_agw_fourwaysplitterConstantsExist(self):
FWS.FLAG_CHANGED
FWS.FLAG_PRESSED
FWS.NOWHERE

View File

@@ -30,7 +30,7 @@ class lib_agw_genericmessagedialog_Tests(wtc.WidgetTestCase):
self.assertEqual(dlg.GetFullMessage(), '%s\n\n%s'%(dlg.GetMessage(), dlg.GetExtendedMessage()))
def test_lib_agw_genericmessagedialogConstantsExists(self):
def test_lib_agw_genericmessagedialogConstantsExist(self):
GMD.BUTTON_SIZER_FLAGS
GMD.GMD_DEFAULT
GMD.GMD_USE_AQUABUTTONS

View File

@@ -48,7 +48,7 @@ class lib_agw_hypertreelist_Tests(wtc.WidgetTestCase):
tree.SetColumnEditable(0, True)
self.assertTrue(tree.IsColumnEditable(0))
def test_lib_agw_hypertreelistConstantsExists(self):
def test_lib_agw_hypertreelistConstantsExist(self):
HTL.TR_ALIGN_WINDOWS
HTL.TR_AUTO_CHECK_CHILD
HTL.TR_AUTO_CHECK_PARENT

View File

@@ -0,0 +1,46 @@
import imp_unittest, unittest
import wtc
import wx
import wx.lib.agw.knobctrl as KC
#---------------------------------------------------------------------------
class lib_agw_knobctrl_Tests(wtc.WidgetTestCase):
def test_lib_agw_knobctrlCtor(self):
knobctrl = KC.KnobCtrl(self.frame, size=(100, 100))
def test_lib_agw_knobctrlMethods(self):
knobctrl = KC.KnobCtrl(self.frame, size=(100, 100))
knobctrl.SetTags(range(0, 151, 10))
knobctrl.SetAngularRange(-45, 225)
knobctrl.SetValue(45)
# Some methods tests...
self.assertEqual(knobctrl.GetAngularRange(), (-45, 225))
self.assertEqual(knobctrl.GetTags(), range(0, 151, 10))
# Should not be possible...
knobctrl.SetValue(-10)
self.assertEqual(knobctrl.GetValue(), 45)
self.assertEqual(knobctrl.GetMinValue(), 0)
self.assertEqual(knobctrl.GetMaxValue(), 150)
def test_lib_agw_knobctrlConstantsExist(self):
KC.KC_BUFFERED_DC
def test_lib_agw_knobctrlEvents(self):
KC.EVT_KC_ANGLE_CHANGED
KC.EVT_KC_ANGLE_CHANGING
KC.wxEVT_KC_ANGLE_CHANGED
KC.wxEVT_KC_ANGLE_CHANGING
#---------------------------------------------------------------------------
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,31 @@
import imp_unittest, unittest
import wtc
import wx
import wx.lib.agw.multidirdialog as MDD
#---------------------------------------------------------------------------
class lib_agw_multidirdialog_Tests(wtc.WidgetTestCase):
def test_lib_agw_multidirdialogCtor(self):
dlg = MDD.MultiDirDialog(self.frame, title="Custom MultiDirDialog",
agwStyle=MDD.DD_MULTIPLE|MDD.DD_DIR_MUST_EXIST)
def test_lib_agw_multidirdialogMethods(self):
dlg = MDD.MultiDirDialog(self.frame, title="Custom MultiDirDialog",
agwStyle=MDD.DD_MULTIPLE|MDD.DD_DIR_MUST_EXIST)
self.assertTrue(dlg.GetPaths() == [])
def test_lib_agw_multidirdialogConstantsExist(self):
MDD.DD_DEFAULT_STYLE
MDD.DD_DIR_MUST_EXIST
MDD.DD_MULTIPLE
MDD.DD_NEW_DIR_BUTTON
#---------------------------------------------------------------------------
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,54 @@
import imp_unittest, unittest
import wtc
import wx
import random
import wx.lib.agw.peakmeter as PM
#---------------------------------------------------------------------------
class lib_agw_peakmeter_Tests(wtc.WidgetTestCase):
def get_data(self):
arrayData = []
for i in range(15):
nRandom = random.randint(0, 100)
arrayData.append(nRandom)
return arrayData
def test_lib_agw_peakmeterCtor(self):
peak = PM.PeakMeterCtrl(self.frame, -1, style=wx.SIMPLE_BORDER, agwStyle=PM.PM_VERTICAL)
peak.SetMeterBands(10, 15)
peak.SetRangeValue(1, 10, 20)
peak.SetData(self.get_data(), 0, 15)
def test_lib_agw_peakmeterMethods(self):
peak = PM.PeakMeterCtrl(self.frame, -1, style=wx.SIMPLE_BORDER, agwStyle=PM.PM_HORIZONTAL)
peak.SetMeterBands(10, 15)
peak.SetRangeValue(1, 10, 20)
peak.SetData(self.get_data(), 0, 15)
self.assertTrue(peak.GetFalloffEffect())
self.assertTrue(not peak.IsGridVisible())
self.assertTrue(peak.GetAGWWindowStyleFlag() & PM.PM_HORIZONTAL == 0)
self.assertEqual(peak.GetRangeValue(), (1, 10, 20))
def test_lib_agw_peakmeterConstantsExist(self):
PM.BAND_DEFAULT
PM.BAND_PERCENT
PM.DEFAULT_SPEED
PM.FALL_INCREASEBY
PM.GRID_INCREASEBY
PM.LEDS_DEFAULT
PM.PM_HORIZONTAL
PM.PM_VERTICAL
#---------------------------------------------------------------------------
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,44 @@
import imp_unittest, unittest
import wtc
import wx
import wx.lib.agw.piectrl as PC
#---------------------------------------------------------------------------
class lib_agw_piectrl_Tests(wtc.WidgetTestCase):
def test_lib_agw_piectrlCtor(self):
pie = PC.PieCtrl(self.frame)
def test_lib_agw_piectrlMethods(self):
# create a simple PieCtrl with 2 sectors
mypie = PC.PieCtrl(self.frame)
part1 = PC.PiePart()
part1.SetLabel("Label 1")
part1.SetValue(300)
part1.SetColour(wx.Colour(200, 50, 50))
mypie._series.append(part1)
part2 = PC.PiePart()
part2.SetLabel("Label 2")
part2.SetValue(200)
part2.SetColour(wx.Colour(50, 200, 50))
mypie._series.append(part2)
self.assertEqual(part1.GetLabel(), 'Label 1')
self.assertEqual(part2.GetLabel(), 'Label 2')
self.assertEqual(part1.GetValue(), 300)
self.assertEqual(part2.GetValue(), 200)
self.assertEqual(mypie.GetRotationAngle(), 0)
#---------------------------------------------------------------------------
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,27 @@
import imp_unittest, unittest
import wtc
import wx
import wx.lib.agw.pybusyinfo as PBI
#---------------------------------------------------------------------------
class lib_agw_pybusyinfo_Tests(wtc.WidgetTestCase):
def test_lib_agw_pybusyinfoCtor(self):
message = 'Please wait...'
busy = PBI.PyBusyInfo(message, parent=self.frame, title='Really Busy')
wx.Yield()
self.assertTrue(busy._infoFrame.IsShown())
for indx in xrange(5):
wx.MilliSleep(10)
del busy
#---------------------------------------------------------------------------
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,47 @@
import imp_unittest, unittest
import wtc
import wx
import wx.lib.agw.pycollapsiblepane as PCP
#---------------------------------------------------------------------------
class lib_agw_pycollapsiblepane_Tests(wtc.WidgetTestCase):
def test_lib_agw_pycollapsiblepaneCtor(self):
pane = PCP.PyCollapsiblePane(self.frame, label='Some Data',
style=wx.CP_DEFAULT_STYLE|wx.CP_NO_TLW_RESIZE)
def test_lib_agw_pycollapsiblepaneMethods(self):
pane = PCP.PyCollapsiblePane(self.frame, label='Some Data',
style=wx.CP_DEFAULT_STYLE|wx.CP_NO_TLW_RESIZE)
content = pane.GetPane()
nameLbl = wx.StaticText(content, -1, "Name:")
name = wx.TextCtrl(content, -1, "");
# Some methods tests...
self.assertTrue(pane.GetWindowStyleFlag() & wx.CP_USE_STATICBOX == 0)
self.assertEqual(pane.GetLabel(), 'Some Data')
self.assertTrue(pane.IsCollapsed())
self.assertTrue(not pane.IsExpanded())
pane.Expand()
self.assertTrue(pane.IsExpanded())
def test_lib_agw_pycollapsiblepaneConstantsExist(self):
PCP.CP_DEFAULT_STYLE
PCP.CP_GTK_EXPANDER
PCP.CP_LINE_ABOVE
PCP.CP_NO_TLW_RESIZE
PCP.CP_USE_STATICBOX
def test_lib_agw_pycollapsiblepaneEvents(self):
PCP.EVT_COLLAPSIBLEPANE_CHANGED
#---------------------------------------------------------------------------
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,36 @@
import imp_unittest, unittest
import wtc
import wx
import wx.lib.agw.pygauge as PG
#---------------------------------------------------------------------------
class lib_agw_pygauge_Tests(wtc.WidgetTestCase):
def test_lib_agw_pygaugeCtor(self):
gauge = PG.PyGauge(self.frame, style=wx.GA_HORIZONTAL)
def test_lib_agw_pygaugeMethods(self):
gauge = PG.PyGauge(self.frame, range=120, style=wx.GA_HORIZONTAL)
gauge.SetValue([20, 80])
gauge.SetBarColor([wx.RED, wx.BLUE])
gauge.SetBackgroundColour(wx.WHITE)
gauge.SetBorderColor(wx.BLACK)
gauge.SetBorderPadding(2)
# Some methods tests...
self.assertEqual(gauge.GetValue(), 20)
self.assertEqual(gauge.GetBarColour(), wx.Colour('red'))
self.assertEqual(gauge.GetBackgroundColour(), wx.Colour('white'))
self.assertEqual(gauge.GetBorderColour(), wx.Colour('black'))
self.assertEqual(gauge.GetRange(), 120)
#---------------------------------------------------------------------------
if __name__ == '__main__':
unittest.main()

View File

@@ -5,7 +5,7 @@
# Python Code By:
#
# Andrea Gavana, @ 12 March 2012
# Latest Revision: 22 Mar 2012, 21.00 GMT
# Latest Revision: 16 Jul 2012, 15.00 GMT
#
#
# TODO List/Caveats
@@ -21,6 +21,7 @@
#
# Or, Obviously, To The wxPython Mailing List!!!
#
# Tags: phoenix-port, unittest, documented
#
# End Of Comments
# --------------------------------------------------------------------------- #
@@ -91,7 +92,7 @@ The simplest possible example of using this class would be::
self._infoBar = IB.InfoBar(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.AddF(self._infoBar, wx.SizerFlags().Expand())
sizer.Add(self._infoBar, wx.SizerFlags().Expand())
panel = wx.Panel(self)
sizer.Add(panel, 1, wx.EXPAND)
@@ -149,14 +150,14 @@ License And Version
:class:`InfoBar` control is distributed under the wxPython license.
Latest Revision: Andrea Gavana @ 22 Mar 2012, 21.00 GMT
Latest Revision: Andrea Gavana @ 16 Jul 2012, 15.00 GMT
Version 0.2
Version 0.3
"""
# Version Info
__version__ = "0.2"
__version__ = "0.3"
# Start the imports
import wx
@@ -165,7 +166,7 @@ import wx
# is managed by PyAUI or wx.aui, in which case the handling
# of the showing/dismissing is done a bit differently
import wx.aui
import aui.framemanager as framemanager
from aui import framemanager as framemanager
# These are for the AutoWrapStaticText class
from wx.lib.wordwrap import wordwrap
@@ -211,13 +212,13 @@ def GetCloseButtonBitmap(win, size, colBg, flags=0):
``wx.CONTROL_ISDEFAULT`` bit set.
"""
bmp = wx.EmptyBitmap(*size)
bmp = wx.Bitmap(*size)
dc = wx.MemoryDC()
dc.SelectObject(bmp)
dc.SetBackground(wx.Brush(colBg))
dc.Clear()
wx.RendererNative.Get().DrawTitleBarBitmap(win, dc, wx.RectS(size), wx.TITLEBAR_BUTTON_CLOSE, flags)
wx.RendererNative.Get().DrawTitleBarBitmap(win, dc, wx.Rect(size), wx.TITLEBAR_BUTTON_CLOSE, flags)
dc.SelectObject(wx.NullBitmap)
return bmp
@@ -305,7 +306,7 @@ class AutoWrapStaticText(StaticText):
:param bool `wrapped`: ``True`` if this method was called by the developer using :meth:`~AutoWrapStaticText.SetLabel`,
``False`` if it comes from the :meth:`~AutoWrapStaticText.OnSize` event handler.
:note: Reimplemented from :class:`PyControl`.
:note: Reimplemented from :class:`Control`.
"""
if not wrapped:
@@ -318,7 +319,7 @@ class AutoWrapStaticText(StaticText):
# Implementation
# ============================================================================
class InfoBar(wx.PyControl):
class InfoBar(wx.Control):
"""
An info bar is a transient window shown at top or bottom of its parent window to display
non-critical information to the user.
@@ -343,7 +344,7 @@ class InfoBar(wx.PyControl):
:param string `name`: the control name.
"""
wx.PyControl.__init__(self, parent, id, pos, size, style|wx.BORDER_NONE, name=name)
wx.Control.__init__(self, parent, id, pos, size, style|wx.BORDER_NONE, name=name)
self.SetInitialSize(size)
self.Init()
@@ -379,7 +380,7 @@ class InfoBar(wx.PyControl):
self._button.SetBitmapCurrent(GetCloseButtonBitmap(self, sizeBmp, colBg, wx.CONTROL_CURRENT))
self._button.SetBackgroundColour(colBg)
self._button.SetToolTipString(_("Hide this notification message."))
self._button.SetToolTip(_("Hide this notification message."))
# center the text inside the sizer with an icon to the left of it and a
# button at the very right
@@ -387,10 +388,10 @@ class InfoBar(wx.PyControl):
# NB: AddButton() relies on the button being the last control in the sizer
# and being preceded by a spacer
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.AddF(self._icon, wx.SizerFlags().Centre().Border())
sizer.Add(self._icon, wx.SizerFlags().Centre().Border())
sizer.Add(self._text, 2000000, wx.ALIGN_CENTER_VERTICAL)
sizer.AddStretchSpacer()
sizer.AddF(self._button, wx.SizerFlags().Centre().Border())
sizer.Add(self._button, wx.SizerFlags().Centre().Border())
self.SetSizer(sizer)
self.Bind(wx.EVT_BUTTON, self.OnButton)
@@ -421,7 +422,7 @@ class InfoBar(wx.PyControl):
:note: Reimplemented from :class:`Window`.
"""
if not wx.PyControl.SetFont(self, font):
if not wx.Control.SetFont(self, font):
return False
# check that we're not called before Create()
@@ -578,14 +579,14 @@ class InfoBar(wx.PyControl):
# without really showing it
self.GetParent().Freeze()
wx.PyControl.Show(self)
wx.Control.Show(self)
# adjust the parent layout to account for us
self.UpdateParent()
# reset the flag back before really showing the window or it wouldn't be
# shown at all because it would believe itself already visible
wx.PyControl.Show(self, False)
wx.Control.Show(self, False)
self.GetParent().Thaw()
# finally do really show the window.
@@ -625,16 +626,16 @@ class InfoBar(wx.PyControl):
else: # do show an icon
bitmap = wx.ArtProvider.GetBitmap(FLAGS2ART[flags], wx.ART_BUTTON)
iconSize = bitmap.GetWidth() + wx.SizerFlags().Border().GetBorderInPixels()
iconSize = bitmap.GetWidth() + wx.SizerFlags().Border().GetDefaultBorder()
self._icon.SetBitmap(bitmap)
self._icon.Show()
# notice the use of EscapeMnemonics() to ensure that "&" come through
# correctly
self._text.SetLabel(wx.PyControl.EscapeMnemonics(msg))
self._text.SetLabel(wx.Control.EscapeMnemonics(msg))
parentSize = self.GetParent().GetSize()
self._text.Wrap(parentSize.x - iconSize - wx.SizerFlags().Border().GetBorderInPixels())
self._text.Wrap(parentSize.x - iconSize - wx.SizerFlags().Border().GetDefaultBorder())
# then show this entire window if not done yet
if not self.IsShown():
@@ -709,7 +710,7 @@ class InfoBar(wx.PyControl):
# smaller buttons look better in the(narrow)info bar under OS X
button.SetWindowVariant(wx.WINDOW_VARIANT_SMALL)
sizer.AddF(button, wx.SizerFlags().Centre().DoubleBorder())
sizer.Add(button, wx.SizerFlags().Centre().DoubleBorder())
if self.IsShown():
self.UpdateParent()
@@ -829,3 +830,43 @@ class InfoBar(wx.PyControl):
return self._effectDuration
if __name__ == '__main__':
import wx
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, 'InfoBar Demo')
self._infoBar = InfoBar(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self._infoBar, wx.SizerFlags().Expand())
panel = wx.Panel(self)
sizer.Add(panel, 1, wx.EXPAND)
# ... Add other frame controls to the sizer ...
self.SetSizer(sizer)
wx.CallLater(2000, self.SomeMethod)
def SomeMethod(self):
self._infoBar.ShowMessage("Something happened", wx.ICON_INFORMATION)
# our normal wxApp-derived class, as usual
app = wx.App(0)
frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()

View File

@@ -2,7 +2,7 @@
# KNOBCTRL wxPython IMPLEMENTATION
#
# Andrea Gavana, @ 03 Nov 2006
# Latest Revision: 17 Aug 2011, 15.00 GMT
# Latest Revision: 16 Jul 2012, 15.00 GMT
#
#
# TODO List
@@ -17,6 +17,7 @@
#
# Or, Obviously, To The wxPython Mailing List!!!
#
# Tags: phoenix-port, unittest, documented
#
# End Of Comments
# --------------------------------------------------------------------------------- #
@@ -134,9 +135,9 @@ License And Version
:class:`KnobCtrl` is distributed under the wxPython license.
Latest Revision: Andrea Gavana @ 17 Aug 2011, 15.00 GMT
Latest Revision: Andrea Gavana @ 16 Jul 2012, 15.00 GMT
Version 0.3
Version 0.4
"""
@@ -163,7 +164,7 @@ EVT_KC_ANGLE_CHANGED = wx.PyEventBinder(wxEVT_KC_ANGLE_CHANGED, 1)
# Class KnobCtrlEvent
# ---------------------------------------------------------------------------- #
class KnobCtrlEvent(wx.PyCommandEvent):
class KnobCtrlEvent(wx.CommandEvent):
"""
Represent details of the events that the :class:`KnobCtrl` object sends.
"""
@@ -177,7 +178,7 @@ class KnobCtrlEvent(wx.PyCommandEvent):
:param `eventId`: the event identifier.
"""
wx.PyCommandEvent.__init__(self, eventType, eventId)
wx.CommandEvent.__init__(self, eventType, eventId)
def SetOldValue(self, oldValue):
@@ -299,13 +300,13 @@ class BufferedWindow(wx.Window):
# The Buffer init is done here, to make sure the buffer is always
# the same size as the Window
self.Width, self.Height = self.GetClientSizeTuple()
self.Width, self.Height = self.GetClientSize()
# Make new off screen bitmap: this bitmap will always have the
# current drawing in it, so it can be used to save the image to
# a file, or whatever.
# This seems required on MacOS, it doesn't like wx.EmptyBitmap with
# This seems required on MacOS, it doesn't like wx.Bitmap with
# size = (0, 0)
# Thanks to Gerard Grazzini
@@ -315,7 +316,7 @@ class BufferedWindow(wx.Window):
if self.Height == 0:
self.Height = 1
self._Buffer = wx.EmptyBitmap(self.Width, self.Height)
self._Buffer = wx.Bitmap(self.Width, self.Height)
memory = wx.MemoryDC()
memory.SelectObject(self._Buffer)
@@ -323,10 +324,10 @@ class BufferedWindow(wx.Window):
memory.SetPen(wx.TRANSPARENT_PEN)
memory.Clear()
minradius = min(0.9*self.Width/2, 0.9*self.Height/2)
memory.DrawCircle(self.Width/2, self.Height/2, minradius)
minradius = min(0.9*self.Width/2.0, 0.9*self.Height/2.0)
memory.DrawCircle(self.Width//2, self.Height//2, minradius)
memory.SelectObject(wx.NullBitmap)
self._region = wx.RegionFromBitmapColour(self._Buffer, self.GetBackgroundColour())
self._region = wx.Region(self._Buffer, self.GetBackgroundColour())
self._minradius = minradius
self.UpdateDrawing()
@@ -382,7 +383,7 @@ class KnobCtrl(BufferedWindow):
"""
self._agwStyle = agwStyle
self._knobcolour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_3DFACE)
self._knobcolour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DFACE)
self._startcolour = wx.WHITE
self._endcolour = wx.Colour(170, 170, 150)
@@ -586,7 +587,7 @@ class KnobCtrl(BufferedWindow):
if size.x < 21 or size.y < 21:
return
dc.SetClippingRegionAsRegion(self._region)
dc.SetClippingRegion(self._region.GetBox())
self.DrawDiagonalGradient(dc, size)
self.DrawInsetCircle(dc, self._knobcolour)
dc.DestroyClippingRegion()
@@ -644,8 +645,8 @@ class KnobCtrl(BufferedWindow):
dxi = math.cos(angle)*((width - xshift + tagLen - 6)/2.0 - tagLen)
dyi = math.sin(angle)*((height - yshift + tagLen - 6)/2.0 - tagLen)
dc.DrawLine(width/2 - sxi, height/2 - syi,
width/2 - dxi, height/2 - dyi)
dc.DrawLine(width//2 - sxi, height//2 - syi,
width//2 - dxi, height//2 - dyi)
def DrawDiagonalGradient(self, dc, size):
@@ -673,7 +674,7 @@ class KnobCtrl(BufferedWindow):
rf, gf, bf = 0, 0, 0
dc.SetBrush(wx.TRANSPARENT_BRUSH)
for ii in xrange(0, maxsize, 2):
for ii in range(0, maxsize, 2):
currCol = (r1 + rf, g1 + gf, b1 + bf)
dc.SetPen(wx.Pen(currCol, 2))
dc.DrawLine(0, ii+2, ii+2, 0)
@@ -681,7 +682,7 @@ class KnobCtrl(BufferedWindow):
gf = gf + gstep
bf = bf + bstep
for ii in xrange(0, maxsize, 2):
for ii in range(0, maxsize, 2):
currCol = (r1 + rf, g1 + gf, b1 + bf)
dc.SetPen(wx.Pen(currCol, 2))
dc.DrawLine(ii+2, maxsize, maxsize, ii+2)
@@ -750,7 +751,7 @@ class KnobCtrl(BufferedWindow):
"""
self._knobcenter = self.CircleCoords(self._minradius*0.8, self.GetTrackPosition(),
self.Width/2, self.Height/2)
self.Width//2, self.Height//2)
cx, cy = self._knobcenter
r = self._knobradius
@@ -758,13 +759,13 @@ class KnobCtrl(BufferedWindow):
p1 = wx.Pen(self.OffsetColour(pencolour, -70), 2)
p2 = wx.Pen(self.OffsetColour(pencolour, 10), 1)
pt1 = wx.Point(cx-r*math.sqrt(2)/2, cy+r*math.sqrt(2)/2)
pt2 = wx.Point(cx+r*math.sqrt(2)/2, cy-r*math.sqrt(2)/2)
pt1 = wx.Point(cx-r*math.sqrt(2)/2.0, cy+r*math.sqrt(2)/2.0)
pt2 = wx.Point(cx+r*math.sqrt(2)/2.0, cy-r*math.sqrt(2)/2.0)
dc.SetPen(p2)
dc.DrawArcPoint(pt1, pt2, (cx, cy))
dc.DrawArc(pt1, pt2, (cx, cy))
dc.SetPen(p1)
dc.DrawArcPoint(pt2, pt1, (cx, cy))
dc.DrawArc(pt2, pt1, (cx, cy))
def DrawBoundingCircle(self, dc, size):
@@ -775,10 +776,10 @@ class KnobCtrl(BufferedWindow):
:param `size`: the control size.
"""
radius = 0.9*min(size.x, size.y)/2
radius = 0.9*min(size.x, size.y)/2.0
dc.SetBrush(wx.TRANSPARENT_BRUSH)
dc.SetPen(wx.Pen(self._boundingcolour))
dc.DrawCircle(self.Width/2, self.Height/2, radius)
dc.DrawCircle(self.Width//2, self.Height//2, radius)
def CircleCoords(self, radius, angle, centerX, centerY):
@@ -890,8 +891,8 @@ class KnobCtrl(BufferedWindow):
width, height = self.GetSize()
ang = 0
y = (height/2 - float(cy))/(height/2)
x = (float(cx) - width/2)/(height/2)
y = (height/2.0 - float(cy))/(height/2.0)
x = (float(cx) - width/2.0)/(height/2.0)
ang = ang - math.atan2(-y, -x)
@@ -900,3 +901,45 @@ class KnobCtrl(BufferedWindow):
return ang
if __name__ == '__main__':
import wx
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "KnobCtrl Demo")
panel = wx.Panel(self)
knob1 = KnobCtrl(panel, -1, size=(100, 100))
knob2 = KnobCtrl(panel, -1, size=(100, 100))
knob1.SetTags(range(0, 151, 10))
knob1.SetAngularRange(-45, 225)
knob1.SetValue(45)
knob2.SetTags(range(0, 151, 10))
knob2.SetAngularRange(0, 270)
knob2.SetValue(100)
main_sizer = wx.BoxSizer(wx.VERTICAL)
main_sizer.Add(knob1, 0, wx.EXPAND|wx.ALL, 20)
main_sizer.Add(knob2, 0, wx.EXPAND|wx.ALL, 20)
panel.SetSizer(main_sizer)
main_sizer.Layout()
# our normal wxApp-derived class, as usual
app = wx.App(0)
frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()

View File

@@ -2,7 +2,7 @@
# MULTIDIRDIALOG wxPython IMPLEMENTATION
#
# Andrea Gavana, @ 07 October 2008
# Latest Revision: 14 Mar 2012, 21.00 GMT
# Latest Revision: 16 Jul 2012, 15.00 GMT
#
#
# TODO List
@@ -21,6 +21,7 @@
#
# Or, obviously, to the wxPython mailing list!!!
#
# Tags: phoenix-port, unittest, documented
#
# End Of Comments
# --------------------------------------------------------------------------------- #
@@ -91,7 +92,7 @@ This class supports the following window styles:
===================== =========== ==================================================
Window Styles Hex Value Description
===================== =========== ==================================================
``DD_NEW_DIR_BUTTON`` 0x000 Enable/disable the "Make new folder" button
``DD_NEW_DIR_BUTTON`` 0x080 Enable/disable the "Make new folder" button
``DD_DIR_MUST_EXIST`` 0x200 The dialog will allow the user to choose only an existing folder. When this style is not given, a "Create new directory" button is added to the dialog (on Windows) or some other way is provided to the user to type the name of a new folder.
``DD_MULTIPLE`` 0x400 Allows the selection of multiple folders.
===================== =========== ==================================================
@@ -108,9 +109,9 @@ License And Version
:class:`MultiDirDialog` is distributed under the wxPython license.
Latest Revision: Andrea Gavana @ 14 Mar 2012, 21.00 GMT
Latest Revision: Andrea Gavana @ 16 Jul 2012, 15.00 GMT
Version 0.3
Version 0.4
"""
@@ -127,7 +128,7 @@ DD_DEFAULT_STYLE = wx.DD_DEFAULT_STYLE
""" Equivalent to a combination of ``wx.DEFAULT_DIALOG_STYLE`` and ``wx.RESIZE_BORDER``. """
DD_DIR_MUST_EXIST = wx.DD_DIR_MUST_EXIST
""" The dialog will allow the user to choose only an existing folder. When this style is not given, a "Create new directory" button is added to the dialog (on Windows) or some other way is provided to the user to type the name of a new folder. """
DD_NEW_DIR_BUTTON = wx.DD_NEW_DIR_BUTTON
DD_NEW_DIR_BUTTON = 0x080
""" The `Make New Folder` button will be displayed. """
_ = wx.GetTranslation
@@ -314,7 +315,7 @@ class MultiDirDialog(wx.Dialog):
===================== =========== ==================================================
Window Styles Hex Value Description
===================== =========== ==================================================
``DD_NEW_DIR_BUTTON`` 0x000 Enable/disable the "Make new folder" button
``DD_NEW_DIR_BUTTON`` 0x080 Enable/disable the "Make new folder" button
``DD_DIR_MUST_EXIST`` 0x200 The dialog will allow the user to choose only an existing folder. When this style is not given, a "Create new directory" button is added to the dialog (on Windows) or some other way is provided to the user to type the name of a new folder.
``DD_MULTIPLE`` 0x400 Allows the selection of multiple folders.
===================== =========== ==================================================
@@ -582,3 +583,30 @@ class MultiDirDialog(wx.Dialog):
event.Skip()
if __name__ == '__main__':
import os, sys
import wx
# Our normal wxApp-derived class, as usual
app = wx.App(0)
dlg = MultiDirDialog(None, title="Custom MultiDirDialog", defaultPath=os.getcwd(),
agwStyle=DD_MULTIPLE|DD_DIR_MUST_EXIST)
if dlg.ShowModal() != wx.ID_OK:
print("You Cancelled The Dialog!")
dlg.Destroy()
sys.exit()
paths = dlg.GetPaths()
for indx, path in enumerate(paths):
print(("Path %d: %s"%(indx+1, path)))
dlg.Destroy()
app.MainLoop()

View File

@@ -2,7 +2,7 @@
# PEAKMETERCTRL wxPython IMPLEMENTATION
#
# Andrea Gavana, @ 07 October 2008
# Latest Revision: 14 Mar 2012, 21.00 GMT
# Latest Revision: 16 Jul 2012, 15.00 GMT
#
#
# TODO List
@@ -20,6 +20,7 @@
#
# Or, obviously, to the wxPython mailing list!!!
#
# Tags: phoenix-port, unittest, documented
#
# End Of Comments
# --------------------------------------------------------------------------------- #
@@ -87,10 +88,10 @@ Usage example::
def Start(self):
''' Starts the PeakMeterCtrl. '''
self.timer.Start(1000/2) # 2 fps
self.timer.Start(1000//2) # 2 fps
self.vertPeak.Start(1000/18) # 18 fps
self.horzPeak.Start(1000/20) # 20 fps
self.vertPeak.Start(1000//18) # 18 fps
self.horzPeak.Start(1000//20) # 20 fps
def OnTimer(self, event):
@@ -155,9 +156,9 @@ License And Version
:class:`PeakMeterCtrl` is distributed under the wxPython license.
Latest Revision: Andrea Gavana @ 14 Mar 2012, 21.00 GMT
Latest Revision: Andrea Gavana @ 16 Jul 2012, 21.00 GMT
Version 0.3
Version 0.4
"""
@@ -284,7 +285,7 @@ class PeakMeterData(object):
return self._value < pm._value
class PeakMeterCtrl(wx.PyControl):
class PeakMeterCtrl(wx.Control):
""" The main :class:`PeakMeterCtrl` implementation. """
def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.DefaultSize,
@@ -298,7 +299,7 @@ class PeakMeterCtrl(wx.PyControl):
chosen by either the windowing system or wxPython, depending on platform;
:param `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 `style`: the underlying :class:`PyControl` window style;
:param `style`: the underlying :class:`Control` window style;
:param `agwStyle`: the AGW-specific window style, which can be one of the following bits:
================= =========== ==================================================
@@ -310,7 +311,7 @@ class PeakMeterCtrl(wx.PyControl):
"""
wx.PyControl.__init__(self, parent, id, pos, size, style)
wx.Control.__init__(self, parent, id, pos, size, style)
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
self._agwStyle = agwStyle
@@ -383,7 +384,7 @@ class PeakMeterCtrl(wx.PyControl):
""" Resets the :class:`PeakMeterCtrl`. """
# Initialize vector
for i in xrange(self._numBands):
for i in range(self._numBands):
pm = PeakMeterData(self._maxValue, self._maxValue, self._speed)
self._meterData.append(pm)
@@ -404,10 +405,10 @@ class PeakMeterCtrl(wx.PyControl):
you may wish to call :meth:`Window.ClearBackground` or :meth:`Window.Refresh` after
calling this function.
:note: Overridden from :class:`PyControl`.
:note: Overridden from :class:`Control`.
"""
wx.PyControl.SetBackgroundColour(self, colourBgnd)
wx.Control.SetBackgroundColour(self, colourBgnd)
self._clrBackground = colourBgnd
self.Refresh()
@@ -548,7 +549,7 @@ class PeakMeterCtrl(wx.PyControl):
maxSize = offset + size
for i in xrange(offset, maxSize):
for i in range(offset, maxSize):
if i < len(self._meterData):
@@ -608,14 +609,14 @@ class PeakMeterCtrl(wx.PyControl):
self.Refresh()
decValue = self._maxValue/self._ledBands
decValue = self._maxValue//self._ledBands
noChange = True
for pm in self._meterData:
if pm._value > 0:
pm._value -= (self._ledBands > 1 and [decValue] or [self._maxValue*BAND_PERCENT/100])[0]
pm._value -= (self._ledBands > 1 and [decValue] or [self._maxValue*BAND_PERCENT//100])[0]
if pm._value < 0:
pm._value = 0
@@ -646,7 +647,7 @@ class PeakMeterCtrl(wx.PyControl):
minimal size which doesn't truncate the control, for a panel - the same size
as it would have after a call to `Fit()`.
:note: Overridden from :class:`PyControl`.
:note: Overridden from :class:`Control`.
"""
# something is better than nothing...
@@ -719,25 +720,25 @@ class PeakMeterCtrl(wx.PyControl):
.. todo:: Implement falloff effect for horizontal bands.
"""
horzBands = (self._ledBands > 1 and [self._ledBands] or [self._maxValue*BAND_PERCENT/100])[0]
minHorzLimit = self._minValue*horzBands/self._maxValue
medHorzLimit = self._medValue*horzBands/self._maxValue
horzBands = (self._ledBands > 1 and [self._ledBands] or [self._maxValue*BAND_PERCENT//100])[0]
minHorzLimit = self._minValue*horzBands//self._maxValue
medHorzLimit = self._medValue*horzBands//self._maxValue
maxHorzLimit = horzBands
size = wx.Size(rect.width/horzBands, rect.height/self._numBands)
rectBand = wx.RectPS(rect.GetTopLeft(), size)
size = wx.Size(rect.width//horzBands, rect.height//self._numBands)
rectBand = wx.Rect(rect.GetTopLeft(), size)
# Draw band from top
rectBand.OffsetXY(0, rect.height-size.y*self._numBands)
rectBand.Offset(0, rect.height-size.y*self._numBands)
xDecal = (self._ledBands > 1 and [1] or [0])[0]
yDecal = (self._numBands > 1 and [1] or [0])[0]
for vert in xrange(self._numBands):
for vert in range(self._numBands):
self._value = self._meterData[vert]._value
horzLimit = self._value*horzBands/self._maxValue
horzLimit = self._value*horzBands//self._maxValue
for horz in xrange(horzBands):
for horz in range(horzBands):
rectBand.Deflate(0, yDecal)
@@ -748,12 +749,12 @@ class PeakMeterCtrl(wx.PyControl):
if self._showGrid and (horz == minHorzLimit or horz == (horzBands-1)):
points = [wx.Point() for i in xrange(2)]
points = [wx.Point() for i in range(2)]
points[0].x = rectBand.GetTopLeft().x + (rectBand.width >> 1)
points[0].y = rectBand.GetTopLeft().y - yDecal
points[1].x = points[0].x
points[1].y = rectBand.GetBottomRight().y + yDecal
dc.DrawLinePoint(points[0], points[1])
dc.DrawLine(points[0], points[1])
if horz < horzLimit:
@@ -765,13 +766,13 @@ class PeakMeterCtrl(wx.PyControl):
colourRect = self._clrHigh
dc.SetBrush(wx.Brush(colourRect))
dc.DrawRectangleRect(rectBand)
dc.DrawRectangle(rectBand)
rectBand.Inflate(0, yDecal)
rectBand.OffsetXY(size.x, 0)
rectBand.Offset(size.x, 0)
# Move to Next Vertical band
rectBand.OffsetXY(-size.x*horzBands, size.y)
rectBand.Offset(-size.x*horzBands, size.y)
def DrawVertBand(self, dc, rect):
@@ -782,26 +783,26 @@ class PeakMeterCtrl(wx.PyControl):
:param `rect`: the vertical bands client rectangle.
"""
vertBands = (self._ledBands > 1 and [self._ledBands] or [self._maxValue*BAND_PERCENT/100])[0]
minVertLimit = self._minValue*vertBands/self._maxValue
medVertLimit = self._medValue*vertBands/self._maxValue
vertBands = (self._ledBands > 1 and [self._ledBands] or [self._maxValue*BAND_PERCENT//100])[0]
minVertLimit = self._minValue*vertBands//self._maxValue
medVertLimit = self._medValue*vertBands//self._maxValue
maxVertLimit = vertBands
size = wx.Size(rect.width/self._numBands, rect.height/vertBands)
rectBand = wx.RectPS(rect.GetTopLeft(), size)
size = wx.Size(rect.width//self._numBands, rect.height//vertBands)
rectBand = wx.Rect(rect.GetTopLeft(), size)
# Draw band from bottom
rectBand.OffsetXY(0, rect.bottom-size.y)
rectBand.Offset(0, rect.bottom-size.y)
xDecal = (self._numBands > 1 and [1] or [0])[0]
yDecal = (self._ledBands > 1 and [1] or [0])[0]
for horz in xrange(self._numBands):
for horz in range(self._numBands):
self._value = self._meterData[horz]._value
vertLimit = self._value*vertBands/self._maxValue
vertLimit = self._value*vertBands//self._maxValue
rectPrev = wx.Rect(*rectBand)
for vert in xrange(vertBands):
for vert in range(vertBands):
rectBand.Deflate(xDecal, 0)
@@ -813,12 +814,12 @@ class PeakMeterCtrl(wx.PyControl):
# Draw grid line (level) bar
if self._showGrid and (vert == minVertLimit or vert == (vertBands-1)):
points = [wx.Point() for i in xrange(2)]
points = [wx.Point() for i in range(2)]
points[0].x = rectBand.GetTopLeft().x - xDecal
points[0].y = rectBand.GetTopLeft().y + (rectBand.height >> 1)
points[1].x = rectBand.GetBottomRight().x + xDecal
points[1].y = points[0].y
dc.DrawLinePoint(points[0], points[1])
dc.DrawLine(points[0], points[1])
if vert < vertLimit:
@@ -830,10 +831,10 @@ class PeakMeterCtrl(wx.PyControl):
colourRect = self._clrHigh
dc.SetBrush(wx.Brush(colourRect))
dc.DrawRectangleRect(rectBand)
dc.DrawRectangle(rectBand)
rectBand.Inflate(xDecal, 0)
rectBand.OffsetXY(0, -size.y)
rectBand.Offset(0, -size.y)
# Draw falloff effect
if self._showFalloff:
@@ -841,15 +842,90 @@ class PeakMeterCtrl(wx.PyControl):
oldPen = dc.GetPen()
pen = wx.Pen(DarkenColour(self._clrBackground, FALL_INCREASEBY))
maxHeight = size.y*vertBands
points = [wx.Point() for i in xrange(2)]
points = [wx.Point() for i in range(2)]
points[0].x = rectPrev.GetTopLeft().x + xDecal
points[0].y = rectPrev.GetBottomRight().y - self._meterData[horz]._falloff*maxHeight/self._maxValue
points[0].y = rectPrev.GetBottomRight().y - self._meterData[horz]._falloff*maxHeight//self._maxValue
points[1].x = rectPrev.GetBottomRight().x - xDecal
points[1].y = points[0].y
dc.SetPen(pen)
dc.DrawLinePoint(points[0], points[1])
dc.DrawLine(points[0], points[1])
dc.SetPen(oldPen)
# Move to Next Horizontal band
rectBand.OffsetXY(size.x, size.y*vertBands)
rectBand.Offset(size.x, size.y*vertBands)
if __name__ == '__main__':
import wx
import random
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "PeakMeterCtrl Demo")
panel = wx.Panel(self)
# Initialize Peak Meter control 1
self.vertPeak = PeakMeterCtrl(panel, -1, style=wx.SIMPLE_BORDER, agwStyle=PM_VERTICAL)
# Initialize Peak Meter control 2
self.horzPeak = PeakMeterCtrl(panel, -1, style=wx.SUNKEN_BORDER, agwStyle=PM_HORIZONTAL)
self.vertPeak.SetMeterBands(10, 15)
self.horzPeak.SetMeterBands(10, 15)
# Layout the two PeakMeterCtrl
mainSizer = wx.BoxSizer(wx.HORIZONTAL)
mainSizer.Add(self.vertPeak, 0, wx.EXPAND|wx.ALL, 15)
mainSizer.Add(self.horzPeak, 0, wx.EXPAND|wx.ALL, 15)
panel.SetSizer(mainSizer)
mainSizer.Layout()
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.OnTimer)
wx.CallLater(500, self.Start)
def Start(self):
''' Starts the PeakMeterCtrl. '''
self.timer.Start(1000//2) # 2 fps
self.vertPeak.Start(1000//18) # 18 fps
self.horzPeak.Start(1000//20) # 20 fps
def OnTimer(self, event):
'''
Handles the ``wx.EVT_TIMER`` event for :class:`PeakMeterCtrl`.
:param `event`: a :class:`TimerEvent` event to be processed.
'''
# Generate 15 random number and set them as data for the meter
nElements = 15
arrayData = []
for i in xrange(nElements):
nRandom = random.randint(0, 100)
arrayData.append(nRandom)
self.vertPeak.SetData(arrayData, 0, nElements)
self.horzPeak.SetData(arrayData, 0, nElements)
# our normal wxApp-derived class, as usual
app = wx.App(0)
frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()

View File

@@ -3,7 +3,7 @@
# Python Code By:
#
# Andrea Gavana, @ 31 Oct 2005
# Latest Revision: 17 Aug 2011, 15.00 GMT
# Latest Revision: 16 Jul 2012, 15.00 GMT
#
#
# TODO List/Caveats
@@ -22,6 +22,7 @@
#
# Or, Obviously, To The wxPython Mailing List!!!
#
# Tags: phoenix-port, unittest, documented
#
# End Of Comments
# --------------------------------------------------------------------------- #
@@ -87,7 +88,7 @@ Usage example::
wx.Size(180, 200), wx.SIMPLE_BORDER)
progress_pie.SetBackColour(wx.Colour(150, 200, 255))
progress_pie.SetFilledcolour(wx.Colour(255, 0, 0))
progress_pie.SetFilledColour(wx.Colour(255, 0, 0))
progress_pie.SetUnfilledColour(wx.WHITE)
progress_pie.SetHeight(20)
@@ -142,9 +143,9 @@ License And Version
:class:`PieCtrl` is distributed under the wxPython license.
Latest revision: Andrea Gavana @ 17 Aug 2011, 15.00 GMT
Latest revision: Andrea Gavana @ 16 Jul 2012, 15.00 GMT
Version 0.2
Version 0.3
"""
@@ -191,6 +192,7 @@ class PieCtrlLegend(wx.Window):
self._verborder = 5
self._titlecolour = wx.Colour(0, 0, 127)
self._labelcolour = wx.BLACK
self._labelfont = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
self._backcolour = wx.Colour(255, 255, 0)
self._backgroundDC = wx.MemoryDC()
self._parent = parent
@@ -218,7 +220,7 @@ class PieCtrlLegend(wx.Window):
"""
w, h = self.GetSize()
self._background = wx.EmptyBitmap(w, h)
self._background = wx.Bitmap(w, h)
self._backgroundDC.SelectObject(self._background)
if self.IsTransparent():
@@ -335,7 +337,7 @@ class PieCtrlLegend(wx.Window):
pdc = wx.PaintDC(self)
w, h = self.GetSize()
bmp = wx.EmptyBitmap(w, h)
bmp = wx.Bitmap(w, h)
mdc = wx.MemoryDC()
mdc.SelectObject(bmp)
@@ -354,11 +356,11 @@ class PieCtrlLegend(wx.Window):
mdc.SetTextForeground(self._labelcolour)
maxwidth = 0
for ii in xrange(len(self._parent._series)):
for ii in range(len(self._parent._series)):
tw, th = mdc.GetTextExtent(self._parent._series[ii].GetLabel())
mdc.SetBrush(wx.Brush(self._parent._series[ii].GetColour()))
mdc.DrawCircle(self._horborder+5, dy+th/2, 5)
mdc.DrawCircle(self._horborder+5, dy+th//2, 5)
mdc.DrawText(self._parent._series[ii].GetLabel(), self._horborder+15, dy)
dy = dy + th + 3
maxwidth = max(maxwidth, int(2*self._horborder+tw+15))
@@ -472,11 +474,11 @@ class PieCtrl(wx.Window):
wx.Window.__init__(self, parent, id, pos, size, style, name)
self._angle = pi/12
self._angle = pi/12.0
self._rotationangle = 0
self._height = 10
self._background = wx.NullBitmap
self._canvasbitmap = wx.EmptyBitmap(1, 1)
self._canvasbitmap = wx.Bitmap(1, 1)
self._canvasDC = wx.MemoryDC()
self._backcolour = wx.WHITE
self._showedges = True
@@ -522,8 +524,8 @@ class PieCtrl(wx.Window):
def RecreateCanvas(self):
""" Recreates the :class:`PieCtrl` container (canvas). """
self._canvasbitmap = wx.EmptyBitmap(self.GetSize().GetWidth(),
self.GetSize().GetHeight())
self._canvasbitmap = wx.Bitmap(self.GetSize().GetWidth(),
self.GetSize().GetHeight())
self._canvasDC.SelectObject(self._canvasbitmap)
@@ -533,13 +535,13 @@ class PieCtrl(wx.Window):
angles = []
total = 0.0
for ii in xrange(len(self._series)):
for ii in range(len(self._series)):
total = total + self._series[ii].GetValue()
current = 0.0
angles.append(current)
for ii in xrange(len(self._series)):
for ii in range(len(self._series)):
current = current + self._series[ii].GetValue()
angles.append(360.0*current/total)
@@ -664,7 +666,7 @@ class PieCtrl(wx.Window):
if self._showedges:
dc.SetPen(wx.BLACK_PEN)
for ii in xrange(len(angles)):
for ii in range(len(angles)):
if ii > 0:
@@ -674,7 +676,7 @@ class PieCtrl(wx.Window):
dc.SetBrush(wx.Brush(self._series[ii-1].GetColour()))
if angles[ii-1] != angles[ii]:
dc.DrawEllipticArc(0, int((1-sin(self._angle))*(h/2)+cy), w,
dc.DrawEllipticArc(0, int((1-sin(self._angle))*(h//2)+cy), w,
int(h*sin(self._angle)),
angles[ii-1]+self._rotationangle/pi*180,
angles[ii]+self._rotationangle/pi*180)
@@ -683,7 +685,7 @@ class PieCtrl(wx.Window):
if len(self._series) == 1:
dc.SetBrush(wx.Brush(self._series[0].GetColour()))
dc.DrawEllipticArc(0, int((1-sin(self._angle))*(h/2)+cy), w,
dc.DrawEllipticArc(0, int((1-sin(self._angle))*(h//2)+cy), w,
int(h*sin(self._angle)), 0, 360)
dc.SetPen(oldpen)
@@ -698,15 +700,14 @@ class PieCtrl(wx.Window):
w, h = self.GetSize()
self._canvasDC.BeginDrawing()
self._canvasDC.SetBackground(wx.WHITE_BRUSH)
self._canvasDC.Clear()
if self._background != wx.NullBitmap:
for ii in xrange(0, w, self._background.GetWidth()):
for ii in range(0, w, self._background.GetWidth()):
for jj in xrange(0, h, self._background.GetHeight()):
for jj in range(0, h, self._background.GetHeight()):
self._canvasDC.DrawBitmap(self._background, ii, jj)
@@ -745,10 +746,10 @@ class PieCtrl(wx.Window):
x = angles[angleindex+1]*pi/180.0
points[0] = points[1]
px = int(w/2*(1+cos(x+self._rotationangle)))
py = int(h/2-sin(self._angle)*h/2*sin(x+self._rotationangle)-1)
px = int(w/2.0*(1+cos(x+self._rotationangle)))
py = int(h/2.0-sin(self._angle)*h/2.0*sin(x+self._rotationangle)-1)
points[1] = [px, py]
triangle[0] = [w / 2, h / 2]
triangle[0] = [w // 2, h // 2]
triangle[1] = points[0]
triangle[2] = points[1]
@@ -768,10 +769,10 @@ class PieCtrl(wx.Window):
x = 2*pi
points[0] = points[1]
px = int(w/2 * (1+cos(x+self._rotationangle)))
py = int(h/2-sin(self._angle)*h/2*sin(x+self._rotationangle)-1)
px = int(w/2.0 * (1+cos(x+self._rotationangle)))
py = int(h/2.0-sin(self._angle)*h/2.0*sin(x+self._rotationangle)-1)
points[1] = [px, py]
triangle[0] = [w / 2, h / 2]
triangle[0] = [w // 2, h // 2]
triangle[1] = points[0]
triangle[2] = points[1]
@@ -797,16 +798,16 @@ class PieCtrl(wx.Window):
points[0] = points[1]
points[3] = points[2]
px = int(w/2 * (1+cos(x+self._rotationangle)))
py = int(h/2-sin(self._angle)*h/2*sin(x+self._rotationangle)-1)
px = int(w/2.0 * (1+cos(x+self._rotationangle)))
py = int(h/2.0-sin(self._angle)*h/2.0*sin(x+self._rotationangle)-1)
points[1] = [px, py]
points[2] = [px, int(py+self._height*cos(self._angle))]
if w > 0:
curColour = wx.Colour(self._series[angleindex].GetColour().Red()*(1.0-float(px)/w),
self._series[angleindex].GetColour().Green()*(1.0-float(px)/w),
self._series[angleindex].GetColour().Blue()*(1.0-float(px)/w))
curColour = wx.Colour(int(self._series[angleindex].GetColour().Red()*(1.0-float(px)/w)),
int(self._series[angleindex].GetColour().Green()*(1.0-float(px)/w)),
int(self._series[angleindex].GetColour().Blue()*(1.0-float(px)/w)))
if not self._showedges:
self._canvasDC.SetPen(wx.Pen(curColour))
@@ -825,16 +826,16 @@ class PieCtrl(wx.Window):
x = 2*pi
points[0] = points[1]
points[3] = points[2]
px = int(w/2 * (1+cos(x+self._rotationangle)))
py = int(h/2-sin(self._angle)*h/2*sin(x+self._rotationangle)-1)
px = int(w/2.0 * (1+cos(x+self._rotationangle)))
py = int(h/2.0-sin(self._angle)*h/2.0*sin(x+self._rotationangle)-1)
points[1] = [px, py]
points[2] = [px, int(py+self._height*cos(self._angle))]
if w > 0:
curColour = wx.Colour(self._series[angleindex].GetColour().Red()*(1.0-float(px)/w),
self._series[angleindex].GetColour().Green()*(1.0-float(px)/w),
self._series[angleindex].GetColour().Blue()*(1.0-float(px)/w))
curColour = wx.Colour(int(self._series[angleindex].GetColour().Red()*(1.0-float(px)/w)),
int(self._series[angleindex].GetColour().Green()*(1.0-float(px)/w)),
int(self._series[angleindex].GetColour().Blue()*(1.0-float(px)/w)))
if not self._showedges:
self._canvasDC.SetPen(wx.Pen(curColour))
@@ -849,8 +850,6 @@ class PieCtrl(wx.Window):
else:
self.DrawParts(self._canvasDC, 0, int(self._height*cos(self._angle)), w, h)
self._canvasDC.EndDrawing()
pdc.Blit(0, 0, w, h, self._canvasDC, 0, 0)
self._legend.RecreateBackground(self._canvasDC)
@@ -986,3 +985,69 @@ class ProgressPie(PieCtrl):
return self._unfilledcolour
if __name__ == '__main__':
import wx
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "PieCtrl Demo")
panel = wx.Panel(self)
# create a simple PieCtrl with 3 sectors
mypie = PieCtrl(panel, -1, wx.DefaultPosition, wx.Size(180,270))
part = PiePart()
part.SetLabel("Label 1")
part.SetValue(300)
part.SetColour(wx.Colour(200, 50, 50))
mypie._series.append(part)
part = PiePart()
part.SetLabel("Label 2")
part.SetValue(200)
part.SetColour(wx.Colour(50, 200, 50))
mypie._series.append(part)
part = PiePart()
part.SetLabel("helloworld label 3")
part.SetValue(50)
part.SetColour(wx.Colour(50, 50, 200))
mypie._series.append(part)
# create a ProgressPie
progress_pie = ProgressPie(panel, 100, 50, -1, wx.DefaultPosition,
wx.Size(180, 200), wx.SIMPLE_BORDER)
progress_pie.SetBackColour(wx.Colour(150, 200, 255))
progress_pie.SetFilledColour(wx.Colour(255, 0, 0))
progress_pie.SetUnfilledColour(wx.WHITE)
progress_pie.SetHeight(20)
main_sizer = wx.BoxSizer(wx.HORIZONTAL)
main_sizer.Add(mypie, 1, wx.EXPAND | wx.ALL, 5)
main_sizer.Add(progress_pie, 1, wx.EXPAND | wx.ALL, 5)
panel.SetSizer(main_sizer)
main_sizer.Layout()
# our normal wxApp-derived class, as usual
app = wx.App(0)
frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()

View File

@@ -1,3 +1,31 @@
# --------------------------------------------------------------------------- #
# PYBUSYINFO Control wxPython IMPLEMENTATION
# Inspired By And Heavily Based On wxBusyInfo.
#
# Python Code By:
#
# Andrea Gavana, @ 10 December 2009
# Latest Revision: 16 Jul 2012, 15.00 GMT
#
#
# TODO List/Caveats
#
# 1. ?
#
#
# For All Kind Of Problems, Requests Of Enhancements And Bug Reports, Please
# Write To Me At:
#
# andrea.gavana@gmail.com
# andrea.gavana@maerskoil.com
#
# Or, Obviously, To The wxPython Mailing List!!!
#
# Tags: phoenix-port, unittest, documented
#
# End Of Comments
# --------------------------------------------------------------------------- #
"""
:class:`PyBusyInfo` constructs a busy info window and displays a message in it.
@@ -95,14 +123,14 @@ License And Version
:class:`PyBusyInfo` is distributed under the wxPython license.
Latest Revision: Andrea Gavana @ 20 Mar 2012, 21.00 GMT
Latest Revision: Andrea Gavana @ 16 Jul 2012, 15.00 GMT
Version 0.2
Version 0.3
"""
# Version Info
__version__ = "0.2"
__version__ = "0.3"
import wx
@@ -133,7 +161,7 @@ class PyInfoFrame(wx.Frame):
self._icon = icon
dc = wx.ClientDC(self)
textWidth, textHeight, dummy = dc.GetMultiLineTextExtent(self._message)
textWidth, textHeight, dummy = dc.GetFullMultiLineTextExtent(self._message)
sizeText = wx.Size(textWidth, textHeight)
self.SetClientSize((max(sizeText.x, 340) + 60, max(sizeText.y, 40) + 60))
@@ -148,13 +176,13 @@ class PyInfoFrame(wx.Frame):
# Create a non-rectangular region to set the frame shape
size = self.GetSize()
bmp = wx.EmptyBitmap(size.x, size.y)
bmp = wx.Bitmap(size.x, size.y)
dc = wx.BufferedDC(None, bmp)
dc.SetBackground(wx.Brush(wx.Colour(0, 0, 0), wx.SOLID))
dc.SetBackground(wx.Brush(wx.Colour(0, 0, 0)))
dc.Clear()
dc.SetPen(wx.Pen(wx.Colour(0, 0, 0), 1))
dc.DrawRoundedRectangle(0, 0, size.x, size.y, 12)
r = wx.RegionFromBitmapColour(bmp, wx.Colour(0, 0, 0))
r = wx.Region(bmp, wx.Colour(0, 0, 0))
# Store the non-rectangular region
self.reg = r
@@ -193,14 +221,14 @@ class PyInfoFrame(wx.Frame):
dc.Clear()
# Fill the background with a gradient shading
startColour = wx.SystemSettings_GetColour(wx.SYS_COLOUR_ACTIVECAPTION)
startColour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_ACTIVECAPTION)
endColour = wx.WHITE
rect = panel.GetRect()
dc.GradientFillLinear(rect, startColour, endColour, wx.SOUTH)
# Draw the label
font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
dc.SetFont(font)
# Draw the message
@@ -211,13 +239,13 @@ class PyInfoFrame(wx.Frame):
# Draw the top title
font.SetWeight(wx.BOLD)
dc.SetFont(font)
dc.SetPen(wx.Pen(wx.SystemSettings_GetColour(wx.SYS_COLOUR_CAPTIONTEXT)))
dc.SetTextForeground(wx.SystemSettings_GetColour(wx.SYS_COLOUR_CAPTIONTEXT))
dc.SetPen(wx.Pen(wx.SystemSettings.GetColour(wx.SYS_COLOUR_CAPTIONTEXT)))
dc.SetTextForeground(wx.SystemSettings.GetColour(wx.SYS_COLOUR_CAPTIONTEXT))
if self._icon.IsOk():
iconWidth, iconHeight = self._icon.GetWidth(), self._icon.GetHeight()
dummy, textHeight = dc.GetTextExtent(self._title)
textXPos, textYPos = iconWidth + 10, (iconHeight-textHeight)/2
textXPos, textYPos = iconWidth + 10, (iconHeight-textHeight)//2
dc.DrawBitmap(self._icon, 5, 5, True)
else:
textXPos, textYPos = 5, 0
@@ -329,3 +357,44 @@ class PyBusyInfo(object):
self._infoFrame.Update()
if __name__ == '__main__':
import wx
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "PyBusyInfo Demo")
panel = wx.Panel(self)
b = wx.Button(panel, -1, "Test PyBusyInfo ", (50,50))
self.Bind(wx.EVT_BUTTON, self.OnButton, b)
def OnButton(self, event):
message = "Please wait 5 seconds, working..."
busy = PyBusyInfo(message, parent=self, title="Really Busy")
wx.Yield()
for indx in xrange(5):
wx.MilliSleep(1000)
del busy
# our normal wxApp-derived class, as usual
app = wx.App(0)
frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()

View File

@@ -3,7 +3,7 @@
# Generic Implementation Based On wx.CollapsiblePane.
#
# Andrea Gavana, @ 09 Aug 2007
# Latest Revision: 14 Mar 2012, 21.00 GMT
# Latest Revision: 16 Jul 2012, 15.00 GMT
#
#
# For All Kind Of Problems, Requests Of Enhancements And Bug Reports, Please
@@ -14,6 +14,7 @@
#
# Or, Obviously, To The wxPython Mailing List!!!
#
# Tags: phoenix-port, unittest, documented
#
# End Of Comments
# --------------------------------------------------------------------------------- #
@@ -61,7 +62,7 @@ Usage example::
title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
title.SetForegroundColour("blue")
self.cp = cp = PCP.PyCollapsiblePane(panel, label=label1,
self.cp = cp = PCP.PyCollapsiblePane(panel, label="Some Data",
style=wx.CP_DEFAULT_STYLE|wx.CP_NO_TLW_RESIZE)
self.MakePaneContent(cp.GetPane())
@@ -158,9 +159,9 @@ License And Version
:class:`PyCollapsiblePane` is distributed under the wxPython license.
Latest Revision: Andrea Gavana @ 14 Mar 2012, 21.00 GMT
Latest Revision: Andrea Gavana @ 16 Jul 2012, 15.00 GMT
Version 0.4
Version 0.5
"""
@@ -197,7 +198,7 @@ if wx.VERSION < (2, 9):
# GTKExpander widget
#-----------------------------------------------------------------------------
class GTKExpander(wx.PyControl):
class GTKExpander(wx.Control):
"""
A :class:`GTKExpander` allows the user to hide or show its child by clicking on an expander
triangle.
@@ -218,7 +219,7 @@ class GTKExpander(wx.PyControl):
:param `style`: the expander style.
"""
wx.PyControl.__init__(self, parent, id, pos, size, style)
wx.Control.__init__(self, parent, id, pos, size, style)
self.SetLabel(label)
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
@@ -243,16 +244,16 @@ class GTKExpander(wx.PyControl):
dc.SetPen(wx.BLACK_PEN)
if self._parent.IsCollapsed():
startX, startY = triangleWidth/2, size.y - triangleHeight - 1 - descent
startX, startY = triangleWidth//2, size.y - triangleHeight - 1 - descent
pt1 = wx.Point(startX, startY)
pt2 = wx.Point(startX, size.y - 1 - descent)
pt3 = wx.Point(startX+triangleWidth, size.y-triangleHeight/2 - 1 - descent)
pt3 = wx.Point(startX+triangleWidth, size.y-triangleHeight//2 - 1 - descent)
else:
startX, startY = 0, size.y - triangleWidth - descent - 1
pt1 = wx.Point(startX, startY)
pt2 = wx.Point(startX+triangleHeight, startY)
pt3 = wx.Point(startX+triangleHeight/2, size.y - descent - 1)
pt3 = wx.Point(startX+triangleHeight//2, size.y - descent - 1)
dc.DrawPolygon([pt1, pt2, pt3])
@@ -280,7 +281,7 @@ class GTKExpander(wx.PyControl):
minimal size which doesn't truncate the control, for a panel - the same size
as it would have after a call to `Fit()`.
:note: Overridden from :class:`PyControl`.
:note: Overridden from :class:`Control`.
"""
triangleWidth, triangleHeight = self._parent.GetExpanderDimensions()
@@ -309,7 +310,7 @@ class GTKExpander(wx.PyControl):
# PyCollapsiblePane
#-----------------------------------------------------------------------------
class PyCollapsiblePane(wx.PyPanel):
class PyCollapsiblePane(wx.Panel):
"""
:class:`PyCollapsiblePane` is a container with an embedded button-like control which
can be used by the user to collapse or expand the pane's contents.
@@ -329,7 +330,7 @@ class PyCollapsiblePane(wx.PyPanel):
chosen by either the windowing system or wxPython, depending on platform;
:param `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 `style`: the underlying :class:`PyPanel` window style;
:param `style`: the underlying :class:`Panel` window style;
:param `agwStyle`: the AGW-specifi window style. This can be a combination of the
following bits:
@@ -347,7 +348,7 @@ class PyCollapsiblePane(wx.PyPanel):
"""
wx.PyPanel.__init__(self, parent, id, pos, size, style, name)
wx.Panel.__init__(self, parent, id, pos, size, style, name)
self._pButton = self._pStaticLine = self._pPane = self._sz = None
self._strLabel = label
@@ -595,7 +596,7 @@ class PyCollapsiblePane(wx.PyPanel):
:param `label`: the new button label.
:note: Overridden from :class:`PyPanel`.
:note: Overridden from :class:`Panel`.
"""
self._strLabel = label
@@ -610,7 +611,7 @@ class PyCollapsiblePane(wx.PyPanel):
"""
Returns the button label.
:note: Overridden from :class:`PyPanel`.
:note: Overridden from :class:`Panel`.
"""
return self._strLabel
@@ -641,7 +642,7 @@ class PyCollapsiblePane(wx.PyPanel):
elif wx.Platform == "__WXGTK__":
return 3
elif wx.Platform == "__WXMSW__":
return self._pButton.ConvertDialogSizeToPixels(wx.Size(2, 0)).x
return self._pButton.ConvertDialogToPixels(wx.Size(2, 0)).x
else:
return 5
@@ -676,7 +677,7 @@ class PyCollapsiblePane(wx.PyPanel):
minimal size which doesn't truncate the control, for a panel - the same size
as it would have after a call to `Fit()`.
:note: Overridden from :class:`PyPanel`.
:note: Overridden from :class:`Panel`.
"""
if self.HasAGWFlag(CP_USE_STATICBOX):
@@ -694,8 +695,8 @@ class PyCollapsiblePane(wx.PyPanel):
adjustment = 0
if 'wxMac' not in wx.PlatformInfo:
adjustment = -3
self._sz.Children[0].AssignSpacer((1, sz.height/2 + adjustment))
self._contentSizer.Children[0].AssignSpacer((1, sz.height/2))
self._sz.Children[0].AssignSpacer((1, sz.height//2 + adjustment))
self._contentSizer.Children[0].AssignSpacer((1, sz.height//2))
ssz = self._sz.GetMinSize()
sz.width = max(sz.width, ssz.width)
@@ -748,7 +749,7 @@ class PyCollapsiblePane(wx.PyPanel):
# move & resize the container window
yoffset = self._sz.GetSize().GetHeight() + self.GetBorder()
self._pPane.SetDimensions(0, yoffset, oursz.x, oursz.y - yoffset)
self._pPane.SetSize(0, yoffset, oursz.x, oursz.y - yoffset)
# this is very important to make the pane window layout show correctly
self._pPane.Show()
@@ -855,3 +856,82 @@ class PyCollapsiblePane(wx.PyPanel):
self._pButton.OnDrawGTKText(dc)
if __name__ == '__main__':
import wx
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "PyCollapsiblePane Demo")
panel = wx.Panel(self)
title = wx.StaticText(panel, label="PyCollapsiblePane")
title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
title.SetForegroundColour("blue")
self.cp = cp = PyCollapsiblePane(panel, label='Some Data', style=wx.CP_DEFAULT_STYLE|wx.CP_NO_TLW_RESIZE)
self.MakePaneContent(cp.GetPane())
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(title, 0, wx.ALL, 25)
sizer.Add(cp, 0, wx.RIGHT|wx.LEFT|wx.EXPAND, 25)
panel.SetSizer(sizer)
sizer.Layout()
def MakePaneContent(self, pane):
''' Just makes a few controls to put on `PyCollapsiblePane`. '''
nameLbl = wx.StaticText(pane, -1, "Name:")
name = wx.TextCtrl(pane, -1, "");
addrLbl = wx.StaticText(pane, -1, "Address:")
addr1 = wx.TextCtrl(pane, -1, "");
addr2 = wx.TextCtrl(pane, -1, "");
cstLbl = wx.StaticText(pane, -1, "City, State, Zip:")
city = wx.TextCtrl(pane, -1, "", size=(150,-1));
state = wx.TextCtrl(pane, -1, "", size=(50,-1));
zip = wx.TextCtrl(pane, -1, "", size=(70,-1));
addrSizer = wx.FlexGridSizer(cols=2, hgap=5, vgap=5)
addrSizer.AddGrowableCol(1)
addrSizer.Add(nameLbl, 0,
wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
addrSizer.Add(name, 0, wx.EXPAND)
addrSizer.Add(addrLbl, 0,
wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
addrSizer.Add(addr1, 0, wx.EXPAND)
addrSizer.Add((5, 5))
addrSizer.Add(addr2, 0, wx.EXPAND)
addrSizer.Add(cstLbl, 0,
wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
cstSizer = wx.BoxSizer(wx.HORIZONTAL)
cstSizer.Add(city, 1)
cstSizer.Add(state, 0, wx.LEFT|wx.RIGHT, 5)
cstSizer.Add(zip)
addrSizer.Add(cstSizer, 0, wx.EXPAND)
border = wx.BoxSizer()
border.Add(addrSizer, 1, wx.EXPAND|wx.ALL, 5)
pane.SetSizer(border)
# our normal wxApp-derived class, as usual
app = wx.App(0)
frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()

View File

@@ -2,7 +2,7 @@
# PYGAUGE wxPython IMPLEMENTATION
#
# Mark Reed, @ 28 Jul 2010
# Latest Revision: 17 Aug 2011, 15.00 GMT
# Latest Revision: 16 Jul 2012, 15.00 GMT
#
# TODO List
#
@@ -20,6 +20,8 @@
#
# wxPython Mailing List!!!
#
# Tags: phoenix-port, unittest, documented
#
# End Of Comments
# --------------------------------------------------------------------------------- #
@@ -114,7 +116,7 @@ import wx
import copy
class PyGauge(wx.PyWindow):
class PyGauge(wx.Window):
"""
This class provides a visual alternative for :class:`Gauge`. It currently
only support determinate mode (see :meth:`PyGauge.SetValue() <PyGauge.SetValue>` and
@@ -132,10 +134,10 @@ class PyGauge(wx.PyWindow):
chosen by either the windowing system or wxPython, depending on platform;
:param `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 `style`: the underlying :class:`PyWindow` window style.
:param `style`: the underlying :class:`Window` window style.
"""
wx.PyWindow.__init__(self, parent, id, pos, size, style)
wx.Window.__init__(self, parent, id, pos, size, style)
self._size = size
@@ -162,7 +164,7 @@ class PyGauge(wx.PyWindow):
the minimal size which doesn't truncate the control, for a panel - the
same size as it would have after a call to `Fit()`.
:note: Overridden from :class:`PyWindow`.
:note: Overridden from :class:`Window`.
"""
return wx.Size(self._size[0], self._size[1])
@@ -325,12 +327,12 @@ class PyGauge(wx.PyWindow):
colour = self.GetBackgroundColour()
dc.SetBrush(wx.Brush(colour))
dc.SetPen(wx.Pen(colour))
dc.DrawRectangleRect(rect)
dc.DrawRectangle(rect)
if self._border_colour:
dc.SetPen(wx.Pen(self.GetBorderColour()))
dc.DrawRectangleRect(rect)
dc.DrawRectangle(rect)
pad = 1 + self.GetBorderPadding()
rect.Deflate(pad,pad)
@@ -349,7 +351,7 @@ class PyGauge(wx.PyWindow):
w = rect.width * (float(self._valueSorted[i]) / self._range)
r = copy.copy(rect)
r.width = w
dc.DrawRectangleRect(r)
dc.DrawRectangle(r)
def OnTimer(self,event):
@@ -403,7 +405,7 @@ class PyGauge(wx.PyWindow):
raise Exception("ERROR:\n Gauge value must be between 0 and its range. ")
self._update_value.append(value[i] + v)
self._update_step.append(float(value[i])/(time/50))
self._update_step.append(float(value[i])/(time/50.0))
#print self._update_
@@ -427,3 +429,56 @@ class PyGauge(wx.PyWindow):
self._valueSorted = list(a)
self._barColourSorted = list(b)
if __name__ == '__main__':
import wx
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "PyGauge Demo")
panel = wx.Panel(self)
gauge1 = PyGauge(panel, -1, size=(100, 25), style=wx.GA_HORIZONTAL)
gauge1.SetValue(80)
gauge1.SetBackgroundColour(wx.WHITE)
gauge1.SetBorderColor(wx.BLACK)
gauge2 = PyGauge(panel, -1, size=(100, 25), style=wx.GA_HORIZONTAL)
gauge2.SetValue([20, 80])
gauge2.SetBarColor([wx.Colour(162, 255, 178), wx.Colour(159, 176, 255)])
gauge2.SetBackgroundColour(wx.WHITE)
gauge2.SetBorderColor(wx.BLACK)
gauge2.SetBorderPadding(2)
gauge2.Update([30, 0], 2000)
gauge3 = PyGauge(panel, -1, size=(100, 25), style=wx.GA_HORIZONTAL)
gauge3.SetValue(50)
gauge3.SetBarColor(wx.GREEN)
gauge3.SetBackgroundColour(wx.WHITE)
gauge3.SetBorderColor(wx.BLACK)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(gauge1, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 20)
sizer.Add(gauge2, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 20)
sizer.Add(gauge3, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 20)
panel.SetSizer(sizer)
sizer.Layout()
# our normal wxApp-derived class, as usual
app = wx.App(0)
frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()