Update examples

This commit is contained in:
2021-01-18 15:53:41 +01:00
parent 30bfc796b9
commit b85ff4a782
3 changed files with 48 additions and 20 deletions

View File

@@ -235,11 +235,25 @@ class GenericMonitor:
class GenericMonitorGenericWidget:
""" Generic widget class, parent of all widgets
"""
def __init__(self):
self.valuesToMap = []
def __init__(self, style='', name='', signals={}):
"""
Parameters
----------
name : str, optional
Widget name
signals : dictionary, optional
Dictionary of signals and their action
"""
self.valuesToMap = ['name', 'style']
self.mapValues = {}
self.mapName = ''
self.style = style
self.name = name
self.signals = signals
def setStyle(self, style):
self.style = style
def _toMap(self):
""" Return dictionary of class elements to send to addon
"""
@@ -247,12 +261,14 @@ class GenericMonitorGenericWidget:
for p in self.valuesToMap:
if self.__dict__[p]:
self.mapValues[p] = self.__dict__[p]
for (name, value) in self.signals.items():
self.mapValues[name] = value
return {self.mapName:self.mapValues}
class GenericMonitorTextWidget(GenericMonitorGenericWidget):
""" Text widget
"""
def __init__(self, text, style=''):
def __init__(self, text, style='', name='', signals={}):
"""
Parameters
----------
@@ -260,19 +276,20 @@ class GenericMonitorTextWidget(GenericMonitorGenericWidget):
Text to display
style : str, optional
CSS style
name : str, optional
Widget name
signals : dictionary, optional
Dictionary of signals and their action
"""
self.valuesToMap = ('text', 'style')
super().__init__(style, name, signals)
self.valuesToMap += ['text']
self.mapName = 'text'
self.text = text
self.style = style
def setText(self, text):
self.text = text
def setStyle(self, style):
self.style = style
class GenericMonitorIconWidget(GenericMonitorGenericWidget):
""" Icon widget
"""
@@ -285,7 +302,8 @@ class GenericMonitorIconWidget(GenericMonitorGenericWidget):
style : str, optional
CSS style
"""
self.valuesToMap = ('path', 'style')
super().__init__(style=style)
self.valuesToMap += ['path']
self.mapName = 'icon'
self.path = path
@@ -293,15 +311,12 @@ class GenericMonitorIconWidget(GenericMonitorGenericWidget):
def setPath(self, path):
self.path = path
def setStyle(self, style):
self.style = style
class GenericMonitorPictureWidget(GenericMonitorIconWidget):
class GenericMonitorPictureWidget(GenericMonitorGenericWidget):
""" Picture widget
"""
def __init__(self, path, style='', width=-1, height=-1):
def __init__(self, path, style='', width=-1, height=-1, name='', signals={}):
"""
Parameters
----------
@@ -313,15 +328,23 @@ class GenericMonitorPictureWidget(GenericMonitorIconWidget):
Width of displayed picture (-1 for default width)
height : int, optional
Width of displayed picture (-1 for default width)
name : str, optional
Widget name
signals : dictionary, optional
Dictionary of signals and their action
"""
super().__init__(path, style)
self.valuesToMap = ('path', 'style', 'width', 'height')
super().__init__(style, name, signals)
self.valuesToMap += ['path', 'width', 'height']
self.mapName = 'picture'
self.path = path
self.width = width
self.height = height
def setPath(self, path):
self.path = path
def setWidth(self, width):
self.width = width