Added AnalogClock class to library

Added NewNamespace sample to the demo
Other demo tweaks


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@20273 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2003-04-18 21:10:28 +00:00
parent 0776fe07e4
commit e8e8026ec7
9 changed files with 370 additions and 75 deletions

View File

@@ -41,6 +41,11 @@ Added __nonzero__ method to wxTreeItemId, wxBitmap, wxImage, wxFont,
and most other classes that have an Ok or IsOK method. This allows and most other classes that have an Ok or IsOK method. This allows
code like "if obj: ..." to be the same as "if obj.IsOk(): ..." code like "if obj: ..." to be the same as "if obj.IsOk(): ..."
Toolbars on wxMac can now have controls on them.
Added wxPython.lib.analogclock module based on samples that were
passed back and forth on wxPython-users a while back.

View File

@@ -1,3 +1,5 @@
# This is way out of date. (It's not activly used anymore...)
include *.txt include *.txt
include my_distutils.py include my_distutils.py
## include my_install_data.py ## include my_install_data.py

View File

@@ -0,0 +1,79 @@
from wxPython.wx import *
from wxPython.lib.analogclock import AnalogClockWindow
#----------------------------------------------------------------------
class TestPanel(wxPanel):
def __init__(self, parent, log):
self.log = log
wxPanel.__init__(self, parent, -1)
c1 = AnalogClockWindow(self)
c1.SetBackgroundColour("RED")
c1.SetHandsColour("BLUE")
c1.SetTickMarkColours("WHITE")
c2 = AnalogClockWindow(self)
c2.SetBackgroundColour("WHITE")
c2.SetHandsColour("RED")
c2.SetTickMarkColours("BLUE")
c3 = AnalogClockWindow(self)
c3.SetBackgroundColour("BLUE")
c3.SetHandsColour("WHITE")
c3.SetTickMarkColours("RED")
c4 = AnalogClockWindow(self, style=wxRAISED_BORDER)
c4.SetTickMarkStyle(AnalogClockWindow.TICKS_CIRCLE)
c5 = AnalogClockWindow(self)
c5.SetTickMarkStyle(AnalogClockWindow.TICKS_NONE)
c6 = AnalogClockWindow(self, style=wxSUNKEN_BORDER)
# layout the clocks in a grid
gs = wxGridSizer(2, 3, 4, 4)
gs.Add(c1, 0, wxEXPAND)
gs.Add(c2, 0, wxEXPAND)
gs.Add(c3, 0, wxEXPAND)
gs.Add(c4, 0, wxEXPAND)
gs.Add(c5, 0, wxEXPAND)
gs.Add(c6, 0, wxEXPAND)
# put it in another sizer for a border
sizer = wxBoxSizer(wxVERTICAL)
sizer.Add(gs, 1, wxEXPAND|wxALL, 10)
self.SetSizer(sizer)
#----------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
#----------------------------------------------------------------------
overview = """<html><body>
<h2><center>AnalogClockWindow</center></h2>
This is a nice little clock class that was contributed to by several
members of the wxPython-users group.
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -26,11 +26,11 @@ import images
_treeList = [ _treeList = [
# new stuff # new stuff
('Recent Additions', [ ('Recent Additions', [
'wxIntCtrl',
'wxPyColourChooser',
'wxScrolledPanel', 'wxScrolledPanel',
'ShapedWindow', 'ShapedWindow',
'NewNamespace',
'PopupMenu', 'PopupMenu',
'AnalogClockWindow',
]), ]),
# managed windows == things with a (optional) caption you can close # managed windows == things with a (optional) caption you can close
@@ -104,7 +104,8 @@ _treeList = [
('More Windows/Controls', [ ('More Windows/Controls', [
#'wxFloatBar', deprecated #'wxFloatBar', deprecated
#'wxMVCTree', deprecated #'wxMVCTree', deprecated
#'wxRightTextCtrl', deprecated as we have wxTE_RIGHT now. #'wxRightTextCtrl', deprecated as we have wxTE_RIGHT now.
'AnalogClockWindow',
'ColourSelect', 'ColourSelect',
'ContextHelp', 'ContextHelp',
'FancyText', 'FancyText',
@@ -326,7 +327,8 @@ class wxPythonDemo(wxFrame):
aTable = wxAcceleratorTable([(wxACCEL_ALT, ord('X'), exitID), aTable = wxAcceleratorTable([(wxACCEL_ALT, ord('X'), exitID),
(wxACCEL_CTRL, ord('H'), helpID), (wxACCEL_CTRL, ord('H'), helpID),
(wxACCEL_CTRL, ord('F'), findID), (wxACCEL_CTRL, ord('F'), findID),
(wxACCEL_NORMAL, WXK_F3, findnextID)]) (wxACCEL_NORMAL, WXK_F3, findnextID)
])
self.SetAcceleratorTable(aTable) self.SetAcceleratorTable(aTable)
@@ -366,7 +368,7 @@ class wxPythonDemo(wxFrame):
self.ovr = wxHtmlWindow(self.nb, -1, size=(400, 400)) self.ovr = wxHtmlWindow(self.nb, -1, size=(400, 400))
self.nb.AddPage(self.ovr, self.overviewText) self.nb.AddPage(self.ovr, self.overviewText)
else: # hopefully I can remove this hacky code soon, see bug #216861 else: # hopefully I can remove this hacky code soon, see SF bug #216861
panel = wxPanel(self.nb, -1, style=wxCLIP_CHILDREN) panel = wxPanel(self.nb, -1, style=wxCLIP_CHILDREN)
self.ovr = wxHtmlWindow(panel, -1, size=(400, 400)) self.ovr = wxHtmlWindow(panel, -1, size=(400, 400))
self.nb.AddPage(panel, self.overviewText) self.nb.AddPage(panel, self.overviewText)

View File

@@ -0,0 +1,47 @@
import os
import wx
from wx import html
#----------------------------------------------------------------------
class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent, -1)
hwin = html.HtmlWindow(self, -1)
hwin.LoadFile(os.path.join(os.path.dirname(wx.__file__), 'wx.html'))
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(hwin, 1, wx.EXPAND)
self.SetSizer(sizer)
#----------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
#----------------------------------------------------------------------
overview = """<html><body>
<h2><center>Using the New Namespace</center></h2>
This sample isn't really a demo, but rather a place to display the
introductory doc for using the new namespace.
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -281,37 +281,22 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin):
self.popupID4 = wxNewId() self.popupID4 = wxNewId()
self.popupID5 = wxNewId() self.popupID5 = wxNewId()
self.popupID6 = wxNewId() self.popupID6 = wxNewId()
self.popupID7 = wxNewId()
self.popupID8 = wxNewId()
self.popupID9 = wxNewId()
EVT_MENU(self, self.popupID1, self.OnPopupOne) EVT_MENU(self, self.popupID1, self.OnPopupOne)
EVT_MENU(self, self.popupID2, self.OnPopupTwo) EVT_MENU(self, self.popupID2, self.OnPopupTwo)
EVT_MENU(self, self.popupID3, self.OnPopupThree) EVT_MENU(self, self.popupID3, self.OnPopupThree)
EVT_MENU(self, self.popupID4, self.OnPopupFour) EVT_MENU(self, self.popupID4, self.OnPopupFour)
EVT_MENU(self, self.popupID5, self.OnPopupFive) EVT_MENU(self, self.popupID5, self.OnPopupFive)
EVT_MENU(self, self.popupID6, self.OnPopupSix) EVT_MENU(self, self.popupID6, self.OnPopupSix)
EVT_MENU(self, self.popupID7, self.OnPopupSeven)
EVT_MENU(self, self.popupID8, self.OnPopupEIght)
EVT_MENU(self, self.popupID9, self.OnPopupNine)
# make a menu # make a menu
menu = wxMenu() menu = wxMenu()
# Show how to put an icon in the menu # add some items
item = wxMenuItem(menu, self.popupID1,"One") menu.Append(self.popupID1, "FindItem tests")
item.SetBitmap(images.getSmilesBitmap()) # menu.Append(self.popupID2, "Two")
menu.AppendItem(item)
# add some other items
menu.Append(self.popupID2, "Two")
menu.Append(self.popupID3, "ClearAll and repopulate") menu.Append(self.popupID3, "ClearAll and repopulate")
menu.Append(self.popupID4, "DeleteAllItems") menu.Append(self.popupID4, "DeleteAllItems")
menu.Append(self.popupID5, "GetItem") menu.Append(self.popupID5, "GetItem")
menu.Append(self.popupID6, "Edit") menu.Append(self.popupID6, "Edit")
# make a submenu
sm = wxMenu()
sm.Append(self.popupID8, "sub item 1")
sm.Append(self.popupID9, "sub item 1")
menu.AppendMenu(self.popupID7, "Test Submenu", sm)
# Popup the menu. If an item is selected then its handler # Popup the menu. If an item is selected then its handler
# will be called before PopupMenu returns. # will be called before PopupMenu returns.
@@ -331,8 +316,6 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin):
self.log.WriteText("Popup three\n") self.log.WriteText("Popup three\n")
self.list.ClearAll() self.list.ClearAll()
wxCallAfter(self.PopulateList) wxCallAfter(self.PopulateList)
#wxYield()
#self.PopulateList()
def OnPopupFour(self, event): def OnPopupFour(self, event):
self.list.DeleteAllItems() self.list.DeleteAllItems()
@@ -345,15 +328,6 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin):
self.list.EditLabel(self.currentItem) self.list.EditLabel(self.currentItem)
def OnPopupSeven(self, event):
self.log.WriteText("Popup seven\n")
def OnPopupEIght(self, event):
self.log.WriteText("Popup eight\n")
def OnPopupNine(self, event):
self.log.WriteText("Popup nine\n")
def OnSize(self, event): def OnSize(self, event):
w,h = self.GetClientSizeTuple() w,h = self.GetClientSizeTuple()
self.list.SetDimensions(0, 0, w, h) self.list.SetDimensions(0, 0, w, h)

