~ubuntu-branches/ubuntu/lucid/wxwidgets2.8/lucid

« back to all changes in this revision

Viewing changes to wxPython/wx/lib/agw/toasterbox.py

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2009-08-11 14:33:24 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20090811143324-gw6dj432dbe8lw3w
Tags: 2.8.10.1-0ubuntu1
* New upstream release (LP: #387424).
* Update debian/patches/tcl_tk.tcl.dpatch patch.
* Update debian/patches/editra_pixmaps.dpatch patch.
* Remove debian/patches/colours.dpatch patch, merged upstream.
* Remove useless debian/patches/WX_CONFIG.dpatch file.
* debian/control.in: modify *-dbg Section field to debug.
* debian/control.in: unfold the Build-Depends, Suggests, Replaces and
  Depends fields.
* Override ancient-libtool and outdated-autotools-helper-file lintian
  warnings and ancient-autotools-helper-file lintian errors.
* Fix debian-watch-file-should-use-sf-redirector lintian warning.
* Fix binary-control-field-duplicates-source lintian infos.
* Fix duplicate-short-description lintian info.
* Move debian/*.desktop files to debian/desktop_files directory.
* Move debian/*.1 files to debian/manpages directory.
* Remove useless debian/README.HowToBuild.txt file.
* Remove debian/build_all file, it isn't used.
* Add debian/patches/CVE-2009-2369.dpatch patch taken from Debian unstable,
  fix an integer overflow in the wxImage::Create function (CVE-2009-2369).
* Add debian/patches/svn61009_fix_ftbfs.dpatch patch taken from upstream
  SVN rev 61009, fix FTBFS caused by new versions of glib.
* debian/rules: fix FTBFS caused by some changes introduced in
  2.8.9.1-0ubuntu5.
* Add debian/patches/{wxversion_path, wx_pth_dbg}.dpatch patches with
  changes introduced directly to source in 2.8.9.1-0ubuntu5.
  PLEASE REMEMBER, THERE IS NOTHING WRONG WITH USING DPATCH!
* Do not provide python-wxaddons package, upstream doesn't ship wxaddons
  anymore.
* debian/control.in: add Homepage field.
* Fix description-possibly-contains-homepage lintian infos.
* Bump Standards-Version to 3.8.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# --------------------------------------------------------------------------- #
 
2
# TOASTERBOX wxPython IMPLEMENTATION
 
3
# Ported And Enhanced From wxWidgets Contribution (Aj Bommarito) By:
 
4
#
 
5
# Andrea Gavana, @ 16 September 2005
 
6
# Latest Revision: 12 May 2009, 15.00 GMT
 
7
#
 
8
#
 
9
# TODO/Caveats List
 
10
#
 
11
# 1. Any Idea?
 
12
#
 
13
#
 
14
# For All Kind Of Problems, Requests Of Enhancements And Bug Reports, Please
 
15
# Write To Me At:
 
16
#
 
17
# andrea.gavana@gmail.com
 
18
# gavana@kpo.kz
 
19
#
 
20
# Or, Obviously, To The wxPython Mailing List!!!
 
21
#
 
22
#
 
23
# End Of Comments
 
24
# --------------------------------------------------------------------------- #
 
25
 
 
26
 
 
27
"""
 
28
Description:
 
29
 
 
30
ToasterBox is a cross-platform widget to make the creation of MSN style "toaster"
 
31
popups easier. The syntax is really easy especially if you are familiar with the
 
32
syntax of wxPython.
 
33
 
 
34
It has 2 main styles:
 
35
 
 
36
- TB_SIMPLE: using this style, you will be able to specify a background image for
 
37
             ToasterBox, text properties as text colour, font and label.
 
38
 
 
39
- TB_COMPLEX: this style will allow you to put almost any control inside a
 
40
              ToasterBox. You can add a panel in which you can put all the controls
 
41
              you like.
 
42
 
 
43
Both styles support the setting of ToasterBox position (on screen coordinates),
 
44
size, the time after which the ToasterBox is destroyed (linger), and the scroll
 
45
speed of ToasterBox.
 
46
 
 
47
ToasterBox has been tested on the following platforms:
 
48
 
 
49
Windows (verified on Windows XP, 2000)
 
50
 
 
51
 
 
52
Latest revision: Andrea Gavana @ 12 May 2009, 15.00 GMT
 
53
Version 0.2
 
54
 
 
55
"""
 
56
 
 
57
import textwrap
 
58
import wx
 
59
 
 
60
from wx.lib.statbmp import GenStaticBitmap as StaticBitmap
 
61
 
 
62
# Define Window List, We Use It Globally
 
63
winlist = []
 
64
 
 
65
TB_SIMPLE = 1
 
66
TB_COMPLEX = 2
 
67
 
 
68
DEFAULT_TB_STYLE = wx.SIMPLE_BORDER | wx.STAY_ON_TOP | wx.FRAME_NO_TASKBAR
 
69
TB_CAPTION = DEFAULT_TB_STYLE | wx.CAPTION | wx.SYSTEM_MENU | wx.CLOSE_BOX | wx.FRAME_TOOL_WINDOW
 
70
 
 
71
TB_ONTIME = 1
 
72
TB_ONCLICK = 2
 
73
 
 
74
# scroll from up to down
 
75
TB_SCR_TYPE_UD = 1
 
76
# scroll from down to up
 
77
TB_SCR_TYPE_DU = 2
 
78
 
 
79
# ------------------------------------------------------------------------------ #
 
80
# Class ToasterBox
 
81
#    Main Class Implementation. It Is Basically A wx.Timer. It Creates And
 
82
#    Displays Popups And Handles The "Stacking".
 
83
# ------------------------------------------------------------------------------ #
 
84
 
 
85
class ToasterBox(wx.Timer):
 
86
 
 
87
   def __init__(self, parent, tbstyle=TB_SIMPLE, windowstyle=DEFAULT_TB_STYLE,
 
88
                closingstyle=TB_ONTIME, scrollType=TB_SCR_TYPE_DU):
 
89
       """
 
90
       Default class constructor.
 
91
 
 
92
       ToasterBox.__init__(self, tbstyle=TB_SIMPLE, windowstyle=DEFAULT_TB_STYLE)
 
93
 
 
94
       Parameters:
 
95
 
 
96
       - tbstyle: this parameter may have 2 values:
 
97
         (a) TB_SIMPLE: a simple ToasterBox, with background image and text
 
98
             customization can be created;
 
99
         (b) TB_COMPLEX: ToasterBoxes with different degree of complexity can
 
100
             be created. You can add as many controls as you want, provided
 
101
             that you call the AddPanel() method and pass to it a dummy frame
 
102
             and a wx.Panel. see the demo for details.
 
103
 
 
104
       - windowstyle: this parameter influences the visual appearance of ToasterBox:
 
105
         (a) DEFAULT_TB_STYLE: default style, no caption nor close box;
 
106
         (b) TB_CAPTION: ToasterBox will have a caption, with the possibility to
 
107
             set a title for ToasterBox frame, and a close box;
 
108
 
 
109
       - closingstyle: set this value to TB_ONCLICK if you want to be able to close
 
110
         ToasterBox by a mouse click anywhere in the ToasterBox frame.
 
111
 
 
112
       """
 
113
 
 
114
       self._parent = parent
 
115
       self._sleeptime = 10
 
116
       self._pausetime = 1700
 
117
       self._popuptext = "default"
 
118
       self._popupposition = wx.Point(100,100)
 
119
       self._popuptop = wx.Point(0,0)
 
120
       self._popupsize = wx.Size(150, 170)
 
121
 
 
122
       self._backgroundcolour = wx.WHITE
 
123
       self._foregroundcolour = wx.BLACK
 
124
       self._textfont = wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL, False, "Verdana")
 
125
 
 
126
       self._bitmap = None
 
127
 
 
128
       self._tbstyle = tbstyle
 
129
       self._windowstyle = windowstyle
 
130
       self._closingstyle = closingstyle
 
131
 
 
132
       self._panel = None
 
133
 
 
134
       self._bottomright = wx.Point(wx.GetDisplaySize().GetWidth(),
 
135
                                    wx.GetDisplaySize().GetHeight())
 
136
 
 
137
       parent.Bind(wx.EVT_ICONIZE, lambda evt: [w.Hide() for w in winlist])
 
138
 
 
139
       self._tb = ToasterBoxWindow(self._parent, self, self._tbstyle, self._windowstyle,
 
140
                                   self._closingstyle, scrollType=scrollType)
 
141
 
 
142
 
 
143
   def SetPopupPosition(self, pos):
 
144
       """ Sets the ToasterBox position on screen. """
 
145
 
 
146
       self._popupposition = pos
 
147
 
 
148
 
 
149
   def SetPopupPositionByInt(self, pos):
 
150
       """ Sets the ToasterBox position on screen, at one of the screen corners. """
 
151
 
 
152
       self._bottomright = wx.Point(wx.GetDisplaySize().GetWidth(),
 
153
                                    wx.GetDisplaySize().GetHeight())
 
154
 
 
155
       # top left
 
156
       if pos == 0:
 
157
           popupposition = wx.Point(0,0)
 
158
       # top right
 
159
       elif pos == 1:
 
160
           popupposition = wx.Point(wx.GetDisplaySize().GetWidth() -
 
161
                                    self._popupsize[0], 0)
 
162
       # bottom left
 
163
       elif pos == 2:
 
164
           popupposition = wx.Point(0, wx.GetDisplaySize().GetHeight() -
 
165
                                   self._popupsize[1])
 
166
       # bottom right
 
167
       elif pos == 3:
 
168
           popupposition = wx.Point(self._bottomright.x - self._popupsize[0],
 
169
                                    self._bottomright.y - self._popupsize[1])
 
170
 
 
171
       self._bottomright = wx.Point(popupposition.x + self._popupsize[0],
 
172
                                    popupposition.y + self._popupsize[1])
 
173
 
 
174
 
 
175
   def SetPopupBackgroundColor(self, colour=None):
 
176
       """
 
177
       Sets the ToasterBox background colour. Use it only for ToasterBoxes created
 
178
       with TB_SIMPLE style.
 
179
       """
 
180
 
 
181
       if colour is None:
 
182
           colour = wx.WHITE
 
183
 
 
184
       self._backgroundcolour = colour
 
185
 
 
186
 
 
187
   def SetPopupTextColor(self, colour=None):
 
188
       """
 
189
       Sets the ToasterBox foreground colour. Use it only for ToasterBoxes created
 
190
       with TB_SIMPLE style.
 
191
       """
 
192
 
 
193
       if colour is None:
 
194
           colour = wx.BLACK
 
195
 
 
196
       self._foregroundcolour = colour
 
197
 
 
198
 
 
199
   def SetPopupTextFont(self, font=None):
 
200
       """
 
201
       Sets the ToasterBox text font. Use it only for ToasterBoxes created
 
202
       with TB_SIMPLE style.
 
203
       """
 
204
 
 
205
       if font is None:
 
206
           font = wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL, False)
 
207
 
 
208
       self._textfont = font
 
209
 
 
210
 
 
211
   def SetPopupSize(self, size):
 
212
       """ Sets the ToasterBox size. """
 
213
 
 
214
       self._popupsize = size
 
215
 
 
216
 
 
217
   def SetPopupPauseTime(self, pausetime):
 
218
       """ Sets the time after which the ToasterBox is destroyed (linger). """
 
219
 
 
220
       self._pausetime = pausetime
 
221
 
 
222
 
 
223
   def SetPopupBitmap(self, bitmap=None):
 
224
       """
 
225
       Sets the ToasterBox background image. Use it only for ToasterBoxes created
 
226
       with TB_SIMPLE style.
 
227
       """
 
228
 
 
229
       if bitmap is not None:
 
230
           bitmap = wx.Bitmap(bitmap, wx.BITMAP_TYPE_BMP)
 
231
 
 
232
       self._bitmap = bitmap
 
233
 
 
234
 
 
235
   def SetPopupScrollSpeed(self, speed):
 
236
       """
 
237
       Sets the ToasterBox scroll speed. The speed parameter is the pause
 
238
       time (in ms) for every step in the ScrollUp() method.
 
239
       """
 
240
 
 
241
       self._sleeptime = speed
 
242
 
 
243
 
 
244
   def SetPopupText(self, text):
 
245
       """
 
246
       Sets the ToasterBox text. Use it only for ToasterBoxes created
 
247
       with TB_SIMPLE style.
 
248
       """
 
249
 
 
250
       self._popuptext = text
 
251
 
 
252
 
 
253
   def AddPanel(self, panel):
 
254
       """
 
255
       Adds a panel to the ToasterBox. Use it only for ToasterBoxes created
 
256
       with TB_COMPLEX style.
 
257
       """
 
258
 
 
259
       if not self._tbstyle & TB_COMPLEX:
 
260
           raise Exception("\nERROR: Panel Can Not Be Added When Using TB_SIMPLE ToasterBox Style")
 
261
 
 
262
       self._panel = panel
 
263
 
 
264
 
 
265
   def Play(self):
 
266
       """ Creates the ToasterBoxWindow, that does all the job. """
 
267
 
 
268
       # create new window
 
269
       self._tb.SetPopupSize((self._popupsize[0], self._popupsize[1]))
 
270
       self._tb.SetPopupPosition((self._popupposition[0], self._popupposition[1]))
 
271
       self._tb.SetPopupPauseTime(self._pausetime)
 
272
       self._tb.SetPopupScrollSpeed(self._sleeptime)
 
273
 
 
274
       if self._tbstyle == TB_SIMPLE:
 
275
           self._tb.SetPopupTextColor(self._foregroundcolour)
 
276
           self._tb.SetPopupBackgroundColor(self._backgroundcolour)
 
277
           self._tb.SetPopupTextFont(self._textfont)
 
278
 
 
279
           if self._bitmap is not None:
 
280
               self._tb.SetPopupBitmap(self._bitmap)
 
281
 
 
282
           self._tb.SetPopupText(self._popuptext)
 
283
 
 
284
       if self._tbstyle == TB_COMPLEX:
 
285
           if self._panel is not None:
 
286
               self._tb.AddPanel(self._panel)
 
287
 
 
288
       # clean up the list
 
289
       self.CleanList()
 
290
 
 
291
       # check to see if there is already a window displayed
 
292
       # by looking at the linked list
 
293
       if len(winlist) > 0:
 
294
           # there ARE other windows displayed already
 
295
           # reclac where it should display
 
296
           self.MoveAbove(self._tb)
 
297
 
 
298
       # shift new window on to the list
 
299
       winlist.append(self._tb)
 
300
 
 
301
       if not self._tb.Play():
 
302
           # if we didn't show the window properly, remove it from the list
 
303
           winlist.remove(winlist[-1])
 
304
           # delete the object too
 
305
           self._tb.Destroy()
 
306
           return
 
307
 
 
308
 
 
309
   def MoveAbove(self, tb):
 
310
       """ If a ToasterBox already exists, move the new one above. """
 
311
 
 
312
       # recalc where to place this popup
 
313
 
 
314
       self._tb.SetPopupPosition((self._popupposition[0], self._popupposition[1] -
 
315
                                  self._popupsize[1]*len(winlist)))
 
316
 
 
317
 
 
318
   def GetToasterBoxWindow(self):
 
319
       """ Returns the ToasterBox frame. """
 
320
 
 
321
       return self._tb
 
322
 
 
323
 
 
324
   def SetTitle(self, title):
 
325
       """ Sets the ToasterBox title if it was created with TB_CAPTION window style. """
 
326
 
 
327
       self._tb.SetTitle(title)
 
328
 
 
329
 
 
330
   def Notify(self):
 
331
       """ It's time to hide a ToasterBox! """
 
332
 
 
333
       if len(winlist) == 0:
 
334
           return
 
335
 
 
336
       # clean the window list
 
337
       self.CleanList()
 
338
 
 
339
       # figure out how many blanks we have
 
340
       try:
 
341
           node = winlist[0]
 
342
       except:
 
343
           return
 
344
 
 
345
       if not node:
 
346
           return
 
347
 
 
348
       # move windows to fill in blank space
 
349
       for i in xrange(node.GetPosition()[1], self._popupposition[1], 4):
 
350
           if i > self._popupposition[1]:
 
351
               i = self._popupposition[1]
 
352
 
 
353
           # loop through all the windows
 
354
           for j in xrange(0, len(winlist)):
 
355
               ourNewHeight = i - (j*self._popupsize[1] - 8)
 
356
               tmpTb = winlist[j]
 
357
               # reset where the object THINKS its supposed to be
 
358
               tmpTb.SetPopupPosition((self._popupposition[0], ourNewHeight))
 
359
               # actually move it
 
360
               tmpTb.SetDimensions(self._popupposition[0], ourNewHeight, tmpTb.GetSize().GetWidth(),
 
361
                                   tmpTb.GetSize().GetHeight())
 
362
 
 
363
           wx.Usleep(self._sleeptime)
 
364
 
 
365
 
 
366
   def CleanList(self):
 
367
       """ Clean the window list. """
 
368
 
 
369
       if len(winlist) == 0:
 
370
           return
 
371
 
 
372
       node = winlist[0]
 
373
       while node:
 
374
           if not node.IsShown():
 
375
               winlist.remove(node)
 
376
               try:
 
377
                   node = winlist[0]
 
378
               except:
 
379
                   node = 0
 
380
           else:
 
381
               indx = winlist.index(node)
 
382
               try:
 
383
                   node = winlist[indx+1]
 
384
               except:
 
385
                   node = 0
 
386
 
 
387
 
 
388
# ------------------------------------------------------------------------------ #
 
389
# Class ToasterBoxWindow
 
390
#    This Class Does All The Job, By Handling Background Images, Text Properties
 
391
#    And Panel Adding. Depending On The Style You Choose, ToasterBoxWindow Will
 
392
#    Behave Differently In Order To Handle Widgets Inside It.
 
393
# ------------------------------------------------------------------------------ #
 
394
 
 
395
class ToasterBoxWindow(wx.Frame):
 
396
 
 
397
   def __init__(self, parent, parent2, tbstyle, windowstyle,
 
398
       closingstyle, scrollType=TB_SCR_TYPE_DU):
 
399
       """
 
400
       Default class constructor.
 
401
 
 
402
       Used internally. Do not call directly this class in your application!
 
403
       """
 
404
 
 
405
       wx.Frame.__init__(self, parent, wx.ID_ANY, "window", wx.DefaultPosition,
 
406
                         wx.DefaultSize, style=windowstyle | wx.CLIP_CHILDREN)
 
407
 
 
408
       self._starttime = wx.GetLocalTime()
 
409
       self._parent2 = parent2
 
410
       self._parent = parent
 
411
       self._sleeptime = 10
 
412
       self._step = 4
 
413
       self._pausetime = 1700
 
414
       self._textcolour = wx.BLACK
 
415
       self._popuptext = "Change Me!"
 
416
       # the size we want the dialog to be
 
417
       framesize = wx.Size(150, 170)
 
418
       self._count = 1
 
419
       self._tbstyle = tbstyle
 
420
       self._windowstyle = windowstyle
 
421
       self._closingstyle = closingstyle
 
422
       self._scrollType = scrollType
 
423
 
 
424
 
 
425
       if tbstyle == TB_COMPLEX:
 
426
           self.sizer = wx.BoxSizer(wx.VERTICAL)
 
427
       else:
 
428
           self._staticbitmap = None
 
429
 
 
430
       if self._windowstyle == TB_CAPTION:
 
431
           self.Bind(wx.EVT_CLOSE, self.OnClose)
 
432
           self.SetTitle("")
 
433
 
 
434
       if self._closingstyle & TB_ONCLICK and self._windowstyle != TB_CAPTION:
 
435
           self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
 
436
 
 
437
       self._bottomright = wx.Point(wx.GetDisplaySize().GetWidth(),
 
438
                                    wx.GetDisplaySize().GetHeight())
 
439
 
 
440
       self.SetDimensions(self._bottomright.x, self._bottomright.y,
 
441
                          framesize.GetWidth(), framesize.GetHeight())
 
442
 
 
443
 
 
444
   def OnClose(self, event):
 
445
 
 
446
       self.NotifyTimer(None)
 
447
       event.Skip()
 
448
 
 
449
 
 
450
   def OnMouseDown(self, event):
 
451
 
 
452
       self.NotifyTimer(None)
 
453
       event.Skip()
 
454
 
 
455
 
 
456
   def SetPopupBitmap(self, bitmap):
 
457
       """
 
458
       Sets the ToasterBox background image. Use it only for ToasterBoxes created
 
459
       with TB_SIMPLE style.
 
460
       """
 
461
 
 
462
       bitmap = bitmap.ConvertToImage()
 
463
       xsize, ysize = self.GetSize()
 
464
       bitmap = bitmap.Scale(xsize, ysize)
 
465
       bitmap = bitmap.ConvertToBitmap()
 
466
       self._staticbitmap = StaticBitmap(self, -1, bitmap, pos=(0,0))
 
467
 
 
468
       if self._closingstyle & TB_ONCLICK and self._windowstyle != TB_CAPTION:
 
469
           self._staticbitmap.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
 
470
 
 
471
 
 
472
   def SetPopupSize(self, size):
 
473
       """ Sets the ToasterBox size. """
 
474
 
 
475
       self.SetDimensions(self._bottomright.x, self._bottomright.y, size[0], size[1])
 
476
 
 
477
 
 
478
   def SetPopupPosition(self, pos):
 
479
       """ Sets the ToasterBox position on screen. """
 
480
 
 
481
       self._bottomright = wx.Point(pos[0] + self.GetSize().GetWidth(),
 
482
                                    pos[1] + self.GetSize().GetHeight())
 
483
       self._dialogtop = pos
 
484
 
 
485
 
 
486
   def SetPopupPositionByInt(self, pos):
 
487
       """ Sets the ToasterBox position on screen, at one of the screen corners. """
 
488
 
 
489
       self._bottomright = wx.Point(wx.GetDisplaySize().GetWidth(),
 
490
                                    wx.GetDisplaySize().GetHeight())
 
491
 
 
492
       # top left
 
493
       if pos == 0:
 
494
           popupposition = wx.Point(0,0)
 
495
       # top right
 
496
       elif pos == 1:
 
497
           popupposition = wx.Point(wx.GetDisplaySize().GetWidth() -
 
498
                                    self._popupsize[0], 0)
 
499
       # bottom left
 
500
       elif pos == 2:
 
501
           popupposition = wx.Point(0, wx.GetDisplaySize().GetHeight() -
 
502
                                   self._popupsize[1])
 
503
       # bottom right
 
504
       elif pos == 3:
 
505
           popupposition = wx.Point(self._bottomright.x - self._popupsize[0],
 
506
                                    self._bottomright.y - self._popupsize[1])
 
507
 
 
508
       self._bottomright = wx.Point(popupposition.x + self._popupsize[0],
 
509
                                    popupposition.y + self._popupsize[1])
 
510
 
 
511
       self._dialogtop = popupposition
 
512
 
 
513
 
 
514
   def SetPopupPauseTime(self, pausetime):
 
515
       """ Sets the time after which the ToasterBox is destroyed (linger). """
 
516
 
 
517
       self._pausetime = pausetime
 
518
 
 
519
 
 
520
   def SetPopupScrollSpeed(self, speed):
 
521
       """
 
522
       Sets the ToasterBox scroll speed. The speed parameter is the pause
 
523
       time (in ms) for every step in the ScrollUp() method.
 
524
       """
 
525
 
 
526
       self._sleeptime = speed
 
527
 
 
528
 
 
529
   def AddPanel(self, panel):
 
530
       """
 
531
       Adds a panel to the ToasterBox. Use it only for ToasterBoxes created
 
532
       with TB_COMPLEX style.
 
533
       """
 
534
 
 
535
       if not self._tbstyle & TB_COMPLEX:
 
536
           raise Exception("\nERROR: Panel Can Not Be Added When Using TB_SIMPLE ToasterBox Style")
 
537
 
 
538
       self.sizer.Add(panel, 1, wx.EXPAND)
 
539
       self.sizer.Layout()
 
540
       self.SetSizer(self.sizer)
 
541
 
 
542
       if self._closingstyle & TB_ONCLICK and self._windowstyle != TB_CAPTION:
 
543
           panel.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)
 
544
 
 
545
 
 
546
   def SetPopupText(self, text):
 
547
       """
 
548
       Sets the ToasterBox text. Use it only for ToasterBoxes created
 
549
       with TB_SIMPLE style.
 
550
       """
 
551
 
 
552
       self._popuptext = text
 
553
 
 
554
 
 
555
   def SetPopupTextFont(self, font):
 
556
       """
 
557
       Sets the ToasterBox text font. Use it only for ToasterBoxes created
 
558
       with TB_SIMPLE style.
 
559
       """
 
560
 
 
561
       self._textfont = font
 
562
 
 
563
 
 
564
   def GetPopupText(self):
 
565
       """
 
566
       Returns the ToasterBox text. Use it only for ToasterBoxes created
 
567
       with TB_SIMPLE style.
 
568
       """
 
569
 
 
570
       return self._popuptext
 
571
 
 
572
 
 
573
   def Play(self):
 
574
       """ Creates the ToasterBoxWindow, that does all the job. """
 
575
 
 
576
       # do some checks to make sure this window is valid
 
577
       if self._bottomright.x < 1 or self._bottomright.y < 1:
 
578
           return False
 
579
 
 
580
       if self.GetSize().GetWidth() < 50 or self.GetSize().GetWidth() < 50:
 
581
           # toasterbox launches into a endless loop for some reason
 
582
           # when you try to make the window too small.
 
583
           return False
 
584
 
 
585
       self.ScrollUp()
 
586
       timerid = wx.NewId()
 
587
       self.showtime = wx.Timer(self, timerid)
 
588
       self.showtime.Start(self._pausetime)
 
589
       self.Bind(wx.EVT_TIMER, self.NotifyTimer, id=timerid)
 
590
 
 
591
       return True
 
592
 
 
593
 
 
594
   def NotifyTimer(self, event):
 
595
       """ Hides gradually the ToasterBoxWindow. """
 
596
 
 
597
       self.showtime.Stop()
 
598
       del self.showtime
 
599
       self.ScrollDown()
 
600
 
 
601
 
 
602
   def SetPopupBackgroundColor(self, colour):
 
603
       """
 
604
       Sets the ToasterBox background colour. Use it only for ToasterBoxes created
 
605
       with TB_SIMPLE style.
 
606
       """
 
607
 
 
608
       self.SetBackgroundColour(colour)
 
609
 
 
610
 
 
611
   def SetPopupTextColor(self, colour):
 
612
       """
 
613
       Sets the ToasterBox foreground colour. Use it only for ToasterBoxes created
 
614
       with TB_SIMPLE style.
 
615
       """
 
616
 
 
617
       self._textcolour = colour
 
618
 
 
619
 
 
620
   def ScrollUp(self):
 
621
       """ Scrolls the ToasterBox up, which means gradually showing the ToasterBox. """
 
622
 
 
623
       self.Show(True)
 
624
 
 
625
       # walk the Y value up in a raise motion
 
626
       xpos = self.GetPosition().x
 
627
       ypos = self._bottomright[1]
 
628
       windowsize = 0
 
629
 
 
630
       # checking the type of the scroll (from up to down or from down to up)
 
631
       if self._scrollType == TB_SCR_TYPE_UD:
 
632
           start = self._dialogtop[1]
 
633
           stop = ypos
 
634
           step = self._step
 
635
       elif self._scrollType == TB_SCR_TYPE_DU:
 
636
           start = ypos
 
637
           stop = self._dialogtop[1]
 
638
           step = -self._step
 
639
       else:
 
640
           errMsg = ("scrollType not supported (in ToasterBoxWindow.ScrollUp): %s" %
 
641
                 self._scrollType)
 
642
           raise ValueError(errMsg)
 
643
 
 
644
       for i in xrange(start, stop, step):
 
645
           if i < self._dialogtop[1]:
 
646
             i = self._dialogtop[1]
 
647
 
 
648
           windowsize = windowsize + self._step
 
649
 
 
650
           # checking the type of the scroll (from up to down or from down to up)
 
651
           if self._scrollType == TB_SCR_TYPE_UD:
 
652
               dimY = self._dialogtop[1]
 
653
           elif self._scrollType == TB_SCR_TYPE_DU:
 
654
               dimY = i
 
655
           else:
 
656
               errMsg = ("scrollType not supported (in ToasterBoxWindow.ScrollUp): %s" %
 
657
                     self._scrollType)
 
658
               raise ValueError(errMsg)
 
659
 
 
660
           self.SetDimensions(self._dialogtop[0], dimY, self.GetSize().GetWidth(),
 
661
                              windowsize)
 
662
 
 
663
           if self._tbstyle == TB_SIMPLE:
 
664
               self.DrawText()
 
665
 
 
666
           wx.Usleep(self._sleeptime)
 
667
           self.Update()
 
668
           self.Refresh()
 
669
 
 
670
       self.Update()
 
671
 
 
672
       if self._tbstyle == TB_SIMPLE:
 
673
           self.DrawText()
 
674
 
 
675
       self.SetFocus()
 
676
 
 
677
 
 
678
   def ScrollDown(self):
 
679
       """ Scrolls the ToasterBox down, which means gradually hiding the ToasterBox. """
 
680
 
 
681
       # walk down the Y value
 
682
       windowsize = self.GetSize().GetHeight()
 
683
 
 
684
       # checking the type of the scroll (from up to down or from down to up)
 
685
       if self._scrollType == TB_SCR_TYPE_UD:
 
686
           start = self._bottomright.y
 
687
           stop = self._dialogtop[1]
 
688
           step = -self._step
 
689
       elif self._scrollType == TB_SCR_TYPE_DU:
 
690
           start = self._dialogtop[1]
 
691
           stop = self._bottomright.y
 
692
           step = self._step
 
693
       else:
 
694
           errMsg = ("scrollType not supported (in ToasterBoxWindow.ScrollUp): %s" %
 
695
                 self._scrollType)
 
696
           raise ValueError(errMsg)
 
697
 
 
698
       for i in xrange(start, stop, step):
 
699
           if i > self._bottomright.y:
 
700
               i = self._bottomright.y
 
701
 
 
702
           windowsize = windowsize - self._step
 
703
 
 
704
           # checking the type of the scroll (from up to down or from down to up)
 
705
           if self._scrollType == TB_SCR_TYPE_UD:
 
706
               dimY = self._dialogtop[1]
 
707
           elif self._scrollType == TB_SCR_TYPE_DU:
 
708
               dimY = i
 
709
           else:
 
710
               errMsg = ("scrollType not supported (in ToasterBoxWindow.ScrollUp): %s" %
 
711
                     self._scrollType)
 
712
               raise ValueError(errMsg)
 
713
 
 
714
           self.SetDimensions(self._dialogtop[0], dimY,
 
715
                              self.GetSize().GetWidth(), windowsize)
 
716
 
 
717
           wx.Usleep(self._sleeptime)
 
718
           self.Refresh()
 
719
 
 
720
       self.Hide()
 
721
       if self._parent2:
 
722
           self._parent2.Notify()
 
723
 
 
724
 
 
725
   def DrawText(self):
 
726
      
 
727
       if self._staticbitmap is not None:
 
728
           dc = wx.ClientDC(self._staticbitmap)
 
729
       else:
 
730
           dc = wx.ClientDC(self)
 
731
           
 
732
       dc.SetFont(self._textfont)
 
733
 
 
734
       if not hasattr(self, "text_coords"):
 
735
           self._getTextCoords(dc)
 
736
 
 
737
       fg = dc.GetTextForeground()
 
738
       dc.SetTextForeground(self._textcolour)
 
739
       dc.DrawTextList(*self.text_coords)
 
740
       dc.SetTextForeground(fg)
 
741
 
 
742
 
 
743
   def _getTextCoords(self, dc):
 
744
       """
 
745
       Draw the user specified text using the wx.DC. Use it only for ToasterBoxes created
 
746
       with TB_SIMPLE style.
 
747
       """
 
748
 
 
749
       # border from sides and top to text (in pixels)
 
750
       border = 7
 
751
       # how much space between text lines
 
752
       textPadding = 2
 
753
 
 
754
       pText = self.GetPopupText()
 
755
 
 
756
       max_len = len(pText)
 
757
 
 
758
       tw, th = self._parent2._popupsize
 
759
 
 
760
       if self._windowstyle == TB_CAPTION:
 
761
           th = th - 20
 
762
 
 
763
       while 1:
 
764
           lines = textwrap.wrap(pText, max_len)
 
765
 
 
766
           for line in lines:
 
767
               w, h = dc.GetTextExtent(line)
 
768
               if w > tw - border * 2:
 
769
                   max_len -= 1
 
770
                   break
 
771
           else:
 
772
               break
 
773
 
 
774
       fh = 0
 
775
       for line in lines:
 
776
           w, h = dc.GetTextExtent(line)
 
777
           fh += h + textPadding
 
778
       y = (th - fh) / 2; coords = []
 
779
 
 
780
       for line in lines:
 
781
           w, h = dc.GetTextExtent(line)
 
782
           x = (tw - w) / 2
 
783
           coords.append((x, y))
 
784
           y += h + textPadding
 
785
 
 
786
       self.text_coords = (lines, coords)