What's new in 2.1.11
--------------------
+Skipped a few version numbers so wxMSW, wxGTK and wxPython are all
+syncronized.
+
wxImage.SetData now makes a copy of the image data before giving it to
wxImage. I mistakenly thought that wxImage would copy the data
itself.
Many updates to wxMenu, wxMenuBar.
wxPyEvent and wxPyCommandEvent derived classes now give you the actual
-Python object in the event handler.
+Python object in the event handler instead of a new shadow.
+
+Added a Calendar widget from Lorne White.
+
+Made some fixes to the wxFloatbar.
+
+Added the HTML printing classes.
+
('wxPython Library', ['OldSizers', 'Layoutf', 'wxScrolledMessageDialog',
'wxMultipleChoiceDialog', 'wxPlotCanvas', 'wxFloatBar',
- 'PyShell']),
+ 'PyShell', 'wxCalendar']),
('Cool Contribs', ['pyTree', 'hangman', 'SlashDot', 'XMLtreeview']),
--- /dev/null
+#! /usr/local/bin/python
+#----------------------------------------------------------------------------
+# Name: CalendPanel.py
+# Purpose: Calendar control display testing on panel
+#
+# Author: Lorne White (email: lwhite1@planet.eon.net)
+#
+# Created:
+# Version 0.5 1999/11/03
+# Licence: wxWindows license
+#----------------------------------------------------------------------------
+
+from wxPython.wx import *
+from wxPython.lib.calendar import Calendar, Month, using_mxDateTime
+
+import os
+dir_path = os.getcwd()
+
+
+# highlighted days in month
+
+test_days ={ 0: [],
+ 1: [3, 7, 9, 21],
+ 2: [2, 10, 4, 9],
+ 3: [4, 20, 29],
+ 4: [1, 12, 22],
+ 5: [2, 10, 15],
+ 6: [4, 8, 17],
+ 7: [6, 7, 8],
+ 8: [5, 10, 20],
+ 9: [1, 2, 5, 29],
+ 10: [2, 4, 6, 22],
+ 11: [6, 9, 12, 28, 29],
+ 12: [8, 9, 10, 11, 20] }
+
+# test of full window calendar control functions
+
+def GetMonthList():
+ monthlist = []
+ for i in range(13):
+ name = Month[i]
+ if name != None:
+ monthlist.append(name)
+ return monthlist
+
+class TestPanel(wxPanel):
+ def __init__(self, parent, log):
+ wxPanel.__init__(self, parent, -1)
+
+ self.log = log
+
+ if using_mxDateTime is true:
+ self.log.WriteText('Using mxDateTime module\n')
+ else:
+ self.log.WriteText('Using Built in CDate module\n')
+
+ self.calend = Calendar(self, -1, wxPoint(100, 50), wxSize(200, 180))
+
+ start_month = 11
+ start_year = 1999
+
+# month list from DateTime module
+
+ monthlist = GetMonthList()
+
+ self.date = wxComboBox(self, 10, Month[start_month], wxPoint(100, 20), wxSize(90, -1), monthlist, wxCB_DROPDOWN)
+ EVT_COMBOBOX(self, 10, self.EvtComboBox)
+
+# set start month and year
+
+ self.calend.SetMonth(start_month)
+ self.calend.SetYear(start_year)
+
+# set attributes of calendar
+
+ self.calend.HideTitle()
+ self.calend.HideGrid()
+
+# display routine
+
+ self.ResetDisplay()
+
+# mouse click event
+
+ self.Connect(self.calend.GetId(), -1, 2100, self.MouseClick)
+
+# scroll bar for month selection
+
+ self.scroll = wxScrollBar(self, 40, wxPoint(100, 240), wxSize(200, 20), wxSB_HORIZONTAL)
+ self.scroll.SetScrollbar(start_month-1, 1, 12, 1, TRUE)
+ EVT_COMMAND_SCROLL(self, 40, self.Scroll)
+
+# spin control for year selection
+
+ self.dtext = wxTextCtrl(self, -1, str(start_year), wxPoint(200, 20), wxSize(60, -1))
+ h = self.dtext.GetSize().height
+
+ self.spin = wxSpinButton(self, 20, wxPoint(270, 20), wxSize(h*2, h))
+ self.spin.SetRange(1980, 2010)
+ self.spin.SetValue(start_year)
+ EVT_SPIN(self, 20, self.OnSpin)
+
+# button for calendar dialog test
+
+ wxStaticText(self, -1, "Test Calendar Dialog", wxPoint(350, 50)).SetBackgroundColour(wxNamedColour('Red'))
+
+ bmp = wxBitmap('CalBmp/Calend.bmp', wxBITMAP_TYPE_BMP)
+ self.but = wxBitmapButton(self, 60, bmp, wxPoint(380, 80), wxSize(30, 30))
+ EVT_BUTTON(self, 60, self.TestDlg)
+
+# button for calendar window test
+
+ wxStaticText(self, -1, "Test Calendar Window", wxPoint(350, 150)).SetBackgroundColour(wxNamedColour('Blue'))
+
+ bmp = wxBitmap('CalBmp/Calend.bmp', wxBITMAP_TYPE_BMP)
+ self.but = wxBitmapButton(self, 160, bmp, wxPoint(380, 180), wxSize(30, 30))
+ EVT_BUTTON(self, 160, self.TestFrame)
+
+# calendar dialog
+
+ def TestDlg(self, event):
+ dlg = CalenDlg(self, self.log)
+ dlg.Centre()
+ dlg.ShowModal()
+ dlg.Destroy()
+
+# calendar window test
+
+ def TestFrame(self, event):
+ frame = CalendFrame(NULL, -1, "Test Calendar", self.log)
+ frame.Show(true)
+ self.SetTopWindow(frame)
+ return true
+
+# month and year control events
+
+ def OnSpin(self, event):
+ year = event.GetPosition()
+ self.dtext.SetValue(str(year))
+ self.calend.SetYear(year)
+ self.calend.Refresh()
+
+ def EvtComboBox(self, event):
+ name = event.GetString()
+ self.log.WriteText('EvtComboBox: %s\n' % name)
+ monthval = self.date.FindString(name)
+ self.scroll.SetScrollbar(monthval, 1, 12, 1, TRUE)
+
+ self.calend.SetMonth(monthval+1)
+ self.ResetDisplay()
+
+ def Scroll(self, event):
+ value = self.scroll.GetThumbPosition()
+ monthval = int(value)+1
+ self.calend.SetMonth(monthval)
+ self.ResetDisplay()
+ self.log.WriteText('Month: %s\n' % value)
+
+ name = Month[monthval]
+ self.date.SetValue(name)
+
+# log mouse events
+
+ def MouseClick(self, evt):
+ text = '%s CLICK %02d/%02d/%d' % (evt.click, evt.day, evt.month, evt.year) # format date
+ self.log.WriteText('Date Selected: ' + text + '\n')
+
+ def OnCloseWindow(self, event):
+ self.Destroy()
+
+# set the highlighted days for the calendar
+
+ def ResetDisplay(self):
+ month = self.calend.GetMonth()
+ try:
+ set_days = test_days[month]
+ except:
+ set_days = [1, 5, 12]
+
+ self.calend.SetSelDay(set_days)
+ self.calend.Refresh()
+
+# increment and decrement toolbar controls
+
+ def OnIncYear(self, event):
+ self.calend.IncYear()
+ self.ResetDisplay()
+
+ def OnDecYear(self, event):
+ self.calend.DecYear()
+ self.ResetDisplay()
+
+ def OnIncMonth(self, event):
+ self.calend.IncMonth()
+ self.ResetDisplay()
+
+ def OnDecMonth(self, event):
+ self.calend.DecMonth()
+ self.ResetDisplay()
+
+ def OnCurrent(self, event):
+ self.calend.SetCurrentDay()
+ self.ResetDisplay()
+
+# test the calendar control in a dialog
+
+class CalenDlg(wxDialog):
+ def __init__(self, parent, log):
+ self.log = log
+ wxDialog.__init__(self, parent, -1, "Test Calendar", wxPyDefaultPosition, wxSize(280, 300))
+
+ start_month = 2
+ start_year = 1999
+
+# get month list from DateTime
+
+ monthlist = GetMonthList()
+
+# select the month
+
+ self.date = wxComboBox(self, 100, Month[start_month], wxPoint(20, 20), wxSize(90, -1), monthlist, wxCB_DROPDOWN)
+ EVT_COMBOBOX(self, 100, self.EvtComboBox)
+
+# alternate spin button to control the month
+
+ h = self.date.GetSize().height
+ self.m_spin = wxSpinButton(self, 120, wxPoint(130, 20), wxSize(h*2, h), wxSP_VERTICAL)
+ self.m_spin.SetRange(1, 12)
+ self.m_spin.SetValue(start_month)
+
+ EVT_SPIN(self, 120, self.OnMonthSpin)
+
+# spin button to conrol the year
+
+ self.dtext = wxTextCtrl(self, -1, str(start_year), wxPoint(160, 20), wxSize(60, -1))
+ h = self.dtext.GetSize().height
+
+ self.y_spin = wxSpinButton(self, 20, wxPoint(220, 20), wxSize(h*2, h), wxSP_VERTICAL)
+ self.y_spin.SetRange(1980, 2010)
+ self.y_spin.SetValue(start_year)
+
+ EVT_SPIN(self, 20, self.OnYrSpin)
+
+# set the calendar and attributes
+
+ self.calend = Calendar(self, -1, wxPoint(20, 60), wxSize(240, 200))
+ self.calend.SetMonth(start_month)
+ self.calend.SetYear(start_year)
+
+ self.calend.HideTitle()
+ self.ResetDisplay()
+
+ self.Connect(self.calend.GetId(), -1, 2100, self.MouseClick)
+
+# log the mouse clicks
+
+ def MouseClick(self, evt):
+ text = '%s CLICK %02d/%02d/%d' % (evt.click, evt.day, evt.month, evt.year) # format date
+ self.log.WriteText('Date Selected: ' + text + '\n')
+
+ if evt.click == 'DLEFT':
+ self.EndModal(wxID_OK)
+
+# month and year spin selection routines
+
+ def OnMonthSpin(self, event):
+ month = event.GetPosition()
+ self.date.SetValue(Month[month])
+ self.calend.SetMonth(month)
+ self.calend.Refresh()
+
+ def OnYrSpin(self, event):
+ year = event.GetPosition()
+ self.dtext.SetValue(str(year))
+ self.calend.SetYear(year)
+ self.calend.Refresh()
+
+ def EvtComboBox(self, event):
+ name = event.GetString()
+ self.log.WriteText('EvtComboBox: %s\n' % name)
+ monthval = self.date.FindString(name)
+ self.m_spin.SetValue(monthval+1)
+
+ self.calend.SetMonth(monthval+1)
+ self.ResetDisplay()
+
+# set the calendar for highlighted days
+
+ def ResetDisplay(self):
+ month = self.calend.GetMonth()
+ try:
+ set_days = test_days[month]
+ except:
+ set_days = [1, 5, 12]
+
+ self.calend.SetSelDay(set_days)
+ self.calend.Refresh()
+
+# test of full window calendar control functions
+
+class CalendFrame(wxFrame):
+ def __init__(self, parent, id, title, log):
+ wxFrame.__init__(self, parent, id, title, wxPyDefaultPosition, wxSize(400, 400))
+
+ self.log = log
+ self.CreateStatusBar()
+ self.mainmenu = wxMenuBar()
+ menu = wxMenu()
+
+ menu = self.MakeFileMenu()
+ self.mainmenu.Append(menu, '&File')
+
+ self.MakeToolMenu() # toolbar
+
+ self.SetMenuBar(self.mainmenu)
+ self.calend = Calendar(self, -1)
+ self.calend.SetCurrentDay()
+ self.calend.grid_color = 'BLUE'
+ self.ResetDisplay()
+
+ self.Connect(self.calend.GetId(), -1, 2100, self.MouseClick)
+
+ def MouseClick(self, evt):
+ text = '%s CLICK %02d/%02d/%d' % (evt.click, evt.day, evt.month, evt.year) # format date
+ self.log.WriteText('Date Selected: ' + text + '\n')
+
+ def OnCloseWindow(self, event):
+ self.Destroy()
+
+ def ResetDisplay(self):
+ month = self.calend.GetMonth()
+ try:
+ set_days = test_days[month]
+ except:
+ set_days = [1, 5, 12]
+
+ self.calend.SetSelDay(set_days)
+ self.calend.Refresh()
+
+ def OnIncYear(self, event):
+ self.calend.IncYear()
+ self.ResetDisplay()
+
+ def OnDecYear(self, event):
+ self.calend.DecYear()
+ self.ResetDisplay()
+
+ def OnIncMonth(self, event):
+ self.calend.IncMonth()
+ self.ResetDisplay()
+
+ def OnDecMonth(self, event):
+ self.calend.DecMonth()
+ self.ResetDisplay()
+
+ def OnCurrent(self, event):
+ self.calend.SetCurrentDay()
+ self.ResetDisplay()
+
+ def MakeFileMenu(self):
+ menu = wxMenu()
+
+ mID = NewId()
+ menu.Append(mID, 'Decrement', 'Next')
+ EVT_MENU(self, mID, self.OnDecMonth)
+
+ mID = NewId()
+ menu.Append(mID, 'Increment', 'Dec')
+ EVT_MENU(self, mID, self.OnIncMonth)
+
+ menu.AppendSeparator()
+
+ mID = NewId()
+ menu.Append(mID, 'E&xit', 'Exit')
+ EVT_MENU(self, mID, self.OnCloseWindow)
+
+ return menu
+
+ def MakeToolMenu(self):
+ tb = self.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER)
+
+ bmp_path = 'CalBmp/'
+ SetToolPath(self, tb, 10, bmp_path + 'DbDec.bmp', 'Dec Year')
+ EVT_TOOL(self, 10, self.OnDecYear)
+
+ SetToolPath(self, tb, 15, bmp_path + 'Dec.bmp', 'Dec Month')
+ EVT_TOOL(self, 15, self.OnDecMonth)
+
+ SetToolPath(self, tb, 30, bmp_path + 'Pt.bmp', 'Current Month')
+ EVT_TOOL(self, 30, self.OnCurrent)
+
+ SetToolPath(self, tb, 40, bmp_path + 'Inc.bmp', 'Inc Month')
+ EVT_TOOL(self, 40, self.OnIncMonth)
+
+ SetToolPath(self, tb, 45, bmp_path + 'DbInc.bmp', 'Inc Year')
+ EVT_TOOL(self, 45, self.OnIncYear)
+
+ tb.Realize()
+
+def SetToolPath(self, tb, id, bmp, title):
+ global dir_path
+ tb.AddTool(id, wxBitmap(os.path.join(dir_path, bmp), wxBITMAP_TYPE_BMP), wxNullBitmap, false, -1, -1, title, title)
+
+class MyApp(wxApp):
+ def OnInit(self):
+ frame = CalendFrame(NULL, -1, "Test Calendar")
+ frame.Show(true)
+ self.SetTopWindow(frame)
+ return true
+
+#---------------------------------------------------------------------------
+
+def MessageDlg(self, message, type = 'Message'):
+ dlg = wxMessageDialog(self, message, type, wxOK | wxICON_INFORMATION)
+ dlg.ShowModal()
+ dlg.Destroy()
+
+#---------------------------------------------------------------------------
+
+def main():
+ app = MyApp(0)
+ app.MainLoop()
+
+
+if __name__ == '__main__':
+ main()
+
+
+#---------------------------------------------------------------------------
+
+def runTest(frame, nb, log):
+ win = TestPanel(nb, log)
+ return win
+
+#---------------------------------------------------------------------------
+
+
+overview = """\
+This control provides a calendar control class for displaying and selecting dates.
+
+See example for various methods used to set display month, year, and highlighted dates (different colour).
+
+by Lorne White
+
+"""
wxPoint(0,0), wxSize(500, 300))
self.log = log
- wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
+ win = wxWindow(self, -1)
+ win.SetBackgroundColour(wxNamedColour("WHITE"))
+ wxStaticText(win, -1, "Drag the toolbar to float it,\n"
+ "Toggle the last tool to remove the title.", wxPoint(15,15))
tb = wxFloatBar(self, -1)
self.SetToolBar(tb)
tb.AddSeparator()
- tb.AddTool(50, wxBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
- wxNullBitmap, true, -1, -1, "Toggle this")
- EVT_TOOL(self, 50, self.OnToolClick)
- EVT_TOOL_RCLICKED(self, 50, self.OnToolRClick)
tb.AddTool(60, wxBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP),
wxBitmap('bitmaps/tog2.bmp', wxBITMAP_TYPE_BMP),
EVT_TOOL(self, 60, self.OnToolClick)
EVT_TOOL_RCLICKED(self, 60, self.OnToolRClick)
tb.Realize()
-# b = wxButton(tb, -1, "HELLO!")
-# EVT_BUTTON(b, b.GetId(), self.test)
+
+ self.tb = tb
def OnCloseWindow(self, event):
def OnToolClick(self, event):
self.log.WriteText("tool %s clicked\n" % event.GetId())
+ if event.GetId() == 60:
+ if event.GetExtraLong():
+ self.tb.SetTitle("")
+ else:
+ self.tb.SetTitle("Floating!")
def OnToolRClick(self, event):
self.log.WriteText("tool %s right-clicked\n" % event.GetId())
overview = """\
wxFloatBar is a subclass of wxToolBar, implemented in Python, which can be detached from its frame.
-Drag the toolbar with the mouse to make it float, and drag it back, or close it to make the toolbar
-
-return to its original position.
-
-wxFloatBar()
------------------------
-
-Default constructor.
-
-wxFloatBar(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTB_HORIZONTAL | wxNO_BORDER, const wxString& name = wxPanelNameStr)
-
-Constructs a floatable toolbar.
-
-Parameters
--------------------
-
-parent = Pointer to a parent window.
-
-id = Window identifier. If -1, will automatically create an identifier.
-
-pos = Window position. wxDefaultPosition is (-1, -1) which indicates that wxWindows should generate a default position for the window. If using the wxWindow class directly, supply an actual position.
-
-size = Window size. wxDefaultSize is (-1, -1) which indicates that wxWindows should generate a default size for the window.
-
-style = Window style. Se wxToolBar for details.
+Drag the toolbar with the mouse to make it float, and drag it back, or close it to make the toolbar return to its original position.
-name = Window name.
"""
--- /dev/null
+# Name: CDate.py
+# Purpose: Date and Calendar classes
+#
+# Author: Lorne White (email: lwhite1@planet.eon.net)
+#
+# Created:
+# Version 0.2 1999/11/08
+# Licence: wxWindows license
+#----------------------------------------------------------------------------
+
+import time
+
+Month = {2: 'February', 3: 'March', None: 0, 'July': 7, 11:
+ 'November', 'December': 12, 'June': 6, 'January': 1, 'September': 9,
+ 'August': 8, 'March': 3, 'November': 11, 'April': 4, 12: 'December',
+ 'May': 5, 10: 'October', 9: 'September', 8: 'August', 7: 'July', 6:
+ 'June', 5: 'May', 4: 'April', 'October': 10, 'February': 2, 1:
+ 'January', 0: None}
+
+# Number of days per month (except for February in leap years)
+mdays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
+
+# Full and abbreviated names of weekdays
+day_name = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
+day_abbr = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', ]
+
+# Return number of leap years in range [y1, y2)
+# Assume y1 <= y2 and no funny (non-leap century) years
+
+def leapdays(y1, y2):
+ return (y2+3)/4 - (y1+3)/4
+
+# Return 1 for leap years, 0 for non-leap years
+def isleap(year):
+ return year % 4 == 0 and (year % 100 <> 0 or year % 400 == 0)
+
+def FillDate(val):
+ s = str(val)
+ if len(s) < 2:
+ s = '0' + s
+ return s
+
+
+def julianDay(year, month, day):
+ b = 0L
+ year, month, day = long(year), long(month), long(day)
+ if month > 12L:
+ year = year + month/12L
+ month = month%12
+ elif month < 1L:
+ month = -month
+ year = year - month/12L - 1L
+ month = 12L - month%12L
+ if year > 0L:
+ yearCorr = 0L
+ else:
+ yearCorr = 3L
+ if month < 3L:
+ year = year - 1L
+ month = month + 12L
+ if year*10000L + month*100L + day > 15821014L:
+ b = 2L - year/100L + year/400L
+ return (1461L*year - yearCorr)/4L + 306001L*(month + 1L)/10000L + day + 1720994L + b
+
+
+def TodayDay():
+ date = time.localtime(time.time())
+ year = date[0]
+ month = date[1]
+ day = date[2]
+ julian = julianDay(year, month, day)
+ daywk = dayOfWeek(julian)
+ daywk = day_name[daywk]
+ return(daywk)
+
+def FormatDay(value):
+ date = FromFormat(value)
+ daywk = DateCalc.dayOfWeek(date)
+ daywk = day_name[daywk]
+ return(daywk)
+
+def FromJulian(julian):
+ julian = long(julian)
+ if (julian < 2299160L):
+ b = julian + 1525L
+ else:
+ alpha = (4L*julian - 7468861L)/146097L
+ b = julian + 1526L + alpha - alpha/4L
+ c = (20L*b - 2442L)/7305L
+ d = 1461L*c/4L
+ e = 10000L*(b - d)/306001L
+ day = int(b - d - 306001L*e/10000L)
+ if e < 14L:
+ month = int(e - 1L)
+ else:
+ month = int(e - 13L)
+ if month > 2:
+ year = c - 4716L
+ else:
+ year = c - 4715L
+ year = int(year)
+ return year, month, day
+
+def dayOfWeek(julian):
+ return int((julian + 1L)%7L)
+
+def daysPerMonth(month, year):
+ ndays = mdays[month] + (month == 2 and isleap(year))
+ return ndays
+
+class now:
+ def __init__(self):
+ self.date = time.localtime(time.time())
+ self.year = self.date[0]
+ self.month = self.date[1]
+ self.day = self.date[2]
+
+class Date:
+ def __init__(self, year, month, day):
+ self.julian = julianDay(year, month, day)
+ self.month = month
+ self.year = year
+ self.day_of_week = dayOfWeek(self.julian)
+ self.days_in_month = daysPerMonth(self.month, self.year)
+
--- /dev/null
+#! /usr/local/bin/python
+#----------------------------------------------------------------------------
+# Name: wxCalend.py
+# Purpose: Calendar display control
+#
+# Author: Lorne White (email: lwhite1@planet.eon.net)
+#
+# Created:
+# Version 0.5 1999/11/03
+# Licence: wxWindows license
+#----------------------------------------------------------------------------
+
+from wxPython.wx import *
+
+try:
+ from DateTime import *
+ using_mxDateTime = true
+except ImportError:
+ from CDate import *
+ using_mxDateTime = false
+
+import string, time
+
+CalDays = [6, 0, 1, 2, 3, 4, 5]
+AbrWeekday = {6:"Sun", 0:"Mon", 1:"Tue", 2:"Wed", 3:"Thu", 4:"Fri", 5:"Sat"}
+
+
+# calendar drawing routing
+
+class CalDraw:
+ def __init__(self):
+ self.rg = {}
+ self.y_st = 15 # start of vertical draw default
+
+ def SetSize(self, size):
+ self.sizew = size.width
+ self.sizeh = size.height
+
+# draw the various elements of the calendar
+
+ def DrawCal(self, DC, sel_lst):
+ self.DC = DC
+
+ self.DrawBorder()
+
+ if self.hide_title is FALSE:
+ self.DrawMonth()
+
+ self.Center()
+
+ self.DrawGrid()
+ self.GetRect()
+
+ self.DrawSel(sel_lst) # highlighted days
+ self.DrawWeek()
+ self.DrawNum()
+
+# draw border around the outside of the main display rectangle
+
+ def DrawBorder(self):
+ rect = wxRect(0, 0, self.sizew, self.sizeh) # full display window area
+ self.DC.DrawRectangle(rect.x, rect.y, rect.width, rect.height)
+
+ def DrawNumVal(self):
+ self.DrawNum()
+
+# calculate the calendar days and offset position
+
+ def SetCal(self, year, month):
+ self.year = year
+ self.month = month
+
+ day = 1
+ t = Date(year, month, day)
+ dow = t.day_of_week # start day in month
+ dim = t.days_in_month # number of days in month
+ start_pos = dow+1
+ self.st_pos = start_pos
+
+ self.cal = []
+ for i in range(start_pos):
+ self.cal.append('')
+ i = 1
+ while i <= dim:
+ self.cal.append(str(i))
+ i = i + 1
+ return start_pos
+
+# get the display rectange list of the day grid
+
+ def GetRect(self):
+ cnt = 0
+ for y in self.gridy[1:-1]:
+ for x in self.gridx[:-1]:
+ rect = wxRect(x, y, self.dl_w, self.dl_h) # create rect region
+ self.rg[cnt] = rect
+ cnt = cnt + 1
+ return self.rg
+
+ def GetCal(self):
+ return self.cal
+
+ def GetOffset(self):
+ return self.st_pos
+
+# month and year title
+
+ def DrawMonth(self):
+ month = Month[self.month]
+
+ sizef = 12
+ if self.sizeh < 200:
+ sizef = 8
+
+ f = wxFont(sizef, self.font, wxNORMAL, wxNORMAL)
+ self.DC.SetFont(f)
+
+ tw,th = self.DC.GetTextExtent(month)
+ adjust = (self.sizew-tw)/2
+ self.DC.DrawText(month, adjust, 10)
+
+ year = str(self.year)
+ tw,th = self.DC.GetTextExtent(year)
+ adjust = self.sizew-tw-20
+
+ self.y_st = th * 3
+
+ f = wxFont(sizef, self.font, wxNORMAL, wxNORMAL)
+ self.DC.SetFont(f)
+ self.DC.DrawText(year, adjust, 10)
+
+# draw the week days
+
+ def DrawWeek(self):
+ sizef = 8
+ if self.sizeh < 300:
+ sizef = 6
+
+ f = wxFont(sizef, self.font, wxNORMAL, wxNORMAL)
+ self.DC.SetFont(f)
+
+ cnt_x = 0
+ cnt_y = 0
+ width = self.gridx[1]-self.gridx[0]
+ height = self.gridy[1] - self.gridy[0]
+
+ for val in CalDays:
+ day = AbrWeekday[val]
+ if self.sizew < 200:
+ day = day[0]
+ dw,dh = self.DC.GetTextExtent(day)
+ diffx = (width-dw)/2
+ diffy = (height-dh)/2
+
+ x = self.gridx[cnt_x]
+ y = self.gridy[cnt_y]
+ self.DC.DrawText(day, x+diffx, y+diffy)
+ cnt_x = cnt_x + 1
+
+# draw the day numbers
+
+ def DrawNum(self):
+ sizef = 9
+ if self.sizeh < 260:
+ sizef = 6
+ f = wxFont(sizef, self.font, wxNORMAL, wxNORMAL)
+ self.DC.SetFont(f)
+
+ cnt_x = 0
+ cnt_y = 1
+ for val in self.cal:
+ x = self.gridx[cnt_x]
+ y = self.gridy[cnt_y]
+ self.DC.DrawText(val, x+5, y+5)
+ if cnt_x < 6:
+ cnt_x = cnt_x + 1
+ else:
+ cnt_x = 0
+ cnt_y = cnt_y + 1
+
+# calculate the dimensions in the center of the drawing area
+
+ def Center(self):
+ self.x_st = 10
+ self.y_end = 10
+
+ bdw = self.x_st * 2
+ bdh = self.y_st + self.y_end
+
+ self.dl_w = (self.sizew-bdw)/7
+ self.dl_h = (self.sizeh-bdh)/7
+
+ self.cwidth = self.dl_w * 7
+ self.cheight = self.dl_h * 6 + self.dl_h/2
+
+# highlighted selectioned days
+
+ def DrawSel(self, sel_lst):
+ for key in sel_lst:
+ brush = wxBrush(wxNamedColour(self.high_color), wxSOLID)
+ self.DC.SetBrush(brush)
+ if self.hide_grid is FALSE:
+ self.DC.SetPen(wxPen(wxNamedColour(self.grid_color), 0))
+ else:
+ self.DC.SetPen(wxPen(wxNamedColour(self.back_color), 0))
+ nkey = key + self.st_pos -1
+ rect = self.rg[nkey]
+ self.DC.DrawRectangle(rect.x, rect.y, rect.width+1, rect.height+1)
+
+# calculate and draw the grid lines
+
+ def DrawGrid(self):
+ self.DC.SetPen(wxPen(wxNamedColour(self.grid_color), 0))
+
+ self.gridx = []
+ self.gridy = []
+
+ x1 = self.x_st
+ y1 = self.y_st
+ y1 = self.y_st
+ y2 = self.y_st + self.cheight
+ for i in range(8):
+ if self.hide_grid is FALSE:
+ self.DC.DrawLine(x1, y1, x1, y2)
+ self.gridx.append(x1)
+ x1 = x1 + self.dl_w
+
+ x1 = self.x_st
+ y1 = self.y_st
+ x2 = self.x_st + self.cwidth
+ for i in range(8):
+ if self.hide_grid is FALSE:
+ self.DC.DrawLine(x1, y1, x2, y1)
+ self.gridy.append(y1)
+ if i == 0:
+ y1 = y1 + self.dl_h/2
+ else:
+ y1 = y1 + self.dl_h
+
+
+class Calendar(wxWindow):
+ def __init__(self, parent, id, pos=wxDefaultPosition, size=wxDefaultSize):
+ wxWindow.__init__(self, parent, id, pos, size)
+
+ # set the calendar control attributes
+
+ self.grid_color = 'BLACK'
+ self.back_color = 'WHITE'
+ self.sel_color = 'RED'
+ self.high_color = 'LIGHT BLUE'
+ self.font = wxSWISS
+
+ self.SetBackgroundColour(wxNamedColor(self.back_color))
+ self.Connect(-1, -1, wxEVT_LEFT_DOWN, self.OnLeftEvent)
+ self.Connect(-1, -1, wxEVT_LEFT_DCLICK, self.OnLeftDEvent)
+ self.Connect(-1, -1, wxEVT_RIGHT_DOWN, self.OnRightEvent)
+ self.Connect(-1, -1, wxEVT_RIGHT_DCLICK, self.OnRightDEvent)
+
+ self.sel_key = None # last used by
+ self.sel_lst = [] # highlighted selected days
+
+ self.SetNow() # default calendar for current month
+
+ self.size = None
+ self.hide_title = FALSE
+ self.hide_grid = FALSE
+ self.set_day = None
+
+# control some of the main calendar attributes
+
+ def HideTitle(self):
+ self.hide_title = TRUE
+
+ def HideGrid(self):
+ self.hide_grid = TRUE
+
+# determine the calendar rectangle click area and draw a selection
+
+ def ProcessClick(self, event):
+ self.x, self.y = event.GetX(), event.GetY()
+ key = self.GetDayHit(self.x, self.y)
+ self.SelectDay(key)
+
+# tab mouse click events and process
+
+ def OnLeftEvent(self, event):
+ self.click = 'LEFT'
+ self.ProcessClick(event)
+
+ def OnLeftDEvent(self, event):
+ self.click = 'DLEFT'
+ self.ProcessClick(event)
+
+ def OnRightEvent(self, event):
+ self.click = 'RIGHT'
+ self.ProcessClick(event)
+
+ def OnRightDEvent(self, event):
+ self.click = 'DRIGHT'
+ self.ProcessClick(event)
+
+ def SetSize(self, set_size):
+ self.size = set_size
+
+ def SetSelDay(self, sel):
+ self.sel_lst = sel # list of highlighted days
+
+# get the current date
+
+ def SetNow(self):
+ dt = now()
+ self.month = dt.month
+ self.year = dt.year
+ self.day = dt.day
+
+# set the current day
+
+ def SetCurrentDay(self):
+ self.SetNow()
+ self.set_day = self.day
+
+# get the date, day, month, year set in calendar
+
+ def GetDate(self):
+ return self.day, self.month, self.year
+
+ def GetDay(self):
+ return self.day
+
+ def GetMonth(self):
+ return self.month
+
+ def GetYear(self):
+ return self.year
+
+# set the day, month, and year
+
+ def SetDayValue(self, day):
+ self.set_day = day
+
+ def SetMonth(self, month):
+ if month >= 1 and month <= 12:
+ self.month = month
+ else:
+ self.month = 1
+ self.set_day = None
+
+ def SetYear(self, year):
+ self.year = year
+
+# increment year and month
+
+ def IncYear(self):
+ self.year = self.year + 1
+ self.set_day = None
+
+ def DecYear(self):
+ self.year = self.year - 1
+ self.set_day = None
+
+ def IncMonth(self):
+ self.month = self.month + 1
+ if self.month > 12:
+ self.month = 1
+ self.year = self.year + 1
+ self.set_day = None
+
+ def DecMonth(self):
+ self.month = self.month - 1
+ if self.month < 1:
+ self.month = 12
+ self.year = self.year - 1
+ self.set_day = None
+
+# test to see if the selection has a date and create event
+
+ def TestDay(self, key):
+ try:
+ self.day = int(self.cal[key])
+ except:
+ return None
+ if self.day == "":
+ return None
+ else:
+ evt = wxPyCommandEvent(2100, self.GetId())
+ evt.click, evt.day, evt.month, evt.year = self.click, self.day, self.month, self.year
+ self.GetEventHandler().ProcessEvent(evt)
+
+ self.set_day = self.day
+ return key
+
+# find the clicked area rectangle
+
+ def GetDayHit(self, mx, my):
+ for key in self.rg.keys():
+ val = self.rg[key]
+ rt = wxRegion()
+ rt.Union(val)
+ if rt.Contains(mx, my) != 0:
+ result = self.TestDay(key)
+ return result
+ return None
+
+# calendar drawing
+
+ def OnPaint(self, event):
+ DC = wxPaintDC(self)
+ self.DoDrawing(DC)
+
+ def DoDrawing(self, DC):
+ DC = wxPaintDC(self)
+ DC.BeginDrawing()
+
+ self.cal = cal = CalDraw()
+ if self.size is None:
+ size = self.GetClientSize()
+ else:
+ size = self.size
+
+# drawing attributes
+
+ cal.hide_title = self.hide_title
+ cal.hide_grid = self.hide_grid
+
+ cal.grid_color = self.grid_color
+ cal.high_color = self.high_color
+ cal.back_color = self.back_color
+ cal.font = self.font
+
+ cal.SetSize(size)
+ cal.SetCal(self.year, self.month)
+ cal.DrawCal(DC, self.sel_lst)
+
+ self.rg = cal.GetRect()
+ self.cal = cal.GetCal()
+ self.st_pos = cal.GetOffset()
+ self.ymax = DC.MaxY()
+
+ if self.set_day != None:
+ self.SetDay(self.set_day)
+ DC.EndDrawing()
+
+# draw the selection rectangle
+
+ def DrawRect(self, key, color = 'BLACK', width = 0):
+ if key == None:
+ return
+ DC = wxClientDC(self)
+ DC.BeginDrawing()
+
+ brush = wxBrush(wxColour(0, 0xFF, 0x80), wxTRANSPARENT)
+ DC.SetBrush(brush)
+ DC.SetPen(wxPen(wxNamedColour(color), width))
+
+ rect = self.rg[key]
+ DC.DrawRectangle(rect.x, rect.y, rect.width+1, rect.height+1)
+
+ DC.EndDrawing()
+
+# set the day selection
+
+ def SetDay(self, day):
+ day = day + self.st_pos - 1
+ self.SelectDay(day)
+
+ def SelectDay(self, key):
+ sel_size = 1
+ self.DrawRect(self.sel_key, self.back_color, sel_size) # clear large selection
+ if self.hide_grid is FALSE:
+ self.DrawRect(self.sel_key, self.grid_color)
+
+ self.DrawRect(key, self.sel_color, sel_size)
+ self.sel_key = key # store last used by
+ self.select_day = None
+
+ def ClearDsp(self):
+ self.Clear()
+
+
position. Programmatically, call SetFloatable(true) and then
Float(true) to float, Float(false) to dock.
"""
+
def __init__(self,*_args,**_kwargs):
"""
In addition to the usual arguments, wxFloatBar accepts keyword
self.title = ""
EVT_MOUSE_EVENTS(self, self.OnMouse)
self.parentframe = wxPyTypeCast(args[1], 'wxFrame')
+
def IsFloatable(self):
return self.floatable
+
def SetFloatable(self, float):
self.floatable = float
#Find the size of a title bar.
test.SetClientSize(wxSize(0,0))
self.titleheight = test.GetSizeTuple()[1]
test.Destroy()
+
def IsFloating(self):
return self.floating
+
def Realize(self):
wxToolBar.Realize(self)
self.barheight = -1
+
def GetTitle(self):
return self.title
+
def SetTitle(self, title):
self.title = title
if self.IsFloating():
self.floatframe.SetTitle(self.title)
+
def GetHome(self):
"""
Returns the frame which this toolbar will return to when
return self.parentframe
else:
return wxPyTypeCast(self.GetParent(), 'wxFrame')
+
def SetHome(self, frame):
"""
Called when docked, this will remove the toolbar from its
size = frame.GetSize()
frame.SetSize(wxSize(0,0))
frame.SetSize(size)
+
def Float(self, bool):
"Floats or docks the toolbar programmatically."
if bool:
self.parentframe = wxPyTypeCast(self.GetParent(), 'wxFrame')
clientsize = self.parentframe.GetClientSizeTuple()
- self.floatframe = wxMiniFrame(self.parentframe, -1, self.title, wxDefaultPosition, wxDefaultSize, wxTHICK_FRAME)
+ if self.title:
+ useStyle = wxDEFAULT_FRAME_STYLE
+ else:
+ useStyle = 0 #wxTHICK_FRAME
+ self.floatframe = wxMiniFrame(self.parentframe, -1, self.title,
+ style = useStyle)
self.Reparent(self.floatframe)
self.parentframe.SetToolBar(None)
self.floating = 1
self.floatframe.SetPosition(newpos)
self.floatframe.Show(true)
EVT_CLOSE(self.floatframe, self.OnDock)
-# EVT_MOVE(self.floatframe, self.OnMove)
+ EVT_MOVE(self.floatframe, self.OnMove)
else:
self.Reparent(self.parentframe)
self.parentframe.SetToolBar(self)
self.parentframe.SetSize(wxSize(0,0))
self.parentframe.SetSize(size)
self.SetBackgroundColour(self.oldcolor)
+
def OnDock(self, e):
self.Float(0)
if hasattr(self, 'oldpos'):
homepos = self.parentframe.GetPositionTuple()
homepos = homepos[0], homepos[1] + self.titleheight
floatpos = self.floatframe.GetPositionTuple()
- if abs(homepos[0]-floatpos[0]) < 35 and abs(homepos[1]-floatpos[1]) < 35:
+ if abs(homepos[0] - floatpos[0]) < 35 and abs(homepos[1] - floatpos[1]) < 35:
self._SetFauxBarVisible(true)
else:
self._SetFauxBarVisible(false)
if e.ButtonDown() or e.ButtonUp() or e.ButtonDClick(1) or e.ButtonDClick(2) or e.ButtonDClick(3):
e.Skip()
if e.ButtonDown():
+ self.CaptureMouse()
self.oldpos = (e.GetX(), e.GetY())
if e.Entering():
self.oldpos = (e.GetX(), e.GetY())
if e.ButtonUp():
+ self.ReleaseMouse()
if self.IsFloating():
homepos = self.parentframe.GetPositionTuple()
homepos = homepos[0], homepos[1] + self.titleheight
self.floatframe.SetPosition(pt)
def _SetFauxBarVisible(self, vis):
-# return
+ return
if vis:
if self.parentframe.GetToolBar() == None:
if not hasattr(self, 'nullbar'):
class wxPyDropSource : public wxDropSource {
public:
+#ifdef __WXMSW__
wxPyDropSource(wxWindow *win = NULL,
const wxCursor &cursorCopy = wxNullCursor,
const wxCursor &cursorMove = wxNullCursor,
const wxCursor &cursorStop = wxNullCursor)
: wxDropSource(win, cursorCopy, cursorMove, cursorStop) {}
-
+#else
+ wxPyDropSource(wxWindow *win = NULL,
+ const wxIcon &go = wxNullIcon)
+ : wxDropSource(win, go) {}
+#endif
DEC_PYCALLBACK_BOOL_DR(GiveFeedback);
PYPRIVATE;
};