#
# Author: Lorne White, Lorne.White@telusplanet.net
#
-# Created: Sept 4, 2001
+# Created: Feb 25, 2001
# Licence: wxWindows license
#----------------------------------------------------------------------------
# Updates:
# call back to function if changes made
+# Cliff Wells, logiplexsoftware@earthlink.net:
+# - Made ColourSelect into "is a button" rather than "has a button"
+# - Added label parameter and logic to adjust the label colour according to the background
+# colour
+# - Added id argument
+# - Rearranged arguments to more closely follow wx conventions
+# - Simplified some of the code
+
+
class ColourSelect(wxButton):
- def __init__(self, parent, ID, bcolour=[0, 0, 0], pos=wxPoint(20, 20), size=wxSize(20, 20), style=0, callback=None):
- wxButton.__init__(self, parent, ID, "", pos, size, style)
- self.win = parent
+ def __init__(self, parent, id, label = "", bcolour=(0, 0, 0),
+ pos = wxDefaultPosition, size = wxDefaultSize,
+ callback = None):
+ wxButton.__init__(self, parent, id, label, pos=pos, size=size)
+ self.SetColour(bcolour)
self.callback = callback
- EVT_BUTTON(self, ID, self.OnClick)
- self.SetColourValue(bcolour)
+ EVT_BUTTON(parent, self.GetId(), self.OnClick)
- def SetColour(self, bcolour):
- self.SetBackgroundColour(bcolour)
+ def GetColour(self):
+ return self.set_colour
+
+ def GetValue(self):
+ return self.set_colour
- def SetColourValue(self, bcolour):
+ def SetColour(self, bcolour):
+ self.set_colour_val = wxColor(bcolour[0], bcolour[1], bcolour[2])
+ self.SetBackgroundColour(self.set_colour_val)
+ avg = reduce(lambda a, b: a + b, bcolour) / 3
+ fcolour = avg > 128 and (0, 0, 0) or (255, 255, 255)
+ self.SetForegroundColour(apply(wxColour, fcolour))
self.set_colour = bcolour
- self.SetBackgroundColour(self.Get_wxColour())
- self.SetForegroundColour(wxWHITE)
def SetValue(self, bcolour):
- self.SetColourValue(bcolour)
-
- def GetColour(self):
- return self.set_colour
-
- def Get_wxColour(self):
- return wxColour(self.set_colour[0], self.set_colour[1], self.set_colour[2])
+ self.SetColour(bcolour)
def OnChange(self):
- if self.callback != None:
+ if self.callback is not None:
self.callback()
def OnClick(self, event):
data = wxColourData()
data.SetChooseFull(true)
- data.SetColour(self.Get_wxColour())
- dlg = wxColourDialog(self.win, data)
- if dlg.ShowModal() == wxID_OK:
+ data.SetColour(self.set_colour_val)
+ dlg = wxColourDialog(self.GetParent(), data)
+ changed = dlg.ShowModal() == wxID_OK
+ if changed:
data = dlg.GetColourData()
- self.set_colour = set = data.GetColour().Get()
- self.SetBackgroundColour(self.Get_wxColour())
- self.OnChange()
+ self.SetColour(data.GetColour().Get())
dlg.Destroy()
+ if changed:
+ self.OnChange() # moved after dlg.Destroy, since who knows what the callback will do...
# Author: Lorne White (email: lorne.white@telusplanet.net)
#
# Created:
-# Version 0.72
-# Date: Sept 8, 2001
+# Version 0.75
+# Date: Sept 18, 2001
# Licence: wxWindows license
#----------------------------------------------------------------------------
import copy
class PrintBase:
+ def SetPrintFont(self, font): # set the DC font parameters
+ fattr = font["Attr"]
+ if fattr[0] == 1:
+ weight = wxBOLD
+ else:
+ weight = wxNORMAL
+
+ if fattr[1] == 1:
+ set_style = wxITALIC
+ else:
+ set_style = wxNORMAL
+
+ underline = fattr[2]
+ fcolour = self.GetFontColour(font)
+ self.DC.SetTextForeground(fcolour)
+
+ setfont = wxFont(font["Size"], wxSWISS, set_style, weight, underline)
+ setfont.SetFaceName(font["Name"])
+ self.DC.SetFont(setfont)
+
+ def GetFontColour(self, font):
+ fcolour = font["Colour"]
+ return wxColour(fcolour[0], fcolour[1], fcolour[2])
+
def OutTextRegion(self, textout, txtdraw = TRUE):
textlines = string.splitfields(textout, '\n')
y = copy.copy(self.y) + self.pt_space_before
y = y + y_line
return y - y_line
+ def GetDate(self):
+ date, time = self.GetNow()
+ return date
+
+ def GetDateTime(self):
+ date, time = self.GetNow()
+ return date + ' ' + time
+
+ def GetNow(self):
+ full = str(wxDateTime_Now()) # get the current date and time in print format
+ flds = string.splitfields(full)
+ date = flds[0]
+ time = flds[1]
+ return date, time
+
def SetPreview(self, preview):
self.preview = preview
self.column_def_line_colour = self.parent.column_def_line_colour
self.text_font = self.parent.text_font
- self.text_font_name = self.parent.text_font_name
- self.text_font_colour = self.parent.text_font_colour
self.label_font = self.parent.label_font
- self.label_font_name = self.parent.label_font_name
- self.label_font_colour = self.parent.label_font_colour
def AdjustValues(self):
self.vertical_offset = self.pheight * self.parent.vertical_offset
try:
colour = set_column_txtcolour[col] # check if custom column text colour
except:
- colour = self.parent.text_font_colour
+ colour = self.GetFontColour(self.parent.text_font)
+
self.column_txtcolour.append(colour)
col = col + 1
def SetPointAdjust(self):
f = wxFont(10, wxSWISS, wxNORMAL, wxNORMAL) # setup using 10 point
self.DC.SetFont(f)
- f.SetFaceName(self.text_font_name)
+ f.SetFaceName(self.text_font["Name"])
x, y = self.DC.GetTextExtent("W")
self.label_pt_space_before = self.parent.label_pt_adj_before * y/10 # extra spacing for label per point value
self.y_start = self.ptop_margin + self.vertical_offset
self.y_end = self.parent.page_height * self.pheight - self.pbottom_margin + self.vertical_offset
- self.text_font.SetFaceName(self.label_font_name)
- self.DC.SetFont(self.label_font)
+ self.SetPrintFont(self.label_font)
+
x, y = self.DC.GetTextExtent("W")
self.label_space = y
- self.text_font.SetFaceName(self.text_font_name)
- self.DC.SetFont(self.text_font)
+ self.SetPrintFont(self.text_font)
+
x, y = self.DC.GetTextExtent("W")
self.space = y
self.pt_space_after = self.label_pt_space_after
self.LabelColorRow(self.label_colour)
- self.label_font.SetFaceName(self.label_font_name)
- self.DC.SetFont(self.label_font)
- self.DC.SetTextForeground(self.label_font_colour)
+ self.SetPrintFont(self.label_font)
self.col = 0
max_y = 0
return
for val in self.parent.header:
- f = wxFont(val["Size"], wxSWISS, wxNORMAL, val["Attr"])
- self.DC.SetFont(f)
- fontname = val["Name"]
-
- f.SetFaceName(fontname)
- self.DC.SetTextForeground(val["Colour"])
+ self.SetPrintFont(val["Font"])
header_indent = val["Indent"] * self.pwidth
- self.OutTextPageWidth(val["Text"], self.pheader_margin, val["Align"], header_indent, TRUE)
+ text = val["Text"]
+
+ htype = val["Type"]
+ if htype == "Date":
+ addtext = self.GetDate()
+ elif htype == "Date & Time":
+ addtext = self.GetDateTime()
+ else:
+ addtext = ""
+
+ self.OutTextPageWidth(text+addtext, self.pheader_margin, val["Align"], header_indent, TRUE)
def PrintFooter(self): # print the header array
if self.draw == FALSE:
footer_pos = self.parent.page_height * self.pheight - self.pfooter_margin + self.vertical_offset
for val in self.parent.footer:
- f = wxFont(val["Size"], wxSWISS, wxNORMAL, val["Attr"])
- self.DC.SetFont(f)
- fontname = val["Name"]
-
- f.SetFaceName(fontname)
- self.DC.SetTextForeground(val["Colour"])
+ self.SetPrintFont(val["Font"])
footer_indent = val["Indent"] * self.pwidth
+ text = val["Text"]
+
ftype = val["Type"]
if ftype == "Pageof":
- text = "Page " + str(self.page) + " of " + str(self.total_pages)
+ addtext = "Page " + str(self.page) + " of " + str(self.total_pages)
elif ftype == "Page":
- text = "Page " + str(self.page)
+ addtext = "Page " + str(self.page)
elif ftype == "Num":
- text = str(self.page)
+ addtext = str(self.page)
+ elif ftype == "Date":
+ addtext = self.GetDate()
+ elif ftype == "Date & Time":
+ addtext = self.GetDateTime()
else:
- text = ""
+ addtext = ""
+
+ self.OutTextPageWidth(text+addtext, footer_pos, val["Align"], footer_indent, TRUE)
- self.OutTextPageWidth(text, footer_pos, val["Align"], footer_indent, TRUE)
def LabelColorRow(self, colour):
brush = wxBrush(colour, wxSOLID)
col = col + 1
def PrintRow(self, row_val, draw = TRUE, align = wxALIGN_LEFT):
- self.text_font.SetFaceName(self.text_font_name)
- self.DC.SetFont(self.text_font)
+ self.SetPrintFont(self.text_font)
self.pt_space_before = self.text_pt_space_before # set the point spacing
self.pt_space_after = self.text_pt_space_after
self.col = 0
max_y = 0
- self.DC.SetTextForeground(self.text_font_colour)
for vtxt in row_val:
self.region = self.column[self.col+1] - self.column[self.col]
self.indent = self.column[self.col]
self.label_colour = wxNamedColour('LIGHT GREY')
def SetFonts(self):
- self.label_font_size = 12
- self.label_font_attr = wxNORMAL
- self.label_font_name = "Arial"
- self.label_font_colour = wxNamedColour('BLACK')
-
- self.text_font_size = 10
- self.text_font_attr = wxNORMAL
- self.text_font_name = "Arial"
- self.text_font_colour = wxNamedColour('BLACK')
+ self.label_font = { "Name": self.default_font_name, "Size": 12, "Colour": [0, 0, 0], "Attr": [0, 0, 0] }
+ self.text_font = { "Name": self.default_font_name, "Size": 10, "Colour": [0, 0, 0], "Attr": [0, 0, 0] }
def TextSpacing(self):
self.label_pt_adj_before = 0 # point adjustment before and after the label text
def SetHeaderValue(self):
self.header_margin = 0.25
- self.header_font_size = 12
- self.header_font_colour = wxNamedColour('BLACK')
- self.header_font_attr = wxBOLD
- self.header_font_name = self.text_font_name
+ self.header_font = { "Name": self.default_font_name, "Size": 11, "Colour": [0, 0, 0], "Attr": [0, 0, 0] }
self.header_align = wxALIGN_CENTRE
self.header_indent = 0
- self.header_type = None
+ self.header_type = "Text"
def SetFooterValue(self):
self.footer_margin = 0.7
- self.footer_font_size = 10
- self.footer_font_colour = wxNamedColour('BLACK')
- self.footer_font_attr = wxNORMAL
- self.footer_font_name = self.text_font_name
+ self.footer_font = { "Name": self.default_font_name, "Size": 11, "Colour": [0, 0, 0], "Attr": [0, 0, 0] }
self.footer_align = wxALIGN_CENTRE
self.footer_indent = 0
self.footer_type = "Pageof"
self.preview = None
self.page = 0
+ self.default_font_name = "Arial"
+ self.default_font = { "Name": self.default_font_name, "Size": 10, "Colour": [0, 0, 0], "Attr": [0, 0, 0] }
+
def SetColAlignment(self, col, align=wxALIGN_LEFT):
self.set_column_align[col] = align
def SetRowLineColour(self, row, colour):
self.row_line_colour[row] = colour
- def SetHeader(self, text = "", type = None, name=None, size=None, colour = None, align = None, indent = None, attr=None):
+ def GetColour(self, colour): # returns colours based from wxColour value
+ red = colour.Red()
+ blue = colour.Blue()
+ green = colour.Green()
+ return [red, green, blue ]
+
+ def SetHeader(self, text = "", type = "Text", font=None, align = None, indent = None, colour = None, size = None):
set = { "Text": text }
- if name == None:
- set["Name"] = self.header_font_name
+ if font == None:
+ set["Font"] = copy.copy(self.default_font)
else:
- set["Name"] = name
+ set["Font"] = font
- if size == None:
- set["Size"] = self.header_font_size
- else:
- set["Size"] = size
+ if colour != None:
+ setfont = set["Font"]
+ setfont["Colour"] = self.GetColour(colour)
- if colour == None:
- set["Colour"] = self.header_font_colour
- else:
- set["Colour"] = colour
+ if size != None:
+ setfont = set["Font"]
+ setfont["Size"] = size
if align == None:
set["Align"] = self.header_align
else:
set["Indent"] = indent
- if attr == None:
- set["Attr"] = self.header_font_attr
- else:
- set["Attr"] = attr
-
if type == None:
set["Type"] = self.header_type
else:
self.header.append(set)
- def SetFooter(self, text = "", type = None, name=None, size=None, colour = None, align = None, indent = None, attr=None):
+ def SetFooter(self, text = "", type = None, font=None, align = None, indent = None, colour = None, size = None):
set = { "Text": text }
- if name == None:
- set["Name"] = self.footer_font_name
+ if font == None:
+ set["Font"] = copy.copy(self.default_font)
else:
- set["Name"] = name
+ set["Font"] = font
- if size == None:
- set["Size"] = self.footer_font_size
- else:
- set["Size"] = size
+ if colour != None:
+ setfont = set["Font"]
+ setfont["Colour"] = self.GetColour(colour)
- if colour == None:
- set["Colour"] = self.footer_font_colour
- else:
- set["Colour"] = colour
+ if size != None:
+ setfont = set["Font"]
+ setfont["Size"] = size
if align == None:
set["Align"] = self.footer_align
else:
set["Type"] = type
- if attr == None:
- set["Attr"] = self.footer_font_attr
- else:
- set["Attr"] = attr
-
self.footer.append(set)
def Preview(self):
frame.SetSize(self.preview_frame_size)
frame.Show(true)
-
def Print(self):
pdd = wxPrintDialogData()
pdd.SetPrintData(self.printData)
size = DC.GetSizeTuple()
DC.BeginDrawing()
- self.text_font = wxFont(self.text_font_size, wxSWISS, self.text_font_attr, wxNORMAL)
- self.label_font = wxFont(self.label_font_size, wxSWISS, self.label_font_attr, wxNORMAL)
-
table = PrintTableDraw(self, DC, size)
table.data = self.data
table.set_column = self.set_column