Added more contribs from Lorne White, and updated some of the existing ones.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11553 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -29,7 +29,7 @@ day_abbr = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', ]
|
||||
|
||||
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)
|
||||
@@ -40,7 +40,7 @@ def FillDate(val):
|
||||
s = '0' + s
|
||||
return s
|
||||
|
||||
|
||||
|
||||
def julianDay(year, month, day):
|
||||
b = 0L
|
||||
year, month, day = long(year), long(month), long(day)
|
||||
@@ -62,7 +62,7 @@ def julianDay(year, month, day):
|
||||
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]
|
||||
@@ -109,14 +109,14 @@ def daysPerMonth(month, year):
|
||||
return ndays
|
||||
|
||||
class now:
|
||||
def __init__(self):
|
||||
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):
|
||||
def __init__(self, year, month, day):
|
||||
self.julian = julianDay(year, month, day)
|
||||
self.month = month
|
||||
self.year = year
|
||||
|
@@ -366,7 +366,6 @@ class wxGenBitmapButton(wxGenButton):
|
||||
return -1, -1, false
|
||||
return self.bmpLabel.GetWidth()+2, self.bmpLabel.GetHeight()+2, false
|
||||
|
||||
|
||||
def DrawLabel(self, dc, width, height, dw=0, dy=0):
|
||||
bmp = self.bmpLabel
|
||||
if self.bmpDisabled and not self.IsEnabled():
|
||||
@@ -384,6 +383,7 @@ class wxGenBitmapButton(wxGenButton):
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
class wxGenBitmapTextButton(wxGenBitmapButton): # generic bitmapped button with Text Label
|
||||
def __init__(self, parent, ID, bitmap, label,
|
||||
pos = wxDefaultPosition, size = wxDefaultSize,
|
||||
@@ -443,8 +443,10 @@ class wxGenBitmapTextButton(wxGenBitmapButton): # generic bitmapped button w
|
||||
|
||||
dc.DrawText(label, pos_x + dw+bw, (height-th)/2+dy) # draw the text
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
class __ToggleMixin:
|
||||
def SetToggle(self, flag):
|
||||
self.up = not flag
|
||||
@@ -490,6 +492,7 @@ class wxGenBitmapToggleButton(__ToggleMixin, wxGenBitmapButton):
|
||||
|
||||
class wxGenBitmapTextToggleButton(__ToggleMixin, wxGenBitmapTextButton):
|
||||
pass
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
|
@@ -5,8 +5,8 @@
|
||||
# Author: Lorne White (email: lorne.white@telusplanet.net)
|
||||
#
|
||||
# Created:
|
||||
# Version 0.85
|
||||
# Date: June 20, 2001
|
||||
# Version 0.90
|
||||
# Date: July 19, 2001
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
@@ -18,7 +18,7 @@ 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"}
|
||||
_MIDSIZE = 160
|
||||
_MIDSIZE = 180
|
||||
|
||||
BusCalDays = [0, 1, 2, 3, 4, 5, 6]
|
||||
|
||||
@@ -44,6 +44,19 @@ class CalDraw:
|
||||
self.DefParms()
|
||||
|
||||
def DefParms(self):
|
||||
self.num_auto = TRUE # auto scale of the cal number day size
|
||||
self.num_size = 12 # default size of calendar if no auto size
|
||||
self.max_num_size = 12 # maximum size for calendar number
|
||||
|
||||
self.num_align_horz = wxALIGN_CENTRE # alignment of numbers
|
||||
self.num_align_vert = wxALIGN_CENTRE
|
||||
self.num_indent_horz = 0 # points indent from position, used to offset if not centered
|
||||
self.num_indent_vert = 0
|
||||
|
||||
self.week_auto = TRUE # auto scale of week font text
|
||||
self.week_size = 10
|
||||
self.max_week_size = 12
|
||||
|
||||
self.grid_color = 'BLACK' # grid and selection colors
|
||||
self.back_color = 'WHITE'
|
||||
self.sel_color = 'RED'
|
||||
@@ -227,20 +240,29 @@ class CalDraw:
|
||||
self.DC.DrawText(year, self.cx_st + adjust, self.cy_st + th)
|
||||
|
||||
def DrawWeek(self): # draw the week days
|
||||
sizef = 8
|
||||
if self.sizeh < _MIDSIZE:
|
||||
sizef = 7
|
||||
width = self.gridx[1]-self.gridx[0]
|
||||
height = self.gridy[1] - self.gridy[0]
|
||||
rect_w = self.gridx[7]-self.gridx[0]
|
||||
|
||||
f = wxFont(10, self.font, wxNORMAL, self.bold) # initial font setting
|
||||
if self.week_auto == TRUE:
|
||||
test_size = self.max_week_size # max size
|
||||
test_day = ' Sun '
|
||||
while test_size > 2:
|
||||
f.SetPointSize(test_size)
|
||||
self.DC.SetFont(f)
|
||||
tw,th = self.DC.GetTextExtent(test_day)
|
||||
if tw < width and th < height:
|
||||
break
|
||||
test_size = test_size - 1
|
||||
else:
|
||||
f.SetPointSize(self.week_size) # set fixed size
|
||||
self.DC.SetFont(f)
|
||||
|
||||
f = wxFont(sizef, self.font, wxNORMAL, self.bold)
|
||||
self.DC.SetFont(f)
|
||||
self.DC.SetTextForeground(wxNamedColour(self.week_font_color))
|
||||
|
||||
cnt_x = 0
|
||||
cnt_y = 0
|
||||
width = self.gridx[1]-self.gridx[0]
|
||||
height = self.gridy[1] - self.gridy[0]
|
||||
|
||||
rect_w = self.gridx[7]-self.gridx[0]
|
||||
|
||||
brush = wxBrush(wxNamedColour(self.week_color), wxSOLID)
|
||||
self.DC.SetBrush(brush)
|
||||
@@ -265,12 +287,22 @@ class CalDraw:
|
||||
self.DC.DrawText(day, x+diffx, y+diffy)
|
||||
cnt_x = cnt_x + 1
|
||||
|
||||
|
||||
def DrawNum(self): # draw the day numbers
|
||||
sizef = 10
|
||||
if self.sizeh < _MIDSIZE:
|
||||
sizef = 8
|
||||
f = wxFont(sizef, self.font, wxNORMAL, self.bold)
|
||||
f = wxFont(10, self.font, wxNORMAL, self.bold) # initial font setting
|
||||
if self.num_auto == TRUE:
|
||||
test_size = self.max_num_size # max size
|
||||
test_day = ' 99 '
|
||||
while test_size > 2:
|
||||
f.SetPointSize(test_size)
|
||||
self.DC.SetFont(f)
|
||||
tw,th = self.DC.GetTextExtent(test_day)
|
||||
if tw < self.dl_w and th < self.dl_h:
|
||||
sizef = test_size
|
||||
break
|
||||
test_size = test_size - 1
|
||||
else:
|
||||
f.SetPointSize(self.num_size) # set fixed size
|
||||
self.DC.SetFont(f)
|
||||
|
||||
cnt_x = 0
|
||||
cnt_y = 1
|
||||
@@ -287,7 +319,26 @@ class CalDraw:
|
||||
self.DC.SetTextForeground(wxNamedColour(num_color))
|
||||
self.DC.SetFont(f)
|
||||
|
||||
self.DC.DrawText(val, x+5, y+5)
|
||||
tw,th = self.DC.GetTextExtent(val)
|
||||
if self.num_align_horz == wxALIGN_CENTRE:
|
||||
adj_h = (self.dl_w - tw)/2
|
||||
elif self.num_align_horz == wxALIGN_RIGHT:
|
||||
adj_h = self.dl_w - tw
|
||||
else:
|
||||
adj_h = 0 # left alignment
|
||||
|
||||
adj_h = adj_h + self.num_indent_horz
|
||||
|
||||
if self.num_align_vert == wxALIGN_CENTRE:
|
||||
adj_v = (self.dl_h - th)/2
|
||||
elif self.num_align_horz == wxALIGN_RIGHT:
|
||||
adj_v = self.dl_h - th
|
||||
else:
|
||||
adj_v = 0 # left alignment
|
||||
|
||||
adj_v = adj_v + self.num_indent_vert
|
||||
|
||||
self.DC.DrawText(val, x+adj_h, y+adj_v)
|
||||
if cnt_x < 6:
|
||||
cnt_x = cnt_x + 1
|
||||
else:
|
||||
@@ -425,6 +476,8 @@ class wxCalendar(wxWindow):
|
||||
|
||||
def OnLeftEvent(self, event):
|
||||
self.click = 'LEFT'
|
||||
self.shiftkey = event.ShiftDown()
|
||||
self.ctrlkey = event.ControlDown()
|
||||
self.ProcessClick(event)
|
||||
|
||||
def OnLeftDEvent(self, event):
|
||||
@@ -524,6 +577,8 @@ class wxCalendar(wxWindow):
|
||||
else:
|
||||
evt = wxPyCommandEvent(2100, self.GetId())
|
||||
evt.click, evt.day, evt.month, evt.year = self.click, self.day, self.month, self.year
|
||||
evt.shiftkey = self.shiftkey
|
||||
evt.ctrlkey = self.ctrlkey
|
||||
self.GetEventHandler().ProcessEvent(evt)
|
||||
|
||||
self.set_day = self.day
|
||||
|
@@ -17,30 +17,37 @@ from wxPython.wx import *
|
||||
# GetColour method to get the selected colour
|
||||
|
||||
class ColourSelect(wxButton):
|
||||
def __init__(self, parent, id, bcolour=(0, 0, 0), pos=wxDefaultPosition, size=wxDefaultSize):
|
||||
wxButton.__init__(self, parent, id, "", pos=pos, size=size)
|
||||
EVT_BUTTON(parent, self.GetId(), self.OnClick)
|
||||
self.SetForegroundColour(wxWHITE)
|
||||
self.SetColour(bcolour)
|
||||
def __init__(self, parent, position = wxPoint(20, 20), bcolour = [0, 0, 0], size = wxSize(20, 20)):
|
||||
self.win = parent
|
||||
|
||||
mID = NewId()
|
||||
self.b = b = wxButton(parent, mID, "", position, size)
|
||||
EVT_BUTTON(parent, mID, self.OnClick)
|
||||
|
||||
def SetColour(self, bcolour):
|
||||
self.set_colour_val = set_colour = wxColor(bcolour[0], bcolour[1], bcolour[2])
|
||||
self.SetBackgroundColour(set_colour)
|
||||
b.SetBackgroundColour(set_colour)
|
||||
b.SetForegroundColour(wxWHITE)
|
||||
self.set_colour = bcolour
|
||||
|
||||
def SetColour(self, bcolour):
|
||||
self.b.SetBackgroundColour(bcolour)
|
||||
|
||||
def GetColour(self):
|
||||
return self.set_colour
|
||||
|
||||
|
||||
def OnClick(self, event):
|
||||
data = wxColourData()
|
||||
data.SetChooseFull(true)
|
||||
data.SetColour(self.set_colour_val)
|
||||
dlg = wxColourDialog(self.GetParent(), data)
|
||||
dlg = wxColourDialog(self.win, data)
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
data = dlg.GetColourData()
|
||||
self.SetColour(data.GetColour().Get())
|
||||
self.set_colour = set = data.GetColour().Get()
|
||||
self.set_colour_val = bcolour = wxColour(set[0],set[1],set[2])
|
||||
self.b.SetBackgroundColour(bcolour)
|
||||
dlg.Destroy()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -5,8 +5,8 @@
|
||||
#
|
||||
# Author: Lorne White
|
||||
#
|
||||
# Version: 0.6
|
||||
# Date: March 27, 2001
|
||||
# Version: 0.9
|
||||
# Date: August 15, 2001
|
||||
# Licence: wxWindows license
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
@@ -17,6 +17,9 @@ dir_path = os.getcwd()
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
def ConvertBMP(file_nm):
|
||||
if file_nm is None:
|
||||
return None
|
||||
|
||||
fl_fld = os.path.splitext(file_nm)
|
||||
ext = fl_fld[1]
|
||||
ext = string.lower(ext[1:])
|
||||
@@ -33,27 +36,62 @@ def ConvertBMP(file_nm):
|
||||
|
||||
return image
|
||||
|
||||
class ImageView:
|
||||
def __init__(self, iparent, ipos, isize):
|
||||
self.win = iparent
|
||||
self.ImagePanel = wxPanel(size = isize, parent = iparent, id = -1, name = 'backgroundPanel', style = wxSIMPLE_BORDER | wxCLIP_CHILDREN, pos= ipos)
|
||||
self.clear = wxColour(255, 255, 255)
|
||||
self.ImagePanel.SetBackgroundColour(self.clear) # clear the panel
|
||||
def GetSize(file_nm): # for scaling image values
|
||||
image = ConvertBMP(file_nm)
|
||||
bmp = image.ConvertToBitmap()
|
||||
size = bmp.GetWidth(), bmp.GetHeight()
|
||||
return size
|
||||
|
||||
self.image_sizex = isize.width
|
||||
self.image_sizey = isize.height
|
||||
self.image_posx = ipos.x
|
||||
self.image_posy = ipos.y
|
||||
class ImageView(wxWindow):
|
||||
def __init__(self, parent, id=-1, pos=wxDefaultPosition, size=wxDefaultSize):
|
||||
wxWindow.__init__(self, parent, id, pos, size)
|
||||
self.win = parent
|
||||
self.image = None
|
||||
self.back_color = 'WHITE'
|
||||
self.border_color = 'BLACK'
|
||||
|
||||
self.image_sizex = size.width
|
||||
self.image_sizey = size.height
|
||||
self.image_posx = pos.x
|
||||
self.image_posy = pos.y
|
||||
EVT_PAINT(self, self.OnPaint)
|
||||
|
||||
wxInitAllImageHandlers()
|
||||
|
||||
def OnPaint(self, event):
|
||||
dc = wxPaintDC(self)
|
||||
self.DrawImage(dc)
|
||||
|
||||
def DrawImage(self, dc):
|
||||
dc.BeginDrawing()
|
||||
self.DrawImage(dc)
|
||||
dc.EndDrawing()
|
||||
|
||||
def SetValue(self, file_nm): # display the selected file in the panel
|
||||
image = ConvertBMP(file_nm).ConvertToBitmap()
|
||||
if image is None:
|
||||
image = ConvertBMP(file_nm)
|
||||
self.image = image
|
||||
self.Refresh()
|
||||
|
||||
def DrawBorder(self, dc):
|
||||
brush = wxBrush(wxNamedColour(self.back_color), wxSOLID)
|
||||
dc.SetBrush(brush)
|
||||
dc.SetPen(wxPen(wxNamedColour(self.border_color), 1))
|
||||
dc.DrawRectangle(0, 0, self.image_sizex, self.image_sizey)
|
||||
|
||||
def DrawImage(self, dc):
|
||||
try:
|
||||
image = self.image
|
||||
except:
|
||||
return
|
||||
|
||||
iwidth = image.GetWidth() # dimensions of image file
|
||||
iheight = image.GetHeight()
|
||||
self.DrawBorder(dc)
|
||||
if image is None:
|
||||
return
|
||||
|
||||
bmp = image.ConvertToBitmap()
|
||||
|
||||
iwidth = bmp.GetWidth() # dimensions of image file
|
||||
iheight = bmp.GetHeight()
|
||||
|
||||
diffx = (self.image_sizex - iwidth)/2 # center calc
|
||||
if iwidth >= self.image_sizex -10: # if image width fits in window adjust
|
||||
@@ -64,13 +102,12 @@ class ImageView:
|
||||
if iheight >= self.image_sizey - 10: # if image height fits in window adjust
|
||||
diffy = 5
|
||||
iheight = self.image_sizey - 10
|
||||
|
||||
self.ClearPanel()
|
||||
wxStaticBitmap(self.win, -1, image, wxPoint(self.image_posx+diffx, self.image_posy+diffy), wxSize(iwidth, iheight ))
|
||||
|
||||
def ClearPanel(self): # clear the image panel
|
||||
self.ImagePanel.SetBackgroundColour(self.clear)
|
||||
self.ImagePanel.Refresh()
|
||||
image.Rescale(iwidth, iheight) # rescale to fit the window
|
||||
image.ConvertToBitmap()
|
||||
bmp = image.ConvertToBitmap()
|
||||
dc.DrawBitmap(bmp, diffx, diffy) # draw the image to window
|
||||
|
||||
|
||||
class ImageDialog(wxDialog):
|
||||
def __init__(self, parent, set_dir = None):
|
||||
@@ -128,7 +165,7 @@ class ImageDialog(wxDialog):
|
||||
self.sel_type = wxComboBox(self, mID, self.set_type, wxPoint(image_posx , self.type_posy), wxSize(150, -1), self.fl_types, wxCB_DROPDOWN)
|
||||
EVT_COMBOBOX(self, mID, self.OnSetType)
|
||||
|
||||
self.image_view = ImageView(self, wxPoint(image_posx, image_posy), wxSize(image_sizex, image_sizey))
|
||||
self.image_view = ImageView(self, pos=wxPoint(image_posx, image_posy), size=wxSize(image_sizex, image_sizey))
|
||||
|
||||
self.y_pos = self.y_pos + height + 20
|
||||
|
||||
@@ -177,7 +214,6 @@ class ImageDialog(wxDialog):
|
||||
dlg.Destroy()
|
||||
|
||||
def ResetFiles(self): # refresh the display with files and initial image
|
||||
self.image_view.ClearPanel()
|
||||
self.DisplayDir()
|
||||
self.GetFiles()
|
||||
self.tb.Set(self.fl_list)
|
||||
@@ -185,10 +221,13 @@ class ImageDialog(wxDialog):
|
||||
self.tb.SetSelection(0)
|
||||
self.SetListValue(0)
|
||||
except:
|
||||
pass
|
||||
self.image_view.SetValue(None)
|
||||
|
||||
def GetFile(self):
|
||||
return self.set_file
|
||||
|
||||
def GetDirectory(self):
|
||||
return self.set_dir
|
||||
|
||||
def OnCancel(self, event):
|
||||
self.result = None
|
||||
|
1063
wxPython/wxPython/lib/printout.py
Normal file
1063
wxPython/wxPython/lib/printout.py
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user