-
Notifications
You must be signed in to change notification settings - Fork 3
/
BalloonTip.py
844 lines (597 loc) · 27.6 KB
/
BalloonTip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
# --------------------------------------------------------------------------- #
# BALLOONTIP wxPython IMPLEMENTATION
# Python Code By:
#
# Andrea Gavana, @ 29 May 2005
# Latest Revision: 6 September 2005, 22.00 CET
#
#
# TODO List/Caveats
#
# 1. With wx.ListBox (And Probably Other Controls), The BalloonTip Sometimes
# Flashes (It Is Created And Suddenly Destroyed). I Don't Know What Is
# Happening. Probably I Don't Handle Correctly The wx.EVT_ENTER_WINDOW
# wx.EVT_LEAVE_WINDOW?
#
# 2. wx.RadioBox Seems Not To Receive The wx.EVT_ENTER_WINDOW Event
#
# 3. wx.SpinCtrl (And Probably Other Controls), When Put In A Sizer, Does Not
# Return The Correct Size/Position. Probably Is Something I Am Missing.
#
# 4. Other Issues?
#
#
# FIXED Problems
#
# 1. Now BalloonTip Control Works Also For TaskBarIcon (Thanks To Everyone
# For The Suggetions I Read In The wxPython Mailing List)
#
#
# For All Kind Of Problems, Requests Of Enhancements And Bug Reports, Please
# Write To Me At:
#
#
# Or, Obviously, To The wxPython Mailing List!!!
#
#
# End Of Comments
# --------------------------------------------------------------------------- #
""" Description:
BalloonTip Is A Class That Allows You To Display Tooltips In A Balloon Style
Window (Actually A Frame), Similarly To The Windows XP Balloon Help. There Is
Also An Arrow That Points To The Center Of The Control Designed As A "Target"
For The BalloonTip.
What It Can Do:
- Set The Balloon Shape As A Rectangle Or A Rounded Rectangle;
- Set An Icon To The Top-Left Of The BalloonTip Frame;
- Set A Title At The Top Of The BalloonTip Frame;
- Automatic "Best" Placement Of BalloonTip Frame Depending On The Target
Control/Window Position;
- Runtime Customization Of Title/Tip Fonts And Foreground Colours;
- Runtime Change Of BalloonTip Frame Shape;
- Set The Balloon Background Colour;
- Possibility To Set The Delay After Which The BalloonTip Is Displayed;
- Possibility To Set The Delay After Which The BalloonTip Is Destroyed;
- Three Different Behaviors For The BalloonTip Window (Regardless The Delay
Destruction Time Set):
a) Destroy By Leave: The BalloonTip Is Destroyed When The Mouse Leaves The
Target Control/Window;
b) Destroy By Click: The BalloonTip Is Destroyed When You Click On Any Area
Of The Target Control/Window;
c) Destroy By Button: The BalloonTip Is Destroyed When You Click On The
Top-Right Close Button;
- Possibility To Enable/Disable Globally The BalloonTip On You Application.
- Set The BalloonTip Also For The TaskBarIcon (Revised 7 September 2005)
Usage Example:
# Let's Suppose That In Your Application You Have A wx.TextCtrl Defined As:
mytextctrl = wx.TextCtrl(panel, -1, "I Am A TextCtrl")
# You Can Define Your BalloonTip As Follows:
tipballoon = BalloonTip(topicon=None, toptitle="TextCtrl",
message="This Is A TextCtrl",
shape=BT_ROUNDED,
tipstyle=BT_LEAVE)
# Set The BalloonTip Target
tipballoon.SetTarget(mytextctrl)
# Set The BalloonTip Background Colour
tipballoon.SetBalloonColour(wx.WHITE)
# Set The Font For The Balloon Title
tipballoon.SetTitleFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False))
# Set The Colour For The Balloon Title
tipballoon.SetTitleColour(wx.BLACK)
# Leave The Message Font As Default
tipballoon.SetMessageFont()
# Set The Message (Tip) Foreground Colour
tipballoon.SetMessageColour(wx.LIGHT_GREY)
# Set The Start Delay For The BalloonTip
tipballoon.SetStartDelay(1000)
# Set The Time After Which The BalloonTip Is Destroyed
tipballoon.SetEndDelay(3000)
BalloonTip Is Freeware And Distributed Under The wxPython License.
Latest Revision: Andrea Gavana @ 7 September 2005, 22.00 CET
"""
import wx
import time
from wx.lib.buttons import GenButton
# Define The Values For The BalloonTip Frame Shape
BT_ROUNDED = 1
BT_RECTANGLE = 2
# Define The Value For The BalloonTip Destruction Behavior
BT_LEAVE = 3
BT_CLICK = 4
BT_BUTTON = 5
# ---------------------------------------------------------------
# Class BalloonFrame
# ---------------------------------------------------------------
# This Class Is Called By The Main BalloonTip Class, And It Is
# Responsible For The Frame Creation/Positioning On Screen
# Depending On Target Control/Window, The Frame Can Position
# Itself To NW (Default), NE, SW, SE. The Switch On Positioning
# Is Done By Calculating The Absolute Position Of The Target
# Control/Window Plus/Minus The BalloonTip Size. The Pointing
# Arrow Is Positioned Accordingly.
# ---------------------------------------------------------------
class BalloonFrame(wx.Frame):
def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
size=wx.DefaultSize, classparent=None):
"""Default Class Constructor.
Used Internally. Do Not Call Directly This Class In Your Application!
"""
wx.Frame.__init__(self, None, -1, "BalloonTip", pos, size,
style=wx.FRAME_SHAPED |
wx.SIMPLE_BORDER |
wx.FRAME_NO_TASKBAR |
wx.STAY_ON_TOP)
self._parent = classparent
self._toptitle = self._parent._toptitle
self._topicon = self._parent._topicon
self._message = self._parent._message
self._shape = self._parent._shape
self._tipstyle = self._parent._tipstyle
self._ballooncolour = self._parent._ballooncolour
self._balloonmsgcolour = self._parent._balloonmsgcolour
self._balloonmsgfont = self._parent._balloonmsgfont
if self._toptitle != "":
self._balloontitlecolour = self._parent._balloontitlecolour
self._balloontitlefont = self._parent._balloontitlefont
panel = wx.Panel(self, -1)
sizer = wx.BoxSizer(wx.VERTICAL)
self.panel = panel
subsizer = wx.BoxSizer(wx.VERTICAL)
hsizer = wx.BoxSizer(wx.HORIZONTAL)
subsizer.Add((0,20), 0, wx.EXPAND)
if self._topicon is not None:
stb = wx.StaticBitmap(panel, -1, self._topicon)
hsizer.Add(stb, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 10)
self._balloonbmp = stb
if self._toptitle != "":
stt = wx.StaticText(panel, -1, self._toptitle)
stt.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False))
if self._topicon is None:
hsizer.Add((10,0), 0, wx.EXPAND)
hsizer.Add(stt, 1, wx.EXPAND | wx.TOP, 10)
self._balloontitle = stt
self._balloontitle.SetForegroundColour(self._balloontitlecolour)
self._balloontitle.SetFont(self._balloontitlefont)
if self._tipstyle == BT_BUTTON:
self._closebutton = GenButton(panel, -1, "X", style=wx.NO_BORDER)
self._closebutton.SetMinSize((16,16))
self._closebutton.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False))
self._closebutton.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterButton)
self._closebutton.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveButton)
self._closebutton.SetUseFocusIndicator(False)
if self._toptitle != "":
hsizer.Add(self._closebutton, 0, wx.TOP | wx.RIGHT, 5)
else:
hsizer.Add((10,0), 1, wx.EXPAND)
hsizer.Add(self._closebutton, 0, wx.ALIGN_RIGHT | wx.TOP
| wx.RIGHT, 5)
if self._topicon is not None or self._toptitle != "" \
or self._tipstyle == BT_BUTTON:
subsizer.Add(hsizer, 0, wx.EXPAND | wx.BOTTOM, 5)
self._firstline = line = wx.StaticLine(panel, -1, style=wx.LI_HORIZONTAL)
if self._topicon is not None or self._toptitle != "" \
or self._tipstyle == BT_BUTTON:
subsizer.Add(self._firstline, 0, wx.EXPAND | wx.LEFT | wx.RIGHT
| wx.BOTTOM, 10)
else:
subsizer.Add(self._firstline, 0, wx.EXPAND | wx.LEFT | wx.RIGHT
| wx.BOTTOM | wx.TOP, 10)
mainstt = wx.StaticText(panel, -1, self._message)
self._balloonmsg = mainstt
self._balloonmsg.SetForegroundColour(self._balloonmsgcolour)
self._balloonmsg.SetFont(self._balloonmsgfont)
subsizer.Add(self._balloonmsg, 1, wx.EXPAND | wx.LEFT | wx.RIGHT |
wx.BOTTOM, 10)
self._secondline = wx.StaticLine(panel, -1, style=wx.LI_HORIZONTAL)
subsizer.Add(self._secondline, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
subsizer.Add((0,0),1)
panel.SetSizer(subsizer)
sizer.Add(panel, 1, wx.EXPAND)
self.SetSizerAndFit(sizer)
sizer.Layout()
if self._tipstyle == BT_CLICK:
if self._toptitle != "":
self._balloontitle.Bind(wx.EVT_LEFT_DOWN, self.OnClose)
if self._topicon is not None:
self._balloonbmp.Bind(wx.EVT_LEFT_DOWN, self.OnClose)
self._balloonmsg.Bind(wx.EVT_LEFT_DOWN, self.OnClose)
self.panel.Bind(wx.EVT_LEFT_DOWN, self.OnClose)
elif self._tipstyle == BT_BUTTON:
self._closebutton.Bind(wx.EVT_BUTTON, self.OnClose)
self.panel.SetBackgroundColour(self._ballooncolour)
if wx.Platform == "__WXGTK__":
self.Bind(wx.EVT_WINDOW_CREATE, self.SetBalloonShape)
else:
self.SetBalloonShape()
self.Show(True)
def SetBalloonShape(self, event=None):
"""Sets The Balloon Shape."""
size = self.GetSize()
pos = self.GetPosition()
dc = wx.MemoryDC()
textlabel = self._balloonmsg.GetLabel()
textfont = self._balloonmsg.GetFont()
textextent = dc.GetFullTextExtent(textlabel, textfont)
boxheight = size.y - textextent[1]*len(textlabel.split("\n"))
boxwidth = size.x
position = wx.GetMousePosition()
xpos = position[0]
ypos = position[1]
if xpos > 20 and ypos > 20:
# This Is NW Positioning
positioning = "NW"
xpos = position[0] - boxwidth + 20
ypos = position[1] - boxheight - 20
elif xpos <= 20 and ypos <= 20:
# This Is SE Positioning
positioning = "SE"
xpos = position[0] - 20
ypos = position[1]
elif xpos > 20 and ypos <= 20:
# This Is SW Positioning
positioning = "SW"
xpos = position[0] - boxwidth + 20
ypos = position[1]
else:
# This Is NE Positioning
positioning = "NE"
xpos = position[0]
ypos = position[1] - boxheight + 20
bmp = wx.EmptyBitmap(size.x,size.y)
dc = wx.BufferedDC(None, bmp)
dc.BeginDrawing()
dc.SetBackground(wx.Brush(wx.Color(0,0,0), wx.SOLID))
dc.Clear()
dc.SetPen(wx.Pen(wx.Color(0,0,0), 1, wx.TRANSPARENT))
if self._shape == BT_ROUNDED:
dc.DrawRoundedRectangle(0, 20, boxwidth, boxheight-20, 12)
elif self._shape == BT_RECTANGLE:
dc.DrawRectangle(0, 20, boxwidth, boxheight-20)
if positioning == "NW":
dc.DrawPolygon(((boxwidth-40, boxheight), (boxwidth-20, boxheight+20),
(boxwidth-20, boxheight)))
elif positioning == "SE":
dc.DrawPolygon(((20, 20), (20, 0), (40, 20)))
elif positioning == "SW":
dc.DrawPolygon(((boxwidth-40, 20), (boxwidth-20, 0), (boxwidth-20, 20)))
else:
dc.DrawPolygon(((20, boxheight), (20, boxheight+20), (40, boxheight)))
dc.EndDrawing()
r = wx.RegionFromBitmapColour(bmp, wx.Color(0,0,0))
self.hasShape = self.SetShape(r)
if self._tipstyle == BT_BUTTON:
colour = self.panel.GetBackgroundColour()
self._closebutton.SetBackgroundColour(colour)
self.SetPosition((xpos, ypos))
def OnEnterButton(self, event):
"""Handles The wx.EVT_ENTER_WINDOW For The BalloonTip Button.
When The BalloonTip Is Created With The TipStyle=BT_BUTTON, This Event
Provide Some Kind Of 3D Effect When The Mouse Enters The Button Area.
"""
button = event.GetEventObject()
colour = button.GetBackgroundColour()
red = colour.Red()
green = colour.Green()
blue = colour.Blue()
if red < 30:
red = red + 30
if green < 30:
green = green + 30
if blue < 30:
blue = blue + 30
colour = wx.Colour(red-30, green-30, blue-30)
button.SetBackgroundColour(colour)
button.SetForegroundColour(wx.WHITE)
button.Refresh()
event.Skip()
def OnLeaveButton(self, event):
"""Handles The wx.EVT_LEAVE_WINDOW For The BalloonTip Button.
When The BalloonTip Is Created With The TipStyle=BT_BUTTON, This Event
Restore The Button Appearance When The Mouse Leaves The Button Area.
"""
button = event.GetEventObject()
colour = self.panel.GetBackgroundColour()
button.SetBackgroundColour(colour)
button.SetForegroundColour(wx.BLACK)
button.Refresh()
event.Skip()
def OnClose(self, event):
""" Handles The wx.EVT_CLOSE Event."""
if isinstance(self._parent._widget, wx.TaskBarIcon):
self._parent.taskbarcreation = 0
self._parent.taskbartime.Stop()
del self._parent.taskbartime
del self._parent.BalloonFrame
self.Destroy()
# ---------------------------------------------------------------
# Class BalloonTip
# ---------------------------------------------------------------
# This Is The Main BalloonTip Implementation
# ---------------------------------------------------------------
class BalloonTip:
def __init__(self, topicon=None, toptitle="",
message="", shape=BT_ROUNDED, tipstyle=BT_LEAVE):
"""Deafult Class Constructor.
BalloonTip.__init__(self, topicon=None, toptitle="", message="",
shape=BT_ROUNDED, tipstyle=BT_LEAVE)
Parameters:
- topicon: An Icon That Will Be Displayed On The Top-Left Part Of The
BalloonTip Frame. If Set To None, No Icon Will Be Displayed;
- toptile: A Title That Will Be Displayed On The Top Part Of The
BalloonTip Frame. If Set To An Empty String, No Title Will Be Displayed;
- message: The Tip Message That Will Be Displayed. It Can Not Be Set To
An Empty String;
- shape: The BalloonTip Shape. It Can Be One Of:
a) BT_RECTANGLE (A Rectangle);
b) BT_ROUNDED (Rounded Rectangle, The Default).
- tipstyle: The BalloonTip Destruction Behavior. It Can Be One Of:
a) BT_LEAVE: The BalloonTip Is Destroyed When The Mouse Leaves The
Target Control/Window;
b) BT_CLICK: The BalloonTip Is Destroyed When You Click On Any Area
Of The Target Control/Window;
c) BT_BUTTON: The BalloonTip Is Destroyed When You Click On The
Top-Right Close Button;
"""
self._shape = shape
self._topicon = topicon
self._toptitle = toptitle
self._message = message
self._tipstyle = tipstyle
app = wx.GetApp()
self._runningapp = app
self._runningapp.__tooltipenabled__ = True
if self._message == "":
raise "\nERROR: You Should At Least Set The Message For The BalloonTip"
if self._shape not in [BT_ROUNDED, BT_RECTANGLE]:
raise '\nERROR: BalloonTip Shape Should Be One Of "BT_ROUNDED", "BT_RECTANGLE"'
if self._tipstyle not in [BT_LEAVE, BT_CLICK, BT_BUTTON]:
msg = '\nERROR: BalloonTip TipStyle Should Be One Of "BT_LEAVE", '\
'"BT_CLICK", "BT_BUTTON"'
raise msg
self.SetStartDelay()
self.SetEndDelay()
self.SetBalloonColour()
if toptitle != "":
self.SetTitleFont()
self.SetTitleColour()
if topicon is not None:
self.SetBalloonIcon(topicon)
self.SetMessageFont()
self.SetMessageColour()
def SetTarget(self, widget):
"""Sets The Target Control/Window For The BalloonTip."""
self._widget = widget
if isinstance(widget, wx.TaskBarIcon):
self._widget.Bind(wx.EVT_TASKBAR_MOVE, self.OnTaskBarMove)
self._widget.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
self.taskbarcreation = 0
else:
self._widget.Bind(wx.EVT_ENTER_WINDOW, self.OnWidgetEnter)
self._widget.Bind(wx.EVT_LEAVE_WINDOW, self.OnWidgetLeave)
self._widget.Bind(wx.EVT_MOTION, self.OnWidgetMotion)
self._widget.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
def GetTarget(self):
"""Returns The Target Window For The BalloonTip."""
if not hasattr(self, "_widget"):
raise "\nERROR: BalloonTip Target Has Not Been Set"
return self._widget
def SetStartDelay(self, delay=1):
"""Sets The Delay Time After Which The BalloonTip Is Created."""
if delay < 1:
raise "\nERROR: Delay Time For BalloonTip Creation Should Be Greater Than 1 ms"
self._startdelaytime = float(delay)
def GetStartDelay(self):
"""Returns The Delay Time After Which The BalloonTip Is Created."""
return self._startdelaytime
def SetEndDelay(self, delay=1e6):
"""Sets The Delay Time After Which The BalloonTip Is Destroyed."""
if delay < 1:
raise "\nERROR: Delay Time For BalloonTip Destruction Should Be Greater Than 1 ms"
self._enddelaytime = float(delay)
def GetEndDelay(self):
"""Returns The Delay Time After Which The BalloonTip Is Destroyed."""
return self._enddelaytime
def OnWidgetEnter(self, event):
"""Starts The BalloonTip Timer For Creation."""
if hasattr(self, "BalloonFrame"):
if self.BalloonFrame:
return
if not self._runningapp.__tooltipenabled__:
return
self.showtime = wx.PyTimer(self.NotifyTimer)
self.showtime.Start(self._startdelaytime)
event.Skip()
def OnWidgetLeave(self, event):
"""Handles The wx.EVT_LEAVE_WINDOW For The Target Control/Window.
If The BalloonTip tipstyle Is Set To BT_LEAVE, The BalloonTip Is Destroyed.
"""
if hasattr(self, "showtime"):
if self.showtime:
self.showtime.Stop()
del self.showtime
if hasattr(self, "BalloonFrame"):
if self.BalloonFrame:
if self._tipstyle == BT_LEAVE:
endtime = time.time()
if endtime - self.starttime > 0.1:
try:
self.BalloonFrame.Destroy()
except:
pass
else:
event.Skip()
else:
event.Skip()
else:
event.Skip()
def OnTaskBarMove(self, event):
""" Handles The Mouse Motion Inside The TaskBar Icon. """
if not hasattr(self, "BalloonFrame"):
if self.taskbarcreation == 0:
self.mousepos = wx.GetMousePosition()
self.currentmousepos = self.mousepos
self.taskbartime = wx.PyTimer(self.TaskBarTimer)
self.taskbartime.Start(100)
self.showtime = wx.PyTimer(self.NotifyTimer)
self.showtime.Start(self._startdelaytime)
if self.taskbarcreation == 0:
self.taskbarcreation = 1
return
event.Skip()
def OnWidgetMotion(self, event):
"""Handle The Mouse Motion Inside The Target.
This Prevents The Annoying Behavior Of BalloonTip To Display When The
User Does Something Else Inside The Window. The BalloonTip Window Is
Displayed Only When The Mouse Does *Not* Move For The Start Delay Time.
"""
if hasattr(self, "BalloonFrame"):
if self.BalloonFrame:
return
if hasattr(self, "showtime"):
if self.showtime:
self.showtime.Start(self._startdelaytime)
event.Skip()
def NotifyTimer(self):
"""The Creation Timer Has Expired. Creates The BalloonTip Frame."""
self.BalloonFrame = BalloonFrame(self._widget, classparent=self)
self.BalloonFrame.Show(True)
self.starttime = time.time()
self.showtime.Stop()
del self.showtime
self.destroytime = wx.PyTimer(self.DestroyTimer)
self.destroytime.Start(self._enddelaytime)
def TaskBarTimer(self):
"""This Timer Check Periodically The Mouse Position.
If The Current Mouse Position Is Sufficiently Far From The Coordinates
It Had When Entered The TaskBar Icon And The BalloonTip Style Is
BT_LEAVE, The BalloonTip Frame Is Destroyed.
"""
self.currentmousepos = wx.GetMousePosition()
mousepos = self.mousepos
if abs(self.currentmousepos[0] - mousepos[0]) > 30 or \
abs(self.currentmousepos[1] - mousepos[1]) > 30:
if hasattr(self, "BalloonFrame"):
if self._tipstyle == BT_LEAVE:
try:
self.BalloonFrame.Destroy()
self.taskbartime.Stop()
del self.taskbartime
del self.BalloonFrame
self.taskbarcreation = 0
except:
pass
def DestroyTimer(self):
"""The Destruction Timer Has Expired. Destroys The BalloonTip Frame."""
self.destroytime.Stop()
del self.destroytime
try:
self.BalloonFrame.Destroy()
except:
pass
def SetBalloonShape(self, shape=BT_ROUNDED):
"""Sets The BalloonTip Frame Shape.
It Should Be One Of BT_ROUNDED, BT_RECTANGLE.
"""
if shape not in [BT_ROUNDED, BT_RECTANGLE]:
raise '\nERROR: BalloonTip Shape Should Be One Of "BT_ROUNDED", "BT_RECTANGLE"'
self._shape = shape
def GetBalloonShape(self):
"""Returns The BalloonTip Frame Shape."""
return self._shape
def SetBalloonIcon(self, icon):
"""Sets The BalloonTip Top-Left Icon."""
if icon.Ok():
self._topicon = icon
else:
raise "\nERROR: Invalid Image Passed To BalloonTip"
def GetBalloonIcon(self):
"""Returns The BalloonTip Top-Left Icon."""
return self._topicon
def SetBalloonTitle(self, title=""):
"""Sets The BalloonTip Top Title."""
self._toptitle = title
def GetBalloonTitle(self):
"""Returns The BalloonTip Top Title."""
return self._toptitle
def SetBalloonMessage(self, message):
"""Sets The BalloonTip Tip Message. It Should Not Be Empty."""
if len(message.strip()) < 1:
raise "\nERROR: BalloonTip Message Can Not Be Empty"
self._message = message
def GetBalloonMessage(self):
"""Returns The BalloonTip Tip Message."""
return self._message
def SetBalloonTipStyle(self, tipstyle=BT_LEAVE):
"""Sets The BalloonTip TipStyle.
It Should Be One Of BT_LEAVE, BT_CLICK, BT_BUTTON.
"""
if tipstyle not in [BT_LEAVE, BT_CLICK, BT_BUTTON]:
msg = '\nERROR: BalloonTip TipStyle Should Be One Of "BT_LEAVE", '\
'"BT_CLICK", "BT_BUTTON"'
raise msg
self._tipstyle = tipstyle
def GetBalloonTipStyle(self):
"""Returns The BalloonTip TipStyle."""
return self._tipstyle
def SetBalloonColour(self, colour=None):
"""Sets The BalloonTip Background Colour."""
if colour is None:
colour = wx.Color(255, 250, 205)
self._ballooncolour = colour
def GetBalloonColour(self):
"""Returns The BalloonTip Background Colour."""
return self._ballooncolour
def SetTitleFont(self, font=None):
"""Sets The Font For The Top Title."""
if font is None:
font = wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False)
self._balloontitlefont = font
def GetTitleFont(self):
"""Returns The Font For The Top Title."""
return self._balloontitlefont
def SetMessageFont(self, font=None):
"""Sets The Font For The Tip Message."""
if font is None:
font = wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL, False)
self._balloonmsgfont = font
def GetMessageFont(self):
"""Returns The Font For The Tip Message."""
return self._balloonmsgfont
def SetTitleColour(self, colour=None):
"""Sets The Colour For The Top Title."""
if colour is None:
colour = wx.BLACK
self._balloontitlecolour = colour
def GetTitleColour(self):
"""Returns The Colour For The Top Title."""
return self._balloontitlecolour
def SetMessageColour(self, colour=None):
"""Sets The Colour For The Tip Message."""
if colour is None:
colour = wx.BLACK
self._balloonmsgcolour = colour
def GetMessageColour(self):
"""Returns The Colour For The Tip Message."""
return self._balloonmsgcolour
def OnDestroy(self, event):
"""Handles The Target Destruction."""
if hasattr(self, "BalloonFrame"):
if self.BalloonFrame:
try:
if isinstance(self._widget, wx.TaskBarIcon):
self._widget.UnBind(wx.EVT_TASKBAR_MOVE)
self.taskbartime.Stop()
del self.taskbartime
else:
self._widget.Unbind(wx.EVT_MOTION)
self._widget.Unbind(wx.EVT_LEAVE_WINDOW)
self._widget.Unbind(wx.EVT_ENTER_WINDOW)
self.BalloonFrame.Destroy()
except:
pass
del self.BalloonFrame
def EnableTip(self, enable=True):
"""Enabel/Disable Globally The BalloonTip."""
self._runningapp.__tooltipenabled__ = enable