forked from manoharan-lab/camera-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQtConvenience.py
More file actions
76 lines (62 loc) · 2.09 KB
/
QtConvenience.py
File metadata and controls
76 lines (62 loc) · 2.09 KB
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
from PyQt4 import QtGui, QtCore
def make_label(text, wordwrap=True):
label = QtGui.QLabel()
label.setText(text)
if wordwrap:
label.setWordWrap(True)
return label
def make_VBox(items, parent=None):
return fill_layout(QtGui.QVBoxLayout(parent), items)
def make_HBox(items, parent=None):
return fill_layout(QtGui.QHBoxLayout(parent), items)
def fill_layout(layout, items):
for item in items:
if isinstance(item, int):
layout.addStretch(item)
elif isinstance(item, QtGui.QBoxLayout):
layout.addLayout(item)
else:
if isinstance(item, basestring):
item = make_label(item)
layout.addWidget(item)
return layout
def make_LineEdit(width, starting_text):
line = QtGui.QLineEdit()
line.setFixedWidth(width)
line.setText(starting_text)
return line
def make_button(label, callback, parent, shortcut=None, height=50, width=100,
tooltip=None):
"""
Handle the common boilerplate for creating buttons
Parameters
----------
label : string
The label to display on the button
callback : function
The function to call when the button is clicked
parent : QtGui.QWidget
the parent widget
height, width : int
The dimensions of the button
tooltip : string
A tooltip for the button
"""
button = QtGui.QPushButton(label, parent)
button.clicked.connect(callback)
button.setFixedHeight(height)
button.setFixedWidth(width)
if shortcut is not None:
button.setShortcut(shortcut)
if tooltip is not None:
button.setToolTip(tooltip)
return button
def make_control_group(parent, buttons, exclusive=True, default=None):
controlgroup = QtGui.QButtonGroup(QtGui.QWidget(parent))
for button in buttons:
controlgroup.addButton(button)
button.setCheckable(True)
if default is not None:
default.toggle()
controlgroup.setExclusive(exclusive)
#def make_radio_group(labels, )