Updated the analogclock.py module to the new analogclock package from
E. A. Tacao. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38120 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
144
wxPython/wx/lib/analogclock/__init__.py
Normal file
144
wxPython/wx/lib/analogclock/__init__.py
Normal file
@@ -0,0 +1,144 @@
|
||||
__author__ = "E. A. Tacao <e.a.tacao |at| estadao.com.br>"
|
||||
__date__ = "15 Fev 2006, 22:00 GMT-03:00"
|
||||
__version__ = "0.02"
|
||||
__doc__ = """
|
||||
AnalogClock - an analog clock.
|
||||
|
||||
This control creates an analog clock window. Its features include shadowing,
|
||||
the ability to render numbers as well as any arbitrary polygon as tick marks,
|
||||
resize marks and hands proportionally as the widget itself is resized, rotate
|
||||
marks in a way the get aligned to the watch. It also has a dialog, accessed
|
||||
via a context menu item, allowing one to change on the fly all of its settings.
|
||||
|
||||
|
||||
Usage:
|
||||
|
||||
AnalogClock(parent, id=-1, pos=wx.DefaultPosition,
|
||||
size=wx.DefaultSize, style=wx.NO_BORDER, name="AnalogClock",
|
||||
clockStyle=DEFAULT_CLOCK_STYLE,
|
||||
minutesStyle=TICKS_CIRCLE, hoursStyle=TICKS_POLY)
|
||||
|
||||
- parent, id, pos, size, style and name are used as in a wx.Window. Please
|
||||
refer to the wx.Window docs for more details.
|
||||
|
||||
- clockStyle defines the clock style, according to the options below:
|
||||
|
||||
==================== ================================
|
||||
SHOW_QUARTERS_TICKS Show marks for hours 3, 6, 9, 12
|
||||
SHOW_HOURS_TICKS Show marks for all hours
|
||||
SHOW_MINUTES_TICKS Show marks for minutes
|
||||
|
||||
SHOW_HOURS_HAND Show hours hand
|
||||
SHOW_MINUTES_HAND Show minutes hand
|
||||
SHOW_SECONDS_HAND Show seconds hand
|
||||
|
||||
SHOW_SHADOWS Show hands and marks shadows
|
||||
|
||||
ROTATE_TICKS Align tick marks to watch
|
||||
OVERLAP_TICKS Draw tick marks for minutes even
|
||||
when they match the hours marks.
|
||||
|
||||
DEFAULT_CLOCK_STYLE The same as SHOW_HOURS_TICKS|
|
||||
SHOW_MINUTES_TICKS|
|
||||
SHOW_HOURS_HAND|
|
||||
SHOW_MINUTES_HAND|
|
||||
SHOW_SECONDS_HAND|
|
||||
SHOW_SHADOWS|ROTATE_TICKS
|
||||
==================== ================================
|
||||
|
||||
- minutesStyle and hoursStyle define the the tick styles, according to the
|
||||
options below:
|
||||
|
||||
================= ======================================
|
||||
TICKS_NONE Don't show tick marks.
|
||||
TICKS_SQUARE Use squares as tick marks.
|
||||
TICKS_CIRCLE Use circles as tick marks.
|
||||
TICKS_POLY Use a polygon as tick marks. A
|
||||
polygon can be passed using
|
||||
SetTickPolygon, otherwise the default
|
||||
polygon will be used.
|
||||
TICKS_DECIMAL Use decimal numbers as tick marks.
|
||||
TICKS_ROMAN Use Roman numbers as tick marks.
|
||||
TICKS_BINARY Use binary numbers as tick marks.
|
||||
TICKS_HEX Use hexadecimal numbers as tick marks.
|
||||
================= ======================================
|
||||
|
||||
|
||||
Notes:
|
||||
|
||||
The 'target' keyword that's present in various of the AnalogClock methods may
|
||||
accept one (or more, combined using '|') of the following values:
|
||||
|
||||
========= ===========================================
|
||||
HOUR The values passed/retrieved are related to
|
||||
the hours hand/ticks
|
||||
|
||||
MINUTE The values passed/retrieved are related to
|
||||
the minutes hand/ticks
|
||||
|
||||
SECOND The values passed/retrieved are related to
|
||||
the seconds hand/ticks
|
||||
|
||||
ALL The same as HOUR|MINUTE|SECOND, i. e., the
|
||||
values passed/retrieved are related to all
|
||||
of the hours hands/ticks. This is the
|
||||
default value in all methods.
|
||||
========= ===========================================
|
||||
|
||||
It is legal to pass target=ALL to methods that don't handle seconds (tick
|
||||
mark related methods). In such cases, ALL will be equivalent to HOUR|MINUTE.
|
||||
|
||||
All of the 'Get' AnalogClock methods that allow the 'target' keyword
|
||||
will always return a tuple, e. g.:
|
||||
|
||||
================================= ========================================
|
||||
GetHandSize(target=HOUR) Returns a 1 element tuple, containing
|
||||
the size of the hours hand.
|
||||
|
||||
GetHandSize(target=HOUR|MINUTE) Returns a 2 element tuple, containing
|
||||
the sizes of the hours and the minutes
|
||||
hands, respectively.
|
||||
|
||||
GetHandSize(target=ALL) Returns a 3 element tuple, containing
|
||||
or the sizes of the hours, minutes and
|
||||
GetHandSize() seconds hands, respectively.
|
||||
================================= ========================================
|
||||
|
||||
|
||||
About:
|
||||
|
||||
Most of the ideas and part of the code of AnalogClock were based on the
|
||||
original wxPython's AnalogClock module, which was created by several folks on
|
||||
the wxPython-users list.
|
||||
|
||||
AnalogClock is distributed under the wxWidgets license.
|
||||
|
||||
This code should meet the wxPython Coding Guidelines
|
||||
<http://www.wxpython.org/codeguidelines.php> and the wxPython Style Guide
|
||||
<http://wiki.wxpython.org/index.cgi/wxPython_20Style_20Guide>.
|
||||
|
||||
For all kind of problems, requests, enhancements, bug reports, etc,
|
||||
please drop me an e-mail.
|
||||
|
||||
For updates please visit <http://j.domaindlx.com/elements28/wxpython/>.
|
||||
"""
|
||||
|
||||
# History:
|
||||
#
|
||||
# Version 0.02:
|
||||
# - Module/namespace rearranges;
|
||||
# - All '-1' occurrences meaning "use any id" were eliminated or replaced
|
||||
# to 'wx.ID_ANY'.
|
||||
# - Better names to the methods triggered by the context menu events.
|
||||
# - Included small demo class code in analogclock.py.
|
||||
# Version 0.01:
|
||||
# - Initial release.
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
from analogclock import AnalogClock, AnalogClockWindow
|
||||
from styles import *
|
||||
|
||||
#
|
||||
##
|
||||
### eof
|
644
wxPython/wx/lib/analogclock/analogclock.py
Normal file
644
wxPython/wx/lib/analogclock/analogclock.py
Normal file
@@ -0,0 +1,644 @@
|
||||
# AnalogClock's main class
|
||||
# E. A. Tacao <e.a.tacao |at| estadao.com.br>
|
||||
# http://j.domaindlx.com/elements28/wxpython/
|
||||
# 15 Fev 2006, 22:00 GMT-03:00
|
||||
# Distributed under the wxWidgets license.
|
||||
#
|
||||
# For more info please see the __init__.py file.
|
||||
|
||||
import wx
|
||||
|
||||
from styles import *
|
||||
from helpers import Dyer, Face, Hand, HandSet, TickSet, Box
|
||||
from setup import Setup
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class AnalogClock(wx.PyWindow):
|
||||
"""An analog clock."""
|
||||
|
||||
def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
|
||||
size=wx.DefaultSize, style=wx.NO_BORDER, name="AnalogClock",
|
||||
clockStyle=DEFAULT_CLOCK_STYLE,
|
||||
minutesStyle=TICKS_CIRCLE, hoursStyle=TICKS_POLY):
|
||||
|
||||
wx.PyWindow.__init__(self, parent, id, pos, size, style, name)
|
||||
|
||||
# Base size for scale calc purposes.
|
||||
self.basesize = wx.Size(348, 348)
|
||||
|
||||
# Store some references.
|
||||
self.clockStyle = clockStyle
|
||||
self.minutesStyle = minutesStyle
|
||||
self.hoursStyle = hoursStyle
|
||||
|
||||
self.DrawHands = self._drawHands
|
||||
self.DrawBox = self._drawBox
|
||||
self.RecalcCoords = self._recalcCoords
|
||||
|
||||
self.shadowOffset = 3
|
||||
|
||||
self.allHandStyles = [SHOW_HOURS_HAND,
|
||||
SHOW_MINUTES_HAND,
|
||||
SHOW_SECONDS_HAND]
|
||||
|
||||
# Initialize clock face.
|
||||
#
|
||||
# By default we don't use colours or borders on the clock face.
|
||||
bg = self.GetBackgroundColour()
|
||||
face = Face(dyer=Dyer(bg, 0, bg))
|
||||
|
||||
# Initialize tick marks.
|
||||
#
|
||||
# TickSet is a set of tick marks; there's always two TickSets defined
|
||||
# regardless whether they're being shown or not.
|
||||
ticksM = TickSet(self, style=minutesStyle, size=5, kind="minutes")
|
||||
ticksH = TickSet(self, style=hoursStyle, size=25, kind="hours",
|
||||
rotate=clockStyle&ROTATE_TICKS)
|
||||
|
||||
# Box holds the clock face and tick marks.
|
||||
self.Box = Box(self, face, ticksM, ticksH)
|
||||
|
||||
# Initialize hands.
|
||||
#
|
||||
# HandSet is the set of hands; there's always one HandSet defined
|
||||
# regardless whether hands are being shown or not.
|
||||
#
|
||||
# A 'lenfac = 0.95', e.g., means that the lenght of that hand will
|
||||
# be 95% of the maximum allowed hand lenght ('nice' maximum lenght).
|
||||
handH = Hand(size=7, lenfac=0.7)
|
||||
handM = Hand(size=5, lenfac=0.95)
|
||||
handS = Hand(size=1, lenfac=0.95)
|
||||
self.Hands = HandSet(self, handH, handM, handS)
|
||||
|
||||
# Create the customization dialog.
|
||||
self.Setup = None
|
||||
|
||||
# Make a context menu.
|
||||
popup1 = wx.NewId()
|
||||
popup2 = wx.NewId()
|
||||
cm = self.cm = wx.Menu()
|
||||
cm.Append(popup1, "Customize...")
|
||||
cm.Append(popup2, "About...")
|
||||
|
||||
# Set event handlers.
|
||||
self.Bind(wx.EVT_SIZE, self._OnSize)
|
||||
self.Bind(wx.EVT_PAINT, self._OnPaint)
|
||||
self.Bind(wx.EVT_ERASE_BACKGROUND, lambda evt: None)
|
||||
self.Bind(wx.EVT_TIMER, self._OnTimer)
|
||||
self.Bind(wx.EVT_WINDOW_DESTROY, self._OnDestroyWindow)
|
||||
self.Bind(wx.EVT_CONTEXT_MENU, self._OnContextMenu)
|
||||
self.Bind(wx.EVT_MENU, self._OnShowSetup, id=popup1)
|
||||
self.Bind(wx.EVT_MENU, self._OnShowAbout, id=popup2)
|
||||
|
||||
# Set initial size based on given size, or best size
|
||||
self.SetBestFittingSize(size)
|
||||
|
||||
# Do initial drawing (in case there is not an initial size event)
|
||||
self.RecalcCoords(self.GetSize())
|
||||
self.DrawBox()
|
||||
|
||||
# Initialize the timer that drives the update of the clock face.
|
||||
# Update every half second to ensure that there is at least one true
|
||||
# update during each realtime second.
|
||||
self.timer = wx.Timer(self)
|
||||
self.timer.Start(500)
|
||||
|
||||
|
||||
def DoGetBestSize(self):
|
||||
# Just pull a number out of the air. If there is a way to
|
||||
# calculate this then it should be done...
|
||||
size = wx.Size(50,50)
|
||||
self.CacheBestSize(size)
|
||||
return size
|
||||
|
||||
|
||||
def _OnSize(self, evt):
|
||||
size = self.GetClientSize()
|
||||
if size.x < 1 or size.y < 1:
|
||||
return
|
||||
|
||||
self.RecalcCoords(size)
|
||||
self.DrawBox()
|
||||
|
||||
|
||||
def _OnPaint(self, evt):
|
||||
dc = wx.BufferedPaintDC(self)
|
||||
self.DrawHands(dc)
|
||||
|
||||
|
||||
def _OnTimer(self, evt):
|
||||
dc = wx.BufferedDC(wx.ClientDC(self), self.GetClientSize())
|
||||
self.DrawHands(dc)
|
||||
|
||||
|
||||
def _OnDestroyWindow(self, evt):
|
||||
self.timer.Stop()
|
||||
del self.timer
|
||||
|
||||
|
||||
def _OnContextMenu(self, evt):
|
||||
self.PopupMenu(self.cm)
|
||||
|
||||
|
||||
def _OnShowSetup(self, evt):
|
||||
if self.Setup is None:
|
||||
self.Setup = Setup(self)
|
||||
self.Setup.Show()
|
||||
self.Setup.Raise()
|
||||
|
||||
|
||||
def _OnShowAbout(self, evt):
|
||||
msg = "AnalogClock\n\n" \
|
||||
"by Several folks on wxPython-users\n" \
|
||||
"with enhancements from E. A. Tacao."
|
||||
title = "About..."
|
||||
style = wx.OK|wx.ICON_INFORMATION
|
||||
|
||||
dlg = wx.MessageDialog(self, msg, title, style)
|
||||
dlg.ShowModal()
|
||||
dlg.Destroy()
|
||||
|
||||
|
||||
def _recalcCoords(self, size):
|
||||
"""
|
||||
Recalculates all coordinates/geometry and inits the faceBitmap
|
||||
to make sure the buffer is always the same size as the window.
|
||||
"""
|
||||
|
||||
self.faceBitmap = wx.EmptyBitmap(*size.Get())
|
||||
|
||||
# Recalc all coords.
|
||||
scale = min([float(size.width) / self.basesize.width,
|
||||
float(size.height) / self.basesize.height])
|
||||
|
||||
centre = wx.Point(size.width / 2., size.height / 2.)
|
||||
|
||||
self.Box.RecalcCoords(size, centre, scale)
|
||||
self.Hands.RecalcCoords(size, centre, scale)
|
||||
|
||||
# Try to find a 'nice' maximum length for the hands so that they won't
|
||||
# overlap the tick marks. OTOH, if you do want to allow overlapping the
|
||||
# lenfac value (defined on __init__ above) has to be set to
|
||||
# something > 1.
|
||||
niceradius = self.Box.GetNiceRadiusForHands(centre)
|
||||
self.Hands.SetMaxRadius(niceradius)
|
||||
|
||||
|
||||
def _drawBox(self):
|
||||
"""Draws clock face and tick marks."""
|
||||
|
||||
dc = wx.BufferedDC(wx.ClientDC(self), self.GetClientSize())
|
||||
dc.BeginDrawing()
|
||||
dc.SelectObject(self.faceBitmap)
|
||||
dc.SetBackground(wx.Brush(self.GetBackgroundColour(), wx.SOLID))
|
||||
dc.Clear()
|
||||
self.Box.Draw(dc)
|
||||
dc.EndDrawing()
|
||||
|
||||
|
||||
def _drawHands(self, dc):
|
||||
"""
|
||||
Draws the face bitmap, created on the last DrawBox call, and
|
||||
clock hands.
|
||||
"""
|
||||
|
||||
dc.BeginDrawing()
|
||||
dc.DrawBitmap(self.faceBitmap, 0, 0)
|
||||
self.Hands.Draw(dc)
|
||||
dc.EndDrawing()
|
||||
|
||||
|
||||
# Public methods --------------------------------------------------
|
||||
|
||||
def GetHandSize(self, target=ALL):
|
||||
"""Gets thickness of hands."""
|
||||
|
||||
return self.Hands.GetSize(target)
|
||||
|
||||
|
||||
def GetHandFillColour(self, target=ALL):
|
||||
"""Gets fill colours of hands."""
|
||||
|
||||
return self.Hands.GetFillColour(target)
|
||||
|
||||
|
||||
def GetHandBorderColour(self, target=ALL):
|
||||
"""Gets border colours of hands."""
|
||||
|
||||
return self.Hands.GetBorderColour(target)
|
||||
|
||||
|
||||
def GetHandBorderWidth(self, target=ALL):
|
||||
"""Gets border widths of hands."""
|
||||
|
||||
return self.Hands.GetBorderWidth(target)
|
||||
|
||||
|
||||
def GetTickSize(self, target=ALL):
|
||||
"""Gets sizes of ticks."""
|
||||
|
||||
return self.Box.GetTickSize(target)
|
||||
|
||||
|
||||
|
||||
def GetTickFillColour(self, target=ALL):
|
||||
"""Gets fill colours of ticks."""
|
||||
|
||||
return self.Box.GetTickFillColour(target)
|
||||
|
||||
|
||||
|
||||
def GetTickBorderColour(self, target=ALL):
|
||||
"""Gets border colours of ticks."""
|
||||
|
||||
return self.Box.GetTickBorderColour(target)
|
||||
|
||||
|
||||
|
||||
def GetTickBorderWidth(self, target=ALL):
|
||||
"""Gets border widths of ticks."""
|
||||
|
||||
return self.Box.GetTickBorderWidth(target)
|
||||
|
||||
|
||||
|
||||
def GetTickPolygon(self, target=ALL):
|
||||
"""
|
||||
Gets lists of points to be used as polygon shapes
|
||||
when using the TICKS_POLY style.
|
||||
"""
|
||||
|
||||
return self.Box.GetTickPolygon(target)
|
||||
|
||||
|
||||
|
||||
def GetTickFont(self, target=ALL):
|
||||
"""
|
||||
Gets fonts for tick marks when using TICKS_DECIMAL or
|
||||
TICKS_ROMAN style.
|
||||
"""
|
||||
|
||||
return self.Box.GetTickFont(target)
|
||||
|
||||
|
||||
|
||||
def GetTickOffset(self, target=ALL):
|
||||
"""Gets the distance of tick marks for hours from border."""
|
||||
|
||||
return self.Box.GetTickOffset(target)
|
||||
|
||||
|
||||
|
||||
def GetFaceFillColour(self):
|
||||
"""Gets fill colours of watch."""
|
||||
|
||||
return self.Box.Face.GetFillColour()
|
||||
|
||||
|
||||
|
||||
def GetFaceBorderColour(self):
|
||||
"""Gets border colours of watch."""
|
||||
|
||||
return self.Box.Face.GetBorderColour()
|
||||
|
||||
|
||||
|
||||
def GetFaceBorderWidth(self):
|
||||
"""Gets border width of watch."""
|
||||
|
||||
return self.Box.Face.GetBorderWidth()
|
||||
|
||||
|
||||
|
||||
def GetShadowColour(self):
|
||||
"""Gets the colour to be used to draw shadows."""
|
||||
|
||||
a_clock_part = self.Box
|
||||
return a_clock_part.GetShadowColour()
|
||||
|
||||
|
||||
|
||||
def GetClockStyle(self):
|
||||
"""Returns the current clock style."""
|
||||
|
||||
return self.clockStyle
|
||||
|
||||
|
||||
def GetTickStyle(self, target=ALL):
|
||||
"""Gets the tick style(s)."""
|
||||
|
||||
return self.Box.GetTickStyle(target)
|
||||
|
||||
|
||||
def Refresh(self):
|
||||
"""
|
||||
Overriden base wx.Window method. Forces an immediate
|
||||
recalculation and redraw of all clock elements.
|
||||
"""
|
||||
|
||||
size = self.GetClientSize()
|
||||
if size.x < 1 or size.y < 1:
|
||||
return
|
||||
self.Freeze()
|
||||
self.RecalcCoords(size)
|
||||
self.DrawBox()
|
||||
dc = wx.BufferedDC(wx.ClientDC(self), self.GetClientSize())
|
||||
self.DrawHands(dc)
|
||||
self.Thaw()
|
||||
|
||||
|
||||
def SetHandSize(self, size, target=ALL):
|
||||
"""Sets thickness of hands."""
|
||||
|
||||
self.Hands.SetSize(size, target)
|
||||
|
||||
|
||||
def SetHandFillColour(self, colour, target=ALL):
|
||||
"""Sets fill colours of hands."""
|
||||
|
||||
self.Hands.SetFillColour(colour, target)
|
||||
|
||||
|
||||
def SetHandBorderColour(self, colour, target=ALL):
|
||||
"""Sets border colours of hands."""
|
||||
|
||||
self.Hands.SetBorderColour(colour, target)
|
||||
|
||||
|
||||
def SetHandBorderWidth(self, width, target=ALL):
|
||||
"""Sets border widths of hands."""
|
||||
|
||||
self.Hands.SetBorderWidth(width, target)
|
||||
|
||||
|
||||
def SetTickSize(self, size, target=ALL):
|
||||
"""Sets sizes of ticks."""
|
||||
|
||||
self.Box.SetTickSize(size, target)
|
||||
self.Refresh()
|
||||
|
||||
|
||||
def SetTickFillColour(self, colour, target=ALL):
|
||||
"""Sets fill colours of ticks."""
|
||||
|
||||
self.Box.SetTickFillColour(colour, target)
|
||||
self.Refresh()
|
||||
|
||||
|
||||
def SetTickBorderColour(self, colour, target=ALL):
|
||||
"""Sets border colours of ticks."""
|
||||
|
||||
self.Box.SetTickBorderColour(colour, target)
|
||||
self.Refresh()
|
||||
|
||||
|
||||
def SetTickBorderWidth(self, width, target=ALL):
|
||||
"""Sets border widths of ticks."""
|
||||
|
||||
self.Box.SetTickBorderWidth(width, target)
|
||||
self.Refresh()
|
||||
|
||||
|
||||
def SetTickPolygon(self, polygon, target=ALL):
|
||||
"""
|
||||
Sets lists of points to be used as polygon shapes
|
||||
when using the TICKS_POLY style.
|
||||
"""
|
||||
|
||||
self.Box.SetTickPolygon(polygon, target)
|
||||
self.Refresh()
|
||||
|
||||
|
||||
def SetTickFont(self, font, target=ALL):
|
||||
"""
|
||||
Sets fonts for tick marks when using text-based tick styles
|
||||
such as TICKS_DECIMAL or TICKS_ROMAN.
|
||||
"""
|
||||
|
||||
self.Box.SetTickFont(font, target)
|
||||
self.Refresh()
|
||||
|
||||
|
||||
def SetTickOffset(self, offset, target=ALL):
|
||||
"""Sets the distance of tick marks for hours from border."""
|
||||
|
||||
self.Box.SetTickOffset(offset, target)
|
||||
self.Refresh()
|
||||
|
||||
|
||||
def SetFaceFillColour(self, colour):
|
||||
"""Sets fill colours of watch."""
|
||||
|
||||
self.Box.Face.SetFillColour(colour)
|
||||
self.Refresh()
|
||||
|
||||
|
||||
def SetFaceBorderColour(self, colour):
|
||||
"""Sets border colours of watch."""
|
||||
|
||||
self.Box.Face.SetBorderColour(colour)
|
||||
self.Refresh()
|
||||
|
||||
|
||||
def SetFaceBorderWidth(self, width):
|
||||
"""Sets border width of watch."""
|
||||
|
||||
self.Box.Face.SetBorderWidth(width)
|
||||
self.Refresh()
|
||||
|
||||
|
||||
def SetShadowColour(self, colour):
|
||||
"""Sets the colour to be used to draw shadows."""
|
||||
|
||||
self.Hands.SetShadowColour(colour)
|
||||
self.Box.SetShadowColour(colour)
|
||||
self.Refresh()
|
||||
|
||||
|
||||
def SetClockStyle(self, style):
|
||||
"""
|
||||
Set the clock style, according to the options below.
|
||||
|
||||
==================== ================================
|
||||
SHOW_QUARTERS_TICKS Show marks for hours 3, 6, 9, 12
|
||||
SHOW_HOURS_TICKS Show marks for all hours
|
||||
SHOW_MINUTES_TICKS Show marks for minutes
|
||||
|
||||
SHOW_HOURS_HAND Show hours hand
|
||||
SHOW_MINUTES_HAND Show minutes hand
|
||||
SHOW_SECONDS_HAND Show seconds hand
|
||||
|
||||
SHOW_SHADOWS Show hands and marks shadows
|
||||
|
||||
ROTATE_TICKS Align tick marks to watch
|
||||
OVERLAP_TICKS Draw tick marks for minutes even
|
||||
when they match the hours marks.
|
||||
==================== ================================
|
||||
"""
|
||||
|
||||
self.clockStyle = style
|
||||
self.Box.SetIsRotated(style & ROTATE_TICKS)
|
||||
self.Refresh()
|
||||
|
||||
|
||||
def SetTickStyle(self, style, target=ALL):
|
||||
"""
|
||||
Set the tick style, according to the options below.
|
||||
|
||||
================= ======================================
|
||||
TICKS_NONE Don't show tick marks.
|
||||
TICKS_SQUARE Use squares as tick marks.
|
||||
TICKS_CIRCLE Use circles as tick marks.
|
||||
TICKS_POLY Use a polygon as tick marks. A
|
||||
polygon can be passed using
|
||||
SetTickPolygon, otherwise the default
|
||||
polygon will be used.
|
||||
TICKS_DECIMAL Use decimal numbers as tick marks.
|
||||
TICKS_ROMAN Use Roman numbers as tick marks.
|
||||
TICKS_BINARY Use binary numbers as tick marks.
|
||||
TICKS_HEX Use hexadecimal numbers as tick marks.
|
||||
================= ======================================
|
||||
"""
|
||||
|
||||
self.Box.SetTickStyle(style, target)
|
||||
self.Refresh()
|
||||
|
||||
|
||||
def SetBackgroundColour(self, colour):
|
||||
"""Overriden base wx.Window method."""
|
||||
|
||||
wx.Window.SetBackgroundColour(self, colour)
|
||||
self.Refresh()
|
||||
|
||||
|
||||
def SetForegroundColour(self, colour):
|
||||
"""
|
||||
Overriden base wx.Window method. This method sets a colour for
|
||||
all hands and ticks at once.
|
||||
"""
|
||||
|
||||
wx.Window.SetForegroundColour(self, colour)
|
||||
self.SetHandFillColour(colour)
|
||||
self.SetHandBorderColour(colour)
|
||||
self.SetTickFillColour(colour)
|
||||
self.SetTickBorderColour(colour)
|
||||
self.Refresh()
|
||||
|
||||
|
||||
def SetWindowStyle(self, *args, **kwargs):
|
||||
"""Overriden base wx.Window method."""
|
||||
|
||||
size = self.GetSize()
|
||||
self.Freeze()
|
||||
wx.Window.SetWindowStyle(self, *args, **kwargs)
|
||||
self.SetSize((10, 10))
|
||||
self.SetSize(size)
|
||||
self.Thaw()
|
||||
|
||||
|
||||
def SetWindowStyleFlag(self, *args, **kwargs):
|
||||
"""Overriden base wx.Window method."""
|
||||
|
||||
self.SetWindowStyle(*args, **kwargs)
|
||||
|
||||
|
||||
# For backwards compatibility -----------------------------------------
|
||||
|
||||
class AnalogClockWindow(AnalogClock):
|
||||
"""
|
||||
A simple derived class that provides some backwards compatibility
|
||||
with the old analogclock module.
|
||||
"""
|
||||
def SetTickShapes(self, tsh, tsm=None):
|
||||
self.SetTickPolygon(tsh)
|
||||
|
||||
def SetHandWeights(self, h=None, m=None, s=None):
|
||||
if h:
|
||||
self.SetHandSize(h, HOUR)
|
||||
if m:
|
||||
self.SetHandSize(m, MINUTE)
|
||||
if s:
|
||||
self.SetHandSize(h, SECOND)
|
||||
|
||||
def SetHandColours(self, h=None, m=None, s=None):
|
||||
if h and not m and not s:
|
||||
m=h
|
||||
s=h
|
||||
if h:
|
||||
self.SetHandBorderColour(h, HOUR)
|
||||
self.SetHandFillColour(h, HOUR)
|
||||
if m:
|
||||
self.SetHandBorderColour(m, MINUTE)
|
||||
self.SetHandFillColour(m, MINUTE)
|
||||
if s:
|
||||
self.SetHandBorderColour(h, SECOND)
|
||||
self.SetHandFillColour(h, SECOND)
|
||||
|
||||
def SetTickColours(self, h=None, m=None):
|
||||
if not m:
|
||||
m=h
|
||||
if h:
|
||||
self.SetTickBorderColour(h, HOUR)
|
||||
self.SetTickFillColour(h, HOUR)
|
||||
if m:
|
||||
self.SetTickBorderColour(m, MINUTE)
|
||||
self.SetTickFillColour(m, MINUTE)
|
||||
|
||||
def SetTickSizes(self, h=None, m=None):
|
||||
if h:
|
||||
self.SetTickSize(h, HOUR)
|
||||
if m:
|
||||
self.SetTickSize(h, MINUTE)
|
||||
|
||||
def SetTickFontss(self, h=None, m=None):
|
||||
if h:
|
||||
self.SetTickFont(h, HOUR)
|
||||
if m:
|
||||
self.SetTickFont(h, MINUTE)
|
||||
|
||||
|
||||
def SetMinutesOffset(self, o):
|
||||
pass
|
||||
|
||||
def SetShadowColour(self, s):
|
||||
pass
|
||||
|
||||
def SetWatchPenBrush(self, p=None, b=None):
|
||||
if p:
|
||||
self.SetFaceBorderColour(p.GetColour())
|
||||
self.SetFaceBorderWidth(p.GetWidth())
|
||||
if b:
|
||||
self.SetFaceFillColour(b.GetColour())
|
||||
|
||||
def SetClockStyle(self, style):
|
||||
style |= SHOW_HOURS_HAND|SHOW_MINUTES_HAND|SHOW_SECONDS_HAND
|
||||
AnalogClock.SetClockStyle(self, style)
|
||||
|
||||
def SetTickStyles(self, h=None, m=None):
|
||||
if h:
|
||||
self.SetTickStyle(h, HOUR)
|
||||
if m:
|
||||
self.SetTickStyle(h, MINUTE)
|
||||
|
||||
|
||||
# Test stuff ----------------------------------------------------------
|
||||
|
||||
if __name__ == "__main__":
|
||||
print wx.VERSION_STRING
|
||||
|
||||
class AcDemoApp(wx.App):
|
||||
def OnInit(self):
|
||||
frame = wx.Frame(None, -1, "AnalogClock", size=(375, 375))
|
||||
clock = AnalogClock(frame)
|
||||
frame.CentreOnScreen()
|
||||
frame.Show()
|
||||
return True
|
||||
|
||||
acApp = AcDemoApp(0)
|
||||
acApp.MainLoop()
|
||||
|
||||
|
||||
#
|
||||
##
|
||||
### eof
|
983
wxPython/wx/lib/analogclock/helpers.py
Normal file
983
wxPython/wx/lib/analogclock/helpers.py
Normal file
@@ -0,0 +1,983 @@
|
||||
# AnalogClock's base classes
|
||||
# E. A. Tacao <e.a.tacao |at| estadao.com.br>
|
||||
# http://j.domaindlx.com/elements28/wxpython/
|
||||
# 15 Fev 2006, 22:00 GMT-03:00
|
||||
# Distributed under the wxWidgets license.
|
||||
|
||||
from time import strftime, localtime
|
||||
import math
|
||||
import wx
|
||||
|
||||
from styles import *
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
_targets = [HOUR, MINUTE, SECOND]
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class Element:
|
||||
"""Base class for face, hands and tick marks."""
|
||||
|
||||
def __init__(self, idx=0, pos=None, size=None, offset=0, clocksize=None,
|
||||
scale=1, rotate=False, kind=""):
|
||||
|
||||
self.idx = idx
|
||||
self.pos = pos
|
||||
self.size = size
|
||||
self.offset = offset
|
||||
self.clocksize = clocksize
|
||||
self.scale = scale
|
||||
self.rotate = rotate
|
||||
self.kind = kind
|
||||
|
||||
self.text = None
|
||||
self.angfac = [6, 30][self.kind == "hours"]
|
||||
|
||||
|
||||
def _pol2rect(self, m, t):
|
||||
return m * math.cos(math.radians(t)), m * math.sin(math.radians(t))
|
||||
|
||||
|
||||
def _rect2pol(self, x, y):
|
||||
return math.hypot(x, y), math.degrees(math.atan2(y, x))
|
||||
|
||||
|
||||
def DrawRotated(self, dc, offset=0):
|
||||
pass
|
||||
|
||||
|
||||
def DrawStraight(self, dc, offset=0):
|
||||
pass
|
||||
|
||||
|
||||
def Draw(self, dc, offset=0):
|
||||
if self.rotate:
|
||||
self.DrawRotated(dc, offset)
|
||||
else:
|
||||
self.DrawStraight(dc, offset)
|
||||
|
||||
|
||||
def RecalcCoords(self, clocksize, centre, scale):
|
||||
pass
|
||||
|
||||
|
||||
def GetSize(self):
|
||||
return self.size
|
||||
|
||||
|
||||
def GetOffset(self):
|
||||
return self.offset
|
||||
|
||||
|
||||
def GetIsRotated(self, rotate):
|
||||
return self.rotate
|
||||
|
||||
|
||||
def GetMaxSize(self, scale=1):
|
||||
return self.size * scale
|
||||
|
||||
|
||||
def GetScale(self):
|
||||
return self.scale
|
||||
|
||||
|
||||
def SetIsRotated(self, rotate):
|
||||
self.rotate = rotate
|
||||
|
||||
|
||||
def GetMaxSize(self, scale=1):
|
||||
return self.size * scale
|
||||
|
||||
|
||||
def GetPolygon(self):
|
||||
return self.polygon
|
||||
|
||||
|
||||
def SetPosition(self, pos):
|
||||
self.pos = pos
|
||||
|
||||
|
||||
def SetSize(self, size):
|
||||
self.size = size
|
||||
|
||||
|
||||
def SetOffset(self, offset):
|
||||
self.offset = offset
|
||||
|
||||
|
||||
def SetClockSize(self, clocksize):
|
||||
self.clocksize = clocksize
|
||||
|
||||
|
||||
def SetScale(self, scale):
|
||||
self.scale = scale
|
||||
|
||||
|
||||
def SetIsRotated(self, rotate):
|
||||
self.rotate = rotate
|
||||
|
||||
|
||||
def SetPolygon(self, polygon):
|
||||
self.polygon = polygon
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class ElementWithDyer(Element):
|
||||
"""Base class for clock face and hands."""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.dyer = kwargs.pop("dyer", Dyer())
|
||||
Element.__init__(self, **kwargs)
|
||||
|
||||
|
||||
def GetFillColour(self):
|
||||
return self.dyer.GetFillColour()
|
||||
|
||||
|
||||
def GetBorderColour(self):
|
||||
return self.dyer.GetBorderColour()
|
||||
|
||||
|
||||
def GetBorderWidth(self):
|
||||
return self.dyer.GetBorderWidth()
|
||||
|
||||
|
||||
def GetShadowColour(self):
|
||||
return self.dyer.GetShadowColour()
|
||||
|
||||
|
||||
def SetFillColour(self, colour):
|
||||
self.dyer.SetFillColour(colour)
|
||||
|
||||
|
||||
def SetBorderColour(self, colour):
|
||||
self.dyer.SetBorderColour(colour)
|
||||
|
||||
|
||||
def SetBorderWidth(self, width):
|
||||
self.dyer.SetBorderWidth(width)
|
||||
|
||||
|
||||
def SetShadowColour(self, colour):
|
||||
self.dyer.SetShadowColour(colour)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class Face(ElementWithDyer):
|
||||
"""Holds info about the clock face."""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
ElementWithDyer.__init__(self, **kwargs)
|
||||
|
||||
|
||||
def Draw(self, dc):
|
||||
self.dyer.Select(dc)
|
||||
dc.DrawCircle(self.pos.x, self.pos.y, self.radius)
|
||||
|
||||
|
||||
def RecalcCoords(self, clocksize, centre, scale):
|
||||
self.radius = min(clocksize.Get()) / 2. - self.dyer.width / 2.
|
||||
self.pos = centre
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class Hand(ElementWithDyer):
|
||||
"""Holds info about a clock hand."""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.lenfac = kwargs.pop("lenfac")
|
||||
ElementWithDyer.__init__(self, **kwargs)
|
||||
|
||||
self.SetPolygon([[-1, 0], [0, -1], [1, 0], [0, 4]])
|
||||
|
||||
|
||||
def Draw(self, dc, end, offset=0):
|
||||
radius, centre, r = end
|
||||
angle = math.degrees(r)
|
||||
polygon = self.polygon[:]
|
||||
vscale = radius / max([y for x, y in polygon])
|
||||
|
||||
for i, (x, y) in enumerate(polygon):
|
||||
x *= self.scale * self.size
|
||||
y *= vscale * self.lenfac
|
||||
m, t = self._rect2pol(x, y)
|
||||
polygon[i] = self._pol2rect(m, t - angle)
|
||||
|
||||
dc.DrawPolygon(polygon, centre.x + offset, centre.y + offset)
|
||||
|
||||
|
||||
def RecalcCoords(self, clocksize, centre, scale):
|
||||
self.pos = centre
|
||||
self.scale = scale
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TickSquare(Element):
|
||||
"""Holds info about a tick mark."""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
Element.__init__(self, **kwargs)
|
||||
|
||||
|
||||
def Draw(self, dc, offset=0):
|
||||
width = height = self.size * self.scale
|
||||
x = self.pos.x - width / 2.
|
||||
y = self.pos.y - height / 2.
|
||||
|
||||
dc.DrawRectangle(x + offset, y + offset, width, height)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TickCircle(Element):
|
||||
"""Holds info about a tick mark."""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
Element.__init__(self, **kwargs)
|
||||
|
||||
|
||||
def Draw(self, dc, offset=0):
|
||||
radius = self.size * self.scale / 2.
|
||||
x = self.pos.x
|
||||
y = self.pos.y
|
||||
|
||||
dc.DrawCircle(x + offset, y + offset, radius)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TickPoly(Element):
|
||||
"""Holds info about a tick mark."""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
Element.__init__(self, **kwargs)
|
||||
|
||||
self.SetPolygon([[0, 1], [1, 0], [2, 1], [1, 5]])
|
||||
|
||||
|
||||
def _calcPolygon(self):
|
||||
width = max([x for x, y in self.polygon])
|
||||
height = max([y for x, y in self.polygon])
|
||||
tscale = self.size / max(width, height) * self.scale
|
||||
polygon = [(x * tscale, y * tscale) for x, y in self.polygon]
|
||||
|
||||
width = max([x for x, y in polygon])
|
||||
height = max([y for x, y in polygon])
|
||||
|
||||
return polygon, width, height
|
||||
|
||||
|
||||
def DrawStraight(self, dc, offset=0):
|
||||
polygon, width, height = self._calcPolygon()
|
||||
|
||||
x = self.pos.x - width / 2.
|
||||
y = self.pos.y - height / 2.
|
||||
|
||||
dc.DrawPolygon(polygon, x + offset, y + offset)
|
||||
|
||||
|
||||
def DrawRotated(self, dc, offset=0):
|
||||
polygon, width, height = self._calcPolygon()
|
||||
|
||||
angle = 360 - self.angfac * (self.idx + 1)
|
||||
r = math.radians(angle)
|
||||
|
||||
for i in range(len(polygon)):
|
||||
m, t = self._rect2pol(*polygon[i])
|
||||
t -= angle
|
||||
polygon[i] = self._pol2rect(m, t)
|
||||
|
||||
x = self.pos.x - math.cos(r) * width / 2. - math.sin(r) * height / 2.
|
||||
y = self.pos.y - math.cos(r) * height / 2. + math.sin(r) * width / 2.
|
||||
|
||||
dc.DrawPolygon(polygon, x + offset, y + offset)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TickDecimal(Element):
|
||||
"""Holds info about a tick mark."""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
Element.__init__(self, **kwargs)
|
||||
|
||||
self.text = "%s" % (self.idx + 1)
|
||||
|
||||
|
||||
def DrawStraight(self, dc, offset=0):
|
||||
width, height = dc.GetTextExtent(self.text)
|
||||
|
||||
x = self.pos.x - width / 2.
|
||||
y = self.pos.y - height / 2.
|
||||
|
||||
dc.DrawText(self.text, x + offset, y + offset)
|
||||
|
||||
|
||||
def DrawRotated(self, dc, offset=0):
|
||||
width, height = dc.GetTextExtent(self.text)
|
||||
|
||||
angle = 360 - self.angfac * (self.idx + 1)
|
||||
r = math.radians(angle)
|
||||
|
||||
x = self.pos.x - math.cos(r) * width / 2. - math.sin(r) * height / 2.
|
||||
y = self.pos.y - math.cos(r) * height / 2. + math.sin(r) * width / 2.
|
||||
|
||||
dc.DrawRotatedText(self.text, x + offset, y + offset, angle)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TickRoman(TickDecimal):
|
||||
"""Holds info about a tick mark."""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
TickDecimal.__init__(self, **kwargs)
|
||||
|
||||
self.text = ["I","II","III","IV","V", \
|
||||
"VI","VII","VIII","IX","X", \
|
||||
"XI","XII","XIII","XIV","XV", \
|
||||
"XVI","XVII","XVIII","XIX","XX", \
|
||||
"XXI","XXII","XXIII","XXIV","XXV", \
|
||||
"XXVI","XXVII","XXVIII","XXIX","XXX", \
|
||||
"XXXI","XXXII","XXXIII","XXXIV","XXXV", \
|
||||
"XXXVI","XXXVII","XXXVIII","XXXIX","XL", \
|
||||
"XLI","XLII","XLIII","XLIV","XLV", \
|
||||
"XLVI","XLVII","XLVIII","XLIX","L", \
|
||||
"LI","LII","LIII","LIV","LV", \
|
||||
"LVI","LVII","LVIII","LIX","LX"][self.idx]
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TickBinary(TickDecimal):
|
||||
"""Holds info about a tick mark."""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
TickDecimal.__init__(self, **kwargs)
|
||||
|
||||
def d2b(n, b=""):
|
||||
while n > 0:
|
||||
b = str(n % 2) + b; n = n >> 1
|
||||
return b.zfill(4)
|
||||
|
||||
self.text = d2b(self.idx + 1)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TickHex(TickDecimal):
|
||||
"""Holds info about a tick mark."""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
TickDecimal.__init__(self, **kwargs)
|
||||
|
||||
self.text = hex(self.idx + 1)[2:].upper()
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TickNone(Element):
|
||||
"""Holds info about a tick mark."""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
Element.__init__(self, **kwargs)
|
||||
|
||||
|
||||
def Draw(self, dc, offset=0):
|
||||
pass
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class Dyer:
|
||||
"""Stores info about colours and borders of clock Elements."""
|
||||
|
||||
def __init__(self, border=None, width=0, fill=None, shadow=None):
|
||||
"""
|
||||
self.border (wx.Colour) border colour
|
||||
self.width (int) border width
|
||||
self.fill (wx.Colour) fill colour
|
||||
self.shadow (wx.Colour) shadow colour
|
||||
"""
|
||||
|
||||
self.border = border or \
|
||||
wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
|
||||
self.fill = fill or \
|
||||
wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
|
||||
self.shadow = shadow or \
|
||||
wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DSHADOW)
|
||||
self.width = width
|
||||
|
||||
|
||||
def Select(self, dc, shadow=False):
|
||||
"""Selects the current settings into the dc."""
|
||||
|
||||
if not shadow:
|
||||
dc.SetPen(wx.Pen(self.border, self.width, wx.SOLID))
|
||||
dc.SetBrush(wx.Brush(self.fill, wx.SOLID))
|
||||
dc.SetTextForeground(self.fill)
|
||||
else:
|
||||
dc.SetPen(wx.Pen(self.shadow, self.width, wx.SOLID))
|
||||
dc.SetBrush(wx.Brush(self.shadow, wx.SOLID))
|
||||
dc.SetTextForeground(self.shadow)
|
||||
|
||||
|
||||
def GetFillColour(self):
|
||||
return self.fill
|
||||
|
||||
|
||||
def GetBorderColour(self):
|
||||
return self.border
|
||||
|
||||
|
||||
def GetBorderWidth(self):
|
||||
return self.width
|
||||
|
||||
|
||||
def GetShadowColour(self):
|
||||
return self.shadow
|
||||
|
||||
|
||||
def SetFillColour(self, colour):
|
||||
self.fill = colour
|
||||
|
||||
|
||||
def SetBorderColour(self, colour):
|
||||
self.border = colour
|
||||
|
||||
|
||||
def SetBorderWidth(self, width):
|
||||
self.width = width
|
||||
|
||||
|
||||
def SetShadowColour(self, colour):
|
||||
self.shadow = colour
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class HandSet:
|
||||
"""Manages the set of hands."""
|
||||
|
||||
def __init__(self, parent, h, m, s):
|
||||
self.parent = parent
|
||||
|
||||
self.hands = [h, m, s]
|
||||
self.radius = 1
|
||||
self.centre = wx.Point(1, 1)
|
||||
|
||||
|
||||
def _draw(self, dc, shadow=False):
|
||||
ends = [int(x) for x in strftime("%I %M %S", localtime()).split()]
|
||||
|
||||
flags = [self.parent.clockStyle & flag \
|
||||
for flag in self.parent.allHandStyles]
|
||||
|
||||
a_hand = self.hands[0]
|
||||
|
||||
if shadow:
|
||||
offset = self.parent.shadowOffset * a_hand.GetScale()
|
||||
else:
|
||||
offset = 0
|
||||
|
||||
for i, hand in enumerate(self.hands):
|
||||
# Is this hand supposed to be drawn?
|
||||
if flags[i]:
|
||||
idx = ends[i]
|
||||
# Is this the hours hand?
|
||||
if i == 0:
|
||||
idx = idx * 5 + ends[1] / 12
|
||||
# Adjust idx offset and prevent exceptions on leap seconds.
|
||||
idx = idx - 1
|
||||
if idx < 0 or idx > 59:
|
||||
idx = 59
|
||||
angle = math.radians(180 - 6 * (idx + 1))
|
||||
|
||||
hand.dyer.Select(dc, shadow)
|
||||
hand.Draw(dc, (self.radius, self.centre, angle), offset)
|
||||
|
||||
|
||||
def Draw(self, dc):
|
||||
if self.parent.clockStyle & SHOW_SHADOWS:
|
||||
self._draw(dc, True)
|
||||
self._draw(dc)
|
||||
|
||||
|
||||
def RecalcCoords(self, clocksize, centre, scale):
|
||||
self.centre = centre
|
||||
[hand.RecalcCoords(clocksize, centre, scale) for hand in self.hands]
|
||||
|
||||
|
||||
def SetMaxRadius(self, radius):
|
||||
self.radius = radius
|
||||
|
||||
|
||||
def GetSize(self, target):
|
||||
r = []
|
||||
for i, hand in enumerate(self.hands):
|
||||
if _targets[i] & target:
|
||||
r.append(hand.GetSize())
|
||||
return tuple(r)
|
||||
|
||||
|
||||
def GetFillColour(self, target):
|
||||
r = []
|
||||
for i, hand in enumerate(self.hands):
|
||||
if _targets[i] & target:
|
||||
r.append(hand.GetFillColour())
|
||||
return tuple(r)
|
||||
|
||||
|
||||
def GetBorderColour(self, target):
|
||||
r = []
|
||||
for i, hand in enumerate(self.hands):
|
||||
if _targets[i] & target:
|
||||
r.append(hand.GetBorderColour())
|
||||
return tuple(r)
|
||||
|
||||
|
||||
def GetBorderWidth(self, target):
|
||||
r = []
|
||||
for i, hand in enumerate(self.hands):
|
||||
if _targets[i] & target:
|
||||
r.append(hand.GetBorderWidth())
|
||||
return tuple(r)
|
||||
|
||||
|
||||
def GetShadowColour(self):
|
||||
r = []
|
||||
for i, hand in enumerate(self.hands):
|
||||
if _targets[i] & target:
|
||||
r.append(hand.GetShadowColour())
|
||||
return tuple(r)
|
||||
|
||||
|
||||
def SetSize(self, size, target):
|
||||
for i, hand in enumerate(self.hands):
|
||||
if _targets[i] & target:
|
||||
hand.SetSize(size)
|
||||
|
||||
|
||||
def SetFillColour(self, colour, target):
|
||||
for i, hand in enumerate(self.hands):
|
||||
if _targets[i] & target:
|
||||
hand.SetFillColour(colour)
|
||||
|
||||
|
||||
def SetBorderColour(self, colour, target):
|
||||
for i, hand in enumerate(self.hands):
|
||||
if _targets[i] & target:
|
||||
hand.SetBorderColour(colour)
|
||||
|
||||
|
||||
def SetBorderWidth(self, width, target):
|
||||
for i, hand in enumerate(self.hands):
|
||||
if _targets[i] & target:
|
||||
hand.SetBorderWidth(width)
|
||||
|
||||
|
||||
def SetShadowColour(self, colour):
|
||||
for i, hand in enumerate(self.hands):
|
||||
hand.SetShadowColour(colour)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TickSet:
|
||||
"""Manages a set of tick marks."""
|
||||
|
||||
def __init__(self, parent, **kwargs):
|
||||
self.parent = parent
|
||||
self.dyer = Dyer()
|
||||
self.noe = {"minutes": 60, "hours": 12}[kwargs["kind"]]
|
||||
self.font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
|
||||
|
||||
style = kwargs.pop("style")
|
||||
self.kwargs = kwargs
|
||||
self.SetStyle(style)
|
||||
|
||||
|
||||
def _draw(self, dc, shadow=False):
|
||||
dc.SetFont(self.font)
|
||||
|
||||
a_tick = self.ticks[0]
|
||||
|
||||
if shadow:
|
||||
offset = self.parent.shadowOffset * a_tick.GetScale()
|
||||
else:
|
||||
offset = 0
|
||||
|
||||
clockStyle = self.parent.clockStyle
|
||||
|
||||
for idx, tick in self.ticks.items():
|
||||
draw = False
|
||||
|
||||
# Are we a set of hours?
|
||||
if self.noe == 12:
|
||||
# Should we show all hours ticks?
|
||||
if clockStyle & SHOW_HOURS_TICKS:
|
||||
draw = True
|
||||
# Or is this tick a quarter and should we show only quarters?
|
||||
elif clockStyle & SHOW_QUARTERS_TICKS and not (idx + 1) % 3.:
|
||||
draw = True
|
||||
# Are we a set of minutes and minutes should be shown?
|
||||
elif self.noe == 60 and clockStyle & SHOW_MINUTES_TICKS:
|
||||
# If this tick occupies the same position of an hour/quarter
|
||||
# tick, should we still draw it anyway?
|
||||
if clockStyle & OVERLAP_TICKS:
|
||||
draw = True
|
||||
# Right, sir. I promise I won't overlap any tick.
|
||||
else:
|
||||
# Ensure that this tick won't overlap an hour tick.
|
||||
if clockStyle & SHOW_HOURS_TICKS:
|
||||
if (idx + 1) % 5.:
|
||||
draw = True
|
||||
# Ensure that this tick won't overlap a quarter tick.
|
||||
elif clockStyle & SHOW_QUARTERS_TICKS:
|
||||
if (idx + 1) % 15.:
|
||||
draw = True
|
||||
# We're not drawing quarters nor hours, so we can draw all
|
||||
# minutes ticks.
|
||||
else:
|
||||
draw = True
|
||||
|
||||
if draw:
|
||||
tick.Draw(dc, offset)
|
||||
|
||||
|
||||
def Draw(self, dc):
|
||||
if self.parent.clockStyle & SHOW_SHADOWS:
|
||||
self.dyer.Select(dc, True)
|
||||
self._draw(dc, True)
|
||||
self.dyer.Select(dc)
|
||||
self._draw(dc)
|
||||
|
||||
|
||||
def RecalcCoords(self, clocksize, centre, scale):
|
||||
a_tick = self.ticks[0]
|
||||
|
||||
size = a_tick.GetMaxSize(scale)
|
||||
self.font.SetPointSize(size)
|
||||
maxsize = size
|
||||
|
||||
# Try to find a 'good' max size for text-based ticks.
|
||||
if a_tick.text is not None:
|
||||
dc = wx.MemoryDC()
|
||||
dc.SelectObject(wx.EmptyBitmap(*clocksize.Get()))
|
||||
dc.SetFont(self.font)
|
||||
maxsize = size
|
||||
for tick in self.ticks.values():
|
||||
maxsize = max(*(dc.GetTextExtent(tick.text) + (maxsize,)))
|
||||
|
||||
radius = self.radius = min(clocksize.Get()) / 2. - \
|
||||
self.dyer.width / 2. - \
|
||||
maxsize / 2. - \
|
||||
a_tick.GetOffset() * scale - \
|
||||
self.parent.shadowOffset * scale
|
||||
|
||||
# If we are a set of hours, the number of elements of this tickset is
|
||||
# 12 and ticks are separated by a distance of 30 degrees;
|
||||
# if we are a set of minutes, the number of elements of this tickset is
|
||||
# 60 and ticks are separated by a distance of 6 degrees.
|
||||
angfac = [6, 30][self.noe == 12]
|
||||
|
||||
for i, tick in self.ticks.items():
|
||||
tick.SetClockSize(clocksize)
|
||||
tick.SetScale(scale)
|
||||
|
||||
deg = 180 - angfac * (i + 1)
|
||||
angle = math.radians(deg)
|
||||
|
||||
x = centre.x + radius * math.sin(angle)
|
||||
y = centre.y + radius * math.cos(angle)
|
||||
|
||||
tick.SetPosition(wx.Point(x, y))
|
||||
|
||||
|
||||
def GetSize(self):
|
||||
return self.kwargs["size"]
|
||||
|
||||
|
||||
def GetFillColour(self):
|
||||
return self.dyer.GetFillColour()
|
||||
|
||||
|
||||
def GetBorderColour(self):
|
||||
return self.dyer.GetBorderColour()
|
||||
|
||||
|
||||
def GetBorderWidth(self):
|
||||
return self.dyer.GetBorderWidth()
|
||||
|
||||
|
||||
def GetPolygon(self):
|
||||
a_tick = self.ticks.values()[0]
|
||||
return a_tick.GetPolygon()
|
||||
|
||||
|
||||
def GetFont(self):
|
||||
return self.font
|
||||
|
||||
|
||||
def GetOffset(self):
|
||||
a_tick = self.ticks[0]
|
||||
return a_tick.GetOffset()
|
||||
|
||||
|
||||
def GetShadowColour(self):
|
||||
return self.dyer.GetShadowColour()
|
||||
|
||||
|
||||
def GetIsRotated(self):
|
||||
a_tick = self.ticks[0]
|
||||
return a_tick.GetIsRotated()
|
||||
|
||||
|
||||
def GetStyle(self):
|
||||
return self.style
|
||||
|
||||
|
||||
def SetSize(self, size):
|
||||
self.kwargs["size"] = size
|
||||
[tick.SetSize(size) for tick in self.ticks.values()]
|
||||
|
||||
|
||||
def SetFillColour(self, colour):
|
||||
self.dyer.SetFillColour(colour)
|
||||
|
||||
|
||||
def SetBorderColour(self, colour):
|
||||
self.dyer.SetBorderColour(colour)
|
||||
|
||||
|
||||
def SetBorderWidth(self, width):
|
||||
self.dyer.SetBorderWidth(width)
|
||||
|
||||
|
||||
def SetPolygon(self, polygon):
|
||||
[tick.SetPolygon(polygon) for tick in self.ticks.values()]
|
||||
|
||||
|
||||
def SetFont(self, font):
|
||||
self.font = font
|
||||
|
||||
|
||||
def SetOffset(self, offset):
|
||||
self.kwargs["offset"] = offset
|
||||
[tick.SetOffset(offset) for tick in self.ticks.values()]
|
||||
|
||||
|
||||
def SetShadowColour(self, colour):
|
||||
self.dyer.SetShadowColour(colour)
|
||||
|
||||
|
||||
def SetIsRotated(self, rotate):
|
||||
self.kwargs["rotate"] = rotate
|
||||
[tick.SetIsRotated(rotate) for tick in self.ticks.values()]
|
||||
|
||||
|
||||
def SetStyle(self, style):
|
||||
self.style = style
|
||||
tickclass = allTickStyles[style]
|
||||
self.kwargs["rotate"] = self.parent.clockStyle & ROTATE_TICKS
|
||||
|
||||
self.ticks = {}
|
||||
for i in range(self.noe):
|
||||
self.kwargs["idx"] = i
|
||||
self.ticks[i] = tickclass(**self.kwargs)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class Box:
|
||||
"""Gathers info about the clock face and tick sets."""
|
||||
|
||||
def __init__(self, parent, Face, TicksM, TicksH):
|
||||
self.parent = parent
|
||||
self.Face = Face
|
||||
self.TicksH = TicksH
|
||||
self.TicksM = TicksM
|
||||
|
||||
|
||||
def GetNiceRadiusForHands(self, centre):
|
||||
a_tick = self.TicksM.ticks[0]
|
||||
scale = a_tick.GetScale()
|
||||
bw = max(self.TicksH.dyer.width / 2. * scale,
|
||||
self.TicksM.dyer.width / 2. * scale)
|
||||
|
||||
mgt = self.TicksM.ticks[59]
|
||||
my = mgt.pos.y + mgt.GetMaxSize(scale) + bw
|
||||
|
||||
hgt = self.TicksH.ticks[11]
|
||||
hy = hgt.pos.y + hgt.GetMaxSize(scale) + bw
|
||||
|
||||
niceradius = centre.y - max(my, hy)
|
||||
return niceradius
|
||||
|
||||
|
||||
def Draw(self, dc):
|
||||
[getattr(self, attr).Draw(dc) \
|
||||
for attr in ["Face", "TicksM", "TicksH"]]
|
||||
|
||||
|
||||
def RecalcCoords(self, size, centre, scale):
|
||||
[getattr(self, attr).RecalcCoords(size, centre, scale) \
|
||||
for attr in ["Face", "TicksH", "TicksM"]]
|
||||
|
||||
|
||||
def GetTickSize(self, target):
|
||||
r = []
|
||||
for i, attr in enumerate(["TicksH", "TicksM"]):
|
||||
if _targets[i] & target:
|
||||
tick = getattr(self, attr)
|
||||
r.append(tick.GetSize())
|
||||
return tuple(r)
|
||||
|
||||
|
||||
def GetTickFillColour(self, target):
|
||||
r = []
|
||||
for i, attr in enumerate(["TicksH", "TicksM"]):
|
||||
if _targets[i] & target:
|
||||
tick = getattr(self, attr)
|
||||
r.append(tick.GetFillColour())
|
||||
return tuple(r)
|
||||
|
||||
|
||||
def GetTickBorderColour(self, target):
|
||||
r = []
|
||||
for i, attr in enumerate(["TicksH", "TicksM"]):
|
||||
if _targets[i] & target:
|
||||
tick = getattr(self, attr)
|
||||
r.append(tick.GetBorderColour())
|
||||
return tuple(r)
|
||||
|
||||
|
||||
def GetTickBorderWidth(self, target):
|
||||
r = []
|
||||
for i, attr in enumerate(["TicksH", "TicksM"]):
|
||||
if _targets[i] & target:
|
||||
tick = getattr(self, attr)
|
||||
r.append(tick.GetBorderWidth())
|
||||
return tuple(r)
|
||||
|
||||
|
||||
def GetTickPolygon(self, target):
|
||||
r = []
|
||||
for i, attr in enumerate(["TicksH", "TicksM"]):
|
||||
if _targets[i] & target:
|
||||
tick = getattr(self, attr)
|
||||
r.append(tick.GetPolygon())
|
||||
return tuple(r)
|
||||
|
||||
|
||||
def GetTickFont(self, target):
|
||||
r = []
|
||||
for i, attr in enumerate(["TicksH", "TicksM"]):
|
||||
if _targets[i] & target:
|
||||
tick = getattr(self, attr)
|
||||
r.append(tick.GetFont())
|
||||
return tuple(r)
|
||||
|
||||
|
||||
def GetIsRotated(self):
|
||||
a_tickset = self.TicksH
|
||||
return a_tickset.GetIsRotated()
|
||||
|
||||
|
||||
def GetTickOffset(self, target):
|
||||
r = []
|
||||
for i, attr in enumerate(["TicksH", "TicksM"]):
|
||||
if _targets[i] & target:
|
||||
tick = getattr(self, attr)
|
||||
r.append(tick.GetOffset())
|
||||
return tuple(r)
|
||||
|
||||
|
||||
def GetShadowColour(self):
|
||||
a_tickset = self.TicksH
|
||||
return a_tickset.GetShadowColour()
|
||||
|
||||
|
||||
def GetTickStyle(self, target):
|
||||
r = []
|
||||
for i, attr in enumerate(["TicksH", "TicksM"]):
|
||||
if _targets[i] & target:
|
||||
tick = getattr(self, attr)
|
||||
r.append(tick.GetStyle())
|
||||
return tuple(r)
|
||||
|
||||
|
||||
def SetTickSize(self, size, target):
|
||||
for i, attr in enumerate(["TicksH", "TicksM"]):
|
||||
if _targets[i] & target:
|
||||
tick = getattr(self, attr)
|
||||
tick.SetSize(size)
|
||||
|
||||
|
||||
def SetTickFillColour(self, colour, target):
|
||||
for i, attr in enumerate(["TicksH", "TicksM"]):
|
||||
if _targets[i] & target:
|
||||
tick = getattr(self, attr)
|
||||
tick.SetFillColour(colour)
|
||||
|
||||
|
||||
def SetTickBorderColour(self, colour, target):
|
||||
for i, attr in enumerate(["TicksH", "TicksM"]):
|
||||
if _targets[i] & target:
|
||||
tick = getattr(self, attr)
|
||||
tick.SetBorderColour(colour)
|
||||
|
||||
|
||||
def SetTickBorderWidth(self, width, target):
|
||||
for i, attr in enumerate(["TicksH", "TicksM"]):
|
||||
if _targets[i] & target:
|
||||
tick = getattr(self, attr)
|
||||
tick.SetBorderWidth(width)
|
||||
|
||||
|
||||
def SetTickPolygon(self, polygon, target):
|
||||
for i, attr in enumerate(["TicksH", "TicksM"]):
|
||||
if _targets[i] & target:
|
||||
tick = getattr(self, attr)
|
||||
tick.SetPolygon(polygon)
|
||||
|
||||
|
||||
def SetTickFont(self, font, target):
|
||||
fs = font.GetNativeFontInfoDesc()
|
||||
for i, attr in enumerate(["TicksH", "TicksM"]):
|
||||
if _targets[i] & target:
|
||||
tick = getattr(self, attr)
|
||||
tick.SetFont(wx.FontFromNativeInfoString(fs))
|
||||
|
||||
|
||||
def SetIsRotated(self, rotate):
|
||||
[getattr(self, attr).SetIsRotated(rotate) \
|
||||
for attr in ["TicksH", "TicksM"]]
|
||||
|
||||
|
||||
def SetTickOffset(self, offset, target):
|
||||
for i, attr in enumerate(["TicksH", "TicksM"]):
|
||||
if _targets[i] & target:
|
||||
tick = getattr(self, attr)
|
||||
tick.SetOffset(offset)
|
||||
|
||||
|
||||
def SetShadowColour(self, colour):
|
||||
for attr in ["TicksH", "TicksM"]:
|
||||
tick = getattr(self, attr)
|
||||
tick.SetShadowColour(colour)
|
||||
|
||||
|
||||
def SetTickStyle(self, style, target):
|
||||
for i, attr in enumerate(["TicksH", "TicksM"]):
|
||||
if _targets[i] & target:
|
||||
tick = getattr(self, attr)
|
||||
tick.SetStyle(style)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
# Relationship between styles and ticks class names.
|
||||
allTickStyles = {TICKS_BINARY: TickBinary,
|
||||
TICKS_CIRCLE: TickCircle,
|
||||
TICKS_DECIMAL: TickDecimal,
|
||||
TICKS_HEX: TickHex,
|
||||
TICKS_NONE: TickNone,
|
||||
TICKS_POLY: TickPoly,
|
||||
TICKS_ROMAN: TickRoman,
|
||||
TICKS_SQUARE: TickSquare}
|
||||
|
||||
|
||||
#
|
||||
##
|
||||
### eof
|
0
wxPython/wx/lib/analogclock/lib_setup/__init__.py
Normal file
0
wxPython/wx/lib/analogclock/lib_setup/__init__.py
Normal file
350
wxPython/wx/lib/analogclock/lib_setup/buttontreectrlpanel.py
Normal file
350
wxPython/wx/lib/analogclock/lib_setup/buttontreectrlpanel.py
Normal file
@@ -0,0 +1,350 @@
|
||||
__author__ = "E. A. Tacao <e.a.tacao |at| estadao.com.br>"
|
||||
__date__ = "12 Fev 2006, 22:00 GMT-03:00"
|
||||
__version__ = "0.03"
|
||||
__doc__ = """
|
||||
ButtonTreeCtrlPanel is a widget where one can place check buttons, tri-state
|
||||
check buttons, radio buttons, both, and the ability to display them
|
||||
hierarchically.
|
||||
|
||||
|
||||
About:
|
||||
|
||||
ButtonTreeCtrlPanel is distributed under the wxWidgets license.
|
||||
|
||||
For all kind of problems, requests, enhancements, bug reports, etc,
|
||||
please drop me an e-mail.
|
||||
|
||||
For updates please visit <http://j.domaindlx.com/elements28/wxpython/>.
|
||||
"""
|
||||
|
||||
import cStringIO
|
||||
|
||||
import wx
|
||||
from wx.lib.newevent import NewEvent
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
(ButtonTreeCtrlPanelEvent, EVT_BUTTONTREECTRLPANEL) = NewEvent()
|
||||
EVT_CHANGED = EVT_BUTTONTREECTRLPANEL
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
class ButtonTreeCtrlPanel(wx.Panel):
|
||||
def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
|
||||
size=wx.DefaultSize, style=wx.WANTS_CHARS):
|
||||
wx.Panel.__init__(self, parent, id, pos, size, style)
|
||||
|
||||
self.tree = wx.TreeCtrl(self, style=wx.TR_NO_LINES|wx.TR_HIDE_ROOT)
|
||||
|
||||
il = self.il = wx.ImageList(16, 16)
|
||||
self.tree.SetImageList(il)
|
||||
|
||||
for bl in ["checkbox_checked", "checkbox_unchecked", "checkbox_tri",
|
||||
"radiobox_checked", "radiobox_unchecked"]:
|
||||
setattr(self, bl, il.Add(getattr(self, "get%sBitmap" % bl)()))
|
||||
|
||||
bmp = wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_TOOLBAR, (16, 16))
|
||||
self.empty_bitmap = il.Add(bmp)
|
||||
|
||||
self.root = self.tree.AddRoot("Root Item for ButtonTreeCtrlPanel")
|
||||
|
||||
self.Bind(wx.EVT_SIZE, self.OnSize)
|
||||
self.tree.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftClicks)
|
||||
self.tree.Bind(wx.EVT_LEFT_DOWN, self.OnLeftClicks)
|
||||
self.tree.Bind(wx.EVT_RIGHT_DOWN, self.OnRightClick)
|
||||
|
||||
self.allitems = []
|
||||
|
||||
wx.CallAfter(self.OnSize)
|
||||
|
||||
|
||||
def _doLogicTest(self, style, value, item):
|
||||
if style in [wx.CHK_2STATE, wx.CHK_3STATE]:
|
||||
n = [self.checkbox_unchecked, self.checkbox_checked, \
|
||||
self.checkbox_tri][value]
|
||||
|
||||
self.tree.SetPyData(item, (value, style))
|
||||
self.tree.SetItemImage(item, n, wx.TreeItemIcon_Normal)
|
||||
|
||||
elif style == wx.RB_SINGLE:
|
||||
if value:
|
||||
parent = self.tree.GetItemParent(item)
|
||||
(child, cookie) = self.tree.GetFirstChild(parent)
|
||||
|
||||
if self.tree.GetPyData(child):
|
||||
self.tree.SetPyData(child, (False, wx.RB_SINGLE))
|
||||
self.tree.SetItemImage(child, self.radiobox_unchecked, \
|
||||
wx.TreeItemIcon_Normal)
|
||||
|
||||
for x in range(1, self.tree.GetChildrenCount(parent, False)):
|
||||
(child, cookie) = self.tree.GetNextChild(parent, cookie)
|
||||
|
||||
if self.tree.GetPyData(child):
|
||||
self.tree.SetPyData(child, (False, wx.RB_SINGLE))
|
||||
self.tree.SetItemImage(child, self.radiobox_unchecked, \
|
||||
wx.TreeItemIcon_Normal)
|
||||
|
||||
self.tree.SetPyData(item, (True, wx.RB_SINGLE))
|
||||
self.tree.SetItemImage(item, self.radiobox_checked, \
|
||||
wx.TreeItemIcon_Normal)
|
||||
|
||||
else:
|
||||
self.tree.SetPyData(item, (False, wx.RB_SINGLE))
|
||||
self.tree.SetItemImage(item, self.radiobox_unchecked, \
|
||||
wx.TreeItemIcon_Normal)
|
||||
|
||||
|
||||
def _getItems(self, parent=None, value=None):
|
||||
if not parent:
|
||||
parent = self.root
|
||||
cil = []
|
||||
(child, cookie) = self.tree.GetFirstChild(parent)
|
||||
if child.IsOk():
|
||||
d = self.tree.GetPyData(child)
|
||||
if value is None or (d and d[0] == value):
|
||||
cil.append(child)
|
||||
for x in range(1, self.tree.GetChildrenCount(parent, False)):
|
||||
(child, cookie) = self.tree.GetNextChild(parent, cookie)
|
||||
if child.IsOk():
|
||||
d = self.tree.GetPyData(child)
|
||||
if value is None or (d and d[0] == value):
|
||||
cil.append(child)
|
||||
return cil
|
||||
|
||||
|
||||
def AddItem(self, label, bmp=None, parent=None, style=None, value=False):
|
||||
v = None
|
||||
|
||||
if bmp:
|
||||
n = self.il.Add(bmp)
|
||||
if not parent:
|
||||
parent = self.root
|
||||
if style is not None:
|
||||
v = (value, style)
|
||||
|
||||
this_item = self.tree.AppendItem(parent, label)
|
||||
self.tree.SetPyData(this_item, v)
|
||||
|
||||
if v:
|
||||
self._doLogicTest(style, value, this_item)
|
||||
else:
|
||||
if bmp is None:
|
||||
bmp = self.empty_bitmap
|
||||
else:
|
||||
bmp = self.il.Add(bmp)
|
||||
|
||||
self.tree.SetItemImage(this_item, bmp, wx.TreeItemIcon_Normal)
|
||||
|
||||
self.allitems.append(this_item)
|
||||
[self.tree.Expand(x) for x in self.allitems]
|
||||
|
||||
return this_item
|
||||
|
||||
|
||||
def ExpandItem(self, item):
|
||||
self.tree.Expand(item)
|
||||
|
||||
|
||||
def CollapseItem(self, item):
|
||||
self.tree.Collapse(item)
|
||||
|
||||
|
||||
def EnsureFirstVisible(self):
|
||||
(child, cookie) = self.tree.GetFirstChild(self.root)
|
||||
if child.IsOk():
|
||||
self.tree.SelectItem(child)
|
||||
self.tree.EnsureVisible(child)
|
||||
|
||||
|
||||
def SetItemValue(self, item, value):
|
||||
data = self.tree.GetPyData(item)
|
||||
if data:
|
||||
self._doLogicTest(data[1], value, item)
|
||||
|
||||
|
||||
def GetItemValue(self, item):
|
||||
data = self.tree.GetPyData(item)
|
||||
if data:
|
||||
return data[0]
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def GetItemByLabel(self, label, parent=None):
|
||||
r = None
|
||||
for item in self._getItems(parent):
|
||||
if self.tree.GetItemText(item) == label:
|
||||
r = item; break
|
||||
return r
|
||||
|
||||
|
||||
def GetAllItems(self):
|
||||
return self.allitems
|
||||
|
||||
|
||||
def GetRootItems(self):
|
||||
cil = []
|
||||
for x in range(0, len(self.allitems)):
|
||||
d = self.tree.GetPyData(self.allitems[x])
|
||||
if not d:
|
||||
cil.append(self.allitems[x])
|
||||
return cil
|
||||
|
||||
|
||||
def GetStringRootItems(self):
|
||||
return [self.tree.GetItemText(x) for x in self.GetRootItems]
|
||||
|
||||
|
||||
def GetItemsUnchecked(self, parent=None):
|
||||
return self._getItems(parent, 0)
|
||||
|
||||
|
||||
def GetItemsChecked(self, parent=None):
|
||||
return self._getItems(parent, 1)
|
||||
|
||||
|
||||
def GetItemsTri(self, parent=None):
|
||||
return self._getItems(parent, 2)
|
||||
|
||||
|
||||
def GetStringItemsUnchecked(self, parent=None):
|
||||
return [self.tree.GetItemText(x) \
|
||||
for x in self.GetItemsUnchecked(parent)]
|
||||
|
||||
|
||||
def GetStringItemsChecked(self, parent=None):
|
||||
return [self.tree.GetItemText(x) for x in self.GetItemsChecked(parent)]
|
||||
|
||||
|
||||
def GetStringItemsTri(self, parent=None):
|
||||
return [self.tree.GetItemText(x) for x in self.GetItemsTri(parent)]
|
||||
|
||||
|
||||
def OnRightClick(self, evt):
|
||||
item, flags = self.tree.HitTest(evt.GetPosition())
|
||||
self.tree.SelectItem(item)
|
||||
|
||||
|
||||
def OnLeftClicks(self, evt):
|
||||
item, flags = self.tree.HitTest(evt.GetPosition())
|
||||
if item:
|
||||
text, data = self.tree.GetItemText(item), self.tree.GetPyData(item)
|
||||
if data:
|
||||
style = data[1]
|
||||
if style == wx.CHK_2STATE:
|
||||
value = not data[0]
|
||||
elif style == wx.CHK_3STATE:
|
||||
value = data[0] + 1
|
||||
if value == 3: value = 0
|
||||
else:
|
||||
value = True
|
||||
|
||||
self._doLogicTest(style, value, item)
|
||||
|
||||
if value <> data[0]:
|
||||
nevt = ButtonTreeCtrlPanelEvent(obj=self, id=self.GetId(),
|
||||
item=item, val=value)
|
||||
wx.PostEvent(self, nevt)
|
||||
|
||||
evt.Skip()
|
||||
|
||||
|
||||
def OnSize(self, evt=None):
|
||||
self.tree.SetSize(self.GetClientSize())
|
||||
|
||||
# # Images generated by encode_bitmaps.py -----------------------------
|
||||
|
||||
def getcheckbox_uncheckedData(self):
|
||||
return \
|
||||
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
|
||||
\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
|
||||
\x00\x00AIDAT8\x8d\xed\x93;\x0e\x00 \x14\xc2\xca\xd3\xfb\xdf\xd8\xcf\xac\x83\
|
||||
\x89\xe2dd\xa7\xe9\x00R$\x9c\x84\xd5\x062@\xab\xa5\xed\x16\x15I\xf7\x0cf\xea\
|
||||
*\xb3\xadm\xf0\x01O\x00\x86!\x9dL\xda6\x90{\xe7\x0e\xbf\x98\x0c*\xf3\x13\xe2\
|
||||
e\x00\x00\x00\x00IEND\xaeB`\x82'
|
||||
|
||||
def getcheckbox_uncheckedBitmap(self):
|
||||
return wx.BitmapFromImage(self.getcheckbox_uncheckedImage())
|
||||
|
||||
def getcheckbox_uncheckedImage(self):
|
||||
stream = cStringIO.StringIO(self.getcheckbox_uncheckedData())
|
||||
return wx.ImageFromStream(stream)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def getradiobox_checkedData(self):
|
||||
return \
|
||||
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
|
||||
\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
|
||||
\x00\x00qIDAT8\x8d\xadR\xd1\x12\x80 \x08\x03\xed\xff\xffX\xe9\xa9n\xd1\xe6\
|
||||
\xd9\x11o\xca6\x18\xe0\xde\xbaU\xa2\x95\xd8fv\xa8D\xcc\x11\xf8\xf6\xd6\x9d\
|
||||
\xe1<[\xc8\xc4\x17!\t=\x04\x90\x9c\x81*Gg\xc0\xdaU\x16n\x81\xab\x02\x02c\x8e\
|
||||
`\x95\xf1On\x01A\xab\xb9\x94\xd7(\x05\xd0\x8a\xf2o&\xb6\xa0\x08,O;`\x9e\xd5\
|
||||
\x1c\xfe=\xa4\x95\xd0\xf6)\x7f\x8d\xf2\x1aO_y@8\xb08r\xf9\x00\x00\x00\x00IEN\
|
||||
D\xaeB`\x82'
|
||||
|
||||
def getradiobox_checkedBitmap(self):
|
||||
return wx.BitmapFromImage(self.getradiobox_checkedImage())
|
||||
|
||||
def getradiobox_checkedImage(self):
|
||||
stream = cStringIO.StringIO(self.getradiobox_checkedData())
|
||||
return wx.ImageFromStream(stream)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def getradiobox_uncheckedData(self):
|
||||
return \
|
||||
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
|
||||
\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
|
||||
\x00\x00gIDAT8\x8d\xcd\x92K\x12\x800\x08C\x81z\xff\x1bk\xbb\xd2\xc1\x98t\xea\
|
||||
\xe0Bv\x1d\xc8k\xf8\xb8G\xb3JDImf\x9bJ\xf4c\xef\xf9\xed\xd1\x9c\xd59\xb6\x80\
|
||||
\xc2\x87\x00@7@\x16c\xa1\xca\xd1\x190\xbb\xaa\x85\x0bp\xfe\xa0\ns.\xbb)o\xe1\
|
||||
G\x00\xd6\x1f\x06\x9b\x13u\xc0 \n\xfc\xed!\xcd@\xcb\xa7\xfc6\xca[\x18\xdf\
|
||||
\x0e0Ao\x7fq\xe8\x00\x00\x00\x00IEND\xaeB`\x82'
|
||||
|
||||
def getradiobox_uncheckedBitmap(self):
|
||||
return wx.BitmapFromImage(self.getradiobox_uncheckedImage())
|
||||
|
||||
def getradiobox_uncheckedImage(self):
|
||||
stream = cStringIO.StringIO(self.getradiobox_uncheckedData())
|
||||
return wx.ImageFromStream(stream)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def getcheckbox_checkedData(self):
|
||||
return \
|
||||
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
|
||||
\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
|
||||
\x00\x00gIDAT8\x8d\xad\x93Q\x0e\x800\x08C[\xe6\xfdo\xac\xf3k\x89\xa9\xb01\
|
||||
\x91o^S\xa0\x90\xd6P)+\xd1\x00\x0e\x00\xe8\xd7\xd9wAZ\xe3\x7f\x0eTuV\xea6\
|
||||
\xed \x1a3%0\xdb\xd1K@\x9bW\x0bv\x1d\x0c\xe8\tG\xfb\tG\xc8\xc0\xae\x806\xaf.\
|
||||
\xe3:\x18P\xe6\xac\xe1\x08\x19\x18\x90 }\x89t9\xca\xac\xbe\xf3\r?\xc9(*%&\
|
||||
\xec\x9b\x00\x00\x00\x00IEND\xaeB`\x82'
|
||||
|
||||
def getcheckbox_checkedBitmap(self):
|
||||
return wx.BitmapFromImage(self.getcheckbox_checkedImage())
|
||||
|
||||
def getcheckbox_checkedImage(self):
|
||||
stream = cStringIO.StringIO(self.getcheckbox_checkedData())
|
||||
return wx.ImageFromStream(stream)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def getcheckbox_triData(self):
|
||||
return \
|
||||
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
|
||||
\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
|
||||
\x00\x00pIDAT8\x8d\xad\x93A\x0e\x800\x08\x04\x97\xea\xab\xd4\xa3\xfah\xf5h\
|
||||
\xfdV{jb\x08 \x8a\x9c\x99\xcd\xd0l\x89R\x87\xc8\xa4\x10\r\xa0\x07\x80i\x1c\
|
||||
\xca[\xf0\xcc\x17\xfdg\xc0S\xad\xe1\xb6n\x83c\xdf\xc43]\x01\x1a,\x06\xf0e\
|
||||
\x0bV\r\x1at\x87\xe7e\x15\xdfG=\xc1\x03\x8b\x01|\xd9\x82U\x83\x06=\xc1j\x80\
|
||||
\x17\x06X\x91\xbeT:\\e\x8a~\xe7\nM\x85%\xe1\xceT8v\x00\x00\x00\x00IEND\xaeB`\
|
||||
\x82'
|
||||
|
||||
def getcheckbox_triBitmap(self):
|
||||
return wx.BitmapFromImage(self.getcheckbox_triImage())
|
||||
|
||||
def getcheckbox_triImage(self):
|
||||
stream = cStringIO.StringIO(self.getcheckbox_triData())
|
||||
return wx.ImageFromStream(stream)
|
||||
|
||||
|
||||
#
|
||||
##
|
||||
### eof
|
80
wxPython/wx/lib/analogclock/lib_setup/colourselect.py
Normal file
80
wxPython/wx/lib/analogclock/lib_setup/colourselect.py
Normal file
@@ -0,0 +1,80 @@
|
||||
# AnalogClock's colour selector for setup dialog
|
||||
# E. A. Tacao <e.a.tacao |at| estadao.com.br>
|
||||
# http://j.domaindlx.com/elements28/wxpython/
|
||||
# 15 Fev 2006, 22:00 GMT-03:00
|
||||
# Distributed under the wxWidgets license.
|
||||
|
||||
import wx
|
||||
from wx.lib.newevent import NewEvent
|
||||
from wx.lib.buttons import GenBitmapButton
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
(ColourSelectEvent, EVT_COLOURSELECT) = NewEvent()
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
class ColourSelect(GenBitmapButton):
|
||||
def __init__(self, parent, size=(21, 21), value=wx.BLACK):
|
||||
w, h = size[0] - 5, size[1] - 5
|
||||
GenBitmapButton.__init__(self, parent, wx.ID_ANY, wx.EmptyBitmap(w, h),
|
||||
size=size)
|
||||
self.SetBezelWidth(1)
|
||||
|
||||
self.parent = parent
|
||||
self.SetValue(value)
|
||||
|
||||
self.parent.Bind(wx.EVT_BUTTON, self.OnClick, self)
|
||||
|
||||
|
||||
def _makeBitmap(self):
|
||||
bdr = 8; w, h = self.GetSize()
|
||||
bmp = wx.EmptyBitmap(w - bdr, h - bdr)
|
||||
|
||||
dc = wx.MemoryDC()
|
||||
dc.SelectObject(bmp)
|
||||
dc.SetBackground(wx.Brush(self.value, wx.SOLID))
|
||||
dc.Clear()
|
||||
dc.SelectObject(wx.NullBitmap)
|
||||
|
||||
self.SetBitmapLabel(bmp)
|
||||
self.Refresh()
|
||||
|
||||
|
||||
def GetValue(self):
|
||||
return self.value
|
||||
|
||||
|
||||
def SetValue(self, value):
|
||||
self.value = value
|
||||
self._makeBitmap()
|
||||
|
||||
|
||||
def OnClick(self, event):
|
||||
win = wx.GetTopLevelParent(self)
|
||||
|
||||
data = wx.ColourData()
|
||||
data.SetChooseFull(True)
|
||||
data.SetColour(self.value)
|
||||
[data.SetCustomColour(colour_index, win.customcolours[colour_index])
|
||||
for colour_index in range(0, 16)]
|
||||
|
||||
dlg = wx.ColourDialog(win, data)
|
||||
dlg.SetTitle("Select Colour")
|
||||
changed = dlg.ShowModal() == wx.ID_OK
|
||||
|
||||
if changed:
|
||||
data = dlg.GetColourData()
|
||||
self.SetValue(data.GetColour())
|
||||
win.customcolours = [data.GetCustomColour(colour_index) \
|
||||
for colour_index in range(0, 16)]
|
||||
dlg.Destroy()
|
||||
|
||||
if changed:
|
||||
nevt = ColourSelectEvent(id=self.GetId(), obj=self, val=self.value)
|
||||
wx.PostEvent(self.parent, nevt)
|
||||
|
||||
|
||||
#
|
||||
##
|
||||
### eof
|
61
wxPython/wx/lib/analogclock/lib_setup/fontselect.py
Normal file
61
wxPython/wx/lib/analogclock/lib_setup/fontselect.py
Normal file
@@ -0,0 +1,61 @@
|
||||
# AnalogClock's font selector for setup dialog
|
||||
# E. A. Tacao <e.a.tacao |at| estadao.com.br>
|
||||
# http://j.domaindlx.com/elements28/wxpython/
|
||||
# 15 Fev 2006, 22:00 GMT-03:00
|
||||
# Distributed under the wxWidgets license.
|
||||
|
||||
import wx
|
||||
from wx.lib.newevent import NewEvent
|
||||
from wx.lib.buttons import GenButton
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
(FontSelectEvent, EVT_FONTSELECT) = NewEvent()
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
class FontSelect(GenButton):
|
||||
def __init__(self, parent, size=(75, 21), value=None):
|
||||
GenButton.__init__(self, parent, wx.ID_ANY, label="Select...",
|
||||
size=size)
|
||||
self.SetBezelWidth(1)
|
||||
|
||||
self.parent = parent
|
||||
self.SetValue(value)
|
||||
|
||||
self.parent.Bind(wx.EVT_BUTTON, self.OnClick, self)
|
||||
|
||||
|
||||
def GetValue(self):
|
||||
return self.value
|
||||
|
||||
|
||||
def SetValue(self, value):
|
||||
if value is None:
|
||||
value = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
|
||||
self.value = value
|
||||
|
||||
|
||||
def OnClick(self, event):
|
||||
data = wx.FontData()
|
||||
data.EnableEffects(False)
|
||||
font = self.value; font.SetPointSize(10)
|
||||
data.SetInitialFont(font)
|
||||
|
||||
dlg = wx.FontDialog(self, data)
|
||||
changed = dlg.ShowModal() == wx.ID_OK
|
||||
|
||||
if changed:
|
||||
data = dlg.GetFontData()
|
||||
self.value = data.GetChosenFont()
|
||||
self.Refresh()
|
||||
dlg.Destroy()
|
||||
|
||||
if changed:
|
||||
nevt = FontSelectEvent(id=self.GetId(), obj=self, val=self.value)
|
||||
wx.PostEvent(self.parent, nevt)
|
||||
|
||||
|
||||
#
|
||||
##
|
||||
### eof
|
479
wxPython/wx/lib/analogclock/setup.py
Normal file
479
wxPython/wx/lib/analogclock/setup.py
Normal file
@@ -0,0 +1,479 @@
|
||||
# AnalogClock setup dialog
|
||||
# E. A. Tacao <e.a.tacao |at| estadao.com.br>
|
||||
# http://j.domaindlx.com/elements28/wxpython/
|
||||
# 15 Fev 2006, 22:00 GMT-03:00
|
||||
# Distributed under the wxWidgets license.
|
||||
|
||||
import wx
|
||||
|
||||
import styles
|
||||
import lib_setup.colourselect as csel
|
||||
import lib_setup.fontselect as fsel
|
||||
import lib_setup.buttontreectrlpanel as bt
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
_window_styles = ['wx.SIMPLE_BORDER', 'wx.DOUBLE_BORDER', 'wx.SUNKEN_BORDER',
|
||||
'wx.RAISED_BORDER', 'wx.STATIC_BORDER', 'wx.NO_BORDER']
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class _GroupBase(wx.Panel):
|
||||
def __init__(self, parent, title, group):
|
||||
wx.Panel.__init__(self, parent)
|
||||
|
||||
self.parent = parent
|
||||
self.clock = self.parent.clock
|
||||
self.group = group
|
||||
self.target = {"Hours": styles.HOUR,
|
||||
"Minutes": styles.MINUTE,
|
||||
"Seconds": styles.SECOND}.get(title)
|
||||
|
||||
self.Bind(fsel.EVT_FONTSELECT, self.OnSelectFont)
|
||||
self.Bind(csel.EVT_COLOURSELECT, self.OnSelectColour)
|
||||
self.Bind(wx.EVT_SPINCTRL, self.OnSpin)
|
||||
self.Bind(wx.EVT_TEXT_ENTER, self.OnSpin)
|
||||
self.Bind(wx.EVT_CHOICE, self.OnChoice)
|
||||
|
||||
|
||||
def OnSelectFont(self, evt):
|
||||
self.clock.SetTickFont(evt.val, self.target)
|
||||
|
||||
|
||||
def OnSelectColour(self, evt):
|
||||
obj = evt.obj; val = evt.val
|
||||
|
||||
if hasattr(self, "fc") and obj == self.fc:
|
||||
if self.group == "Hands":
|
||||
self.clock.SetHandFillColour(val, self.target)
|
||||
elif self.group == "Ticks":
|
||||
self.clock.SetTickFillColour(val, self.target)
|
||||
elif self.group == "Face":
|
||||
self.clock.SetFaceFillColour(val)
|
||||
|
||||
elif hasattr(self, "bc") and obj == self.bc:
|
||||
if self.group == "Hands":
|
||||
self.clock.SetHandBorderColour(val, self.target)
|
||||
elif self.group == "Ticks":
|
||||
self.clock.SetTickBorderColour(val, self.target)
|
||||
elif self.group == "Face":
|
||||
self.clock.SetFaceBorderColour(val)
|
||||
|
||||
elif hasattr(self, "sw") and obj == self.sw:
|
||||
self.clock.SetShadowColour(val)
|
||||
|
||||
elif hasattr(self, "bg") and obj == self.bg:
|
||||
self.clock.SetBackgroundColour(val)
|
||||
|
||||
elif hasattr(self, "fg") and obj == self.fg:
|
||||
self.clock.SetForegroundColour(val)
|
||||
self.parent.GetGrandParent().UpdateControls()
|
||||
|
||||
|
||||
def OnSpin(self, evt):
|
||||
obj = evt.GetEventObject(); val = evt.GetInt()
|
||||
|
||||
if hasattr(self, "bw") and obj == self.bw:
|
||||
if self.group == "Hands":
|
||||
self.clock.SetHandBorderWidth(val, self.target)
|
||||
elif self.group == "Ticks":
|
||||
self.clock.SetTickBorderWidth(val, self.target)
|
||||
elif self.group == "Face":
|
||||
self.clock.SetFaceBorderWidth(val)
|
||||
|
||||
elif hasattr(self, "sz") and obj == self.sz:
|
||||
if self.group == "Hands":
|
||||
self.clock.SetHandSize(val, self.target)
|
||||
elif self.group == "Ticks":
|
||||
self.clock.SetTickSize(val, self.target)
|
||||
|
||||
elif hasattr(self, "of") and obj == self.of:
|
||||
self.clock.SetTickOffset(val, self.target)
|
||||
|
||||
|
||||
def OnChoice(self, evt):
|
||||
self.clock.SetWindowStyle(eval(evt.GetString()))
|
||||
|
||||
|
||||
def UpdateControls(self):
|
||||
if hasattr(self, "ft"):
|
||||
self.ft.SetValue(self.clock.GetTickFont(self.target)[0])
|
||||
|
||||
if hasattr(self, "fc"):
|
||||
if self.group == "Hands":
|
||||
self.fc.SetValue(self.clock.GetHandFillColour(self.target)[0])
|
||||
elif self.group == "Ticks":
|
||||
self.fc.SetValue(self.clock.GetTickFillColour(self.target)[0])
|
||||
elif self.group == "Face":
|
||||
self.fc.SetValue(self.clock.GetFaceFillColour())
|
||||
|
||||
if hasattr(self, "bc"):
|
||||
if self.group == "Hands":
|
||||
self.bc.SetValue(self.clock.GetHandBorderColour(self.target)[0])
|
||||
elif self.group == "Ticks":
|
||||
self.bc.SetValue(self.clock.GetTickBorderColour(self.target)[0])
|
||||
elif self.group == "Face":
|
||||
self.bc.SetValue(self.clock.GetFaceBorderColour())
|
||||
|
||||
if hasattr(self, "sw"):
|
||||
self.sw.SetValue(self.clock.GetShadowColour())
|
||||
|
||||
if hasattr(self, "bg"):
|
||||
self.bg.SetValue(self.clock.GetBackgroundColour())
|
||||
|
||||
if hasattr(self, "fg"):
|
||||
self.fg.SetValue(self.clock.GetForegroundColour())
|
||||
|
||||
if hasattr(self, "bw"):
|
||||
if self.group == "Hands":
|
||||
self.bw.SetValue(self.clock.GetHandBorderWidth(self.target)[0])
|
||||
elif self.group == "Ticks":
|
||||
self.bw.SetValue(self.clock.GetTickBorderWidth(self.target)[0])
|
||||
elif self.group == "Face":
|
||||
self.bw.SetValue(self.clock.GetFaceBorderWidth())
|
||||
|
||||
if hasattr(self, "sz"):
|
||||
if self.group == "Hands":
|
||||
self.sz.SetValue(self.clock.GetHandSize(self.target)[0])
|
||||
elif self.group == "Ticks":
|
||||
self.sz.SetValue(self.clock.GetTickSize(self.target)[0])
|
||||
|
||||
if hasattr(self, "of"):
|
||||
self.of.SetValue(self.clock.GetTickOffset(self.target)[0])
|
||||
|
||||
if hasattr(self, "ws"):
|
||||
for style in _window_styles:
|
||||
if self.clock.GetWindowStyleFlag() & eval(style):
|
||||
self.ws.SetStringSelection(style)
|
||||
break
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class _Group_1(_GroupBase):
|
||||
def __init__(self, parent, title, group="Hands"):
|
||||
_GroupBase.__init__(self, parent, title, group)
|
||||
|
||||
box = wx.StaticBoxSizer(wx.StaticBox(self, label=title), wx.VERTICAL)
|
||||
|
||||
sizer = self.sizer = wx.GridBagSizer(2, 6)
|
||||
|
||||
p = wx.StaticText(self, label="Border:")
|
||||
sizer.Add(p, pos=(0, 0), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
p = self.bc = csel.ColourSelect(self)
|
||||
sizer.Add(p, pos=(0, 1), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
p = self.bw = wx.SpinCtrl(self, size=(75, 21),
|
||||
min=0, max=100, value="75")
|
||||
sizer.Add(p, pos=(0, 2), span=(1, 2), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
p = wx.StaticText(self, label="Fill:")
|
||||
sizer.Add(p, pos=(1, 0), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
p = self.fc = csel.ColourSelect(self)
|
||||
sizer.Add(p, pos=(1, 1), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
p = self.ls = wx.StaticText(self, label="Size:")
|
||||
sizer.Add(p, pos=(2, 0), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
p = self.sz = wx.SpinCtrl(self, size=(75, 21),
|
||||
min=0, max=100, value="75")
|
||||
sizer.Add(p, pos=(2, 1), span=(1, 3), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
box.Add(sizer)
|
||||
|
||||
self.SetSizer(box)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class _Group_2(_Group_1):
|
||||
def __init__(self, parent, title, group="Ticks"):
|
||||
_Group_1.__init__(self, parent, title, group)
|
||||
|
||||
sizer = self.sizer
|
||||
|
||||
p = wx.StaticText(self, label="Offset:")
|
||||
sizer.Add(p, pos=(3, 0), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
p = self.of = wx.SpinCtrl(self, size=(75, 21),
|
||||
min=0, max=100, value="75")
|
||||
sizer.Add(p, pos=(3, 1), span=(1, 3), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
p = wx.StaticText(self, label="Font:")
|
||||
sizer.Add(p, pos=(4, 0), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
p = self.ft = fsel.FontSelect(self)
|
||||
sizer.Add(p, pos=(4, 1), span=(1, 3), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
self.GetSizer().Layout()
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class _Group_3(_Group_1):
|
||||
def __init__(self, parent, title, group="Face"):
|
||||
_Group_1.__init__(self, parent, title, group)
|
||||
|
||||
sizer = self.sizer
|
||||
|
||||
for widget in [self.ls, self.sz]:
|
||||
sizer.Detach(widget)
|
||||
widget.Destroy()
|
||||
sizer.Layout()
|
||||
|
||||
p = wx.StaticText(self, label="Shadow:")
|
||||
sizer.Add(p, pos=(2, 0), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
p = self.sw = csel.ColourSelect(self)
|
||||
sizer.Add(p, pos=(2, 1), span=(1, 3), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
self.GetSizer().Layout()
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class _Group_4(_GroupBase):
|
||||
def __init__(self, parent, title, group="Window"):
|
||||
_GroupBase.__init__(self, parent, title, group)
|
||||
|
||||
box = wx.StaticBoxSizer(wx.StaticBox(self, label=title), wx.VERTICAL)
|
||||
|
||||
sizer = self.sizer = wx.GridBagSizer(2, 6)
|
||||
|
||||
p = wx.StaticText(self, label="Foreground:")
|
||||
sizer.Add(p, pos=(0, 0), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
p = self.fg = csel.ColourSelect(self)
|
||||
sizer.Add(p, pos=(0, 1), span=(1, 3), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
p = wx.StaticText(self, label="Background:")
|
||||
sizer.Add(p, pos=(1, 0), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
p = self.bg = csel.ColourSelect(self)
|
||||
sizer.Add(p, pos=(1, 1), span=(1, 3), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
p = wx.StaticText(self, label="Style:")
|
||||
sizer.Add(p, pos=(2, 0), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
p = self.ws = wx.Choice(self, choices=_window_styles)
|
||||
sizer.Add(p, pos=(2, 1), span=(1, 3), flag=wx.ALIGN_CENTRE_VERTICAL)
|
||||
|
||||
box.Add(sizer)
|
||||
|
||||
self.SetSizer(box)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class _PageBase(wx.Panel):
|
||||
def __init__(self, parent):
|
||||
wx.Panel.__init__(self, parent)
|
||||
|
||||
self.clock = self.GetGrandParent().GetParent()
|
||||
self.sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.SetSizer(self.sizer)
|
||||
|
||||
|
||||
def UpdateControls(self):
|
||||
[group.UpdateControls() for group in self.GetChildren()]
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class StylesPanel(bt.ButtonTreeCtrlPanel):
|
||||
def __init__(self, parent):
|
||||
bt.ButtonTreeCtrlPanel.__init__(self, parent)
|
||||
|
||||
self.clock = self.GetGrandParent().GetParent()
|
||||
|
||||
root = self.AddItem("Styles")
|
||||
g1 = self.AddItem("General", parent=root)
|
||||
g2 = self.AddItem("Hours", parent=root)
|
||||
g3 = self.AddItem("Minutes", parent=root)
|
||||
self.groups = [g1, g2, g3]
|
||||
|
||||
clockStyle = self.clock.GetClockStyle()
|
||||
hourStyle, minuteStyle = self.clock.GetTickStyle()
|
||||
|
||||
for label in dir(styles):
|
||||
if label.startswith("TICKS_"):
|
||||
value = bool(getattr(styles, label) & hourStyle)
|
||||
self.AddItem(label, parent=g2, style=wx.RB_SINGLE, value=value)
|
||||
|
||||
value = bool(getattr(styles, label) & minuteStyle)
|
||||
self.AddItem(label, parent=g3, style=wx.RB_SINGLE, value=value)
|
||||
|
||||
elif not (label.startswith("DEFAULT_") or \
|
||||
label.startswith("_") or \
|
||||
label in ["HOUR", "MINUTE", "SECOND", "ALL"]):
|
||||
value = bool(getattr(styles, label) & clockStyle)
|
||||
self.AddItem(label, parent=g1, style=wx.CHK_2STATE, value=value)
|
||||
|
||||
self.EnsureFirstVisible()
|
||||
|
||||
self.Bind(bt.EVT_CHANGED, self.OnChanged)
|
||||
|
||||
|
||||
def OnChanged(self, evt):
|
||||
clockStyle, hourStyle, minuteStyle = \
|
||||
[reduce(lambda x, y: x | y,
|
||||
[getattr(styles, item) \
|
||||
for item in self.GetStringItemsChecked(group)], 0) \
|
||||
for group in self.groups]
|
||||
|
||||
self.clock.SetClockStyle(clockStyle)
|
||||
self.clock.SetTickStyle(hourStyle, styles.HOUR)
|
||||
self.clock.SetTickStyle(minuteStyle, styles.MINUTE)
|
||||
|
||||
|
||||
def UpdateControls(self):
|
||||
clockStyle = self.clock.GetClockStyle()
|
||||
hourStyle, minuteStyle = self.clock.GetTickStyle()
|
||||
|
||||
[g1, g2, g3] = self.groups
|
||||
|
||||
for label in dir(styles):
|
||||
if label.startswith("TICKS_"):
|
||||
item = self.GetItemByLabel(label, g2)
|
||||
value = bool(getattr(styles, label) & hourStyle)
|
||||
self.SetItemValue(item, value)
|
||||
|
||||
item = self.GetItemByLabel(label, g3)
|
||||
value = bool(getattr(styles, label) & minuteStyle)
|
||||
self.SetItemValue(item, value)
|
||||
|
||||
elif not (label.startswith("DEFAULT_") or \
|
||||
label.startswith("_") or \
|
||||
label in ["HOUR", "MINUTE", "SECOND", "ALL"]):
|
||||
item = self.GetItemByLabel(label, g1)
|
||||
value = bool(getattr(styles, label) & clockStyle)
|
||||
self.SetItemValue(item, value)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class HandsPanel(_PageBase):
|
||||
def __init__(self, parent):
|
||||
_PageBase.__init__(self, parent)
|
||||
|
||||
[self.sizer.Add(_Group_1(self, title), 1,
|
||||
flag=wx.EXPAND|wx.ALL, border=6) \
|
||||
for title in ["Hours", "Minutes", "Seconds"]]
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class TicksPanel(_PageBase):
|
||||
def __init__(self, parent):
|
||||
_PageBase.__init__(self, parent)
|
||||
|
||||
[self.sizer.Add(_Group_2(self, title), 1,
|
||||
flag=wx.EXPAND|wx.ALL, border=6) \
|
||||
for title in ["Hours", "Minutes"]]
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class MiscPanel(_PageBase):
|
||||
def __init__(self, parent):
|
||||
_PageBase.__init__(self, parent)
|
||||
|
||||
self.sizer.Add(_Group_3(self, "Face"), 1,
|
||||
flag=wx.EXPAND|wx.ALL, border=6)
|
||||
self.sizer.Add(_Group_4(self, "Window"), 1,
|
||||
flag=wx.EXPAND|wx.ALL, border=6)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
class Setup(wx.Dialog):
|
||||
"""AnalogClock customization dialog."""
|
||||
|
||||
def __init__(self, parent):
|
||||
wx.Dialog.__init__(self, parent, title="AnalogClock Setup")
|
||||
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
|
||||
nb = self.nb = wx.Notebook(self)
|
||||
for s in ["Styles", "Hands", "Ticks", "Misc"]:
|
||||
page = eval(s + "Panel(nb)"); page.Fit()
|
||||
nb.AddPage(page, s)
|
||||
nb.Fit()
|
||||
sizer.Add(nb, 1, flag = wx.EXPAND|wx.ALL, border=6)
|
||||
|
||||
bsizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
bsizer.Add(wx.Button(self, label="Reset"),
|
||||
flag = wx.LEFT|wx.RIGHT, border=6)
|
||||
bsizer.Add(wx.Button(self, wx.ID_OK),
|
||||
flag = wx.LEFT|wx.RIGHT, border=6)
|
||||
sizer.Add(bsizer, 0, flag=wx.ALIGN_RIGHT|wx.ALL, border=6)
|
||||
|
||||
self.Bind(wx.EVT_SHOW, self.OnShow)
|
||||
self.Bind(wx.EVT_CLOSE, self.OnClose)
|
||||
self.Bind(wx.EVT_BUTTON, self.OnButton)
|
||||
|
||||
self.customcolours = [None] * 16
|
||||
|
||||
self.SetSizerAndFit(sizer)
|
||||
|
||||
|
||||
def OnShow(self, evt):
|
||||
if self.IsShown():
|
||||
self.UpdateControls()
|
||||
evt.Skip()
|
||||
|
||||
|
||||
def OnClose(self, evt):
|
||||
self.Hide()
|
||||
|
||||
|
||||
def OnButton(self, evt):
|
||||
if evt.GetEventObject().GetLabel() == "Reset":
|
||||
self.ResetClock()
|
||||
evt.Skip()
|
||||
|
||||
|
||||
def UpdateControls(self):
|
||||
wx.BeginBusyCursor()
|
||||
for i in range(self.nb.GetPageCount()):
|
||||
self.nb.GetPage(i).UpdateControls()
|
||||
wx.EndBusyCursor()
|
||||
|
||||
|
||||
def ResetClock(self):
|
||||
clock = self.GetParent()
|
||||
|
||||
wx.BeginBusyCursor()
|
||||
|
||||
clock.SetClockStyle(styles.DEFAULT_CLOCK_STYLE)
|
||||
clock.SetTickStyle(styles.TICKS_POLY, styles.HOUR)
|
||||
clock.SetTickStyle(styles.TICKS_CIRCLE, styles.MINUTE)
|
||||
|
||||
clock.SetTickFont(wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT))
|
||||
|
||||
clock.SetHandBorderWidth(0)
|
||||
clock.SetTickBorderWidth(0)
|
||||
clock.SetFaceBorderWidth(0)
|
||||
|
||||
clock.SetHandSize(7, styles.HOUR)
|
||||
clock.SetHandSize(5, styles.MINUTE)
|
||||
clock.SetHandSize(1, styles.SECOND)
|
||||
|
||||
clock.SetTickSize(25, styles.HOUR)
|
||||
clock.SetTickSize(5, styles.MINUTE)
|
||||
|
||||
clock.SetTickOffset(0)
|
||||
|
||||
clock.SetWindowStyle(wx.NO_BORDER)
|
||||
|
||||
sw = wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DSHADOW)
|
||||
clock.SetShadowColour(sw)
|
||||
|
||||
no_color = wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DFACE)
|
||||
clock.SetFaceFillColour(no_color)
|
||||
clock.SetFaceBorderColour(no_color)
|
||||
clock.SetBackgroundColour(no_color)
|
||||
|
||||
fg = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
|
||||
clock.SetForegroundColour(fg)
|
||||
|
||||
self.UpdateControls()
|
||||
|
||||
wx.EndBusyCursor()
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
### eof
|
47
wxPython/wx/lib/analogclock/styles.py
Normal file
47
wxPython/wx/lib/analogclock/styles.py
Normal file
@@ -0,0 +1,47 @@
|
||||
# AnalogClock constants
|
||||
# E. A. Tacao <e.a.tacao |at| estadao.com.br>
|
||||
# http://j.domaindlx.com/elements28/wxpython/
|
||||
# 15 Fev 2006, 22:00 GMT-03:00
|
||||
# Distributed under the wxWidgets license.
|
||||
|
||||
# Style options that control the general clock appearance,
|
||||
# chosen via SetClockStyle.
|
||||
SHOW_QUARTERS_TICKS = 1
|
||||
SHOW_HOURS_TICKS = 2
|
||||
SHOW_MINUTES_TICKS = 4
|
||||
ROTATE_TICKS = 8
|
||||
SHOW_HOURS_HAND = 16
|
||||
SHOW_MINUTES_HAND = 32
|
||||
SHOW_SECONDS_HAND = 64
|
||||
SHOW_SHADOWS = 128
|
||||
OVERLAP_TICKS = 256
|
||||
|
||||
DEFAULT_CLOCK_STYLE = SHOW_HOURS_TICKS|SHOW_MINUTES_TICKS| \
|
||||
SHOW_HOURS_HAND|SHOW_MINUTES_HAND|SHOW_SECONDS_HAND| \
|
||||
SHOW_SHADOWS|ROTATE_TICKS
|
||||
|
||||
|
||||
# Style options that control the appearance of tick marks,
|
||||
# chosen via SetTickStyle.
|
||||
TICKS_NONE = 1
|
||||
TICKS_SQUARE = 2
|
||||
TICKS_CIRCLE = 4
|
||||
TICKS_POLY = 8
|
||||
TICKS_DECIMAL = 16
|
||||
TICKS_ROMAN = 32
|
||||
TICKS_BINARY = 64
|
||||
TICKS_HEX = 128
|
||||
|
||||
|
||||
# Constants that may be used as 'target' keyword value in
|
||||
# the various Get/Set methods.
|
||||
HOUR = 1
|
||||
MINUTE = 2
|
||||
SECOND = 4
|
||||
|
||||
ALL = HOUR|MINUTE|SECOND
|
||||
|
||||
|
||||
#
|
||||
##
|
||||
### eof
|
Reference in New Issue
Block a user