View File

@@ -37,11 +37,6 @@ def runTest(frame, nb, log):
splitter.SetMinimumPaneSize(20) splitter.SetMinimumPaneSize(20)
splitter.SplitVertically(p1, p2, 100) splitter.SplitVertically(p1, p2, 100)
## splitter.SetSize((300,300))
## print splitter.GetSashPosition()
## splitter.SetSashPosition(100)
## print splitter.GetSashPosition()
return splitter return splitter
@@ -50,41 +45,16 @@ def runTest(frame, nb, log):
overview = """\ overview = """\
This class manages up to two subwindows. The current view can be split into two programmatically (perhaps from a menu command), and unsplit either programmatically or via the wxSplitterWindow user interface. This class manages up to two subwindows. The current view can be split
into two programmatically (perhaps from a menu command), and unsplit
wxSplitterWindow() either programmatically or via the wxSplitterWindow user interface.
-----------------------------------
Default constructor.
wxSplitterWindow(wxWindow* parent, wxWindowID id, int x, const wxPoint& point = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style=wxSP_3D, const wxString& name = "splitterWindow")
Constructor for creating the window.
Parameters
-------------------
parent = The parent of the splitter window.
id = The window identifier.
pos = The window position.
size = The window size.
style = The window style. See wxSplitterWindow.
name = The window name.
""" """
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -0,0 +1,15 @@
"""Provides a way to drop the wx prefix from wxPython objects."""
__author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
__cvsid__ = "$Id$"
__revision__ = "$Revision$"[11:-2]
import wx
from wx import prefix
from wxPython.lib import analogclock
prefix.rename(d_new=globals(), d_old=analogclock.__dict__)
del analogclock
del prefix
del wx

