This repository was archived by the owner on Sep 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcommon.py
123 lines (87 loc) · 2.94 KB
/
common.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
#!/usr/bin/python
# -*- coding: latin-1 -*-
# PyQtRibbon: a ribbon library for PyQt
# Copyright (C) 2014 RoadrunnerWMC
# This file is part of PyQtRibbon.
# PyQtRibbon is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# PyQtRibbon is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with PyQtRibbon. If not, see <http://www.gnu.org/licenses/>.
# common.py
# Contains functions used in various places by the library, but
# not intended to be used by other applications
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
Qt = QtCore.Qt
def createButton(icon=None, title=None, handler=None, shortcut=None, statusTip=None):
"""
Create and return a QToolButton with the given options
"""
btn = QtWidgets.QToolButton()
btn.setAutoRaise(True)
# generate a tooltip
tt = '<b>' + title
if shortcut != None:
if isinstance(shortcut, str):
tt += ' (' + shortcut + ')'
elif isinstance(shortcut, QtGui.QKeySequence.StandardKey):
bindings = QtGui.QKeySequence.keyBindings(shortcut)
s = ''
for b in bindings:
s += b.toString() + ', '
s = s[0:-2]
if len(s) > 0:
tt += ' (' + s + ')'
elif isinstance(shortcut, QtGui.QKeySequence):
tt += ' (' + str(shortcut.toString()) + ')'
tt += '</b>'
if statusTip != None:
tt += '<br><br>' + statusTip
# gives it a 2-space indent
btn.setToolTip(tt)
# size
btn.setIconSize(QtCore.QSize(32, 32))
sp = btn.sizePolicy()
sp.setHorizontalPolicy(sp.Expanding)
btn.setSizePolicy(sp)
# icon
if icon != None:
icon = QtGui.QIcon(icon)
btn.setIcon(icon)
# title
if title != None:
btn.setText(title)
btn.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
# handler
if handler != None:
btn.clicked.connect(handler)
# shortcut
if shortcut != None:
btn.setShortcut(shortcut)
# statusTip
if statusTip != None:
btn.setStatusTip(statusTip)
return btn
# From Reggie! Level Editor
def createHorzLine():
"""
Create and return a horizontal line widget
"""
f = QtWidgets.QFrame()
f.setFrameStyle(QtWidgets.QFrame.HLine | QtWidgets.QFrame.Sunken)
f.setEnabled(False)
return f
def createVertLine():
"""
Create and return a vertical line widget
"""
f = QtWidgets.QFrame()
f.setFrameStyle(QtWidgets.QFrame.VLine | QtWidgets.QFrame.Sunken)
f.setEnabled(False)
return f