Skip to content

Commit 667249d

Browse files
committed
qtvcp -stylesheeteditor: search the legacy location of the config directory
Added tooltips of the qss path, to the combobox. Moved the search function to the qt_pstat file.
1 parent 1c9b8aa commit 667249d

File tree

2 files changed

+58
-27
lines changed

2 files changed

+58
-27
lines changed

lib/python/qtvcp/qt_pstat.py

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def set_paths(self, filename='dummy', isscreen=False):
100100
local = []
101101
if self.IS_SCREEN:
102102
# builtin screen folder
103-
default_handler_path = os.path.join(self.SCREENDIR, self.BASEPATH, handler_fn)
103+
self._default_handler_path = os.path.join(self.SCREENDIR, self.BASEPATH, handler_fn)
104104
# relative to configuration folder
105105
local.append( os.path.join(self.CONFIGPATH, handler_fn))
106106
# in standard folder
@@ -113,7 +113,7 @@ def set_paths(self, filename='dummy', isscreen=False):
113113
# relative to configuration folder
114114
local.append( os.path.join(self.WORKINGDIR, handler_fn))
115115
# builtin panel folder
116-
default_handler_path = os.path.join(self.PANELDIR, self.BASEPATH, handler_fn)
116+
self._default_handler_path = os.path.join(self.PANELDIR, self.BASEPATH, handler_fn)
117117

118118
for local_handler_path in local:
119119
LOG.debug("Checking for handler file in: yellow<{}>".format(local_handler_path))
@@ -123,9 +123,9 @@ def set_paths(self, filename='dummy', isscreen=False):
123123
break
124124
# if no break
125125
else:
126-
LOG.debug("Checking for default handler file in: yellow<{}>".format(default_handler_path))
127-
if os.path.exists(default_handler_path):
128-
self.HANDLER = default_handler_path
126+
LOG.debug("Checking for default handler file in: yellow<{}>".format(self._default_handler_path))
127+
if os.path.exists(self._default_handler_path):
128+
self.HANDLER = self._default_handler_path
129129
LOG.info("Using DEFAULT handler file path: yellow<{}>".format(self.HANDLER))
130130
else:
131131
self.HANDLER = None
@@ -419,3 +419,43 @@ def find_vismach_files(self):
419419
tmp.append(file)
420420

421421
return tmp
422+
423+
def isUsingDefaultHandler(self):
424+
return bool(self.HANDLER == self._default_handler_path)
425+
426+
def getQSSPaths(self):
427+
'''
428+
Search for qss files in default builtin directories,
429+
in the configuration expected directory CONFIG DIR/qtvcp/screen/SCREEN NAME, or
430+
CONFIG DIR/qtvcp/panel/PANEL NAME or finally the legacy location in the configuration directory.
431+
Returns two lists of a list of directory/filename pairs. The first list is default
432+
builtin paths, the second is local configuration paths
433+
'''
434+
local = []
435+
if self.IS_SCREEN:
436+
default = os.path.join(self.SCREENDIR, self.BASEPATH)
437+
local.append( os.path.join(self.CONFIGPATH))
438+
local.append( os.path.join(self.CONFIGPATH, 'qtvcp/screens',self.BASEPATH))
439+
local.append( os.path.join(self.CONFIGPATH, self.BASEPATH))
440+
else:
441+
local.append( os.path.join(self.WORKINGDIR, 'qtvcp/panels',self.BASEPATH))
442+
local.append( os.path.join(self.WORKINGDIR))
443+
default = os.path.join(self.PANELDIR, self.BASEPATH)
444+
445+
temp = []
446+
for group in ([default],local):
447+
child = []
448+
for qsspath in group:
449+
if not os.path.exists(qsspath):
450+
continue
451+
try:
452+
fileNames= [f for f in os.listdir(qsspath) if f.endswith('.qss')]
453+
for i in fileNames:
454+
child.append([qsspath,i])
455+
456+
except Exception as e:
457+
print(e)
458+
temp.append(child)
459+
460+
return temp[0], temp[1]
461+

lib/python/qtvcp/widgets/stylesheeteditor.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -96,34 +96,20 @@ def setPath(self):
9696
model = self.styleSheetCombo.model()
9797
self.loadedItem = QtGui.QStandardItem('As Loaded')
9898
self.loadedItem.setData( 'As Loaded', role = QtCore.Qt.UserRole + 1)
99+
self.loadedItem.setData("Use the preference loaded Stylesheet", role = QtCore.Qt.ToolTipRole)
99100
model.appendRow(self.loadedItem)
100101
item = QtGui.QStandardItem('None')
101102
item.setData( 'None', role = QtCore.Qt.UserRole + 1)
103+
item.setData("Use system default Stylesheet", role = QtCore.Qt.ToolTipRole)
102104
model.appendRow(item)
103-
# check for default qss from qtvcp's default folders
104-
if PATH.IS_SCREEN:
105-
DIR = PATH.SCREENDIR
106-
BNAME = PATH.BASENAME
107-
else:
108-
DIR = PATH.PANELDIR
109-
BNAME = PATH.BASENAME
110-
qssname = os.path.join(DIR, BNAME)
111-
try:
112-
fileNames= [f for f in os.listdir(qssname) if f.endswith('.qss')]
113-
for i in(fileNames):
114-
item = QtGui.QStandardItem(i)
115-
item.setData(os.path.join(qssname, i), role = QtCore.Qt.UserRole + 1)
116-
model.appendRow(item)
117-
except Exception as e:
118-
print(e)
119105

120-
# check for qss in the users's config folder
121-
localqss = PATH.CONFIGPATH
106+
# call PATH function to get the found default and local qss files
122107
try:
123-
fileNames= [f for f in os.listdir(localqss) if f.endswith('.qss')]
124-
for i in(fileNames):
125-
item = QtGui.QStandardItem(i)
126-
item.setData(os.path.join(localqss, i), role = QtCore.Qt.UserRole + 1)
108+
for group in (PATH.getQSSPaths()):
109+
for directory, name in(group):
110+
item = QtGui.QStandardItem(name)
111+
item.setData(os.path.join(directory, name), role = QtCore.Qt.UserRole + 1)
112+
item.setData(os.path.join(directory, name), role = QtCore.Qt.ToolTipRole)
127113
model.appendRow(item)
128114
except Exception as e:
129115
print(e)
@@ -153,6 +139,11 @@ def on_applyButton_clicked(self):
153139
# styles can have affect on the dialog widgets
154140
# make sure one can still read the combo box
155141
self.styleSheetCombo.setFixedWidth(200)
142+
try:
143+
path = self.styleSheetCombo.itemData(index,role = QtCore.Qt.UserRole + 1)
144+
self.parent.statusbar.showMessage(f"Stylesheet set to {path}")
145+
except:
146+
pass
156147

157148
@pyqtSlot()
158149
def on_openButton_clicked(self):

0 commit comments

Comments
 (0)