Skip to content

Commit

Permalink
qtvcp -stylesheeteditor: search the legacy location of the config dir…
Browse files Browse the repository at this point in the history
…ectory

Added tooltips of the qss path, to the combobox.
Moved the search function to the qt_pstat file.
  • Loading branch information
c-morley committed Nov 24, 2023
1 parent 1c9b8aa commit 667249d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 27 deletions.
50 changes: 45 additions & 5 deletions lib/python/qtvcp/qt_pstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def set_paths(self, filename='dummy', isscreen=False):
local = []
if self.IS_SCREEN:
# builtin screen folder
default_handler_path = os.path.join(self.SCREENDIR, self.BASEPATH, handler_fn)
self._default_handler_path = os.path.join(self.SCREENDIR, self.BASEPATH, handler_fn)
# relative to configuration folder
local.append( os.path.join(self.CONFIGPATH, handler_fn))
# in standard folder
Expand All @@ -113,7 +113,7 @@ def set_paths(self, filename='dummy', isscreen=False):
# relative to configuration folder
local.append( os.path.join(self.WORKINGDIR, handler_fn))
# builtin panel folder
default_handler_path = os.path.join(self.PANELDIR, self.BASEPATH, handler_fn)
self._default_handler_path = os.path.join(self.PANELDIR, self.BASEPATH, handler_fn)

for local_handler_path in local:
LOG.debug("Checking for handler file in: yellow<{}>".format(local_handler_path))
Expand All @@ -123,9 +123,9 @@ def set_paths(self, filename='dummy', isscreen=False):
break
# if no break
else:
LOG.debug("Checking for default handler file in: yellow<{}>".format(default_handler_path))
if os.path.exists(default_handler_path):
self.HANDLER = default_handler_path
LOG.debug("Checking for default handler file in: yellow<{}>".format(self._default_handler_path))
if os.path.exists(self._default_handler_path):
self.HANDLER = self._default_handler_path
LOG.info("Using DEFAULT handler file path: yellow<{}>".format(self.HANDLER))
else:
self.HANDLER = None
Expand Down Expand Up @@ -419,3 +419,43 @@ def find_vismach_files(self):
tmp.append(file)

return tmp

def isUsingDefaultHandler(self):
return bool(self.HANDLER == self._default_handler_path)

def getQSSPaths(self):
'''
Search for qss files in default builtin directories,
in the configuration expected directory CONFIG DIR/qtvcp/screen/SCREEN NAME, or
CONFIG DIR/qtvcp/panel/PANEL NAME or finally the legacy location in the configuration directory.
Returns two lists of a list of directory/filename pairs. The first list is default
builtin paths, the second is local configuration paths
'''
local = []
if self.IS_SCREEN:
default = os.path.join(self.SCREENDIR, self.BASEPATH)
local.append( os.path.join(self.CONFIGPATH))
local.append( os.path.join(self.CONFIGPATH, 'qtvcp/screens',self.BASEPATH))
local.append( os.path.join(self.CONFIGPATH, self.BASEPATH))
else:
local.append( os.path.join(self.WORKINGDIR, 'qtvcp/panels',self.BASEPATH))
local.append( os.path.join(self.WORKINGDIR))
default = os.path.join(self.PANELDIR, self.BASEPATH)

temp = []
for group in ([default],local):
child = []
for qsspath in group:
if not os.path.exists(qsspath):
continue
try:
fileNames= [f for f in os.listdir(qsspath) if f.endswith('.qss')]
for i in fileNames:
child.append([qsspath,i])

except Exception as e:
print(e)
temp.append(child)

return temp[0], temp[1]

35 changes: 13 additions & 22 deletions lib/python/qtvcp/widgets/stylesheeteditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,34 +96,20 @@ def setPath(self):
model = self.styleSheetCombo.model()
self.loadedItem = QtGui.QStandardItem('As Loaded')
self.loadedItem.setData( 'As Loaded', role = QtCore.Qt.UserRole + 1)
self.loadedItem.setData("Use the preference loaded Stylesheet", role = QtCore.Qt.ToolTipRole)
model.appendRow(self.loadedItem)
item = QtGui.QStandardItem('None')
item.setData( 'None', role = QtCore.Qt.UserRole + 1)
item.setData("Use system default Stylesheet", role = QtCore.Qt.ToolTipRole)
model.appendRow(item)
# check for default qss from qtvcp's default folders
if PATH.IS_SCREEN:
DIR = PATH.SCREENDIR
BNAME = PATH.BASENAME
else:
DIR = PATH.PANELDIR
BNAME = PATH.BASENAME
qssname = os.path.join(DIR, BNAME)
try:
fileNames= [f for f in os.listdir(qssname) if f.endswith('.qss')]
for i in(fileNames):
item = QtGui.QStandardItem(i)
item.setData(os.path.join(qssname, i), role = QtCore.Qt.UserRole + 1)
model.appendRow(item)
except Exception as e:
print(e)

# check for qss in the users's config folder
localqss = PATH.CONFIGPATH
# call PATH function to get the found default and local qss files
try:
fileNames= [f for f in os.listdir(localqss) if f.endswith('.qss')]
for i in(fileNames):
item = QtGui.QStandardItem(i)
item.setData(os.path.join(localqss, i), role = QtCore.Qt.UserRole + 1)
for group in (PATH.getQSSPaths()):
for directory, name in(group):
item = QtGui.QStandardItem(name)
item.setData(os.path.join(directory, name), role = QtCore.Qt.UserRole + 1)
item.setData(os.path.join(directory, name), role = QtCore.Qt.ToolTipRole)
model.appendRow(item)
except Exception as e:
print(e)
Expand Down Expand Up @@ -153,6 +139,11 @@ def on_applyButton_clicked(self):
# styles can have affect on the dialog widgets
# make sure one can still read the combo box
self.styleSheetCombo.setFixedWidth(200)
try:
path = self.styleSheetCombo.itemData(index,role = QtCore.Qt.UserRole + 1)
self.parent.statusbar.showMessage(f"Stylesheet set to {path}")
except:
pass

@pyqtSlot()
def on_openButton_clicked(self):
Expand Down

0 comments on commit 667249d

Please sign in to comment.