Debian Codegraph @

example.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # Standard library imports
4 import sys
5
6 # Third party imports
7 from qtpy import QtCore, QtWidgets
8
9 # Local imports
10 import qtawesome as qta
11
12
13 class AwesomeExample(QtWidgets.QDialog):
14 def __init__(self):
15 super().__init__()
16 self.setWindowIcon(qta.icon("fa5s.icons"))
17
18 # Label for supported fonts
19 supported_fonts_label = QtWidgets.QLabel("Supported fonts (prefix)")
20 supported_fonts_label.setAlignment(QtCore.Qt.AlignCenter)
21
22 # Get FontAwesome 6.x icons by name in various styles:
23 fa6_icon = qta.icon("fa6.flag")
24 fa6_button = QtWidgets.QPushButton(fa6_icon, "Font Awesome 6! (regular)")
25
26 fa6s_icon = qta.icon("fa6s.flag")
27 fa6s_button = QtWidgets.QPushButton(fa6s_icon, "Font Awesome 6! (solid)")
28
29 fa6b_icon = qta.icon("fa6b.github")
30 fa6b_button = QtWidgets.QPushButton(fa6b_icon, "Font Awesome 6! (brands)")
31
32 # Get FontAwesome 5.x icons by name in various styles:
33 fa5_icon = qta.icon("fa5.flag")
34 fa5_button = QtWidgets.QPushButton(fa5_icon, "Font Awesome 5! (regular)")
35
36 fa5s_icon = qta.icon("fa5s.flag")
37 fa5s_button = QtWidgets.QPushButton(fa5s_icon, "Font Awesome 5! (solid)")
38
39 fa5b_icon = qta.icon("fa5b.github")
40 fa5b_button = QtWidgets.QPushButton(fa5b_icon, "Font Awesome 5! (brands)")
41
42 # Get Elusive icons by name
43 asl_icon = qta.icon("ei.asl")
44 elusive_button = QtWidgets.QPushButton(asl_icon, "Elusive Icons (ei)")
45
46 # Get Material Design icons by name
47 apn_icon = qta.icon("mdi6.access-point-network")
48 mdi6_button = QtWidgets.QPushButton(apn_icon, "Material Design (mdi, mdi6)")
49
50 # Get Phosphor by name
51 mic_icon = qta.icon("ph.microphone-fill")
52 ph_button = QtWidgets.QPushButton(mic_icon, "Phosphor Icons (ph)")
53
54 # Get Remix Icon by name
55 truck_icon = qta.icon("ri.truck-fill")
56 ri_button = QtWidgets.QPushButton(truck_icon, "Remix Icons (ri)")
57
58 # Get Microsoft's Codicons by name
59 squirrel_icon = qta.icon("msc.squirrel")
60 msc_button = QtWidgets.QPushButton(squirrel_icon, "Codicons (msc)")
61
62 # Label for style options and animations
63 styles_label = QtWidgets.QLabel("Styles")
64 styles_label.setAlignment(QtCore.Qt.AlignCenter)
65
66 # Rotated
67 rot_icon = qta.icon("mdi.access-point-network", rotated=45)
68 rot_button = QtWidgets.QPushButton(rot_icon, "Rotated Icons")
69
70 # Horizontal flip
71 hflip_icon = qta.icon("mdi.account-alert", hflip=True)
72 hflip_button = QtWidgets.QPushButton(hflip_icon, "Horizontally Flipped Icons")
73
74 # Vertical flip
75 vflip_icon = qta.icon("mdi.account-alert", vflip=True)
76 vflip_button = QtWidgets.QPushButton(vflip_icon, "Vertically Flipped Icons")
77
78 # Styling
79 styling_icon = qta.icon(
80 "fa5s.music",
81 active="fa5s.balance-scale",
82 color="blue",
83 color_active="orange",
84 )
85 music_button = QtWidgets.QPushButton(styling_icon, "Changing colors")
86
87 # Setting an alpha of 165 to the color of this icon. Alpha must be a number
88 # between 0 and 255.
89 icon_with_alpha = qta.icon("mdi.heart", color=("red", 120))
90 heart_button = QtWidgets.QPushButton(icon_with_alpha, "Setting alpha")
91
92 # Toggle
93 toggle_icon = qta.icon(
94 "fa5s.home",
95 selected="fa5s.balance-scale",
96 color_off="black",
97 color_off_active="blue",
98 color_on="orange",
99 color_on_active="yellow",
100 )
101 toggle_button = QtWidgets.QPushButton(toggle_icon, "Toggle")
102 toggle_button.setCheckable(True)
103
104 iconwidget = qta.IconWidget()
105 spin_icon = qta.icon("mdi.loading", color="red", animation=qta.Spin(iconwidget))
106 iconwidget.setIcon(spin_icon)
107 iconwidget.setIconSize(QtCore.QSize(32, 32))
108 iconwidgetholder = QtWidgets.QWidget()
109 lo = QtWidgets.QHBoxLayout()
110 lo.addWidget(iconwidget)
111 lo.addWidget(QtWidgets.QLabel("IconWidget"))
112 iconwidgetholder.setLayout(lo)
113 iconwidget2 = qta.IconWidget("mdi.web", color="blue", size=QtCore.QSize(16, 16))
114
115 # Icon drawn with the `image` option
116 drawn_image_icon = qta.icon("ri.truck-fill", options=[{"draw": "image"}])
117 drawn_image_button = QtWidgets.QPushButton(
118 drawn_image_icon, "Icon drawn as an image"
119 )
120
121 # Stack icons
122 camera_ban = qta.icon(
123 "fa5s.camera",
124 "fa5s.ban",
125 options=[
126 {"scale_factor": 0.5, "active": "fa5s.balance-scale"},
127 {"color": "red", "opacity": 0.7},
128 ],
129 )
130 stack_button = QtWidgets.QPushButton(camera_ban, "Stack")
131 stack_button.setIconSize(QtCore.QSize(32, 32))
132
133 # Stack and offset icons
134 saveall = qta.icon(
135 "fa5.save",
136 "fa5.save",
137 options=[
138 {"scale_factor": 0.8, "offset": (0.2, 0.2), "color": "gray"},
139 {"scale_factor": 0.8},
140 ],
141 )
142 saveall_button = QtWidgets.QPushButton(saveall, "Stack, offset")
143
144 # Spin icons
145 spin_button = QtWidgets.QPushButton(" Spinning icon")
146 animation1 = qta.Spin(spin_button)
147 spin_icon = qta.icon("fa5s.spinner", color="red", animation=animation1)
148 spin_button.setIcon(spin_icon)
149
150 timer1 = QtCore.QTimer()
151 timer1.singleShot(3000, animation1.stop)
152
153 # Pulse icons
154 pulse_button = QtWidgets.QPushButton(" Pulsing icon")
155 animation2 = qta.Pulse(pulse_button, autostart=False)
156 pulse_icon = qta.icon("fa5s.spinner", color="green", animation=animation2)
157 pulse_button.setIcon(pulse_icon)
158
159 timer2 = QtCore.QTimer()
160 timer2.singleShot(1500, animation2.start)
161 timer3 = QtCore.QTimer()
162 timer3.singleShot(6000, animation2.stop)
163
164 # Stacked spin icons
165 stack_spin_button = QtWidgets.QPushButton("Stack spin")
166 options = [
167 {"scale_factor": 0.4, "animation": qta.Spin(stack_spin_button)},
168 {"color": "blue"},
169 ]
170 stack_spin_icon = qta.icon("ei.asl", "fa5.square", options=options)
171 stack_spin_button.setIcon(stack_spin_icon)
172 stack_spin_button.setIconSize(QtCore.QSize(32, 32))
173
174 # Render a label with this font
175 label = QtWidgets.QLabel(chr(0xF19C) + " " + "Label")
176 label.setFont(qta.font("fa5s", 16))
177
178 # Layout
179 grid = QtWidgets.QGridLayout()
180 fonts_widgets = [
181 supported_fonts_label,
182 fa6_button,
183 fa6s_button,
184 fa6b_button,
185 fa5_button,
186 fa5s_button,
187 fa5b_button,
188 elusive_button,
189 mdi6_button,
190 ph_button,
191 ri_button,
192 msc_button,
193 ]
194 styled_widgets = [
195 styles_label,
196 music_button,
197 heart_button,
198 rot_button,
199 hflip_button,
200 vflip_button,
201 toggle_button,
202 drawn_image_button,
203 ]
204 animated_widgets = [
205 spin_button,
206 pulse_button,
207 stack_button,
208 saveall_button,
209 stack_spin_button,
210 ]
211 other_widgets = [label, iconwidgetholder, iconwidget2]
212
213 for idx, w in enumerate(fonts_widgets):
214 grid.addWidget(w, idx, 0)
215
216 for idx, w in enumerate(styled_widgets):
217 grid.addWidget(w, idx, 1)
218
219 for idx, w in enumerate(animated_widgets):
220 grid.addWidget(w, idx + len(styled_widgets), 1)
221
222 for idx, w in enumerate(other_widgets):
223 grid.addWidget(w, idx + len(styled_widgets) + len(animated_widgets), 1)
224
225 title = "Awesome"
226 args = " ".join(sys.argv[1:]).strip()
227 if args:
228 title += " (" + args + ")"
229
230 self.setLayout(grid)
231 self.setWindowTitle(title)
232 self.setMinimumWidth(520)
233 self.show()
234
235
236 def main():
237 global_defaults = {}
238 for arg in sys.argv[1:]:
239 try:
240 key, val = arg.split("=", maxsplit=1)
241 global_defaults[key] = val
242 except Exception:
243 pass
244 if global_defaults:
245 qta.set_global_defaults(**global_defaults)
246
247 app = QtWidgets.QApplication(sys.argv)
248
249 # Enable High DPI display with PyQt5
250 if hasattr(QtCore.Qt, "AA_UseHighDpiPixmaps"):
251 app.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
252
253 # Timer needed to close the example application
254 # when testing
255 QtCore.QTimer.singleShot(10000, app.exit)
256 _ = AwesomeExample()
257 sys.exit(app.exec_())
258
259
260 if __name__ == "__main__":
261 main()