1
2
3 __doc__ = """
4 Module to print a form using the wx. toolkit.
5 includes dialogues for printer calibration, etc.
6 and new form wizard.
7 """
8
9
10 __version__ = "$Revision: 1.12 $"
11 __author__ = "Ian Haywood"
12
13 try:
14 import wxversion
15 import wx
16 except ImportError:
17 from wxPython import wx
18
19 import string
20
21 from Gnumed.pycommon import gmCfg, gmI18N
22
23 try:
24 _('dummy-no-need-to-translate-but-make-epydoc-happy')
25 except NameError:
26 _ = lambda x:x
27
28 cache_form = 0
29 cache_params = {}
30
31 SCRIPT = -100
32
33 PATH = -101
34 RADIOL = -102
35
145
148
149 wx.Dialog.__init__(self, None, -1, _("Printer Setup"))
150 self.formprinter = formprinter
151 self.label_1 = wx.StaticText(self, -1, "Horiz. Offset")
152 self.horiz_off_spin = wx.SpinCtrl(self, -1, min=0, max=100, initial=0)
153 self.label_2 = wx.StaticText(self, -1, "Vert. Offset")
154 self.vert_off_spin = wx.SpinCtrl(self, -1, min=0, max=100, initial=0, style=wx.SP_ARROW_KEYS)
155 self.label_3 = wx.StaticText(self, -1, "Horiz. Scaling")
156 self.horiz_scale_spin = wx.SpinCtrl(self, -1, min=0, max=100, initial=0, style=wx.SP_ARROW_KEYS)
157 self.label_4 = wx.StaticText(self, -1, "Vert. Scaling")
158 self.vert_scale_spin = wx.SpinCtrl(self, -1, min=0, max=100, initial=0)
159 REPRINT_ID = wx.NewId ()
160 self.reprint_button = wx.Button(self, REPRINT_ID, "Re-print")
161 CALIB_ID = wx.NewId ()
162 self.calib_button = wx.Button(self, CALIB_ID, "Re-calibrate")
163 DISMISS_ID = wx.NewId ()
164 self.dismiss_button = wx.Button(self, DISMISS_ID, "Dismiss")
165 self.text_ctrl_1 = wxTextCtrl(self, -1, "You need to enter parameters so forms print properly on this printer", style=wx.TE_MULTILINE|wx.TE_READONLY)
166
167 self.__set_properties()
168 self.__do_layout()
169
170 if not self.formprinter.printer_unset:
171 self.horiz_off_spin.SetValue (self.formprinter.x_off)
172 self.vert_off_spin.SetValue (self.formprinter.y_off)
173 self.horiz_scale_spin.SetValue (self.formprinter.x_scale)
174 self.vert_scale_spin.SetValue (self.formprinter.y_scale)
175 else:
176 self.horiz_off_spin.SetValue (0)
177 self.horiz_scale_spin.SetValue (28.3)
178 self.vert_off_spin.SetValue (0)
179 self.vert_scale_spin.SetValue (28.3)
180 wx.EVT_BUTTON (self, REPRINT_ID, self.OnReprint)
181 wx.EVT_BUTTON (self, CALIB_ID, self.OnRecalibrate)
182 wx.EVT_BUTTON (self, DISMISS_ID, self.OnDismiss)
183 self.Show ()
184
186
187 self.formprinter.x_off = self.horiz_off_spin.GetValue ()
188 self.formprinter.y_off = self.vert_off_spin.GetValue ()
189 self.formprinter.x_scale = self.horiz_scale_spin.GetValue ()
190 self.formprinter.y_scale = self.vert_scale_spin.GetValue ()
191 self.formprinter.save ()
192 self.Destroy ()
193
195
196 self.formprinter.x_off = self.horiz_off_spin.GetValue ()
197 self.formprinter.y_off = self.vert_off_spin.GetValue ()
198 self.formprinter.x_scale = self.horiz_scale_spin.GetValue ()
199 self.formprinter.y_scale = self.vert_scale_spin.GetValue ()
200 self.formprinter.printer_unset = 0
201 if cache_form != 0:
202 self.formprinter.printform (cache_form, cache_params)
203
205 dialog = gmCalibrationDialog ()
206 pd = wxPrintData ()
207 pd.SetPrinterCommand ("lpr")
208 if wxPlatform == '__WXMSW__':
209 dc = wxPrinterDC (pd)
210 else:
211 dc = wxPostScriptDC (pd)
212 dc.StartDoc ("")
213 dc.StartPage ()
214 dc.SetBrush (wx.BLACK_BRUSH)
215 dc.DrawRectangle (1000, 1000, 200, 200)
216 dc.DrawRectangle (2000, 2000, 200, 200)
217 dc.EndPage ()
218 dc.EndDoc ()
219 del dc
220 dialog.ShowModal ()
221 x1, y1, x2, y2 = dialog.GetValues ()
222 dialog.Destroy ()
223 self.formprinter.x_scale = (x2-x1)/1000.0
224 self.formprinter.y_scale = (y2-y1)/1000.0
225 self.formprinter.x_off = x1-(x2-x1)
226 self.formprinter.y_off = y1-(y2-y1)
227 self.formprinter.printer_unset = 0
228 self.horiz_off_spin.SetValue (self.formprinter.x_off)
229 self.vert_off_spin.SetValue (self.formprinter.y_off)
230 self.horiz_scale_spin.SetValue (self.formprinter.x_scale)
231 self.vert_scale_spin.SetValue (self.formprinter.y_scale)
232 self.formprinter.save ()
233
235
236 self.SetTitle("Setup Printer for Forms")
237 self.vert_off_spin.SetToolTipString("Move text down (in millimetres)")
238 self.horiz_scale_spin.SetToolTipString("Horizontal scaling (units per mm)")
239 self.vert_scale_spin.SetToolTipString("Vertical scaling (units per mm)")
240 self.reprint_button.SetToolTipString("Re-print the last printed form")
241 self.calib_button.SetToolTipString("Print a table to calibrate this printer")
242 self.dismiss_button.SetToolTipString("Dismiss this dialog box")
243
244
246
247 sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
248 sizer_2 = wx.BoxSizer(wx.VERTICAL)
249 sizer_3 = wx.BoxSizer(wx.VERTICAL)
250 sizer_7 = wx.BoxSizer(wx.HORIZONTAL)
251 sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
252 sizer_5 = wx.BoxSizer(wx.HORIZONTAL)
253 sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
254 sizer_4.Add(self.label_1, 0, wx.ALL, 10)
255 sizer_4.Add(self.horiz_off_spin, 0, wx.ALL, 10)
256 sizer_3.Add(sizer_4, 1, wx.EXPAND, 0)
257 sizer_5.Add(self.label_2, 0, wx.ALL, 10)
258 sizer_5.Add(self.vert_off_spin, 0, wx.ALL, 10)
259 sizer_3.Add(sizer_5, 1, wx.EXPAND, 0)
260 sizer_6.Add(self.label_3, 0, wx.ALL, 10)
261 sizer_6.Add(self.horiz_scale_spin, 0, wx.ALL, 10)
262 sizer_3.Add(sizer_6, 1, wx.EXPAND, 0)
263 sizer_7.Add(self.label_4, 0, wx.ALL, 10)
264 sizer_7.Add(self.vert_scale_spin, 0, wx.ALL, 10)
265 sizer_3.Add(sizer_7, 1, wx.EXPAND, 0)
266 sizer_1.Add(sizer_3, 1, wx.EXPAND, 0)
267 sizer_2.Add(self.reprint_button, 0, wx.ALL|wx.EXPAND, 10)
268 sizer_2.Add(self.calib_button, 0, wx.ALL|wx.EXPAND, 10)
269 sizer_2.Add(self.dismiss_button, 0, wx.ALL|wx.EXPAND, 10)
270 sizer_2.Add(self.text_ctrl_1, 1, wx.EXPAND, 0)
271 sizer_1.Add(sizer_2, 1, wxALL|wx.EXPAND|wx.ALIGN_RIGHT, 30)
272 self.SetAutoLayout(1)
273 self.SetSizer(sizer_1)
274 sizer_1.Fit(self)
275 self.Layout()
276
277
278
279
282
283
284 wx.Dialog.__init__(self, None, -1, _("Calibration"))
285 self.label_9 = wx.StaticText(self, -1, """Calibration Page now printing.\n
286 Measure the position of the boxes and enter""")
287 self.label_5 = wx.StaticText(self, -1, "Distance of first box from top of page")
288 self.first_top_spin = wx.SpinCtrl(self, -1, min=0, max=100, initial=0)
289 self.label_6 = wx.StaticText(self, -1, "Distance of first box from left of page")
290 self.first_left_spin = wx.SpinCtrl(self, -1, min=0, max=100, initial=0)
291 self.label_7 = wx.StaticText(self, -1, "Distance of second box of top of page")
292 self.sec_top_spin = wx.SpinCtrl(self, -1, min=0, max=100, initial=0)
293 self.label_8 = wx.StaticText(self, -1, "Distance of second box from left of page")
294 self.sec_left_spin = wx.SpinCtrl(self, -1, min=0, max=100, initial=0)
295 ID = wx.NewId ()
296 self.ok_button = wx.Button(self, ID, "OK")
297 wx.EVT_BUTTON (self, ID, self.OnOK)
298 self.__set_properties()
299 self.__do_layout()
300
301 self.Show ()
302
304
305 self.SetTitle("Calibration")
306
307
309
310 sizer_8 = wx.BoxSizer(wx.VERTICAL)
311 grid_sizer_2 = wx.FlexGridSizer(4, 2, 0, 0)
312 sizer_8.Add(self.label_9, 0, wx.ALL|wx.EXPAND, 10)
313 grid_sizer_2.Add(self.label_5, 0, 0, 0)
314 grid_sizer_2.Add(self.first_top_spin, 0, 0, 0)
315 grid_sizer_2.Add(self.label_6, 0, 0, 0)
316 grid_sizer_2.Add(self.first_left_spin, 0, 0, 0)
317 grid_sizer_2.Add(self.label_7, 0, 0, 0)
318 grid_sizer_2.Add(self.sec_top_spin, 0, 0, 0)
319 grid_sizer_2.Add(self.label_8, 0, 0, 0)
320 grid_sizer_2.Add(self.sec_left_spin, 0, 0, 0)
321 grid_sizer_2.AddGrowableRow(0)
322 grid_sizer_2.AddGrowableRow(1)
323 grid_sizer_2.AddGrowableRow(2)
324 grid_sizer_2.AddGrowableRow(3)
325 grid_sizer_2.AddGrowableCol(0)
326 sizer_8.Add(grid_sizer_2, 1, wx.EXPAND, 0)
327 sizer_8.Add(self.ok_button, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 10)
328 self.SetAutoLayout(1)
329 self.SetSizer(sizer_8)
330 sizer_8.Fit(self)
331 self.Layout()
332
333
334 - def OnOK (self, event):
336
342
343
344
345 fp = FormPrinter ()
346 psd = gmPrinterSetupDialog (fp)
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376