2020-02-08 13:45:52 +01:00
|
|
|
import core.input
|
2020-03-01 14:08:16 +01:00
|
|
|
import core.decorators
|
2020-05-01 20:25:10 +02:00
|
|
|
|
2020-01-26 13:58:29 +01:00
|
|
|
import util.store
|
2020-05-01 20:25:10 +02:00
|
|
|
import util.format
|
2020-01-26 13:58:29 +01:00
|
|
|
|
2020-02-08 13:45:52 +01:00
|
|
|
class Widget(util.store.Store, core.input.Object):
|
2020-03-01 14:36:12 +01:00
|
|
|
def __init__(self, full_text='', name=None, module=None):
|
2020-02-08 13:45:52 +01:00
|
|
|
super(Widget, self).__init__()
|
2020-04-04 13:58:22 +02:00
|
|
|
self.__full_text = full_text
|
2020-04-30 12:46:57 +02:00
|
|
|
self.module = module
|
2020-04-30 12:42:34 +02:00
|
|
|
self.name = name
|
2020-01-26 13:58:29 +01:00
|
|
|
|
2020-05-01 20:25:10 +02:00
|
|
|
def index(self):
|
|
|
|
if not self.module: return 0
|
|
|
|
|
|
|
|
idx = 0
|
|
|
|
for w in self.module.widgets():
|
|
|
|
if w.id == self.id:
|
|
|
|
return idx
|
|
|
|
idx = idx + 1
|
|
|
|
return -1 # not found
|
|
|
|
|
|
|
|
def theme(self, attribute):
|
|
|
|
attr = 'theme.{}'.format(attribute)
|
|
|
|
if self.module:
|
|
|
|
param = util.format.aslist(self.module.parameter(attr))
|
|
|
|
if param and len(param) > self.index():
|
|
|
|
return param[self.index()]
|
|
|
|
return self.get(attr)
|
|
|
|
|
2020-01-26 13:58:29 +01:00
|
|
|
def full_text(self, value=None):
|
|
|
|
if value:
|
2020-04-04 13:58:22 +02:00
|
|
|
self.__full_text = value
|
2020-01-26 13:58:29 +01:00
|
|
|
else:
|
2020-04-04 13:58:22 +02:00
|
|
|
if callable(self.__full_text):
|
|
|
|
return self.__full_text(self)
|
|
|
|
return self.__full_text
|
2020-01-26 13:58:29 +01:00
|
|
|
|
2020-02-23 21:13:49 +01:00
|
|
|
def state(self):
|
|
|
|
rv = []
|
2020-03-13 13:56:08 +01:00
|
|
|
if self.get('state', None):
|
|
|
|
tmp = self.get('state')
|
2020-03-27 13:54:22 +01:00
|
|
|
rv = tmp[:] if isinstance(tmp, list) else [tmp]
|
2020-04-30 12:46:57 +02:00
|
|
|
if self.module:
|
|
|
|
tmp = self.module.state(self)
|
2020-03-27 13:54:22 +01:00
|
|
|
rv.extend(tmp if isinstance(tmp, list) else [tmp])
|
|
|
|
return rv
|
2020-02-23 21:13:49 +01:00
|
|
|
|
2020-01-26 13:58:29 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|