Skip to content

Commit a7a7bd0

Browse files
committed
stylesheet clean up
1 parent 66c3ea0 commit a7a7bd0

File tree

4 files changed

+110
-80
lines changed

4 files changed

+110
-80
lines changed

NodeGraphQt/widgets/dialogs.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
from Qt import QtWidgets
44

5-
current_dir = os.path.expanduser('~')
5+
_current_user_directory = os.path.expanduser('~')
66

77

88
def set_dir(file):
9-
global current_dir
9+
global _current_user_directory
1010
if os.path.isdir(file):
11-
current_dir = file
11+
_current_user_directory = file
1212
elif os.path.isfile(file):
13-
current_dir = os.path.split(file)[0]
13+
_current_user_directory = os.path.split(file)[0]
1414

1515

1616
class FileDialog(object):
@@ -19,7 +19,7 @@ class FileDialog(object):
1919
def getSaveFileName(parent=None, title='Save File', file_dir=None,
2020
ext_filter='*'):
2121
if not file_dir:
22-
file_dir = current_dir
22+
file_dir = _current_user_directory
2323
file_dlg = QtWidgets.QFileDialog.getSaveFileName(
2424
parent, title, file_dir, ext_filter)
2525
file = file_dlg[0] or None
@@ -31,7 +31,7 @@ def getSaveFileName(parent=None, title='Save File', file_dir=None,
3131
def getOpenFileName(parent=None, title='Open File', file_dir=None,
3232
ext_filter='*'):
3333
if not file_dir:
34-
file_dir = current_dir
34+
file_dir = _current_user_directory
3535
file_dlg = QtWidgets.QFileDialog.getOpenFileName(
3636
parent, title, file_dir, ext_filter)
3737
file = file_dlg[0] or None

NodeGraphQt/widgets/node_graph.py

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,52 @@
11
from Qt import QtWidgets
22

3+
from NodeGraphQt.constants import (
4+
NODE_SEL_BORDER_COLOR,
5+
VIEWER_BG_COLOR,
6+
VIEWER_GRID_COLOR
7+
)
38
from NodeGraphQt.widgets.viewer_nav import NodeNavigationWidget
49

5-
STYLE_NODE_GRAPH_TAB = '''
6-
QTabWidget::pane {
7-
border: 0px solid black;
8-
background: rgb(45, 45, 45);
9-
top:-1px;
10-
}
11-
QTabBar::tab {
12-
color: rgba(255, 255, 255, 45);
13-
background: rgb(35, 35, 35);
14-
border: 0px solid black;
15-
padding: 10px 20px;
16-
}
17-
QTabBar::tab:selected {
18-
color: rgb(255, 255, 255);
19-
background: rgb(45, 45, 45);
20-
margin-bottom: -1px;
21-
}
22-
'''
23-
2410

2511
class NodeGraphWidget(QtWidgets.QTabWidget):
2612

2713
def __init__(self, parent=None):
2814
super(NodeGraphWidget, self).__init__(parent)
2915
self.setTabsClosable(True)
3016
self.setTabBarAutoHide(True)
31-
self.setStyleSheet(STYLE_NODE_GRAPH_TAB)
17+
text_color = self.palette().text().color().toTuple()
18+
style_dict = {
19+
'QTabWidget::pane': {
20+
'background': 'rgb({0},{1},{2})'.format(*VIEWER_BG_COLOR),
21+
'border': '0px',
22+
'border-top': '1px solid rgb({0},{1},{2})'
23+
.format(*VIEWER_BG_COLOR),
24+
},
25+
'QTabBar::tab': {
26+
'background': 'rgb({0},{1},{2})'.format(*VIEWER_BG_COLOR),
27+
'border': '0px solid black',
28+
'color': 'rgba({0},{1},{2},45)'.format(*text_color),
29+
'min-width': '10px',
30+
'padding': '8px 20px',
31+
},
32+
'QTabBar::tab:selected': {
33+
'color': 'rgb({0},{1},{2})'.format(*text_color),
34+
'background': 'rgb({0},{1},{2})'.format(*VIEWER_BG_COLOR),
35+
'margin-bottom': '-1px',
36+
},
37+
'QTabBar::tab:hover': {
38+
'color': 'rgb({0}, {1}, {2})'.format(*NODE_SEL_BORDER_COLOR),
39+
'background': 'rgb({0}, {1}, {2})'.format(*VIEWER_GRID_COLOR),
40+
}
41+
}
42+
stylesheet = ''
43+
for css_class, css in style_dict.items():
44+
style = '{} {{\n'.format(css_class)
45+
for elm_name, elm_val in css.items():
46+
style += ' {}:{};\n'.format(elm_name, elm_val)
47+
style += '}\n'
48+
stylesheet += style
49+
self.setStyleSheet(stylesheet)
3250

3351
def add_viewer(self, viewer, name, node_id):
3452
self.addTab(viewer, name)

NodeGraphQt/widgets/node_widgets.py

Lines changed: 60 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,9 @@
11
#!/usr/bin/python
2-
import re
3-
42
from Qt import QtCore, QtWidgets
53

6-
from NodeGraphQt.constants import Z_VAL_NODE_WIDGET
4+
from NodeGraphQt.constants import VIEWER_GRID_COLOR, Z_VAL_NODE_WIDGET
75
from NodeGraphQt.errors import NodeWidgetError
86

9-
REGEX = re.compile(r'((?: +)*([\w-]+):(?: )*<\$VALUE>;)')
10-
11-
STYLE_NODE_GROUPBOX = '''
12-
QGroupBox {
13-
background-color: rgba(0, 0, 0, 0);
14-
border: 0px solid rgba(0, 0, 0, 0);
15-
margin-top: 1px;
16-
padding-top: <$VALUE>;
17-
padding-bottom: 2px;
18-
padding-left: 1px;
19-
padding-right: 1px;
20-
font-size: 8pt;
21-
}
22-
QGroupBox::title {
23-
subcontrol-origin: margin;
24-
subcontrol-position: <$VALUE>;
25-
margin-left: <$VALUE>;
26-
margin-right: <$VALUE>;
27-
color: rgba(255, 255, 255, 85);
28-
padding: 0px;
29-
}
30-
'''
31-
STYLE_NODE_LINE_EDIT = '''
32-
QLineEdit {
33-
border: 1px solid rgb(90, 90, 90);
34-
border-radius: 0px;
35-
color: rgba(255, 255, 255, 150);
36-
background: rgba(0, 0, 0, 80);
37-
selection-background-color: rgba(255, 198, 10, 155);
38-
}
39-
'''
40-
417

428
class _NodeGroupBox(QtWidgets.QGroupBox):
439

@@ -53,26 +19,44 @@ def setTitle(self, text):
5319
super(_NodeGroupBox, self).setTitle(text)
5420

5521
def setTitleAlign(self, align='center'):
56-
style_param = {
57-
'padding-top': '14px' if self.title() else '2px',
58-
'subcontrol-position': 'top'
22+
text_color = self.palette().text().color().toTuple()
23+
style_dict = {
24+
'QGroupBox': {
25+
'background-color': 'rgba(0, 0, 0, 0)',
26+
'border': '0px solid rgba(0, 0, 0, 0)',
27+
'margin-top': '1px',
28+
'padding-bottom': '2px',
29+
'padding-left': '1px',
30+
'padding-right': '1px',
31+
'font-size': '8pt',
32+
},
33+
'QGroupBox::title': {
34+
'subcontrol-origin': 'margin',
35+
'color': 'rgba({0}, {1}, {2}, 100)'.format(*text_color),
36+
'padding': '0px',
37+
}
5938
}
39+
if self.title():
40+
style_dict['QGroupBox']['padding-top'] = '14px'
41+
else:
42+
style_dict['QGroupBox']['padding-top'] = '2px'
43+
6044
if align == 'center':
61-
style_param['subcontrol-position'] += ' center'
45+
style_dict['QGroupBox::title']['subcontrol-position'] = 'top center'
6246
elif align == 'left':
63-
style_param['subcontrol-position'] += ' left'
64-
style_param['margin-left'] = '4px'
47+
style_dict['QGroupBox::title']['subcontrol-position'] += 'top left'
48+
style_dict['QGroupBox::title']['margin-left'] = '4px'
6549
elif align == 'right':
66-
style_param['subcontrol-position'] += ' right'
67-
style_param['margin-right'] = '4px'
68-
style = STYLE_NODE_GROUPBOX
69-
for find_str, key in REGEX.findall(style):
70-
if key not in style_param:
71-
style = style.replace(find_str, '')
72-
continue
73-
replace_str = find_str.replace('<$VALUE>', style_param[key])
74-
style = style.replace(find_str, replace_str)
75-
self.setStyleSheet(style)
50+
style_dict['QGroupBox::title']['subcontrol-position'] += 'top right'
51+
style_dict['QGroupBox::title']['margin-right'] = '4px'
52+
stylesheet = ''
53+
for css_class, css in style_dict.items():
54+
style = '{} {{\n'.format(css_class)
55+
for elm_name, elm_val in css.items():
56+
style += ' {}:{};\n'.format(elm_name, elm_val)
57+
style += '}\n'
58+
stylesheet += style
59+
self.setStyleSheet(stylesheet)
7660

7761
def add_node_widget(self, widget):
7862
self.layout().addWidget(widget)
@@ -337,9 +321,31 @@ class NodeLineEdit(NodeBaseWidget):
337321

338322
def __init__(self, parent=None, name='', label='', text=''):
339323
super(NodeLineEdit, self).__init__(parent, name, label)
324+
plt = self.palette()
325+
bg_color = plt.alternateBase().color().toTuple()
326+
text_color = plt.text().color().toTuple()
327+
text_sel_color = plt.highlightedText().color().toTuple()
328+
style_dict = {
329+
'QLineEdit': {
330+
'background': 'rgba({0},{1},{2},20)'.format(*bg_color),
331+
'border': '1px solid rgb({0},{1},{2})'
332+
.format(*VIEWER_GRID_COLOR),
333+
'border-radius': '3px',
334+
'color': 'rgba({0},{1},{2},150)'.format(*text_color),
335+
'selection-background-color': 'rgba({0},{1},{2},100)'
336+
.format(*text_sel_color),
337+
}
338+
}
339+
stylesheet = ''
340+
for css_class, css in style_dict.items():
341+
style = '{} {{\n'.format(css_class)
342+
for elm_name, elm_val in css.items():
343+
style += ' {}:{};\n'.format(elm_name, elm_val)
344+
style += '}\n'
345+
stylesheet += style
340346
ledit = QtWidgets.QLineEdit()
341347
ledit.setText(text)
342-
ledit.setStyleSheet(STYLE_NODE_LINE_EDIT)
348+
ledit.setStyleSheet(stylesheet)
343349
ledit.setAlignment(QtCore.Qt.AlignCenter)
344350
ledit.editingFinished.connect(self.on_value_changed)
345351
ledit.clearFocus()
@@ -361,6 +367,7 @@ def get_value(self):
361367

362368
def set_value(self, text=''):
363369
"""
370+
Sets the widgets current text.
364371
365372
Args:
366373
text (str): new text.
@@ -409,6 +416,7 @@ def get_value(self):
409416

410417
def set_value(self, state=False):
411418
"""
419+
Sets the widget checked state.
412420
413421
Args:
414422
state (bool): check state.

NodeGraphQt/widgets/viewer_nav.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from Qt import QtWidgets, QtCore, QtGui
22

3-
from NodeGraphQt.constants import NODE_SEL_BORDER_COLOR
3+
from NodeGraphQt.constants import NODE_SEL_BORDER_COLOR, VIEWER_BG_COLOR
44

55

66
class NodeNavigationDelagate(QtWidgets.QStyledItemDelegate):
@@ -102,7 +102,11 @@ def __init__(self, parent=None):
102102
self.setMaximumHeight(36)
103103
self.setSpacing(0)
104104

105-
self.viewport().setAutoFillBackground(False)
105+
# self.viewport().setAutoFillBackground(False)
106+
self.setStyleSheet(
107+
'QListView {{border: 0px;background-color: rgb({0},{1},{2});}}'
108+
.format(*VIEWER_BG_COLOR)
109+
)
106110

107111
self.setItemDelegate(NodeNavigationDelagate(self))
108112
self.setModel(QtGui.QStandardItemModel())

0 commit comments

Comments
 (0)