]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/HyperLinkCtrl.py
3 import wx
.lib
.hyperlink
as hl
5 #----------------------------------------------------------------------
7 class TestPanel(wx
.Panel
):
8 def __init__(self
, parent
, log
):
10 wx
.Panel
.__init
__(self
, parent
, -1)
11 self
.SetFont(wx
.Font(10, wx
.SWISS
, wx
.NORMAL
, wx
.NORMAL
, False))
13 sizer
= wx
.BoxSizer(wx
.VERTICAL
)
17 text1
= wx
.StaticText(self
, -1, "HyperLinkCtrl Example By Andrea Gavana")
18 text1
.SetFont(wx
.Font(9, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
, False, 'Verdana'))
21 sizer
.Add(text1
, 0, wx
.LEFT | wx
.TOP | wx
.BOTTOM
, 10)
23 text2
= wx
.StaticText(self
, -1, "Latest Revision: 11 May 2005")
24 text2
.SetFont(wx
.Font(8, wx
.SWISS
, wx
.NORMAL
, wx
.NORMAL
, False, 'Verdana'))
25 sizer
.Add(text2
, 0, wx
.LEFT
, 10)
30 self
._hyper
1 = hl
.HyperLinkCtrl(self
, wx
.ID_ANY
, "wxPython Main Page",
31 URL
="http://www.wxpython.org/")
32 sizer
.Add(self
._hyper
1, 0, wx
.ALL
, 10)
35 # Web link with underline rollovers, opens in window
36 self
._hyper
2 = hl
.HyperLinkCtrl(self
, wx
.ID_ANY
, "My Home Page",
37 URL
="http://xoomer.virgilio.it/infinity77/")
38 sizer
.Add(self
._hyper
2, 0, wx
.ALL
, 10)
39 self
._hyper
2.Bind(hl
.EVT_HYPERLINK_MIDDLE
, self
.OnMiddleLink
)
40 self
._hyper
2.AutoBrowse(False)
41 self
._hyper
2.SetColours("BLUE", "BLUE", "BLUE")
42 self
._hyper
2.EnableRollover(True)
43 self
._hyper
2.SetUnderlines(False, False, True)
44 self
._hyper
2.SetBold(True)
45 self
._hyper
2.OpenInSameWindow(True) # middle click to open in window
46 self
._hyper
2.SetToolTip(wx
.ToolTip("Middle-click to open in browser window"))
47 self
._hyper
2.UpdateLink()
50 # Intense link examples..
51 self
._hyper
3 = hl
.HyperLinkCtrl(self
, wx
.ID_ANY
, "wxPython Mail Archive",
52 URL
="http://lists.wxwidgets.org/")
53 sizer
.Add(self
._hyper
3, 0, wx
.ALL
, 10)
54 self
._hyper
3.Bind(hl
.EVT_HYPERLINK_RIGHT
, self
.OnRightLink
)
56 self
._hyper
3.SetLinkCursor(wx
.CURSOR_QUESTION_ARROW
)
57 self
._hyper
3.SetColours("DARK GREEN", "RED", "NAVY")
58 self
._hyper
3.SetUnderlines(False, False, False)
59 self
._hyper
3.EnableRollover(True)
60 self
._hyper
3.SetBold(True)
61 self
._hyper
3.DoPopup(False)
62 self
._hyper
3.UpdateLink()
65 self
._hyper
4 = hl
.HyperLinkCtrl(self
, wx
.ID_ANY
,
66 "Open Google In Current Browser Window?",
67 URL
="http://www.google.com")
68 sizer
.Add(self
._hyper
4, 0, wx
.ALL
, 10)
69 self
._hyper
4.Bind(hl
.EVT_HYPERLINK_LEFT
, self
.OnLink
)
70 self
._hyper
4.SetToolTip(wx
.ToolTip("Click link for yes, no, cancel dialog"))
71 self
._hyper
4.AutoBrowse(False)
77 def OnLink(self
, event
):
78 # Goto URL, demonstrates attempt to open link in current window:
79 strs
= "Open Google In Current Browser Window "
80 strs
= strs
+ "(NO Opens Google In Another Browser Window)?"
81 nResult
= wx
.MessageBox(strs
, "HyperLinkCtrl", wx
.YES_NO |
82 wx
.CANCEL | wx
.ICON_QUESTION
, self
)
85 self
._hyper
4.GotoURL("http://www.google.com", True, True)
86 elif nResult
== wx
.NO
:
87 self
._hyper
4.GotoURL("http://www.google.com", True, False)
91 def OnRightLink(self
, event
):
92 pos
= self
._hyper
3.GetPosition() + event
.GetPosition()
93 menuPopUp
= wx
.Menu("Having a nice day?")
94 ID_MENU_YES
= wx
.NewId()
95 ID_MENU_NO
= wx
.NewId()
96 menuPopUp
.Append(ID_MENU_YES
, "Yes, absolutely!")
97 menuPopUp
.Append(ID_MENU_NO
, "I've had better")
98 self
.PopupMenu(menuPopUp
)
103 def OnMiddleLink(self
, event
):
104 self
._hyper
2.GotoURL("http://xoomer.virgilio.it/infinity77/",
109 #----------------------------------------------------------------------
111 def runTest(frame
, nb
, log
):
112 win
= TestPanel(nb
, log
)
115 #----------------------------------------------------------------------
119 overview
= """<html><body>
120 <h2><center>Say something nice here</center></h2>
127 if __name__
== '__main__':
130 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])