nobody at rubyforge.org
2006-Oct-17 18:03 UTC
[Wxruby-development] [680] trunk/wxruby2/samples/printing/printing.rb: Cleaned up to use the Ruby naming convention, added #! line, now uses Wx default ID''s in standard menu items.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type"
content="text/html; charset=utf-8" /><style
type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:'':'';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family:
verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;
font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding:
6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid;
padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family:
verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch
.binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[680] trunk/wxruby2/samples/printing/printing.rb: Cleaned up to use
the Ruby naming convention, added #! line, now uses Wx default ID''s in
standard menu items.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>680</dd>
<dt>Author</dt> <dd>seanlong</dd>
<dt>Date</dt> <dd>2006-10-17 14:03:26 -0400 (Tue, 17 Oct
2006)</dd>
</dl>
<h3>Log Message</h3>
<pre>Cleaned up to use the Ruby naming convention, added #! line, now uses
Wx default ID''s in standard menu items.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a
href="#trunkwxruby2samplesprintingprintingrb">trunk/wxruby2/samples/printing/printing.rb</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwxruby2samplesprintingprintingrb"></a>
<div class="modfile"><h4>Modified:
trunk/wxruby2/samples/printing/printing.rb (679 => 680)</h4>
<pre class="diff"><span>
<span class="info">---
trunk/wxruby2/samples/printing/printing.rb        2006-10-17
17:15:41 UTC (rev 679)
+++
trunk/wxruby2/samples/printing/printing.rb        2006-10-17
18:03:26 UTC (rev 680)
</span><span class="lines">@@ -1,15 +1,19 @@
</span><ins>+#!/usr/bin/env ruby
+# wxRuby2 Sample Code. Copyright (c) 2004-2006 Kevin B. Smith
+# Freely reusable code: see SAMPLES-LICENSE.TXT for details
+
</ins><span class="cx"> require ''wx''
</span><span class="cx">
</span><del>-WXPRINT_QUIT = 100
-WXPRINT_PRINT = 101
-WXPRINT_PAGE_SETUP = 103
-WXPRINT_PREVIEW = 104
</del><ins>+WXPRINT_QUIT = Wx::ID_EXIT
+WXPRINT_PRINT = Wx::ID_PRINT
+WXPRINT_PAGE_SETUP = Wx::ID_PRINT_SETUP
+WXPRINT_PREVIEW = Wx::ID_PREVIEW
</ins><span class="cx">
</span><span class="cx"> WXPRINT_PRINT_PS = 105
</span><span class="cx"> WXPRINT_PAGE_SETUP_PS = 107
</span><span class="cx"> WXPRINT_PREVIEW_PS = 108
</span><span class="cx">
</span><del>-WXPRINT_ABOUT = 109
</del><ins>+WXPRINT_ABOUT = Wx::ID_ABOUT
</ins><span class="cx">
</span><span class="cx"> WXPRINT_ANGLEUP = 110
</span><span class="cx"> WXPRINT_ANGLEDOWN = 111
</span><span class="lines">@@ -54,10 +58,8 @@
</span><span class="cx">
</span><span class="cx"> dc.draw_text( "Test
message: this is in 10 point text", 10, 180)
</span><span class="cx">
</span><del>-#if wxUSE_UNICODE
</del><span class="cx"> test = "Hebrew שלום --
Japanese (日本語)"
</span><span class="cx"> dc.draw_text( test, 10, 200 )
</span><del>-#endif
</del><span class="cx">
</span><span class="cx"> points = []
</span><span class="cx"> points <<
Wx::Point.new(0,0)
</span><span class="lines">@@ -126,9 +128,9 @@
</span><span class="cx"> end
</span><span class="cx">
</span><span class="cx"> def on_print(event)
</span><del>- printDialogData =
Wx::PrintDialogData.new(Wx::get_app.print_data)
</del><ins>+ print_dialog_data =
Wx::PrintDialogData.new(Wx::get_app.print_data)
</ins><span class="cx">
</span><del>- printer = Wx::Printer.new(printDialogData)
</del><ins>+ printer = Wx::Printer.new(print_dialog_data)
</ins><span class="cx"> printout =
MyPrintout.new("My printout")
</span><span class="cx"> if (!printer.print(self,
printout, true))
</span><span class="cx"> if
(Wx::Printer.get_last_error == Wx::PRINTER_ERROR)
</span><span class="lines">@@ -143,8 +145,8 @@
</span><span class="cx">
</span><span class="cx"> def on_print_preview(event)
</span><span class="cx"> # Pass two printout objects:
for preview, and possible printing.
</span><del>- printDialogData =
Wx::PrintDialogData.new(Wx::get_app.print_data)
- preview = Wx::PrintPreview.new(MyPrintout.new, MyPrintout.new,
printDialogData)
</del><ins>+ print_dialog_data =
Wx::PrintDialogData.new(Wx::get_app.print_data)
+ preview = Wx::PrintPreview.new(MyPrintout.new, MyPrintout.new,
print_dialog_data)
</ins><span class="cx"> if (!preview.ok)
</span><span class="cx"> #delete preview;
</span><span class="cx">
Wx::message_box("There was a problem previewing.\nPerhaps your current
printer is not set correctly?", "Previewing", Wx::OK)
</span><span class="lines">@@ -159,14 +161,11 @@
</span><span class="cx">
</span><span class="cx"> def on_page_setup(event)
</span><span class="cx"> Wx::get_app.page_setup_data =
Wx::PageSetupDialogData.new(Wx::get_app.print_data)
</span><del>- pageSetupDialog = Wx::PageSetupDialog.new(self,
Wx::get_app.page_setup_data)
-# pageSetupDialog = Wx::PageSetupDialog.new(self)
- pageSetupDialog.show_modal
</del><ins>+ page_setup_dialog = Wx::PageSetupDialog.new(self,
Wx::get_app.page_setup_data)
+ page_setup_dialog.show_modal
</ins><span class="cx">
</span><del>-
- Wx::get_app.print_data = pageSetupDialog.get_page_setup_data.get_print_data
</del><ins>+ Wx::get_app.print_data =
page_setup_dialog.get_page_setup_data.get_print_data
</ins><span class="cx"> Wx::get_app.page_setup_data =
Wx::PageSetupDialogData.new(Wx::get_app.print_data)
</span><del>-# Wx::get_app.page_setup_data =
pageSetupDialog.get_page_setup_data
</del><span class="cx"> end
</span><span class="cx">
</span><span class="cx"> def on_exit(event)
</span><span class="lines">@@ -223,8 +222,8 @@
</span><span class="cx"> end
</span><span class="cx"> end
</span><span class="cx">
</span><del>- def on_begin_document(startPage,endPage)
- go_ahead = super(startPage, endPage)
</del><ins>+ def on_begin_document(start_page,end_page)
+ go_ahead = super(start_page, end_page)
</ins><span class="cx"> if (!go_ahead)
</span><span class="cx"> return false
</span><span class="cx"> end
</span><span class="lines">@@ -236,11 +235,11 @@
</span><span class="cx"> end
</span><span class="cx">
</span><span class="cx"> def get_page_info
</span><del>- minPage = 1
- maxPage = 2
- selPageFrom = 1
- selPageTo = 2
- [minPage,maxPage,selPageFrom,selPageTo]
</del><ins>+ min_page = 1
+ max_page = 2
+ sel_page_from = 1
+ sel_page_to = 2
+ [min_page,max_page,sel_page_from,sel_page_to]
</ins><span class="cx"> end
</span><span class="cx">
</span><span class="cx"> def draw_page_one(dc)
</span><span class="lines">@@ -249,39 +248,39 @@
</span><span class="cx">
</span><span class="cx"> # We know the graphic is
200x200. If we didn''t know this,
</span><span class="cx"> # we''d need to
calculate it.
</span><del>- maxX = 200
- maxY = 200
</del><ins>+ max_x = 200
+ max_y = 200
</ins><span class="cx">
</span><span class="cx"> # Let''s have at
least 50 device units margin
</span><del>- marginX = 50
- marginY = 50
</del><ins>+ margin_x = 50
+ margin_y = 50
</ins><span class="cx">
</span><span class="cx"> # Add the margin to the
graphic size
</span><del>- maxX += (2*marginX)
- maxY += (2*marginY)
</del><ins>+ max_x += (2*margin_x)
+ max_y += (2*margin_y)
</ins><span class="cx">
</span><span class="cx"> # Get the size of the DC in
pixels
</span><span class="cx"> w, h = dc.get_size
</span><span class="cx">
</span><span class="cx"> # Calculate a suitable
scaling factor
</span><del>- scaleX=(w/maxX)
- scaleY=(h/maxY)
</del><ins>+ scale_x=(w/max_x)
+ scale_y=(h/max_y)
</ins><span class="cx">
</span><span class="cx"> # Use x or y scaling factor,
whichever fits on the DC
</span><span class="cx"> #actualScale =
Wx::min(scaleX,scaleY)
</span><del>- if scaleX < scaleY
- actualScale = scaleX
</del><ins>+ if scale_x < scale_y
+ actual_scale = scale_x
</ins><span class="cx"> else
</span><del>- actualScale = scaleY
</del><ins>+ actual_scale = scale_y
</ins><span class="cx"> end
</span><span class="cx">
</span><span class="cx"> # Calculate the position on
the DC for centring the graphic
</span><del>- posX = ((w - (200*actualScale))/2.0)
- posY = ((h - (200*actualScale))/2.0)
</del><ins>+ pos_x = ((w - (200*actual_scale))/2.0)
+ pos_y = ((h - (200*actual_scale))/2.0)
</ins><span class="cx">
</span><span class="cx"> # Set the scale and origin
</span><del>- dc.set_user_scale(actualScale, actualScale)
- dc.set_device_origin( posX.to_i, posY.to_i )
</del><ins>+ dc.set_user_scale(actual_scale, actual_scale)
+ dc.set_device_origin( pos_x.to_i, pos_y.to_i )
</ins><span class="cx">
</span><span class="cx"> Wx::get_app.frame.draw(dc)
</span><span class="cx"> end
</span><span class="lines">@@ -292,26 +291,26 @@
</span><span class="cx"> # 5cm on the page.
</span><span class="cx">
</span><span class="cx"> # Get the logical pixels per
inch of screen and printer
</span><del>- ppiScreenX, ppiScreenY = get_ppi_screen
- ppiPrinterX, ppiPrinterY = get_ppi_printer
</del><ins>+ ppi_screen_x, ppi_screen_y = get_ppi_screen
+ ppi_printer_x, ppi_printer_y = get_ppi_printer
</ins><span class="cx">
</span><span class="cx"> # This scales the DC so that
the printout roughly represents the
</span><span class="cx"> # the screen scaling. The
text point size _should_ be the right size
</span><span class="cx"> # but in fact is too small
for some reason. This is a detail that will
</span><span class="cx"> # need to be addressed at
some point but can be fudged for the
</span><span class="cx"> # moment.
</span><del>- scale = (ppiPrinterX/ppiScreenX)
</del><ins>+ scale = (ppi_printer_x/ppi_screen_x)
</ins><span class="cx">
</span><span class="cx"> # Now we have to check in
case our real page size is reduced
</span><span class="cx"> # (e.g. because
we''re drawing to a print preview memory DC)
</span><del>- pageWidth, pageHeight = get_page_size_pixels
</del><ins>+ page_width, page_height = get_page_size_pixels
</ins><span class="cx"> w, h = dc.get_size
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> # If printer pageWidth ==
current DC width, then this doesn''t
</span><span class="cx"> # change. But w might be the
preview bitmap width, so scale down.
</span><del>- overallScale = scale * (w/pageWidth)
- dc.set_user_scale(overallScale, overallScale)
</del><ins>+ overall_scale = scale * (w/page_width)
+ dc.set_user_scale(overall_scale, overall_scale)
</ins><span class="cx">
</span><span class="cx"> # Calculate conversion factor
for converting millimetres into
</span><span class="cx"> # logical units.
</span><span class="lines">@@ -322,11 +321,11 @@
</span><span class="cx"> # unscale to pass logical
units to DrawLine.
</span><span class="cx">
</span><span class="cx"> # Draw 50 mm by 50 mm L shape
</span><del>- logUnitsFactor = (ppiPrinterX/(scale*25.4))
- logUnits = (50*logUnitsFactor)
</del><ins>+ log_units_factor = (ppi_printer_x/(scale*25.4))
+ log_units = (50*log_units_factor)
</ins><span class="cx"> dc.set_pen(Wx::BLACK_PEN)
</span><del>- dc.draw_line(50, 250, (50.0 + logUnits).to_i, 250)
- dc.draw_line(50, 250, 50, (250.0 + logUnits).to_i)
</del><ins>+ dc.draw_line(50, 250, (50.0 + log_units).to_i, 250)
+ dc.draw_line(50, 250, 50, (250.0 + log_units).to_i)
</ins><span class="cx">
</span><span class="cx">
dc.set_background_mode(Wx::TRANSPARENT)
</span><span class="cx">
dc.set_brush(Wx::TRANSPARENT_BRUSH)
</span><span class="lines">@@ -352,48 +351,46 @@
</span><span class="cx">
</span><span class="cx"> dc.draw_text("Some test
text", 200, 300 )
</span><span class="cx">
</span><del>- # TESTING
</del><ins>+ left_margin = 20
+ right_margin = 20
+ top_margin = 20
+ bottom_margin = 20
</ins><span class="cx">
</span><del>- leftMargin = 20
- rightMargin = 20
- topMargin = 20
- bottomMargin = 20
</del><ins>+ page_width_mm, page_height_mm = get_page_size_mm
</ins><span class="cx">
</span><del>- pageWidthMM, pageHeightMM = get_page_size_mm
</del><ins>+ left_margin_logical =
(log_units_factor*left_margin).to_i
+ top_margin_logical = (log_units_factor*top_margin).to_i
+ bottom_margin_logical = (log_units_factor*(page_height_mm -
bottom_margin)).to_i
+ right_margin_logical = (log_units_factor*(page_width_mm -
right_margin)).to_i
</ins><span class="cx">
</span><del>- leftMarginLogical = (logUnitsFactor*leftMargin)
- topMarginLogical = (logUnitsFactor*topMargin)
- bottomMarginLogical = (logUnitsFactor*(pageHeightMM - bottomMargin))
- rightMarginLogical = (logUnitsFactor*(pageWidthMM - rightMargin))
-
</del><span class="cx"> dc.set_pen(Wx::RED_PEN)
</span><del>- dc.draw_line( leftMarginLogical.to_i,
topMarginLogical.to_i,
- rightMarginLogical.to_i, topMarginLogical.to_i)
- dc.draw_line( leftMarginLogical.to_i, bottomMarginLogical.to_i,
- rightMarginLogical.to_i, bottomMarginLogical.to_i)
</del><ins>+ dc.draw_line( left_margin_logical,
top_margin_logical,
+ right_margin_logical, top_margin_logical)
+ dc.draw_line( left_margin_logical, bottom_margin_logical,
+ right_margin_logical, bottom_margin_logical)
</ins><span class="cx">
</span><del>- write_page_header(self, dc, "A header",
logUnitsFactor)
</del><ins>+ write_page_header(self, dc, "A header",
log_units_factor)
</ins><span class="cx"> end
</span><span class="cx">
</span><span class="cx"> # Writes a header on a page.
Margin units are in millimetres.
</span><del>- def write_page_header(printout, dc, text,
mmToLogical)
- pageWidthMM, pageHeightMM = printout.get_page_size_mm
</del><ins>+ def write_page_header(printout, dc, text,
mm_to_logical)
+ page_width_mm, page_height_mm = printout.get_page_size_mm
</ins><span class="cx">
</span><del>- leftMargin = 10
- topMargin = 10
- rightMargin = 10
</del><ins>+ left_margin = 10
+ top_margin = 10
+ right_margin = 10
</ins><span class="cx">
</span><del>- leftMarginLogical = (mmToLogical*leftMargin)
- topMarginLogical = (mmToLogical*topMargin)
- rightMarginLogical = (mmToLogical*(pageWidthMM - rightMargin))
</del><ins>+ left_margin_logical =
(mm_to_logical*left_margin).to_i
+ top_margin_logical = (mm_to_logical*top_margin).to_i
+ right_margin_logical = (mm_to_logical*(page_width_mm - right_margin)).to_i
</ins><span class="cx">
</span><del>- xExtent, yExtent= dc.get_text_extent(text)
- xPos = (((((pageWidthMM - leftMargin -
rightMargin)/2.0)+leftMargin)*mmToLogical) - (xExtent/2.0))
- dc.draw_text(text, xPos.to_i, topMarginLogical.to_i)
</del><ins>+ x_extent, y_extent= dc.get_text_extent(text)
+ x_pos = (((((page_width_mm - left_margin -
right_margin)/2.0)+left_margin)*mm_to_logical) - (x_extent/2.0))
+ dc.draw_text(text, x_pos.to_i, top_margin_logical)
</ins><span class="cx">
</span><span class="cx"> dc.set_pen(Wx::BLACK_PEN)
</span><del>- dc.draw_line( leftMarginLogical.to_i,
(topMarginLogical+yExtent).to_i,
- rightMarginLogical.to_i, (topMarginLogical+yExtent).to_i )
</del><ins>+ dc.draw_line( left_margin_logical,
(top_margin_logical+y_extent).to_i,
+ right_margin_logical, (top_margin_logical+yExtent).to_i )
</ins><span class="cx">
</span><span class="cx"> return true
</span><span class="cx"> end
</span><span class="lines">@@ -406,7 +403,7 @@
</span><span class="cx"> @test_font = Wx::Font.new(10,
Wx::SWISS, Wx::NORMAL, Wx::NORMAL)
</span><span class="cx">
</span><span class="cx"> # Create the main frame
window
</span><del>- @frame = MyFrame.new(nil, "wxWidgets Printing
Demo", Wx::Point.new(0, 0), Wx::Size.new(400, 400))
</del><ins>+ @frame = MyFrame.new(nil, "wxRuby Printing
Demo", Wx::Point.new(0, 0), Wx::Size.new(400, 400))
</ins><span class="cx">
</span><span class="cx"> # Give it a status line
</span><span class="cx"> @frame.create_status_bar(2)
</span><span class="lines">@@ -435,13 +432,13 @@
</span><span class="cx"> =end
</span><span class="cx">
</span><span class="cx"> file_menu.append_separator()
</span><del>- file_menu.append(WXPRINT_ANGLEUP, "Angle
up\tAlt-U", "Raise rotated text angle")
- file_menu.append(WXPRINT_ANGLEDOWN, "Angle down\tAlt-D",
"Lower rotated text angle")
</del><ins>+ file_menu.append(WXPRINT_ANGLEUP, "Angle
up\tAlt-U","Raise rotated text angle")
+ file_menu.append(WXPRINT_ANGLEDOWN, "Angle
down\tAlt-D","Lower rotated text angle")
</ins><span class="cx"> file_menu.append_separator()
</span><del>- file_menu.append(WXPRINT_QUIT,
"E&xit", "Exit program")
</del><ins>+ file_menu.append(WXPRINT_QUIT,
"E&xit","Exit program")
</ins><span class="cx">
</span><span class="cx"> help_menu = Wx::Menu.new
</span><del>- help_menu.append(WXPRINT_ABOUT,
"&About", "About this demo")
</del><ins>+ help_menu.append(WXPRINT_ABOUT,
"&About","About this demo")
</ins><span class="cx">
</span><span class="cx"> menu_bar = Wx::MenuBar.new
</span><span class="cx">
</span><span class="lines">@@ -463,7 +460,6 @@
</span><span class="cx">
</span><span class="cx">
@frame.set_status_text("Printing demo")
</span><span class="cx">
</span><del>-
</del><span class="cx"> set_top_window(@frame)
</span><span class="cx">
</span><span class="cx"> @print_data =
Wx::PrintData.new
</span></span></pre>
</div>
</div>
</body>
</html>
Maybe Matching Threads
- [1010] trunk/wxruby2: PrintPreview ok method name changed to is_ok, update sample
- [876] trunk/wxruby2/samples/printing/printing.rb: Fix a crasher if scale = 0; fix variable rename
- [736] trunk/wxruby2/samples/dialogs/dialogs.rb: Fixed crashing bug in on_paint and made the code style more Ruby like.
- [709] trunk/wxruby2/samples/dialogs/dialogs.rb: Use paint method again, remove unnecessary global (Alex Fenton)
- [739] trunk/wxruby2/samples/dialogs/dialogs.rb: Changed back to using block version of paint in on_paint method.
