-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunctions_widget.py
More file actions
233 lines (191 loc) · 7.93 KB
/
functions_widget.py
File metadata and controls
233 lines (191 loc) · 7.93 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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
from PyQt5.QtCore import Qt
from dynamic_menu_widgets import ScrollableMenuWidget
from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout, QWidget, QTextEdit, QPushButton, QLineEdit
from PyQt5.QtGui import QFont
from datetime import datetime
class ButtonMenuWidget(QWidget):
def __init__(self):
super().__init__()
#Widget definition
self.clear_button = QPushButton()
self.mod_button = QPushButton()
self.pull_button = QPushButton()
#DEBUG:
self.add_fake_node = QPushButton()
#Widget text
self.clear_button.setText("Clear")
self.mod_button.setText("Mode: Sync") #Defaul: sync modality
self.pull_button.setText("Pull")
#DEBUG:
self.add_fake_node.setText("Add fake node")
#Widget text button
font = QFont("JetBrains Mono", 10)
self.clear_button.setFont(font)
self.mod_button.setFont(font)
self.pull_button.setFont(font)
self.add_fake_node.setFont(font)
#Sizes
self.clear_button.setFixedSize(120,50)
self.mod_button.setFixedSize(120, 90)
#DEBUG:
self.add_fake_node.setFixedSize(120,120)
self.pull_button.setFixedSize(120, 50)
self.setFixedHeight(400)
self.setFixedWidth(200)
#For added customization we define a name for each widget
self.setObjectName("ButtonMenu")
self.pull_button.setObjectName("PullButton")
self.mod_button.setObjectName("ModButton")
self.clear_button.setObjectName("ClearButton")
#Layout: Vertical
layout = QVBoxLayout()
layout.setSpacing(10)
layout.setContentsMargins(40,0,0,0)
#Add widgets
layout.addWidget(self.clear_button)
layout.addWidget(self.mod_button)
layout.addWidget(self.pull_button)
#DEBUG:
#layout.addWidget(self.add_fake_node)
#Set layout
self.setLayout(layout)
#Apply default css
self.apply_css()
def apply_css(self):
# MUST: By default, for efficiency reason, css on custom widget is disabled
# to enable it:
self.setAttribute(Qt.WA_StyledBackground, True)
self.setStyleSheet("""
QWidget#ButtonMenu {
background-color: rgb(67,110,144);
border-top-right-radius: 15px;
border-bottom-right-radius: 15px;
}
QPushButton {
color: white;
border-radius: 10px;
background-color: #044b80;
border: 3px solid white;
}
QPushButton:hover {
background-color: #06538c;
}
""")
def change_mod_text(self, modality : str):
self.mod_button.setText(modality)
class FunctionsMenuWidget(QWidget):
def __init__(self):
super().__init__()
#Widget definition
self.function_menu = ScrollableMenuWidget()
self.button_menu = ButtonMenuWidget()
#For added customization we define a name for each widget
self.setObjectName("Widget")
#Size: no width limit (16777215 is a PyQt constant)
self.function_menu.setMaximumWidth(16777215)
self.function_menu.setMaximumHeight(400)
#Layout: Horizontal
layout = QHBoxLayout()
layout.setSpacing(0)
layout.setContentsMargins(0, 0, 0, 0)
#Adding widgets
layout.addWidget(self.function_menu)
layout.addWidget(self.button_menu)
#Set layout
self.setLayout(layout)
#Apply default css
self.apply_css()
def apply_css(self):
self.function_menu.menu_widget.setStyleSheet("""
QWidget#Menu{
background-color: rgb(67,110,144);
border-top-left-radius: 15px;
border-bottom-left-radius: 15px;
margin: 0px;
}
""")
self.function_menu.setStyleSheet("""
QWidget#ScrollableMenu{
background-color: rgb(67,110,144);
border-top-left-radius: 15px;
border-bottom-left-radius: 15px;
margin: 0px;
border: 0px;
}
QScrollBar:vertical, QScrollBar:horizontal {
width: 0px;
height: 0px;
}
""")
class ScreenAndInputWidget(QWidget):
def __init__(self):
super().__init__()
#Widget definition
self.log = QTextEdit()
self.input = QLineEdit()
# Tweak: Disable editing from the user
self.log.setReadOnly(True)
#Sizes
self.log.setMaximumHeight(300)
self.log.setMinimumHeight(230)
self.input.setFixedHeight(70)
#Input default text
self.input.setPlaceholderText(" Params input block: Try n:5 or string=Ciao !")
#Input font sizes
font = QFont("Jetbrains mono",15)
self.input.setFont(font)
#Layout: vertical
layout = QVBoxLayout()
#No spaces
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)
#Add widgets:
layout.addWidget(self.log)
layout.addWidget(self.input)
#Set layout
self.setLayout(layout)
class FunctionsConsoleWidget(QWidget):
def __init__(self):
super().__init__()
#Widget definition
self.log = ScreenAndInputWidget()
self.function_menu = FunctionsMenuWidget()
#Sizes
self.log.setMaximumHeight(370)
self.log.setMinimumHeight(300)
#Layout: vertical
layout = QVBoxLayout()
#Left and right margins
layout.setContentsMargins(50, 50, 50, 0)
layout.setSpacing(0)
#Add elements:
layout.addWidget(self.log)
layout.addWidget(self.function_menu)
#Set layout
self.setLayout(layout)
#Apply css
self.apply_css()
#Welcome text
self.add_row_text("System","Welcome!",True)
def apply_css(self):
self.log.setStyleSheet("""
border: 3px solid #044b80;
""")
def add_row_text(self,subject : str, text : str, good: bool):
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
color = "#b30412"
notification = " !"
if good:
color = "#32a852"
notification = " ✓"
self.log.log.append(f"""
<span style="font-size: 26px">
<span style="background-color: rgb(3,63,107); color: white; padding: 20px;"> {current_time}
<span style="background-color: #06538c; color: white;"> {subject}
<span style="background-color: {color}; color: white;">{notification}
</span></span></span> {text}
</span>
""")
def clear_text(self):
self.log.log.setHtml("")