This repository has been archived by the owner on Apr 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
styles.py
172 lines (133 loc) · 4.54 KB
/
styles.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/python
# coding: utf-8
class MyStyles():
"""Class to handle the styling of the program.
We do it here and not in css files because some css
is programatically generated, to handle different resolutions"""
# Double { for placeholders
# http://stackoverflow.com/questions/9623134/python-format-throws-keyerror
def __init__(self, app):
self.font = app.font()
screen_rect = app.desktop().screenGeometry()
self.height = screen_rect.height()
# Scale by screen resolution: HD or not
if self.height >= 900:
self.FONT_SIZE = 12
self.DIMENSION = 40
self.ICON_SIZE_BIG = 36
self.ICON_SIZE_SMALL = 30
self.RADIUS = 18
else:
self.FONT_SIZE = 8
self.DIMENSION = 30
self.ICON_SIZE_BIG = 27
self.ICON_SIZE_SMALL = 23
self.RADIUS = 12
def styleToolbar(self):
"""Define the style for the toolbar"""
stylesheet = """
QPushButton[accessibleName="toolbar_text_button"]
{{
background: #EF4C39;
color: white;
border-radius: {2}px;
padding: {4}px;
font-weight: bold;
margin-left: {3}px;
margin-right: {3}px;
}}
QPushButton[accessibleName="toolbar_round_button"]
{{
border: 0px;
margin-top: {3}px;
max-width: {0}px;
max-height: {0}px;
min-width: {0}px;
min-height: {0}px;
background: transparent;
margin-left: {2}px;
}}
QLineEdit
{{
margin-left: {3}px;
margin-top: {3}px;
}}
QPushButton[accessibleName="toolbar_round_button"]:pressed
{{
background: white;
border-radius: {1}px;
}}
QLineEdit > QToolButton
{{
margin-top: 5px;
}}
"""
stylesheet = stylesheet.format(self.DIMENSION, self.DIMENSION / 2,
self.DIMENSION / 4, self.DIMENSION / 8,
self.DIMENSION / 5)
return stylesheet
def styleGeneral(self):
"""Define the general style"""
# NOTE: for the zoom action to be enabled in QTextBrowser, the font
# can't have a fixed size
stylesheet = """
QToolBar, QScrollArea, QTabWidget, QSplitter, .QWidget
{
background: #726E73;
border: 0px;
}
QLabel
{
color: white
}
QWidget:not (QTextBrowser)
{
font-size: FONT_SIZEpt
}
"""
stylesheet = stylesheet.replace('FONT_SIZE', str(self.FONT_SIZE))
return stylesheet
def styleButtons(self):
"""Define the style for the buttons"""
stylesheet = """
QPushButton[accessibleName="round_button_article"]
{{
border: 0px;
margin-top: {2}px;
max-width: {0}px;
max-height: {0}px;
min-width: {0}px;
min-height: {0}px;
background: transparent;
}}
QPushButton[accessibleName="round_button_article"]:pressed
{{
background: white;
border-radius: {4}px;
}}
QPushButton[accessibleName="button_text_left"]
{{
background: grey;
color: white;
border-radius: {1}px;
padding: {3}px;
margin-left: {1}px;
margin-right: {1}px;
}}
QPushButton[accessibleName="button_text_left"]:checked
{{
background: #EF4C39;
}}
"""
# Scale from ICON_SIZE_BIG, not from dimension, otherwiser the blank
# around the button_pressed is too wide
stylesheet = stylesheet.format(self.ICON_SIZE_BIG, self.DIMENSION / 4,
self.DIMENSION / 8, self.DIMENSION / 5,
self.RADIUS)
return stylesheet
if __name__ == '__main__':
from PyQt5 import QtGui
import sys
app = QtGui.QApplication(sys.argv)
test = MyStyles(app)
print(test.styleToolbar())