View File

@@ -0,0 +1,201 @@
#----------------------------------------------------------------------
# Name: wxPython.lib.analogclock
# Purpose: A simple analog clock window
#
# Author: several folks on wxPython-users
#
# Created: 16-April-2003
# RCS-ID: $Id$
# Copyright: (c) 2003 by Total Control Software
# Licence: wxWindows license
#----------------------------------------------------------------------
import math, sys, string, time
from wxPython.wx import *
class AnalogClockWindow(wxWindow):
"""A simple analog clock window"""
TICKS_NONE = 0
TICKS_SQUARE = 1
TICKS_CIRCLE = 2
def __init__(self, parent, ID=-1, pos=wxDefaultPosition, size=wxDefaultSize,
style=0, name="clock"):
# Initialize the wxWindow...
wxWindow.__init__(self, parent, ID, pos, size, style, name)
# Initialize the default clock settings...
self.minuteMarks = 60
self.hourMarks = 12
self.tickMarksBrushC = self.GetForegroundColour()
self.tickMarksPenC = self.GetForegroundColour()
self.tickMarkStyle = self.TICKS_SQUARE
# Make an initial bitmap for the face, it will be updated and
# painted at the first EVT_SIZE event.
W, H = size
self.faceBitmap = wxEmptyBitmap(max(W,1), max(H,1))
# 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 = wxTimer(self)
self.timer.Start(500)
# Set event handlers...
EVT_PAINT(self, self.OnPaint)
EVT_ERASE_BACKGROUND(self, lambda x: None)
EVT_SIZE(self, self.OnSize)
EVT_TIMER(self, -1, self.OnTimerExpire)
EVT_WINDOW_DESTROY(self, self.OnQuit)
def SetTickMarkStyle(self, style):
"""
Set the style of the marks around the edge of the clock.
Options are TICKS_NONE, TICKS_SQUARE, and TICKS_CIRCLE
"""
self.tickMarkStyle = style
def SetTickMarkColours(self, brushC, penC="BLACK"):
"""
Set the brush colour and optionally the pen colour of
the marks around the edge of the clock.
"""
self.tickMarksBrushC = brushC
self.tickMarksPenC = penC
SetTickMarkColour = SetTickMarkColours
def SetHandsColour(self, c):
"""An alias for SetForegroundColour"""
self.SetForegroundColour(c) # the hands just use the foreground colour
# Using the current settings, render the points and line endings for the
# circle inside the specified device context. In this case, the DC is
# a memory based device context that will be blitted to the actual
# display DC inside the OnPaint() event handler.
def OnSize(self, event):
# The faceBitmap init is done here, to make sure the buffer is always
# the same size as the Window
size = self.GetClientSize()
self.faceBitmap = wxEmptyBitmap(size.width, size.height)
self.DrawFace()
def OnPaint(self, event):
self.DrawHands(wxPaintDC(self))
def OnQuit(self, event):
self.timer.Stop()
del self.timer
def OnTimerExpire(self, event):
self.DrawHands(wxClientDC(self))
def DrawHands(self, drawDC):
# Start by drawing the face bitmap
drawDC.DrawBitmap(self.faceBitmap,0,0)
currentTime = time.localtime(time.time())
hour, minutes, seconds = currentTime[3:6]
W,H = self.faceBitmap.GetWidth(), self.faceBitmap.GetHeight()
centerX = W / 2
centerY = H / 2
radius = min(centerX, centerY)
hour += minutes / 60.0 # added so the hour hand moves continuously
x, y = self.point(hour, 12, (radius * .65))
hourX, hourY = (x + centerX), (centerY - y)
x, y = self.point(minutes, 60, (radius * .85))
minutesX, minutesY = (x + centerX), (centerY - y)
x, y = self.point(seconds, 60, (radius * .85))
secondsX, secondsY = (x + centerX), (centerY - y)
# Draw the hour hand...
drawDC.SetPen(wxPen(self.GetForegroundColour(), 5, wxSOLID))
drawDC.DrawLine(centerX, centerY, hourX, hourY)
# Draw the minutes hand...
drawDC.SetPen(wxPen(self.GetForegroundColour(), 3, wxSOLID))
drawDC.DrawLine(centerX, centerY, minutesX, minutesY)
# Draw the seconds hand...
drawDC.SetPen(wxPen(self.GetForegroundColour(), 1, wxSOLID))
drawDC.DrawLine(centerX, centerY, secondsX, secondsY)
# Draw the specified set of line marks inside the clock face for the
# hours or minutes...
def DrawFace(self):
backgroundBrush = wxBrush(self.GetBackgroundColour(), wxSOLID)
drawDC = wxMemoryDC()
drawDC.SelectObject(self.faceBitmap)
drawDC.SetBackground(backgroundBrush)
drawDC.Clear()
W,H = self.faceBitmap.GetWidth(), self.faceBitmap.GetHeight()
centerX = W / 2
centerY = H / 2
# Draw the marks for hours and minutes...
self.DrawTimeMarks(drawDC, self.minuteMarks, centerX, centerY, 4)
self.DrawTimeMarks(drawDC, self.hourMarks, centerX, centerY, 9)
def DrawTimeMarks(self, drawDC, markCount, centerX, centerY, markSize):
for i in range(markCount):
x, y = self.point(i + 1, markCount, min(centerX,centerY) - 16)
scaledX = x + centerX - markSize/2
scaledY = centerY - y - markSize/2
drawDC.SetBrush(wxBrush(self.tickMarksBrushC, wxSOLID))
drawDC.SetPen(wxPen(self.tickMarksPenC, 1, wxSOLID))
if self.tickMarkStyle != self.TICKS_NONE:
if self.tickMarkStyle == self.TICKS_CIRCLE:
drawDC.DrawEllipse(scaledX - 2, scaledY, markSize, markSize)
else:
drawDC.DrawRectangle(scaledX - 3, scaledY, markSize, markSize)
def point(self, tick, range, radius):
angle = tick * (360.0 / range)
radiansPerDegree = math.pi / 180
pointX = int(round(radius * math.sin(angle * radiansPerDegree)))
pointY = int(round(radius * math.cos(angle * radiansPerDegree)))
return wxPoint(pointX, pointY)
if __name__ == "__main__":
class App(wxApp):
def OnInit(self):
frame = wxFrame(None, -1, "AnalogClockWindow Test", size=(375,375))
clock = AnalogClockWindow(frame)
clock.SetTickMarkColours("RED")
clock.SetHandsColour("WHITE")
clock.SetBackgroundColour("BLUE")
frame.Centre(wxBOTH)
frame.Show(True)
self.SetTopWindow(frame)
return true
theApp = App(0)
theApp.MainLoop()