]>
Commit | Line | Data |
---|---|---|
a6987674 RD |
1 | |
2 | import wx | |
3 | import wx.lib.hyperlink as hl | |
4 | ||
5 | #---------------------------------------------------------------------- | |
6 | ||
7 | class TestPanel(wx.Panel): | |
8 | def __init__(self, parent, log): | |
9 | self.log = log | |
10 | wx.Panel.__init__(self, parent, -1) | |
11 | self.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False)) | |
12 | ||
13 | sizer = wx.BoxSizer(wx.VERTICAL) | |
14 | self.SetSizer(sizer) | |
15 | ||
16 | # Creator credits | |
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')) | |
19 | ||
20 | sizer.Add((0,10)) | |
21 | sizer.Add(text1, 0, wx.LEFT | wx.TOP | wx.BOTTOM, 10) | |
22 | ||
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) | |
26 | ||
27 | sizer.Add((0,25)) | |
28 | ||
29 | # Default Web links: | |
30 | self._hyper1 = hl.HyperLinkCtrl(self, wx.ID_ANY, "wxPython Main Page", | |
31 | URL="http://www.wxpython.org/") | |
32 | sizer.Add(self._hyper1, 0, wx.ALL, 10) | |
33 | ||
34 | ||
35 | # Web link with underline rollovers, opens in window | |
36 | self._hyper2 = hl.HyperLinkCtrl(self, wx.ID_ANY, "My Home Page", | |
37 | URL="http://xoomer.virgilio.it/infinity77/") | |
38 | sizer.Add(self._hyper2, 0, wx.ALL, 10) | |
39 | self._hyper2.Bind(hl.EVT_HYPERLINK_MIDDLE, self.OnMiddleLink) | |
40 | self._hyper2.AutoBrowse(False) | |
41 | self._hyper2.SetColours("BLUE", "BLUE", "BLUE") | |
42 | self._hyper2.EnableRollover(True) | |
43 | self._hyper2.SetUnderlines(False, False, True) | |
44 | self._hyper2.SetBold(True) | |
45 | self._hyper2.OpenInSameWindow(True) # middle click to open in window | |
46 | self._hyper2.SetToolTip(wx.ToolTip("Middle-click to open in browser window")) | |
47 | self._hyper2.UpdateLink() | |
48 | ||
49 | ||
50 | # Intense link examples.. | |
51 | self._hyper3 = hl.HyperLinkCtrl(self, wx.ID_ANY, "wxPython Mail Archive", | |
52 | URL="http://lists.wxwidgets.org/") | |
53 | sizer.Add(self._hyper3, 0, wx.ALL, 10) | |
54 | self._hyper3.Bind(hl.EVT_HYPERLINK_RIGHT, self.OnRightLink) | |
55 | ||
56 | self._hyper3.SetLinkCursor(wx.CURSOR_QUESTION_ARROW) | |
5643bdef | 57 | self._hyper3.SetColours("DARK GREEN", "RED", "NAVY") |
a6987674 RD |
58 | self._hyper3.SetUnderlines(False, False, False) |
59 | self._hyper3.EnableRollover(True) | |
60 | self._hyper3.SetBold(True) | |
61 | self._hyper3.DoPopup(False) | |
62 | self._hyper3.UpdateLink() | |
63 | ||
64 | ||
65 | self._hyper4 = hl.HyperLinkCtrl(self, wx.ID_ANY, | |
66 | "Open Google In Current Browser Window?", | |
67 | URL="http://www.google.com") | |
68 | sizer.Add(self._hyper4, 0, wx.ALL, 10) | |
69 | self._hyper4.Bind(hl.EVT_HYPERLINK_LEFT, self.OnLink) | |
70 | self._hyper4.SetToolTip(wx.ToolTip("Click link for yes, no, cancel dialog")) | |
71 | self._hyper4.AutoBrowse(False) | |
72 | ||
73 | ||
74 | ||
75 | ||
76 | ||
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) | |
83 | ||
84 | if nResult == wx.YES: | |
85 | self._hyper4.GotoURL("http://www.google.com", True, True) | |
86 | elif nResult == wx.NO: | |
87 | self._hyper4.GotoURL("http://www.google.com", True, False) | |
88 | ||
89 | ||
90 | ||
91 | def OnRightLink(self, event): | |
92 | pos = 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, self._hyper3.GetPosition()) | |
99 | menuPopUp.Destroy() | |
100 | ||
101 | ||
102 | ||
103 | def OnMiddleLink(self, event): | |
104 | self._hyper2.GotoURL("http://xoomer.virgilio.it/infinity77/", | |
105 | True, True) | |
106 | ||
107 | ||
108 | ||
109 | #---------------------------------------------------------------------- | |
110 | ||
111 | def runTest(frame, nb, log): | |
112 | win = TestPanel(nb, log) | |
113 | return win | |
114 | ||
115 | #---------------------------------------------------------------------- | |
116 | ||
117 | ||
118 | ||
119 | overview = """<html><body> | |
120 | <h2><center>Say something nice here</center></h2> | |
121 | ||
122 | </body></html> | |
123 | """ | |
124 | ||
125 | ||
126 | ||
127 | if __name__ == '__main__': | |
128 | import sys,os | |
129 | import run | |
130 | run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) | |
131 | ||
132 |