From 53fe40bac2443a81d05c4803942731a77de0880d Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 4 Sep 2001 04:17:38 +0000 Subject: [PATCH] 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 --- wxPython/CHANGES.txt | 2 +- wxPython/MANIFEST.in | 2 +- wxPython/demo/GridSimple.py | 31 +- wxPython/demo/Main.py | 4 +- wxPython/demo/TablePrint.py | 207 +++++ wxPython/demo/TestTable.txt | 38 + wxPython/wxPython/lib/CDate.py | 12 +- wxPython/wxPython/lib/buttons.py | 5 +- wxPython/wxPython/lib/calendar.py | 91 ++- wxPython/wxPython/lib/colourselect.py | 27 +- wxPython/wxPython/lib/imagebrowser.py | 91 ++- wxPython/wxPython/lib/printout.py | 1063 +++++++++++++++++++++++++ 12 files changed, 1507 insertions(+), 66 deletions(-) create mode 100644 wxPython/demo/TablePrint.py create mode 100644 wxPython/demo/TestTable.txt create mode 100644 wxPython/wxPython/lib/printout.py diff --git a/wxPython/CHANGES.txt b/wxPython/CHANGES.txt index 956c408a47..62d0a1b478 100644 --- a/wxPython/CHANGES.txt +++ b/wxPython/CHANGES.txt @@ -35,7 +35,7 @@ Updated wxColumnSorterMixin to also be able to place sort icons on the column headers, and updated the wxListCtrl demo to show it off by using wxColumnSorterMixin. -Added wxGenBitmapTextButton contrib from Lorne White. +Added wxGenBitmapTextButton, TablePrint, etc. contribs from Lorne White. diff --git a/wxPython/MANIFEST.in b/wxPython/MANIFEST.in index 9769dcbe3b..0c15db0768 100644 --- a/wxPython/MANIFEST.in +++ b/wxPython/MANIFEST.in @@ -20,7 +20,7 @@ include demo/bmp_source/*.ico include demo/bmp_source/*.gif include demo/bmp_source/*.png include demo/bmp_source/*.jpg -include demo/README.txt +include demo/*.txt include demo/*.xml include demo/data/*.png include demo/data/*.htm diff --git a/wxPython/demo/GridSimple.py b/wxPython/demo/GridSimple.py index c073d48932..3052a26538 100644 --- a/wxPython/demo/GridSimple.py +++ b/wxPython/demo/GridSimple.py @@ -187,8 +187,37 @@ class SimpleGrid(wxGrid): ##, wxGridAutoEditMixin): class TestFrame(wxFrame): def __init__(self, parent, log): wxFrame.__init__(self, parent, -1, "Simple Grid Demo", size=(640,480)) - grid = SimpleGrid(self, log) + self.grid = grid = SimpleGrid(self, log) + self.mainmenu = wxMenuBar() + + menu = wxMenu() + + mID = NewId() + menu.Append(mID, 'Preview Grid', 'Print Displayed Grid') + EVT_MENU(self, mID, self.OnPreviewGrid) + self.mainmenu.Append(menu, '&Print') + + self.SetMenuBar(self.mainmenu) + + def OnPreviewGrid(self, event): + from wxPython.lib.printout import PrintGrid + grid = self.grid + + total_col = 4 # not all columns to be used for printing + total_row = 4 + + format = [1, 1.5, 2.5, 4, 5, 7] # column spacing + + # class to print and preview + prt = PrintGrid(self, grid, format, total_col, total_row ) + prt.SetAttributes() # get the colour and text attributes + + table = prt.GetTable() # the table print control class + table.SetHeader("Simple Grid Test Header") + table.SetFooter() + + prt.Preview() # preview the table #--------------------------------------------------------------------------- diff --git a/wxPython/demo/Main.py b/wxPython/demo/Main.py index 75ec4672da..74318bcd62 100644 --- a/wxPython/demo/Main.py +++ b/wxPython/demo/Main.py @@ -26,10 +26,10 @@ _treeList = [ 'PyCrust', 'VirtualListCtrl', 'wxListCtrl', + 'TablePrint', ]), ('Windows', ['wxFrame', 'wxDialog', 'wxMiniFrame', - '', 'wxGrid', 'wxSashWindow', 'wxScrolledWindow', 'wxSplitterWindow', 'wxStatusBar', 'wxNotebook', @@ -64,7 +64,7 @@ _treeList = [ 'wxCalendar', 'wxMVCTree', 'wxVTKRenderWindow', 'FileBrowseButton', 'GenericButtons', 'wxEditor', 'ColourSelect', 'ImageBrowser', - 'infoframe', 'ColourDB', 'PyCrust', + 'infoframe', 'ColourDB', 'PyCrust', 'TablePrint', ]), ('Cool Contribs', ['pyTree', 'hangman', 'SlashDot', 'XMLtreeview']), diff --git a/wxPython/demo/TablePrint.py b/wxPython/demo/TablePrint.py new file mode 100644 index 0000000000..f1fa250130 --- /dev/null +++ b/wxPython/demo/TablePrint.py @@ -0,0 +1,207 @@ + +from wxPython.wx import * +from wxPython.lib.printout import PrintTable + +import os + +#--------------------------------------------------------------------------- + +buttonDefs = { + 814 : ('PreviewWide', 'Preview print of a wide table'), + 815 : ('PreviewNarrow', 'Preview print of a narrow table with color highlights'), + 818 : ('OnPreviewMatrix', 'Preview print of a narrow column grid without a table header'), + 817 : ('PreviewLine', 'Preview print to demonstrate the use of line breaks'), + 819 : ('PrintWide', 'Direct print (no preview) of a wide table'), + } + + +class TablePanel(wxPanel): + def __init__(self, parent, log, frame): + wxPanel.__init__(self, parent, -1) + self.log = log + self.frame = frame + + box = wxBoxSizer(wxVERTICAL) + box.Add(20, 30) + keys = buttonDefs.keys() + keys.sort() + for k in keys: + text = buttonDefs[k][1] + btn = wxButton(self, k, text) + box.Add(btn, 0, wxALIGN_CENTER|wxALL, 15) + EVT_BUTTON(self, k, self.OnButton) + + self.SetAutoLayout(true) + self.SetSizer(box) + + def OnButton(self, evt): + funct = buttonDefs[evt.GetId()][0] + code = 'self.' + funct + '()' + eval(code) + + def ReadData(self): + test_file = "TestTable.txt" + print "**** ", os.getcwd() + file = open(test_file,'r',1) + i = 0 + + data = [] + while 1: + text = file.readline() + text = string.strip(text) + if not text: + break + + list_val = string.splitfields(text,'\t') + data.append(list_val) + file.close() + + self.header = data[0] + self.data = data[1:] + + def PreviewWide(self): + self.ReadData() + prt = PrintTable(self.frame) + prt.data = self.data + prt.left_margin = 0.5 + prt.set_column = [1.0, 1.0, 1.0, 1.5, 1.0, 3.0] + prt.label = self.header + prt.SetLandscape() + + prt.SetColumnLineSize(2, 3) + prt.SetColumnLineColour(3, wxNamedColour('RED')) + + prt.SetRowLineSize(1, 3) + prt.SetRowLineColour(5, wxNamedColour('RED')) + + prt.SetHeader("wxWindows Applications") + prt.SetFooter() + prt.Preview() + + def PreviewNarrow(self): + self.ReadData() + new_data = [] + for val in self.data: + new_data.append([val[0], val[1], val[2], val[4], val[5]]) + + val = self.header + new_header = [val[0], val[1], val[2], val[4], val[5]] + + prt = PrintTable(self.frame) + prt.data = new_data + prt.set_column = [ 1, 1, 1, 1, 2] + prt.label = new_header + prt.SetColAlignment(1, wxALIGN_CENTRE) + prt.SetColBackgroundColour(0, wxNamedColour('RED')) + prt.SetColTextColour(0, wxNamedColour('WHITE')) + prt.SetCellColour(4, 0, wxNamedColour('LIGHT BLUE')) + prt.SetCellColour(4, 1, wxNamedColour('LIGHT BLUE')) + prt.SetCellColour(17, 1, wxNamedColour('LIGHT BLUE')) + + prt.SetColBackgroundColour(2, wxNamedColour('LIGHT BLUE')) + prt.SetCellText(4, 2, wxNamedColour('RED')) + + prt.SetColTextColour(3, wxNamedColour('RED')) + prt.label_font_colour = wxNamedColour('WHITE') + prt.SetHeader("wxWindows Applications", colour = wxNamedColour('RED')) + + prt.SetHeader("Date", align=wxALIGN_RIGHT, indent = -2, colour = wxNamedColour('BLUE')) + prt.SetFooter("Page No", colour = wxNamedColour('RED'), type ="Num") + prt.Preview() + + def OnPreviewMatrix(self): + total_col = 45 + total_row = 10 + hsize = 0.2 + vsize = 0.2 + + data = [] + startx = 1.0 + columns = [] + for val in range(total_col): + columns.append(hsize) + + prt = PrintTable(self.frame) + + for row in range(total_row): + value = [] + for col in range(total_col): + value.append(str(col)) + data.append(value) + + for col in range(total_col): + prt.SetColAlignment(col, wxALIGN_CENTRE) + + prt.SetLandscape() + prt.text_font_size = 8 + prt.cell_left_margin = 0 + + prt.data = data + prt.set_column = columns + prt.SetHeader("Test of Small Grid Size") + prt.Preview() + + def PreviewLine(self): + prt = PrintTable(self.frame) + prt.label = ["Header 1", "Header 2", "Header 3"] + prt.set_column = [] + prt.data = [["Row 1", "1", "2"], ["Row 2", "3", "4\nNew Line to see if it also can wrap around the cell region properly\nAnother new line"]] + prt.SetFooter() + prt.Preview() + + def PrintWide(self): + self.ReadData() + prt = PrintTable(self.frame) + prt.data = self.data + + prt.left_margin = 0.5 + prt.set_columns = [ 1, 1, 1, 1, 2, 1, 3 ] + prt.label = self.header + prt.SetLandscape() + prt.Print() + + +#--------------------------------------------------------------------------- + +def runTest(frame, nb, log): + win = TablePanel(nb, log, frame) + return win + +#--------------------------------------------------------------------------- + + + + + +import os +import wxPython.lib.printout + + + + +overview = """\ + +

Table Printing

+ +This demo shows various ways of using the new + PrintOut class. To understand the class you need to examine the demo examples +and the library printout.py module classes. +

+The initial class primarily contains a Table preview/printing class. There is alot of flexibility +in manipulating the placement, sizing, colours, alignment of the table text and cell background colors. +There are also a number of options for printing Header and Footer information on the page. +

+There is also a class to extract the parameters from a wxGrid and easily recreate a Table printout. +

+The data is printed from a list object containing the column and row values. The label or table header +can be defined and will be repeated for all pages. +

+The correct "Total Page" does get calculated and used in the print out Footer. +

+There is still problems with the print framework to properly get the total pages in the preview unless +the program knows it before trying to parse through the available pages. This will be fixed +when the framework allows for it. + + +""" % os.path.join(os.path.dirname(wxPython.lib.printout.__file__), "printout.py") + diff --git a/wxPython/demo/TestTable.txt b/wxPython/demo/TestTable.txt new file mode 100644 index 0000000000..beaccdef72 --- /dev/null +++ b/wxPython/demo/TestTable.txt @@ -0,0 +1,38 @@ +Name Type Platform Location Availability Description +WebReuser Development Windows 95, Windows NT, HPUX 9.05 and 10.2, Solaris 2.4 and 2.5 http://www.stablesoft.com Evaluation WebReuser is a re-use tool from Hitachi Europe Limited. WebReuser is a tool that simplifies software reuse. Its ability to track, schematize and search documents makes it the ideal way to understand C++ code. These features also make WebReuser an ideal tool to classify any Web resource. WebReuser can even be used for more general documentation management tasks. +MacAnova Development Windows, Motif, Mac http://www.stat.umn.edu/~gary/macanova/macanova.home.html Free A large statistical application from the School of Statistics, University of Minnesota. It is based on a modified version of wxWindows 1.65. +Hardy Development Win 3.1, WIN32, Motif (Sun only) http://www.aiai.ed.ac.uk/~hardy/ Freeware for personal and academic use A hypertext-based diagramming and knowledge-based system development tool, with NASA's CLIPS built-in. It is a superset of wxCLIPS. +wxCLIPS Development Win 3.1, WIN32, Motif, XView http://web.ukonline.co.uk/julian.smart/wxclips Freeware A GUI development environment for CLIPS applications. +wxPython Development wxWindows 2 for the new version http://alldunn.com/wxPython/ Freeware Python/wxWindows combination by Robin Dunn and Harri Pasanen. Python is an elegant object-oriented, interpreted language that runs on many platforms. +MrEd Development Win 3.1, WIN32, Motif, XView http://www.cs.rice.edu/CS/PLT/packages/mred/ Freeware MrEd is a combined editor and Scheme development environment by Matthew Flatt. +WXLisp Development Win 3.1, WIN32, Motif, XView http://www.cadlab.de/~lipuser/wxlisp/wxlisp.html Freeware A combination of wxWindows and XLisp. +Scriptum Development Motif http://www.isoft.com.ar/eng/products/system/scriptum.html Freeware Graphical editor with visual highlighting, navigation/browsing, undo, class browser for C++ and Java, source code management, file locking, remote editing using ftp, configurable. +WipeOut Development XView/Linux http://www.softwarebuero.de/wipeout-eng.html Giftware WipeOut is an integrated development environment for C++ projects, available for Linux/XView. The authors are working on versions for SunOS/Solaris. Source is available for porting to other platforms. +OPL Development Win 3.1, WIN32, Motif, XView http://www.ozemail.com.au/~adavison/ Freeware Object Prolog is a portable implementation of Prolog by Andrew Davison, with object-oriented extensions, entirely written in C++. In the initial version, a binding to wxWindows is available. In the revamped version, this binding has not been written yet. +Dataplore Graphics and sound Windows, other? http://www.datan.de/dataplore Commercial Data visualisation tool, from Datan +VCG Tool Graphics and sound Win 3.1, WIN32, Motif, XView http://www.cs.uni-sb.de:80/RW/users/sander/html/gsvcg1.html Freeware A graph layout tool similar to GraphPlace, but with extensions. Very nice indeed! +Y.E.S. Graphics and sound Win 3.1, WIN32, XView (Linux) ftp://ftp.musik.uni-essen.de/pub/EsAC/program/ Shareware Monophonic notation program. +JAZZ Graphics and sound XView (Linux) http://rokke.aug.hiagder.no/per/jazz.html Freeware A MIDI sequencer for Linux. +ISP Graphics and sound Win 3.1, WIN32, Motif, XView ftp://www.remstar.com/pub/wxwin/contrib/isp-100/ Freeware Image and sound player educational tool. +ClockWorks Graphics and sound Win 3.1, WIN32, Motif, XView http://web.ukonline.co.uk/Members/julian.smart/freesoft.html#clockworks Freeware A configurable analogue clock, with a collection of 'fine art' faces. By Julian Smart. +M Miscellaneous Windows 95, Windows NT, Linux http://www.phy.hw.ac.uk/~karsten/M/index.html GPL M is a cross-platform e-mail application. It will be available for X11/Unix and Windows platforms, supporting a wide range of e-mail transfer protocols as well as including full MIME support. M's wealth of features and ease of use make it one of the most powerful MUAs available, providing a consistent and intuitive interface across all platforms. +Boolean Miscellaneous Windows 95, Windows NT, Solaris http://www.xs4all.nl/~kholwerd/bool.html Freeware A GDSII CAD file format viewer, and program to perform boolean operations on sets of 2D polygons. By Klaas Holwerda. +TimeMan Miscellaneous wxGTK, Unix http://www.bgif.no/neureka/TimeMan/ Freeware A time manager, written using wxGTK +Forty Thieves Miscellaneous Motif, Windows apps/forty/forty.htm Freeware A fiendish patience game, by Chris Breeze. A nice demo of what's possible with wxWindows. +Lean Integration Platform Miscellaneous Windows NT, various flavours of UNIX http://www.c-lab.de/~lipuser/lip To be decided LIP is a workflow-oriented tool integration system which uses wxLisp (and thus wxWindows) as an implementation basis. Lisp combined with the wxWindows bindings make up the compatible extension language platform of the system. +wxWeb Miscellaneous Win 3.1, WIN32, Motif ftp://www.remstar.com/pub/wxwin/contrib/wxweb Freeware Andrew Davison's Web browser, with SimSock portable socket library and wxHtml canvas. Includes an http server for UNIX and Windows. +SANTIS Miscellaneous Win 3.1, Windows 95, Linux, Solaris OpenLook and Motif, Silicon Graphics http://www.physiology.rwth-aachen.de/bs/santis/ Free for non-commercial use SANTIS is a software tool designed for the analysis of signals and time series data of any kind, in particular for scientific purposes. It was developed at the Laboratory of Biomedical Systems Analysis, Institute of Physiology at the University of Aachen, Germany. +Xbaies Miscellaneous Win 3.1, WIN32, Motif, XView xbaies.htm Freeware A shell for building Bayesian network models, by Robert Cowell. +wxTinyBB Miscellaneous Win 3.1, WIN32, Motif, XView ftp://www.remstar.com/pub/wxwin/contrib/wxtinybb Freeware/commercial A tiny blackboard shell demo showing an embedded (commercial) Prolog engine. Demo written by Arvindra Sehmi. A good example of a nice interface using wxWindows. +Gambit Miscellaneous Win 3.1, WIN32, Motif, XView http://www.hss.caltech.edu/~gambit/Gambit.html Freeware A large wxWindows application with source, and features such as a table control with printing. +Tex2RTF Miscellaneous Win 3.1, WIN32, Motif, XView http://web.ukonline.co.uk/julian.smart/tex2rtf Freeware Converts subset of LaTeX syntax to WinHelp, wordprocessor RTF, HTML, and wxHelp. As used for wxWindows documentation. +wxPoem Miscellaneous Win 3.1, WIN32, Motif, XView none.htm Freeware A poetry display program for wxWindows. Included as a sample in the wxWindows distribution. +Sonar tracking software Miscellaneous See Web site http://www.desertstar.com Demonstration Miscellaneous sonar tracking software from Desert Star Systems, who use wxWindows for all their Windows-based software. +Name Research software Platform Location Availability Description +DisCo Research software N/A http://www.cs.tut.fi/laitos/DisCo/tool.fm.html N/A A tool for specification of reactive systems. +CAFE Research software N/A cafe.htm N/A Cellular Analysis of Fire and Extinction +CODA Research software See Web site http://www.ozemail.com.au/~mbedward/coda/coda.html See Web site CODA assists in the design of networks of nature reserves or protected areas. It has been used for major reserve planning studies, as a teaching resource and for research into conservation planning methods.  +EGRESS Research software N/A http://www.aiai.ed.ac.uk/~jimd/Egress2/projInfo_contents.html N/A An evacuation decision model. +ACT Research software N/A none.htm N/A A general process and tracker and automator being built at NASA. +Rectangular nesting program Research software N/A http://www.elec-eng.leeds.ac.uk/een5mpd/research.html N/A Optimized layout of rectangles on a page. +Finite element post processor Research software N/A http://www.ime.auc.dk/afd3/odessy/manuals/index.htm N/A Finite element postprocessor, produced at Aalborg University in Denmark by John Rasmussen and Erik Lund. diff --git a/wxPython/wxPython/lib/CDate.py b/wxPython/wxPython/lib/CDate.py index b6303df54c..c4f0d9b79c 100644 --- a/wxPython/wxPython/lib/CDate.py +++ b/wxPython/wxPython/lib/CDate.py @@ -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 diff --git a/wxPython/wxPython/lib/buttons.py b/wxPython/wxPython/lib/buttons.py index d81475dbd6..15d1c13288 100644 --- a/wxPython/wxPython/lib/buttons.py +++ b/wxPython/wxPython/lib/buttons.py @@ -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 + #---------------------------------------------------------------------- diff --git a/wxPython/wxPython/lib/calendar.py b/wxPython/wxPython/lib/calendar.py index b523932d01..ba942966a5 100644 --- a/wxPython/wxPython/lib/calendar.py +++ b/wxPython/wxPython/lib/calendar.py @@ -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 diff --git a/wxPython/wxPython/lib/colourselect.py b/wxPython/wxPython/lib/colourselect.py index 93774eb9a6..9f0d7a9506 100644 --- a/wxPython/wxPython/lib/colourselect.py +++ b/wxPython/wxPython/lib/colourselect.py @@ -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() + + + + diff --git a/wxPython/wxPython/lib/imagebrowser.py b/wxPython/wxPython/lib/imagebrowser.py index 4c0d340e3e..0c758a3812 100644 --- a/wxPython/wxPython/lib/imagebrowser.py +++ b/wxPython/wxPython/lib/imagebrowser.py @@ -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 - - self.image_sizex = isize.width - self.image_sizey = isize.height - self.image_posx = ipos.x - self.image_posy = ipos.y +def GetSize(file_nm): # for scaling image values + image = ConvertBMP(file_nm) + bmp = image.ConvertToBitmap() + size = bmp.GetWidth(), bmp.GetHeight() + return size + +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 diff --git a/wxPython/wxPython/lib/printout.py b/wxPython/wxPython/lib/printout.py new file mode 100644 index 0000000000..b158215ff1 --- /dev/null +++ b/wxPython/wxPython/lib/printout.py @@ -0,0 +1,1063 @@ +#---------------------------------------------------------------------------- +# Name: printout.py +# Purpose: preview and printing class -> table/grid printing +# +# Author: Lorne White (email: lorne.white@telusplanet.net) +# +# Created: +# Version 0.7 +# Date: August 18, 2001 +# Licence: wxWindows license +#---------------------------------------------------------------------------- + +import os, sys, string, copy + +from wxPython.wx import * +import copy + +class PrintBase: + def OutTextRegion(self, textout, txtdraw = TRUE): + textlines = string.splitfields(textout, '\n') + y = copy.copy(self.y) + self.pt_space_before + for text in textlines: + remain = 'X' + while remain != "": + vout, remain = self.SetFlow(text, self.region) + if self.draw == TRUE and txtdraw == TRUE: + test_out = self.TestFull(vout) + if self.align == wxALIGN_LEFT: + self.DC.DrawText(test_out, self.indent+self.pcell_left_margin, y) + + elif self.align == wxALIGN_CENTRE: + diff = self.GetCellDiff(test_out, self.region) + self.DC.DrawText(test_out, self.indent+diff/2, y) + + elif self.align == wxALIGN_RIGHT: + diff = self.GetCellDiff(test_out, self.region) + self.DC.DrawText(test_out, self.indent+diff, y) + + else: + self.DC.DrawText(test_out, self.indent+self.pcell_left_margin, y) + text = remain + y = y + self.space + return y - self.space + self.pt_space_after + + def GetCellDiff(self, text, width): # get the remaining cell size for adjustment + w, h = self.DC.GetTextExtent(text) + diff = width - w + if diff < 0: + diff = 0 + return diff + + def TestFull(self, text_test): + w, h = self.DC.GetTextExtent(text_test) + if w > self.region: # trouble fitting into cell + return self.SetChar(text_test, self.region) # fit the text to the cell size + else: + return text_test + + def SetFlow(self, ln_text, width): + width = width - self.pcell_right_margin + text = "" + split = string.split(ln_text) + if len(split) == 1: + return ln_text, "" + + cnt = 0 + for word in split: + bword = " " + word # blank + word + length = len(bword) + + w, h = self.DC.GetTextExtent(text + bword) + if w < width: + text = text + bword + cnt = cnt + 1 + else: + remain = string.joinfields(split[cnt:],' ') + text = string.strip(text) + return text, remain + + remain = string.joinfields(split[cnt:],' ') + vout = string.strip(text) + return vout, remain + + def SetChar(self, ln_text, width): # truncate string to fit into width + width = width - self.pcell_right_margin - self.pcell_left_margin + text = "" + for val in ln_text: + w, h = self.DC.GetTextExtent(text + val) + if w > width: + text = text + ".." + return text # fitted text value + text = text + val + return text + + def OutTextPageWidth(self, textout, y_out, align, indent, txtdraw = TRUE): + textlines = string.splitfields(textout, '\n') + y = copy.copy(y_out) + + pagew = self.parent.page_width * self.pwidth # full page width + w, h = self.DC.GetTextExtent(textout) + y_line = h + + for text in textlines: + remain = 'X' + while remain != "": + vout, remain = self.SetFlow(text, pagew) + if self.draw == TRUE and txtdraw == TRUE: + test_out = vout + if align == wxALIGN_LEFT: + self.DC.DrawText(test_out, indent, y) + + elif align == wxALIGN_CENTRE: + diff = self.GetCellDiff(test_out, pagew) + self.DC.DrawText(test_out, indent+diff/2, y) + + elif align == wxALIGN_RIGHT: + diff = self.GetCellDiff(test_out, pagew) + self.DC.DrawText(test_out, indent+diff, y) + + else: + self.DC.DrawText(test_out, indent, y_out) + text = remain + y = y + y_line + return y - y_line + + def SetPreview(self, preview): + self.preview = preview + + def SetPSize(self, width, height): + self.pwidth = width/self.scale + self.pheight = height/self.scale + + def SetScale(self, scale): + self.scale = scale + + def SetPTSize(self, width, height): + self.ptwidth = width + self.ptheight = height + + def getWidth(self): + return self.sizew + + def getHeight(self): + return self.sizeh + + +class PrintTableDraw(wxScrolledWindow, PrintBase): + def __init__(self, parent, DC, size): + self.parent = parent + self.DC = DC + self.scale = parent.scale + self.width = size[0] + self.height = size[1] + self.SetDefaults() + + def SetDefaults(self): + self.page = 1 + self.total_pages = None + + self.page_width = self.parent.page_width + self.page_height = self.parent.page_height + + self.left_margin = self.parent.left_margin + self.right_margin = self.parent.right_margin + + self.top_margin = self.parent.top_margin + self.bottom_margin = self.parent.bottom_margin + self.cell_left_margin = self.parent.cell_left_margin + self.cell_right_margin = self.parent.cell_right_margin + + self.label_colour = self.parent.label_colour + + self.row_line_colour = self.parent.row_line_colour + self.row_line_size = self.parent.row_line_size + + self.row_def_line_colour = self.parent.row_def_line_colour + self.row_def_line_size = self.parent.row_def_line_size + + self.column_line_colour = self.parent.column_line_colour + self.column_line_size = self.parent.column_line_size + + self.column_def_line_size = self.parent.column_def_line_size + 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 + self.horizontal_offset = self.pheight * self.parent.horizontal_offset + + self.pcell_left_margin = self.pwidth * self.cell_left_margin + self.pcell_right_margin = self.pwidth * self.cell_right_margin + self.ptop_margin = self.pheight * self.top_margin + self.pbottom_margin = self.pheight * self.bottom_margin + + self.pheader_margin = self.pheight * self.parent.header_margin + self.pfooter_margin = self.pheight * self.parent.footer_margin + + self.cell_colour = self.parent.set_cell_colour + self.cell_text = self.parent.set_cell_text + + self.column = [] + self.column_align = [] + self.column_bgcolour = [] + self.column_txtcolour = [] + + set_column_align = self.parent.set_column_align + set_column_bgcolour = self.parent.set_column_bgcolour + set_column_txtcolour = self.parent.set_column_txtcolour + + pos_x = self.left_margin * self.pwidth + self.horizontal_offset # left margin + self.column.append(pos_x) + + if self.set_column == []: + table_width = self.page_width - self.left_margin - self.right_margin + width = table_width/(len(self.label)) + for val in self.label: + column_width = width * self.pwidth + pos_x = pos_x + column_width + self.column.append(pos_x) # position of each column + else: + for val in self.set_column: + column_width = val * self.pwidth + pos_x = pos_x + column_width + self.column.append(pos_x) # position of each column + + if pos_x > self.page_width * self.pwidth: # check if it fits in page + print "Warning, Too Wide for Page" + return + + if self.label != []: + if len(self.column) -1 != len(self.label): + print "Column Settings Incorrect", "\nColumn Value: " + str(self.column), "\nLabel Value: " + str(self.label) + return + + first_value = self.data[0] + column_total = len(first_value) + if column_total != len(self.column) -1: + print "Column Settings Incorrect", first_value, self.column + return + + col = 0 + for col in range(column_total): + try: + align = set_column_align[col] # check if custom column alignment + except: + align = wxALIGN_LEFT + self.column_align.append(align) + + try: + colour = set_column_bgcolour[col] # check if custom column background colour + except: + colour = self.parent.column_colour + self.column_bgcolour.append(colour) + + try: + colour = set_column_txtcolour[col] # check if custom column text colour + except: + colour = self.parent.text_font_colour + 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) + 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.label_pt_space_after = self.parent.label_pt_adj_after * y/10 + + self.text_pt_space_before = self.parent.text_pt_adj_before * y/10 # extra spacing for row text per point value + self.text_pt_space_after = self.parent.text_pt_adj_after * y/10 + + def SetPage(self, page): + self.page = page + + def SetColumns(self, col): + self.column = col + + def OutCanvas(self): + self.AdjustValues() + self.SetPointAdjust() + + 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) + x, y = self.DC.GetTextExtent("W") + self.label_space = y + + self.text_font.SetFaceName(self.text_font_name) + self.DC.SetFont(self.text_font) + x, y = self.DC.GetTextExtent("W") + self.space = y + + if self.total_pages == None: + self.GetTotalPages() # total pages for display/printing + + self.data_cnt = 0 + + cnt = 1 # get selected page + if cnt == self.page: + self.draw = TRUE + else: + self.draw = FALSE + + while cnt < self.page: + self.OutPage() + cnt = cnt + 1 + + self.draw = TRUE + self.PrintHeader() + self.PrintFooter() + self.OutPage() + + + def GetTotalPages(self): + self.data_cnt = 0 + self.draw = FALSE + + cnt = 0 + while 1: + test = self.OutPage() + if test == FALSE: + break + cnt = cnt + 1 + + self.total_pages = cnt + 1 + + def OutPage(self): + self.y = self.y_start + self.end_x = self.column[-1] + + if self.data_cnt < len(self.data)-1: # if there data for display on the page + if self.label != []: # check if header defined + self.PrintLabel() + else: + return FALSE + + for val in self.data: + try: + row_val = self.data[self.data_cnt] + except: + self.FinishDraw() + return FALSE + + max_y = self.PrintRow(row_val, FALSE) # test to see if row will fit in remaining space + test = max_y + self.space + + if test > self.y_end: + break + + self.ColourRowCells(max_y-self.y+self.space) # colour the row/column + max_y = self.PrintRow(row_val, TRUE) # row fits - print text + self.DrawGridLine() # top line of cell + self.y = max_y + self.space + + if self.y > self.y_end: + break + + self.data_cnt = self.data_cnt + 1 + + self.FinishDraw() + + if self.data_cnt == len(self.data): # last value in list + return FALSE + + return TRUE + + + def PrintLabel(self): + self.pt_space_before = self.label_pt_space_before # set the point spacing + 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.col = 0 + max_y = 0 + for vtxt in self.label: + self.region = self.column[self.col+1] - self.column[self.col] + self.indent = self.column[self.col] + + self.align = wxALIGN_LEFT + + max_out = self.OutTextRegion(vtxt, TRUE) + if max_out > max_y: + max_y = max_out + self.col = self.col + 1 + + self.DrawGridLine() # top line of label + self.y = max_y + self.label_space + + def PrintHeader(self): # print the header array + if self.draw == FALSE: + 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"]) + + header_indent = val["Indent"] * self.pwidth + self.OutTextPageWidth(val["Text"], self.pheader_margin, val["Align"], header_indent, TRUE) + + def PrintFooter(self): # print the header array + if self.draw == FALSE: + return + + 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"]) + + footer_indent = val["Indent"] * self.pwidth + ftype = val["Type"] + if ftype == "Pageof": + text = "Page " + str(self.page) + " of " + str(self.total_pages) + elif ftype == "Page": + text = "Page " + str(self.page) + elif ftype == "Num": + text = str(self.page) + else: + text = "" + + self.OutTextPageWidth(text, footer_pos, val["Align"], footer_indent, TRUE) + + def LabelColorRow(self, colour): + brush = wxBrush(colour, wxSOLID) + self.DC.SetBrush(brush) + height = self.label_space + self.label_pt_space_before + self.label_pt_space_after + self.DC.DrawRectangle(self.column[0], self.y, self.end_x-self.column[0]+1, height) + + def ColourRowCells(self, height): + if self.draw == FALSE: + return + + col = 0 + for colour in self.column_bgcolour: + cellcolour = self.GetCellColour(self.data_cnt, col) + if cellcolour != None: + colour = cellcolour + + brush = wxBrush(colour, wxSOLID) + self.DC.SetBrush(brush) + self.DC.SetPen(wxPen(wxNamedColour('WHITE'), 0)) + + start_x = self.column[col] + width = self.column[col+1] - start_x + 2 + self.DC.DrawRectangle(start_x, self.y, width, height) + 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.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.align = self.column_align[self.col] + + fcolour = self.column_txtcolour[self.col] # set font colour + celltext = self.GetCellText(self.data_cnt, self.col) + if celltext != None: + fcolour = celltext # override the column colour + + self.DC.SetTextForeground(fcolour) + + max_out = self.OutTextRegion(vtxt, draw) + if max_out > max_y: + max_y = max_out + self.col = self.col + 1 + return max_y + + def GetCellColour(self, row, col): # check if custom colour defined for the cell background + try: + set = self.cell_colour[row] + except: + return None + try: + colour = set[col] + return colour + except: + return None + + def GetCellText(self, row, col): # check if custom colour defined for the cell text + try: + set = self.cell_text[row] + except: + return None + try: + colour = set[col] + return colour + except: + return None + + def FinishDraw(self): + self.DrawGridLine() # draw last row line + self.DrawColumns() # draw all vertical lines + + def DrawGridLine(self): + if self.draw == TRUE: + try: + size = self.row_line_size[self.data_cnt] + except: + size = self.row_def_line_size + + try: + colour = self.row_line_colour[self.data_cnt] + except: + colour = self.row_def_line_colour + + self.DC.SetPen(wxPen(colour, size)) + + y_out = self.y +# y_out = self.y + self.pt_space_before + self.pt_space_after # adjust for extra spacing + self.DC.DrawLine(self.column[0], y_out, self.end_x, y_out) + + def DrawColumns(self): + if self.draw == TRUE: + col = 0 + for val in self.column: + try: + size = self.column_line_size[col] + except: + size = self.column_def_line_size + + try: + colour = self.column_line_colour[col] + except: + colour = self.column_def_line_colour + + indent = val + + self.DC.SetPen(wxPen(colour, size)) + self.DC.DrawLine(indent, self.y_start, indent, self.y) + col = col + 1 + + def DrawText(self): + self.DoRefresh() + + def DoDrawing(self, DC): + size = DC.GetSizeTuple() + self.DC = DC + + DC.BeginDrawing() + self.DrawText() + DC.EndDrawing() + + self.sizew = DC.MaxY() + self.sizeh = DC.MaxX() + + +class PrintTable: + def __init__(self, parentFrame=None): + self.data = [] + self.set_column = [] + self.label = [] + self.header = [] + self.footer = [] + + self.set_column_align = {} + self.set_column_bgcolour = {} + self.set_column_txtcolour = {} + self.set_cell_colour = {} + self.set_cell_text = {} + self.column_line_size = {} + self.column_line_colour = {} + self.row_line_size = {} + self.row_line_colour = {} + + self.parentFrame = parentFrame + + self.printData = wxPrintData() + self.scale = 1.0 + + self.SetParms() + self.SetColors() + self.SetFonts() + self.TextSpacing() + + self.SetPrinterOffset() + self.SetHeaderValue() + self.SetFooterValue() + self.SetMargins() + self.SetPortrait() + + def SetPaperId(self, paper): + self.printData.SetPaperId(paper) + + def SetOrientation(self, orient): + self.printData.SetOrientation(orient) + + def SetColors(self): + self.row_def_line_colour = wxNamedColour('BLACK') + self.row_def_line_size = 1 + + self.column_def_line_colour = wxNamedColour('BLACK') + self.column_def_line_size = 1 + self.column_colour = wxNamedColour('WHITE') + + 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') + + def TextSpacing(self): + self.label_pt_adj_before = 0 # point adjustment before and after the label text + self.label_pt_adj_after = 0 + + self.text_pt_adj_before = 0 # point adjustment before and after the row text + self.text_pt_adj_after = 0 + + def SetLabelSpacing(self, before, after): # method to set the label space adjustment + self.label_pt_adj_before = before + self.label_pt_adj_after = after + + def SetRowSpacing(self, before, after): # method to set the row space adjustment + self.text_pt_adj_before = before + self.text_pt_adj_after = after + + def SetPrinterOffset(self): # offset to adjust for printer + self.vertical_offset = -0.1 + self.horizontal_offset = -0.1 + + 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_align = wxALIGN_CENTRE + self.header_indent = 0 + self.header_type = None + + 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_align = wxALIGN_CENTRE + self.footer_indent = 0 + self.footer_type = "Pageof" + + def SetMargins(self): + self.left_margin = 1.0 + self.right_margin = 1.0 # only used if no column sizes + + self.top_margin = 0.8 + self.bottom_margin = 1.0 + self.cell_left_margin = 0.1 + self.cell_right_margin = 0.1 + + def SetPortrait(self): + self.printData.SetPaperId(wxPAPER_LETTER) + self.printData.SetOrientation(wxPORTRAIT) + self.page_width = 8.5 + self.page_height = 11.0 + + def SetLandscape(self): + self.printData.SetOrientation(wxLANDSCAPE) + self.page_width = 11.0 + self.page_height = 8.5 + + def SetParms(self): + self.ymax = 1 + self.xmax = 1 + self.page = 1 + self.total_pg = 100 + + self.preview = None + self.page = 0 + + def SetColAlignment(self, col, align=wxALIGN_LEFT): + self.set_column_align[col] = align + + def SetColBackgroundColour(self, col, colour): + self.set_column_bgcolour[col] = colour + + def SetColTextColour(self, col, colour): + self.set_column_txtcolour[col] = colour + + def SetCellColour(self, row, col, colour): # cell background colour + try: + set = self.set_cell_colour[row] # test if row already exists + try: + set[col] = colour # test if column already exists + except: + set = { col: colour } # create the column value + except: + set = { col: colour } # create the column value + + self.set_cell_colour[row] = set # create dictionary item for colour settings + + def SetCellText(self, row, col, colour): # font colour for custom cells + try: + set = self.set_cell_text[row] # test if row already exists + try: + set[col] = colour # test if column already exists + except: + set = { col: colour } # create the column value + except: + set = { col: colour } # create the column value + + self.set_cell_text[row] = set # create dictionary item for colour settings + + def SetColumnLineSize(self, col, size): # column line size + self.column_line_size[col] = size # create dictionary item for column line settings + + def SetColumnLineColour(self, col, colour): + self.column_line_colour[col] = colour + + def SetRowLineSize(self, row, size): + self.row_line_size[row] = size + + 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): + set = { "Text": text } + + if name == None: + set["Name"] = self.header_font_name + else: + set["Name"] = name + + if size == None: + set["Size"] = self.header_font_size + else: + set["Size"] = size + + if colour == None: + set["Colour"] = self.header_font_colour + else: + set["Colour"] = colour + + if align == None: + set["Align"] = self.header_align + else: + set["Align"] = align + + if indent == None: + set["Indent"] = self.header_indent + 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: + set["Type"] = type + + self.header.append(set) + + def SetFooter(self, text = "", type = None, name=None, size=None, colour = None, align = None, indent = None, attr=None): + set = { "Text": text } + + if name == None: + set["Name"] = self.footer_font_name + else: + set["Name"] = name + + if size == None: + set["Size"] = self.footer_font_size + else: + set["Size"] = size + + if colour == None: + set["Colour"] = self.footer_font_colour + else: + set["Colour"] = colour + + if align == None: + set["Align"] = self.footer_align + else: + set["Align"] = align + + if indent == None: + set["Indent"] = self.footer_indent + else: + set["Indent"] = indent + + if type == None: + set["Type"] = self.footer_type + else: + set["Type"] = type + + if attr == None: + set["Attr"] = self.footer_font_attr + else: + set["Attr"] = attr + + self.footer.append(set) + + def Preview(self): + printout = SetPrintout(self) + printout2 = SetPrintout(self) + self.preview = wxPrintPreview(printout, printout2, self.printData) + if not self.preview.Ok(): + wxMessageBox("There was a problem printing!", "Printing", wxOK) + return + + self.preview.SetZoom(60) # initial zoom value + + frame = wxPreviewFrame(self.preview, self.parentFrame, "Print preview") + + frame.Initialize() + if self.parentFrame: + frame.SetPosition(self.parentFrame.GetPosition()) + frame.SetSize(self.parentFrame.GetSize()) + frame.Show(true) + + + def Print(self): + pdd = wxPrintDialogData() + pdd.SetPrintData(self.printData) + printer = wxPrinter(pdd) + printout = SetPrintout(self) + if not printer.Print(self.parentFrame, printout): + wxMessageBox("There was a problem printing.\nPerhaps your current printer is not set correctly?", "Printing", wxOK) + else: + self.printData = printer.GetPrintDialogData().GetPrintData() + printout.Destroy() + + def DoDrawing(self, DC): + 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 + table.label = self.label + table.SetPage(self.page) + + if self.preview is None: + table.SetPSize(size[0]/self.page_width, size[1]/self.page_height) + table.SetPTSize(size[0], size[1]) + table.SetPreview(FALSE) + else: + if self.preview == 1: + table.scale = self.scale + table.SetPSize(size[0]/self.page_width, size[1]/self.page_height) + else: + table.SetPSize(self.pwidth, self.pheight) + + table.SetPTSize(self.ptwidth, self.ptheight) + table.SetPreview(self.preview) + + table.OutCanvas() + self.page_total = table.total_pages # total display pages + + DC.EndDrawing() + + self.ymax = DC.MaxY() + self.xmax = DC.MaxX() + + self.sizeh = size[0] + self.sizew = size[1] + + def GetTotalPages(self): + self.page_total = 100 + return self.page_total + + def HasPage(self, page): + if page <= self.page_total: + return true + else: + return false + + def SetPage(self, page): + self.page = page + + def SetPageSize(self, width, height): + self.pwidth, self.pheight = width, height + + def SetTotalSize(self, width, height): + self.ptwidth, self.ptheight = width, height + + def SetPreview(self, preview, scale): + self.preview = preview + self.scale = scale + + def SetTotalSize(self, width, height): + self.ptwidth = width + self.ptheight = height + +class PrintGrid: + def __init__(self, parent, grid, format = [], total_col = None, total_row = None): + if total_row == None: + total_row = grid.GetNumberRows() + if total_col == None: + total_col = grid.GetNumberCols() + + self.total_row = total_row + self.total_col = total_col + self.grid = grid + + data = [] + for row in range(total_row): + row_val = [] + value = grid.GetRowLabelValue(row) + row_val.append(value) + + for col in range(total_col): + value = grid.GetCellValue(row, col) + row_val.append(value) + data.append(row_val) + + label = [""] + for col in range(total_col): + value = grid.GetColLabelValue(col) + label.append(value) + + self.table = PrintTable(parent) + self.table.cell_left_margin = 0.0 + self.table.cell_right_margin = 0.0 + + self.table.label = label + self.table.set_column = format + self.table.data = data + + def GetTable(self): + return self.table + + def SetAttributes(self): + for row in range(self.total_row): + for col in range(self.total_col): + colour = self.grid.GetCellTextColour(row, col-1) + self.table.SetCellText(row, col, colour) + + colour = self.grid.GetCellBackgroundColour(row, col-1) + self.table.SetCellColour(row, col, colour) + + def Preview(self): + self.table.Preview() + + def Print(self): + self.table.Print() + + +class SetPrintout(wxPrintout): + def __init__(self, canvas): + wxPrintout.__init__(self) + self.canvas = canvas + self.end_pg = 1000 + + def OnBeginDocument(self, start, end): + return self.base_OnBeginDocument(start, end) + + def OnEndDocument(self): + self.base_OnEndDocument() + + def HasPage(self, page): + try: + end = self.canvas.HasPage(page) + return end + except: + return true + + def GetPageInfo(self): + try: + self.end_pg = self.canvas.GetTotalPages() + except: + pass + + end_pg = self.end_pg + str_pg = 1 + return (str_pg, end_pg, str_pg, end_pg) + + def OnPreparePrinting(self): + self.base_OnPreparePrinting() + + def OnBeginPrinting(self): + dc = self.GetDC() + + self.preview = self.IsPreview() + if (self.preview): + self.pixelsPerInch = self.GetPPIScreen() + else: + self.pixelsPerInch = self.GetPPIPrinter() + + (w, h) = dc.GetSizeTuple() + scaleX = float(w) / 1000 + scaleY = float(h) / 1000 + self.printUserScale = min(scaleX, scaleY) + + self.base_OnBeginPrinting() + + def GetSize(self): + self.psizew, self.psizeh = self.GetPPIPrinter() + return self.psizew, self.psizeh + + def GetTotalSize(self): + self.ptsizew, self.ptsizeh = self.GetPageSizePixels() + return self.ptsizew, self.ptsizeh + + def OnPrintPage(self, page): + dc = self.GetDC() + (w, h) = dc.GetSizeTuple() + scaleX = float(w) / 1000 + scaleY = float(h) / 1000 + self.printUserScale = min(scaleX, scaleY) + dc.SetUserScale(self.printUserScale, self.printUserScale) + + self.preview = self.IsPreview() + + self.canvas.SetPreview(self.preview, self.printUserScale) + self.canvas.SetPage(page) + + self.ptsizew, self.ptsizeh = self.GetPageSizePixels() + self.canvas.SetTotalSize(self.ptsizew, self.ptsizeh) + + self.psizew, self.psizeh = self.GetPPIPrinter() + self.canvas.SetPageSize(self.psizew, self.psizeh) + + self.canvas.DoDrawing(dc) + return true + + + + + + -- 2.45.2