Update examples
This commit is contained in:
parent
30bfc796b9
commit
b85ff4a782
|
@ -235,10 +235,24 @@ class GenericMonitor:
|
||||||
class GenericMonitorGenericWidget:
|
class GenericMonitorGenericWidget:
|
||||||
""" Generic widget class, parent of all widgets
|
""" Generic widget class, parent of all widgets
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self, style='', name='', signals={}):
|
||||||
self.valuesToMap = []
|
"""
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
name : str, optional
|
||||||
|
Widget name
|
||||||
|
signals : dictionary, optional
|
||||||
|
Dictionary of signals and their action
|
||||||
|
"""
|
||||||
|
self.valuesToMap = ['name', 'style']
|
||||||
self.mapValues = {}
|
self.mapValues = {}
|
||||||
self.mapName = ''
|
self.mapName = ''
|
||||||
|
self.style = style
|
||||||
|
self.name = name
|
||||||
|
self.signals = signals
|
||||||
|
|
||||||
|
def setStyle(self, style):
|
||||||
|
self.style = style
|
||||||
|
|
||||||
def _toMap(self):
|
def _toMap(self):
|
||||||
""" Return dictionary of class elements to send to addon
|
""" Return dictionary of class elements to send to addon
|
||||||
|
@ -247,12 +261,14 @@ class GenericMonitorGenericWidget:
|
||||||
for p in self.valuesToMap:
|
for p in self.valuesToMap:
|
||||||
if self.__dict__[p]:
|
if self.__dict__[p]:
|
||||||
self.mapValues[p] = 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}
|
return {self.mapName:self.mapValues}
|
||||||
|
|
||||||
class GenericMonitorTextWidget(GenericMonitorGenericWidget):
|
class GenericMonitorTextWidget(GenericMonitorGenericWidget):
|
||||||
""" Text widget
|
""" Text widget
|
||||||
"""
|
"""
|
||||||
def __init__(self, text, style=''):
|
def __init__(self, text, style='', name='', signals={}):
|
||||||
"""
|
"""
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
@ -260,19 +276,20 @@ class GenericMonitorTextWidget(GenericMonitorGenericWidget):
|
||||||
Text to display
|
Text to display
|
||||||
style : str, optional
|
style : str, optional
|
||||||
CSS style
|
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.mapName = 'text'
|
||||||
|
|
||||||
self.text = text
|
self.text = text
|
||||||
self.style = style
|
|
||||||
|
|
||||||
def setText(self, text):
|
def setText(self, text):
|
||||||
self.text = text
|
self.text = text
|
||||||
|
|
||||||
def setStyle(self, style):
|
|
||||||
self.style = style
|
|
||||||
|
|
||||||
class GenericMonitorIconWidget(GenericMonitorGenericWidget):
|
class GenericMonitorIconWidget(GenericMonitorGenericWidget):
|
||||||
""" Icon widget
|
""" Icon widget
|
||||||
"""
|
"""
|
||||||
|
@ -285,7 +302,8 @@ class GenericMonitorIconWidget(GenericMonitorGenericWidget):
|
||||||
style : str, optional
|
style : str, optional
|
||||||
CSS style
|
CSS style
|
||||||
"""
|
"""
|
||||||
self.valuesToMap = ('path', 'style')
|
super().__init__(style=style)
|
||||||
|
self.valuesToMap += ['path']
|
||||||
self.mapName = 'icon'
|
self.mapName = 'icon'
|
||||||
|
|
||||||
self.path = path
|
self.path = path
|
||||||
|
@ -294,14 +312,11 @@ class GenericMonitorIconWidget(GenericMonitorGenericWidget):
|
||||||
def setPath(self, path):
|
def setPath(self, path):
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
def setStyle(self, style):
|
|
||||||
self.style = style
|
|
||||||
|
|
||||||
|
class GenericMonitorPictureWidget(GenericMonitorGenericWidget):
|
||||||
class GenericMonitorPictureWidget(GenericMonitorIconWidget):
|
|
||||||
""" Picture widget
|
""" Picture widget
|
||||||
"""
|
"""
|
||||||
def __init__(self, path, style='', width=-1, height=-1):
|
def __init__(self, path, style='', width=-1, height=-1, name='', signals={}):
|
||||||
"""
|
"""
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
|
@ -313,15 +328,23 @@ class GenericMonitorPictureWidget(GenericMonitorIconWidget):
|
||||||
Width of displayed picture (-1 for default width)
|
Width of displayed picture (-1 for default width)
|
||||||
height : int, optional
|
height : int, optional
|
||||||
Width of displayed picture (-1 for default width)
|
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)
|
super().__init__(style, name, signals)
|
||||||
self.valuesToMap = ('path', 'style', 'width', 'height')
|
self.valuesToMap += ['path', 'width', 'height']
|
||||||
self.mapName = 'picture'
|
self.mapName = 'picture'
|
||||||
|
self.path = path
|
||||||
|
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
|
|
||||||
|
def setPath(self, path):
|
||||||
|
self.path = path
|
||||||
|
|
||||||
def setWidth(self, width):
|
def setWidth(self, width):
|
||||||
self.width = width
|
self.width = width
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
Display random picture from unsplash.com in a popup
|
Display random picture from unsplash.com in a popup
|
||||||
|
|
||||||
* Click : open/close popup
|
* Click : open/close popup
|
||||||
|
* Popup item click : display who clicked
|
||||||
* ScrollUp/ScrollDown/Double click : display next picture
|
* ScrollUp/ScrollDown/Double click : display next picture
|
||||||
* Right click : exit
|
* Right click : exit
|
||||||
'''
|
'''
|
||||||
|
@ -50,8 +51,8 @@ class PicturePopup(GenericMonitor):
|
||||||
with open('/tmp/cat2.jpg', 'wb') as f:
|
with open('/tmp/cat2.jpg', 'wb') as f:
|
||||||
f.write(datatowrite)
|
f.write(datatowrite)
|
||||||
widget = GenericMonitorTextWidget('#%d' % self.imgs_idx, 'color:purple')
|
widget = GenericMonitorTextWidget('#%d' % self.imgs_idx, 'color:purple')
|
||||||
url_widget = GenericMonitorTextWidget(url, 'color:white;font-weight:bold')
|
url_widget = GenericMonitorTextWidget(url, 'color:white;font-weight:bold', signals={'on-click':'signal'}) # No name here
|
||||||
picture_widget = GenericMonitorPictureWidget('/tmp/cat2.jpg')
|
picture_widget = GenericMonitorPictureWidget('/tmp/cat2.jpg', name='NestedWidget', signals={'on-click':'signal'})
|
||||||
popup = GenericMonitorPopup([url_widget, picture_widget])
|
popup = GenericMonitorPopup([url_widget, picture_widget])
|
||||||
signals = {
|
signals = {
|
||||||
'on-click':'toggle-popup',
|
'on-click':'toggle-popup',
|
||||||
|
@ -68,7 +69,11 @@ class PicturePopup(GenericMonitor):
|
||||||
self.imgs_idx += 1
|
self.imgs_idx += 1
|
||||||
|
|
||||||
def _forMe(self, sender):
|
def _forMe(self, sender):
|
||||||
return sender == self.item.getFullName()
|
return str(sender).endswith(self.item.getFullName())
|
||||||
|
|
||||||
|
def onClick(self, sender):
|
||||||
|
if not self._forMe(sender): return
|
||||||
|
print('Click from {}'.format(sender))
|
||||||
|
|
||||||
def _onScroll(self, sender):
|
def _onScroll(self, sender):
|
||||||
if not self._forMe(sender): return
|
if not self._forMe(sender): return
|
||||||
|
|
|
@ -65,7 +65,7 @@ class TimerThread(Thread,GenericMonitor):
|
||||||
self._stopLoop = False
|
self._stopLoop = False
|
||||||
|
|
||||||
self.textWidget = GenericMonitorTextWidget('')
|
self.textWidget = GenericMonitorTextWidget('')
|
||||||
signals = {'on-click':'signal'}
|
signals = {'on-click':'signal','on-dblclick':'signal','on-rightclick':'signal'}
|
||||||
self.monitorItem = GenericMonitorItem('timer', [self.textWidget], signals, box='right')
|
self.monitorItem = GenericMonitorItem('timer', [self.textWidget], signals, box='right')
|
||||||
self.monitorGroup = GenericMonitorGroup('Timer', self.monitorItem)
|
self.monitorGroup = GenericMonitorGroup('Timer', self.monitorItem)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user