-
Notifications
You must be signed in to change notification settings - Fork 9
/
HelpBrick.py
62 lines (41 loc) · 1.73 KB
/
HelpBrick.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
import webbrowser
import logging
import types
from qt import *
from BlissFramework.BaseComponents import BlissWidget
from BlissFramework import Icons
__category__ = 'gui_utils'
class ToolButton(QToolButton):
def __init__(self, parent, icon, text=None, callback=None, tooltip=None):
QToolButton.__init__(self, parent)
self.setIconSet(QIconSet(Icons.load(icon)))
if type(text) != types.StringType:
tooltip = callback
callback = text
else:
self.setTextLabel(text)
self.setTextPosition(QToolButton.BelowIcon)
self.setUsesTextLabel(True)
if callback is not None:
QObject.connect(self, SIGNAL("clicked()"), callback)
if tooltip is not None:
QToolTip.add(self, tooltip)
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
class HelpBrick(BlissWidget):
def __init__(self, *args):
BlissWidget.__init__(self, *args)
self.addProperty("help_url", "string", "http://intranet")
self.addProperty("browser", "combo", ("default", "mozilla", "netscape"), "default")
self.cmdShowHelp = ToolButton(self, "rescue", "Help !", self.cmdShowHelpClicked, "Open help web page")
QVBoxLayout(self)
self.layout().addWidget(self.cmdShowHelp)
self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
def cmdShowHelpClicked(self):
if self["browser"] != "default":
browser = webbrowser.get(self["browser"])
else:
browser = webbrowser
try:
webbrowser.open(self["help_url"])
except:
logging.getLogger().exception("%s: could not open web browser", self.name())