Add controls in UnoPage
This commit is contained in:
parent
f5f53e8ec0
commit
400d59a3b9
|
@ -103,7 +103,7 @@ try:
|
|||
__exception_wrapper__
|
||||
except ImportError as e:
|
||||
Database = DateField = TimeField = DateTimeField = object
|
||||
print('Install peewee')
|
||||
print('You need install peewee, only if you will use Base')
|
||||
|
||||
|
||||
LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
|
||||
|
@ -922,6 +922,7 @@ class ImapServer(object):
|
|||
|
||||
def _login(self, config):
|
||||
try:
|
||||
# ~ hosts = 'gmail' in config['server']
|
||||
if config['ssl']:
|
||||
self._server = imaplib.IMAP4_SSL(config['server'], config['port'])
|
||||
else:
|
||||
|
@ -4139,10 +4140,25 @@ class UnoGrid(UnoBaseObject):
|
|||
return
|
||||
|
||||
|
||||
class UnoPage(UnoBaseObject):
|
||||
class UnoPage(object):
|
||||
|
||||
def __init__(self, obj):
|
||||
super().__init__(obj)
|
||||
self._obj = obj
|
||||
self._events = None
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
pass
|
||||
|
||||
@property
|
||||
def obj(self):
|
||||
return self._obj
|
||||
|
||||
@property
|
||||
def model(self):
|
||||
return self._obj.Model
|
||||
|
||||
# ~ @property
|
||||
# ~ def id(self):
|
||||
|
@ -4152,26 +4168,72 @@ class UnoPage(UnoBaseObject):
|
|||
def parent(self):
|
||||
return self.obj.Context
|
||||
|
||||
# ~ @property
|
||||
# ~ def color(self):
|
||||
# ~ return self.m.BackgroundColor
|
||||
# ~ @color.setter
|
||||
# ~ def color(self, value):
|
||||
# ~ self.m.BackgroundColor = value
|
||||
def _set_image_url(self, image):
|
||||
if _P.exists(image):
|
||||
return _P.to_url(image)
|
||||
|
||||
# ~ @property
|
||||
# ~ def enabled(self):
|
||||
# ~ return self.m.Enabled
|
||||
# ~ @enabled.setter
|
||||
# ~ def enabled(self, value):
|
||||
# ~ self.obj.Enable = value
|
||||
path = _P.join(self._path, DIR['images'], image)
|
||||
return _P.to_url(path)
|
||||
|
||||
# ~ @property
|
||||
# ~ def title(self):
|
||||
# ~ return self.m.Title
|
||||
# ~ @title.setter
|
||||
# ~ def title(self, value):
|
||||
# ~ self.m.Title = value
|
||||
def _special_properties(self, tipo, args):
|
||||
if tipo == 'link' and not 'Label' in args:
|
||||
args['Label'] = args['URL']
|
||||
return args
|
||||
|
||||
if tipo == 'button':
|
||||
if 'ImageURL' in args:
|
||||
args['ImageURL'] = self._set_image_url(args['ImageURL'])
|
||||
args['FocusOnClick'] = args.get('FocusOnClick', False)
|
||||
return args
|
||||
|
||||
if tipo == 'roadmap':
|
||||
args['Height'] = args.get('Height', self.height)
|
||||
if 'Title' in args:
|
||||
args['Text'] = args.pop('Title')
|
||||
return args
|
||||
|
||||
if tipo == 'tree':
|
||||
args['SelectionType'] = args.get('SelectionType', SINGLE)
|
||||
return args
|
||||
|
||||
if tipo == 'grid':
|
||||
args['ShowRowHeader'] = args.get('ShowRowHeader', True)
|
||||
return args
|
||||
|
||||
if tipo == 'pages':
|
||||
args['Width'] = args.get('Width', self.width)
|
||||
args['Height'] = args.get('Height', self.height)
|
||||
|
||||
return args
|
||||
|
||||
def add_control(self, args):
|
||||
tipo = args.pop('Type').lower()
|
||||
root = args.pop('Root', '')
|
||||
sheets = args.pop('Sheets', ())
|
||||
columns = args.pop('Columns', ())
|
||||
|
||||
args = self._special_properties(tipo, args)
|
||||
model = self.model.createInstance(UNO_MODELS[tipo])
|
||||
_set_properties(model, args)
|
||||
name = args['Name']
|
||||
self.model.insertByName(name, model)
|
||||
control = self.obj.getControl(name)
|
||||
_add_listeners(self._events, control, name)
|
||||
control = UNO_CLASSES[tipo](control)
|
||||
|
||||
if tipo in ('listbox',):
|
||||
control.path = self.path
|
||||
|
||||
if tipo == 'tree' and root:
|
||||
control.root = root
|
||||
elif tipo == 'grid' and columns:
|
||||
control.columns = columns
|
||||
elif tipo == 'pages' and sheets:
|
||||
control.sheets = sheets
|
||||
control.events = self.events
|
||||
|
||||
setattr(self, name, control)
|
||||
return control
|
||||
|
||||
|
||||
class UnoPages(UnoBaseObject):
|
||||
|
@ -4192,7 +4254,9 @@ class UnoPages(UnoBaseObject):
|
|||
if isinstance(index, int):
|
||||
name = f'sheet{index}'
|
||||
sheet = self.obj.getControl(name)
|
||||
return UnoPage(sheet)
|
||||
page = UnoPage(sheet)
|
||||
page._events = self._events
|
||||
return page
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
|
@ -4263,7 +4327,22 @@ UNO_CLASSES = {
|
|||
'pages': UnoPages,
|
||||
}
|
||||
|
||||
|
||||
UNO_MODELS = {
|
||||
'label': 'com.sun.star.awt.UnoControlFixedTextModel',
|
||||
'link': 'com.sun.star.awt.UnoControlFixedHyperlinkModel',
|
||||
'button': 'com.sun.star.awt.UnoControlButtonModel',
|
||||
'radio': 'com.sun.star.awt.UnoControlRadioButtonModel',
|
||||
'checkbox': 'com.sun.star.awt.UnoControlCheckBoxModel',
|
||||
'text': 'com.sun.star.awt.UnoControlEditModel',
|
||||
'image': 'com.sun.star.awt.UnoControlImageControlModel',
|
||||
'listbox': 'com.sun.star.awt.UnoControlListBoxModel',
|
||||
'roadmap': 'com.sun.star.awt.UnoControlRoadmapModel',
|
||||
'tree': 'com.sun.star.awt.tree.TreeControlModel',
|
||||
'grid': 'com.sun.star.awt.grid.UnoControlGridModel',
|
||||
'pages': 'com.sun.star.awt.UnoMultiPageModel',
|
||||
'groupbox': 'com.sun.star.awt.UnoControlGroupBoxModel',
|
||||
'combobox': 'com.sun.star.awt.UnoControlComboBoxModel',
|
||||
}
|
||||
# ~ 'CurrencyField': 'com.sun.star.awt.UnoControlCurrencyFieldModel',
|
||||
# ~ 'DateField': 'com.sun.star.awt.UnoControlDateFieldModel',
|
||||
# ~ 'FileControl': 'com.sun.star.awt.UnoControlFileControlModel',
|
||||
|
|
Loading…
Reference in New Issue