mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-09 05:20:08 +01:00
hyperlink FONTWEIGHT_ fixes
This commit is contained in:
@@ -54,7 +54,7 @@ Usage example::
|
||||
class MyFrame(wx.Frame):
|
||||
|
||||
def __init__(self, parent):
|
||||
|
||||
|
||||
wx.Frame.__init__(self, parent, -1, "HyperLink Demo")
|
||||
|
||||
panel = wx.Panel(self, -1)
|
||||
@@ -62,12 +62,12 @@ Usage example::
|
||||
# Default Web links:
|
||||
hyper1 = hl.HyperLinkCtrl(panel, -1, "wxPython Main Page", pos=(100, 100),
|
||||
URL="http://www.wxpython.org/")
|
||||
|
||||
|
||||
|
||||
|
||||
# Web link with underline rollovers, opens in same window
|
||||
hyper2 = hl.HyperLinkCtrl(panel, -1, "My Home Page", pos=(100, 150),
|
||||
URL="http://xoomer.virgilio.it/infinity77/")
|
||||
|
||||
|
||||
hyper2.AutoBrowse(False)
|
||||
hyper2.SetColours("BLUE", "BLUE", "BLUE")
|
||||
hyper2.EnableRollover(True)
|
||||
@@ -76,7 +76,7 @@ Usage example::
|
||||
hyper2.OpenInSameWindow(True)
|
||||
hyper2.SetToolTip(wx.ToolTip("Hello World!"))
|
||||
hyper2.UpdateLink()
|
||||
|
||||
|
||||
|
||||
# our normal wxApp-derived class, as usual
|
||||
|
||||
@@ -87,7 +87,7 @@ Usage example::
|
||||
frame.Show()
|
||||
|
||||
app.MainLoop()
|
||||
|
||||
|
||||
|
||||
|
||||
Window Styles
|
||||
@@ -173,7 +173,7 @@ class HyperLinkEvent(wx.CommandEvent):
|
||||
:param `eventType`: the event type;
|
||||
:param `eventId`: the event identifier.
|
||||
"""
|
||||
|
||||
|
||||
wx.CommandEvent.__init__(self, eventType, eventId)
|
||||
self._eventType = eventType
|
||||
|
||||
@@ -184,13 +184,13 @@ class HyperLinkEvent(wx.CommandEvent):
|
||||
|
||||
:param `pos`: an instance of :class:`wx.Point`.
|
||||
"""
|
||||
|
||||
|
||||
self._pos = pos
|
||||
|
||||
|
||||
def GetPosition(self):
|
||||
""" Returns the event position. """
|
||||
|
||||
|
||||
return self._pos
|
||||
|
||||
|
||||
@@ -208,7 +208,7 @@ class HyperLinkCtrl(StaticText):
|
||||
your own custom event handling and ability to open link in a new
|
||||
or current browser window.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, parent, id=-1, label="", pos=wx.DefaultPosition,
|
||||
size=wx.DefaultSize, style=0, name="staticText", URL=""):
|
||||
"""
|
||||
@@ -227,7 +227,7 @@ class HyperLinkCtrl(StaticText):
|
||||
|
||||
:note: Pass URL="" to use the label as the url link to navigate to.
|
||||
"""
|
||||
|
||||
|
||||
StaticText.__init__(self, parent, id, label, pos, size,
|
||||
style, name)
|
||||
|
||||
@@ -246,26 +246,26 @@ class HyperLinkCtrl(StaticText):
|
||||
# default: True, True, True
|
||||
self.SetUnderlines()
|
||||
|
||||
# default: blue, violet, blue
|
||||
# default: blue, violet, blue
|
||||
self.SetColours()
|
||||
|
||||
# default: False
|
||||
self.SetVisited()
|
||||
|
||||
# default: False
|
||||
# default: False
|
||||
self.EnableRollover()
|
||||
|
||||
# default: False
|
||||
# default: False
|
||||
self.SetBold()
|
||||
|
||||
# default: wx.CURSOR_HAND
|
||||
self.SetLinkCursor()
|
||||
# default: wx.CURSOR_HAND
|
||||
self.SetLinkCursor()
|
||||
|
||||
# default True
|
||||
self.AutoBrowse()
|
||||
|
||||
# default True
|
||||
self.DoPopup()
|
||||
# default True
|
||||
self.DoPopup()
|
||||
|
||||
# default False
|
||||
self.OpenInSameWindow()
|
||||
@@ -274,9 +274,9 @@ class HyperLinkCtrl(StaticText):
|
||||
self.UpdateLink(True)
|
||||
|
||||
self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouseEvent)
|
||||
self.Bind(wx.EVT_MOTION, self.OnMouseEvent)
|
||||
|
||||
|
||||
self.Bind(wx.EVT_MOTION, self.OnMouseEvent)
|
||||
|
||||
|
||||
def GotoURL(self, URL, ReportErrors=True, NotSameWinIfPossible=False):
|
||||
"""
|
||||
Goto the specified URL.
|
||||
@@ -287,17 +287,17 @@ class HyperLinkCtrl(StaticText):
|
||||
:param `NotSameWinIfPossible`: Use ``True`` to attempt to open the URL
|
||||
in new browser window.
|
||||
"""
|
||||
|
||||
|
||||
logOff = wx.LogNull()
|
||||
|
||||
try:
|
||||
try:
|
||||
webbrowser.open(URL, new=NotSameWinIfPossible)
|
||||
self.SetVisited(True)
|
||||
self.UpdateLink(True)
|
||||
|
||||
return True
|
||||
|
||||
except:
|
||||
|
||||
except:
|
||||
self.DisplayError("Unable To Launch Browser.", ReportErrors)
|
||||
return False
|
||||
|
||||
@@ -306,7 +306,7 @@ class HyperLinkCtrl(StaticText):
|
||||
"""
|
||||
Handles the ``wx.EVT_MOUSE_EVENTS`` events for :class:`HyperLinkCtrl`.
|
||||
|
||||
:param `event`: a :class:`MouseEvent` event to be processed.
|
||||
:param `event`: a :class:`MouseEvent` event to be processed.
|
||||
"""
|
||||
|
||||
if event.Moving():
|
||||
@@ -318,8 +318,8 @@ class HyperLinkCtrl(StaticText):
|
||||
fontTemp = self.GetFont()
|
||||
fontTemp.SetUnderlined(self._RolloverUnderline)
|
||||
if self._Bold:
|
||||
fontTemp.SetWeight(wx.BOLD)
|
||||
|
||||
fontTemp.SetWeight(wx.FONTWEIGHT_BOLD)
|
||||
|
||||
needRefresh = False
|
||||
|
||||
if self.GetFont() != fontTemp:
|
||||
@@ -332,16 +332,16 @@ class HyperLinkCtrl(StaticText):
|
||||
|
||||
if needRefresh:
|
||||
self.Refresh()
|
||||
|
||||
else:
|
||||
# Restore The Original Cursor
|
||||
|
||||
else:
|
||||
# Restore The Original Cursor
|
||||
self.SetCursor(wx.NullCursor)
|
||||
if self._EnableRollover:
|
||||
self.UpdateLink(True)
|
||||
|
||||
|
||||
if event.LeftUp():
|
||||
# Left Button Was Pressed
|
||||
if self._AutoBrowse:
|
||||
if self._AutoBrowse:
|
||||
self.GotoURL(self._URL, self._ReportErrors,
|
||||
self._NotSameWinIfPossible)
|
||||
|
||||
@@ -363,8 +363,8 @@ class HyperLinkCtrl(StaticText):
|
||||
self.PopupMenu(menuPopUp, wx.Point(event.x, event.y))
|
||||
menuPopUp.Destroy()
|
||||
self.Unbind(wx.EVT_MENU, id=wxHYPERLINKS_POPUP_COPY)
|
||||
|
||||
else:
|
||||
|
||||
else:
|
||||
eventOut = HyperLinkEvent(wxEVT_HYPERLINK_RIGHT, self.GetId())
|
||||
eventOut.SetEventObject(self)
|
||||
eventOut.SetPosition(event.GetPosition())
|
||||
@@ -385,7 +385,7 @@ class HyperLinkCtrl(StaticText):
|
||||
Handles the ``wx.EVT_MENU`` event for :class:`HyperLinkCtrl`.
|
||||
|
||||
:param `event`: a :class:`wx.MenuEvent` event to be processed.
|
||||
|
||||
|
||||
:note: This method copies the data from the :class:`HyperLinkCtrl` to the clipboard.
|
||||
"""
|
||||
|
||||
@@ -405,8 +405,8 @@ class HyperLinkCtrl(StaticText):
|
||||
- Link visited;
|
||||
- New link;
|
||||
|
||||
:param `OnRefresh`: ``True`` to refresh the control, ``False`` otherwise.
|
||||
|
||||
:param `OnRefresh`: ``True`` to refresh the control, ``False`` otherwise.
|
||||
|
||||
"""
|
||||
|
||||
fontTemp = self.GetFont()
|
||||
@@ -414,19 +414,19 @@ class HyperLinkCtrl(StaticText):
|
||||
if self._Visited:
|
||||
self.SetForegroundColour(self._VisitedColour)
|
||||
fontTemp.SetUnderlined(self._VisitedUnderline)
|
||||
|
||||
|
||||
else:
|
||||
|
||||
self.SetForegroundColour(self._LinkColour)
|
||||
fontTemp.SetUnderlined(self._LinkUnderline)
|
||||
|
||||
if self._Bold:
|
||||
fontTemp.SetWeight(wx.BOLD)
|
||||
fontTemp.SetWeight(wx.FONTWEIGHT_BOLD)
|
||||
|
||||
if self.GetFont() != fontTemp:
|
||||
self.SetFont(fontTemp)
|
||||
|
||||
self.Refresh(OnRefresh)
|
||||
self.Refresh(OnRefresh)
|
||||
|
||||
|
||||
def DisplayError(self, ErrorMessage, ReportErrors=True):
|
||||
@@ -438,7 +438,7 @@ class HyperLinkCtrl(StaticText):
|
||||
:param `ReportErrors`: ``True`` to display error dialog if an error occurrs
|
||||
navigating to the URL.
|
||||
"""
|
||||
|
||||
|
||||
if ReportErrors:
|
||||
wx.MessageBox(ErrorMessage, "HyperLinks Error", wx.OK | wx.CENTRE | wx.ICON_ERROR)
|
||||
|
||||
@@ -458,21 +458,21 @@ class HyperLinkCtrl(StaticText):
|
||||
:param `rollover`: a valid :class:`wx.Colour` to use as text foreground for links
|
||||
rollovers (default=BLUE).
|
||||
"""
|
||||
|
||||
|
||||
self._LinkColour = link
|
||||
self._VisitedColour = visited
|
||||
self._LinkRolloverColour = rollover
|
||||
|
||||
|
||||
|
||||
def GetColours(self):
|
||||
"""
|
||||
Gets the colours for the link, the visited link and the mouse
|
||||
rollover.
|
||||
"""
|
||||
|
||||
|
||||
return self._LinkColour, self._VisitedColour, self._LinkRolloverColour
|
||||
|
||||
|
||||
|
||||
def SetUnderlines(self, link=True, visited=True, rollover=True):
|
||||
"""
|
||||
Sets whether the text should be underlined or not for new links, visited
|
||||
@@ -485,7 +485,7 @@ class HyperLinkCtrl(StaticText):
|
||||
:param `rollover`: ``True`` to set the text of rollovers as underlined,
|
||||
``False`` otherwise.
|
||||
"""
|
||||
|
||||
|
||||
self._LinkUnderline = link
|
||||
self._RolloverUnderline = rollover
|
||||
self._VisitedUnderline = visited
|
||||
@@ -496,9 +496,9 @@ class HyperLinkCtrl(StaticText):
|
||||
Returns if link is underlined, if the mouse rollover is
|
||||
underlined and if the visited link is underlined.
|
||||
"""
|
||||
|
||||
|
||||
return self._LinkUnderline, self._RolloverUnderline, self._VisitedUnderline
|
||||
|
||||
|
||||
|
||||
def SetLinkCursor(self, cur=wx.CURSOR_HAND):
|
||||
"""
|
||||
@@ -506,13 +506,13 @@ class HyperLinkCtrl(StaticText):
|
||||
|
||||
:param `cur`: an integer representing a :ref:`Cursor` constant.
|
||||
"""
|
||||
|
||||
|
||||
self._CursorHand = wx.Cursor(cur)
|
||||
|
||||
|
||||
def GetLinkCursor(self):
|
||||
""" Gets the link cursor. """
|
||||
|
||||
|
||||
return self._CursorHand
|
||||
|
||||
|
||||
@@ -522,13 +522,13 @@ class HyperLinkCtrl(StaticText):
|
||||
|
||||
:param `Visited`: ``True`` to set a link as visited, ``False`` otherwise.
|
||||
"""
|
||||
|
||||
|
||||
self._Visited = Visited
|
||||
|
||||
|
||||
|
||||
def GetVisited(self):
|
||||
""" Returns whether a link has been visited or not. """
|
||||
|
||||
|
||||
return self._Visited
|
||||
|
||||
|
||||
@@ -539,13 +539,13 @@ class HyperLinkCtrl(StaticText):
|
||||
:param `Bold`: ``True`` to set the :class:`HyperLinkCtrl` label as bold, ``False``
|
||||
otherwise.
|
||||
"""
|
||||
|
||||
|
||||
self._Bold = Bold
|
||||
|
||||
|
||||
|
||||
def GetBold(self):
|
||||
""" Returns whether the :class:`HyperLinkCtrl` has text in bold or not. """
|
||||
|
||||
|
||||
return self._Bold
|
||||
|
||||
|
||||
@@ -555,13 +555,13 @@ class HyperLinkCtrl(StaticText):
|
||||
|
||||
:param `URL`: the new URL associated with :class:`HyperLinkCtrl`.
|
||||
"""
|
||||
|
||||
|
||||
self._URL = URL
|
||||
|
||||
|
||||
|
||||
def GetURL(self):
|
||||
""" Retrieve the URL associated to the :class:`HyperLinkCtrl`. """
|
||||
|
||||
|
||||
return self._URL
|
||||
|
||||
|
||||
@@ -572,7 +572,7 @@ class HyperLinkCtrl(StaticText):
|
||||
:param `NotSameWinIfPossible`: ``True`` to open an hyperlink in a new browser
|
||||
window, ``False`` to use an existing browser window.
|
||||
"""
|
||||
|
||||
|
||||
self._NotSameWinIfPossible = NotSameWinIfPossible
|
||||
|
||||
|
||||
@@ -583,10 +583,10 @@ class HyperLinkCtrl(StaticText):
|
||||
:param `EnableRollover`: ``True`` to enable text effects during rollover,
|
||||
``False`` to disable them.
|
||||
"""
|
||||
|
||||
|
||||
self._EnableRollover = EnableRollover
|
||||
|
||||
|
||||
|
||||
def ReportErrors(self, ReportErrors=True):
|
||||
"""
|
||||
Set whether to report browser errors or not.
|
||||
@@ -594,7 +594,7 @@ class HyperLinkCtrl(StaticText):
|
||||
:param `ReportErrors`: Use ``True`` to display error dialog if an error
|
||||
occurrs navigating to the URL;
|
||||
"""
|
||||
|
||||
|
||||
self._ReportErrors = ReportErrors
|
||||
|
||||
|
||||
@@ -604,10 +604,10 @@ class HyperLinkCtrl(StaticText):
|
||||
|
||||
:param `AutoBrowse`: ``True`` to automatically browse to an URL when clicked,
|
||||
``False`` otherwise.
|
||||
|
||||
|
||||
:note: Set `AutoBrowse` to ``False`` to receive ``EVT_HYPERLINK_LEFT`` events.
|
||||
"""
|
||||
|
||||
|
||||
self._AutoBrowse = AutoBrowse
|
||||
|
||||
|
||||
@@ -617,10 +617,10 @@ class HyperLinkCtrl(StaticText):
|
||||
|
||||
:param `DoPopup`: ``True`` to show a popup menu on right click, ``False`` otherwise.
|
||||
"""
|
||||
|
||||
|
||||
self._DoPopup = DoPopup
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -629,7 +629,7 @@ if __name__ == '__main__':
|
||||
class MyFrame(wx.Frame):
|
||||
|
||||
def __init__(self, parent):
|
||||
|
||||
|
||||
wx.Frame.__init__(self, parent, -1, "HyperLink Demo")
|
||||
|
||||
panel = wx.Panel(self, -1)
|
||||
@@ -637,12 +637,12 @@ if __name__ == '__main__':
|
||||
# Default Web links:
|
||||
hyper1 = HyperLinkCtrl(panel, -1, "wxPython Main Page", pos=(100, 100),
|
||||
URL="http://www.wxpython.org/")
|
||||
|
||||
|
||||
|
||||
|
||||
# Web link with underline rollovers, opens in same window
|
||||
hyper2 = HyperLinkCtrl(panel, -1, "My Home Page", pos=(100, 150),
|
||||
URL="http://xoomer.virgilio.it/infinity77/")
|
||||
|
||||
|
||||
hyper2.AutoBrowse(False)
|
||||
hyper2.SetColours("BLUE", "BLUE", "BLUE")
|
||||
hyper2.EnableRollover(True)
|
||||
@@ -651,7 +651,7 @@ if __name__ == '__main__':
|
||||
hyper2.OpenInSameWindow(True)
|
||||
hyper2.SetToolTip(wx.ToolTip("Hello World!"))
|
||||
hyper2.UpdateLink()
|
||||
|
||||
|
||||
|
||||
# our normal wxApp-derived class, as usual
|
||||
|
||||
|
||||
Reference in New Issue
Block a user