Add controls in windows

This commit is contained in:
Mauricio Baeza 2020-12-15 22:04:44 -06:00
parent e4a0b0b2cf
commit 9eb5147eab
2 changed files with 93 additions and 83 deletions

View File

@ -596,88 +596,6 @@ class LODialog(object):
return
class LOWindow(object):
EMPTY = b"""<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="empty" dlg:left="0" dlg:top="0" dlg:width="0" dlg:height="0" dlg:closeable="true" dlg:moveable="true" dlg:withtitlebar="false"/>"""
def __init__(self, **kwargs):
self._events = None
self._menu = None
self._container = None
self._id_extension = ''
self._obj = self._create(kwargs)
@property
def id_extension(self):
return self._id_extension
@id_extension.setter
def id_extension(self, value):
global ID_EXTENSION
ID_EXTENSION = value
self._id_extension = value
def _get_base_control(self, tipo):
services = {
'label': 'com.sun.star.awt.UnoControlFixedText',
'button': 'com.sun.star.awt.UnoControlButton',
'text': 'com.sun.star.awt.UnoControlEdit',
'listbox': 'com.sun.star.awt.UnoControlListBox',
'link': 'com.sun.star.awt.UnoControlFixedHyperlink',
'roadmap': 'com.sun.star.awt.UnoControlRoadmap',
'image': 'com.sun.star.awt.UnoControlImageControl',
'groupbox': 'com.sun.star.awt.UnoControlGroupBox',
'radio': 'com.sun.star.awt.UnoControlRadioButton',
'tree': 'com.sun.star.awt.tree.TreeControl',
'grid': 'com.sun.star.awt.grid.UnoControlGrid',
'tab': 'com.sun.star.awt.tab.UnoControlTabPage',
}
return services[tipo]
def _special_properties(self, tipo, properties):
columns = properties.pop('Columns', ())
if tipo == 'grid':
properties['ColumnModel'] = self._set_column_model(columns)
elif tipo == 'button' and 'ImageURL' in properties:
properties['ImageURL'] = _set_image_url(
properties['ImageURL'], self.id_extension)
elif tipo == 'roadmap':
if not 'Height' in properties:
properties['Height'] = self.height
if 'Title' in properties:
properties['Text'] = properties.pop('Title')
elif tipo == 'tab':
if not 'Width' in properties:
properties['Width'] = self.width - 20
if not 'Height' in properties:
properties['Height'] = self.height - 20
return properties
def add_control(self, properties):
tipo = properties.pop('Type').lower()
root = properties.pop('Root', '')
sheets = properties.pop('Sheets', ())
properties = self._special_properties(tipo, properties)
model = self._subcont.Model.createInstance(get_control_model(tipo))
set_properties(model, properties)
name = properties['Name']
self._subcont.Model.insertByName(name, model)
control = self._subcont.getControl(name)
add_listeners(self.events, control, name)
control = get_custom_class(tipo, control)
if tipo == 'tree' and root:
control.root = root
elif tipo == 'tab' and sheets:
control.sheets = sheets
control.events = self.events
setattr(self, name, control)
return
# ~ Export ok
def merge_zip(target, zips):
try:

View File

@ -3840,6 +3840,8 @@ class EventsButton(EventsListenerBase, XActionListener):
def actionPerformed(self, event):
event_name = f'{self.name}_action'
debug(event_name)
debug(hasattr(self._controller, event_name))
if hasattr(self._controller, event_name):
getattr(self._controller, event_name)(event)
return
@ -5536,12 +5538,30 @@ class LOWindow(object):
EMPTY = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="empty" dlg:left="0" dlg:top="0" dlg:width="0" dlg:height="0" dlg:closeable="true" dlg:moveable="true" dlg:withtitlebar="false"/>"""
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',
}
def __init__(self, args):
self._events = None
self._menu = None
self._container = None
self._id_extension = ''
self._model = None
self._id = ''
self._path = ''
self._obj = self._create(args)
def _create(self, properties):
@ -5598,6 +5618,7 @@ class LOWindow(object):
subcont.setVisible(True)
self._container.addControl('subcont', subcont)
self._subcont = subcont
self._model = subcont.Model
return
def _create_popupmenu(self, menus):
@ -5642,6 +5663,73 @@ class LOWindow(object):
# ~ self._container.addKeyListener(EventsKeyWindow(self))
return
def _set_image_url(self, image):
if _P.exists(image):
return _P.to_url(image)
path = _P.join(self._path, DIR['images'], image)
return _P.to_url(path)
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(self.MODELS[tipo])
_set_properties(model, args)
name = args['Name']
self.model.insertByName(name, model)
control = self._subcont.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
@property
def events(self):
return self._events
@ -5650,6 +5738,10 @@ class LOWindow(object):
self._events = controllers(self)
self._add_listeners()
@property
def model(self):
return self._model
@property
def width(self):
return self._container.Size.Width