11#!/usr/bin/python
2- import re
3-
42from 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
75from 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
428class _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.
0 commit comments