-
Notifications
You must be signed in to change notification settings - Fork 0
/
widgets.py
142 lines (113 loc) · 3.5 KB
/
widgets.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
from ryven.NWENV import *
from qtpy.QtWidgets import (
QLabel,
QTextEdit,
QPushButton,
QFileDialog,
QVBoxLayout,
QWidget,
)
from qtpy.QtCore import Signal
from qtpy.QtGui import QFont
import os
class ChooseFileInputWidget(IWB, QPushButton):
path_chosen = Signal(str)
def __init__(self, params):
IWB.__init__(self, params)
QPushButton.__init__(self, "Select")
self.clicked.connect(self.button_clicked)
def button_clicked(self):
file_path = QFileDialog.getOpenFileName(self, "Select image")[0]
try:
file_path = os.path.relpath(file_path)
except ValueError:
return
self.path_chosen.emit(file_path)
class PathInput(IWB, QWidget):
path_chosen = Signal(str)
def __init__(self, params):
IWB.__init__(self, params)
QWidget.__init__(self)
self.path = ""
# setup UI
l = QVBoxLayout()
button = QPushButton("choose")
button.clicked.connect(self.choose_button_clicked)
l.addWidget(button)
self.path_label = QLabel("path")
l.addWidget(self.path_label)
self.setLayout(l)
def choose_button_clicked(self):
abs_f_path = QFileDialog.getSaveFileName(self, "Save")[0]
self.path = os.path.relpath(abs_f_path)
self.path_label.setText(self.path)
self.adjustSize() # important! otherwise the widget won't shrink
self.path_chosen.emit(self.path)
self.node.update_shape()
def get_state(self):
return {"path": self.path}
def set_state(self, data):
self.path = data["path"]
self.path_label.setText(self.path)
self.node.update_shape()
class WatchWidget(MWB, QTextEdit):
def __init__(self, params, base_width=256, base_height=256):
MWB.__init__(self, params)
QTextEdit.__init__(self)
c = self.node.color
self.setStyleSheet(
"""
QTextEdit{
color: """
+ c
+ """;
background: transparent;
border: none;
border-radius: 4px;
padding: 0px;
font-family: Source Code Pro;
font-size: 10pt;
}
"""
)
# border: 1px solid '''+c+''';
# self.setFont(font)
self.base_width = base_width
self.base_height = base_height
self.setFixedSize(self.base_width, self.base_height)
self.setReadOnly(True)
self.hidden_size = None
def show_val(self, new_val):
self.setText(str(new_val))
class SmallWatchWidget(MWB, QTextEdit):
def __init__(self, params, base_width=60, base_height=80):
MWB.__init__(self, params)
QTextEdit.__init__(self)
c = self.node.color
self.setStyleSheet(
"""
QTextEdit{
color: """
+ c
+ """;
background: transparent;
border: none;
border-radius: 4px;
padding: 0px;
font-family: Source Code Pro;
font-size: 10pt;
}
"""
)
# border: 1px solid '''+c+''';
# self.setFont(font)
self.base_width = base_width
self.base_height = base_height
self.setFixedSize(self.base_width, self.base_height)
self.setReadOnly(True)
self.hidden_size = None
def show_val(self, new_val):
self.setText(str(new_val))
export_widgets(
ChooseFileInputWidget, PathInput, WatchWidget, SmallWatchWidget,
)