Add events mouse and focus

This commit is contained in:
Mauricio 2023-04-25 23:28:45 -06:00
parent b8954d7ade
commit 70654bf40f
10 changed files with 986 additions and 34 deletions

132
doc/docs/dialogs/cmd.md Normal file
View File

@ -0,0 +1,132 @@
# Botón de comando (button)
---
## Propiedades
---
### **type**
Devuelve el tipo de control.
```py
app.debug(button.type)
```
<br>
### **value**
Devuelve o establece la etiqueta del control.
```py
button.value = 'Cerrar'
```
<br>
## Métodos
---
## Eventos
---
### **action**
Se ejecuta al dar click con el botón primario del ratón y con las teclas ++enter++ y ++"Barra Espaciadora"++ cuando el botón de comando tiene el foco.
```py
def button_action(self, event):
return
```
<br>
### **click**
Se ejecuta al dar click con cualquier botón del ratón.
```py
def button_click(self, event):
return
```
<br>
### **double_click**
Se ejecuta al dar doble click con cualquier botón del ratón.
```py
def button_double_click(self, event):
return
```
## Propiedades pyUNO
| Nombre | Descripción |
| ------ | ----------- |
| Align | |
| BackgroundColor | |
| ContextWritingMode | |
| DefaultButton | |
| DefaultControl | |
| EnableVisible | |
| Enabled | |
| FocusOnClick | |
| FontCharWidth | |
| FontCharset | |
| FontDescriptor | |
| FontEmphasisMark | |
| FontFamily | |
| FontHeight | |
| FontKerning | |
| FontName | |
| FontOrientation | |
| FontPitch | |
| FontRelief | |
| FontSlant | |
| FontStrikeout | |
| FontStyleName | |
| FontType | |
| FontUnderline | |
| FontWeight | |
| FontWidth | |
| FontWordLineMode | |
| Graphic | |
| Height | |
| HelpText | |
| HelpURL | |
| ImageAlign | |
| ImagePosition | |
| ImageURL | |
| Label | |
| MultiLine | |
| Name | |
| PositionX | |
| PositionY | |
| Printable | |
| PushButtonType | |
| ReferenceDevice | |
| Repeat | |
| RepeatDelay | |
| ResourceResolver | |
| State | |
| Step | |
| TabIndex | |
| Tabstop | |
| Tag | |
| TextColor | |
| TextLineColor | |
| Toggle | |
| VerticalAlign | |
| Width | |
| WritingMode | |
<br>

47
doc/docs/dialogs/image.md Normal file
View File

@ -0,0 +1,47 @@
# Imagen (image)
---
## Propiedades
---
## Métodos
---
## Eventos
---
## Propiedades pyUNO
| Nombre | Descripción |
| ------ | ----------- |
| BackgroundColor | |
| Border | |
| BorderColor | |
| ContextWritingMode | |
| DefaultControl | |
| EnableVisible | |
| Enabled | |
| Graphic | |
| Height | |
| HelpText | |
| HelpURL | |
| ImageURL | |
| Name | |
| PositionX | |
| PositionY | |
| Printable | |
| ResourceResolver | |
| ScaleImage | |
| ScaleMode | |
| Step | |
| TabIndex | |
| Tabstop | |
| Tag | |
| Width | |
| WritingMode | |
<br>

267
doc/docs/dialogs/index.md Normal file
View File

@ -0,0 +1,267 @@
# Crear cuadros de diálogo
### **create**
---
#### Desde "Mis Macros"
Si el cuadro de diálogo esta en la librería `Standard`.
```py
def crear_cuadro_de_dialogo1():
propiedades = {
'Location': 'user',
'Name': 'Dialog1',
}
dialog = app.dialog.create(propiedades)
dialog.open()
return
```
Si el cuadro de diálogo esta en otra librería.
```py
def crear_cuadro_de_dialogo2():
propiedades = {
'Location': 'user',
'Library': 'MiAplicacion',
'Name': 'Dialog1',
}
dialog = app.dialog.create(propiedades)
dialog.open()
return
```
<br>
#### Dentro de un archivo
Si el cuadro de diálogo esta en el documento activo en la librería `Standard`.
```py
def crear_cuadro_de_dialogo3():
propiedades = {
'Location': 'document',
'Name': 'Dialog1',
}
dialog = app.dialog.create(propiedades)
dialog.open()
return
```
Si el cuadro de diálogo esta en otro documento en la librería `Standard`.
```py
def crear_cuadro_de_dialogo4():
documento = app.docs['OtroArchivo.ods']
propiedades = {
'Location': 'document',
'Document': documento,
'Name': 'Dialog1',
}
dialog = app.dialog.create(propiedades)
dialog.open()
return
```
<br>
#### Desde archivo
Crear un cuadro de diálogo desde un archivo `xdl` previamente creado desde el editor de cuadros de diálogo dentro de LibreOffice y exportado a un archivo.
```py
def crear_cuadro_de_dialogo():
path = '/home/elmau/Desktop/mi_dialogo.xdl'
propiedades = {'Path': path}
dialog = app.dialog.create(propiedades)
dialog.open()
return
```
<br>
#### Crear dinámicamente
Crear un cuadro de diálogo vacío.
```py
def crear_cuadro_de_dialogo():
dialog = app.dialog.create()
dialog.open()
return
```
Cambiar las propiedades iniciales.
```py
propiedades = dict(
Name = 'MiDialogo',
Title = 'Maldito Mundo',
Width = 200,
Height = 100,
)
dialog = app.dialog.create(propiedades)
dialog.open()
```
<br>
!!! tip Importante
Cualquier propiedad usada al crear el cuadro de diálogo, debe ser la original del control pyUNO.
#### Propiedades
| Nombre | Descripción |
| ------ | ----------- |
| AllDialogChildren | |
| BackgroundColor | Color de fondo |
| Closeable | Permite cerrar el cuadro de diálogo con el icono `X` |
| Decoration |
| DefaultControl |
| DesktopAsParent |
| DialogSourceURL |
| Enabled |
| FontCharWidth |
| FontCharset |
| FontDescriptor |
| FontEmphasisMark |
| FontFamily |
| FontHeight |
| FontKerning |
| FontName |
| FontOrientation |
| FontPitch |
| FontRelief |
| FontSlant |
| FontStrikeout |
| FontStyleName |
| FontType |
| FontUnderline |
| FontWeight |
| FontWidth |
| FontWordLineMode |
| Graphic |
| HScroll |
| Height | Altura del control |
| HelpText |
| HelpURL |
| ImageURL |
| Moveable |
| Name | Nombre del control |
| PositionX | Posición en el eje X |
| PositionY | Posición en el eje Y |
| ResourceResolver |
| ScrollHeight |
| ScrollLeft |
| ScrollTop |
| ScrollWidth |
| Sizeable | Si el control cambia de tamaño |
| Step |
| TabIndex |
| Tag |
| TextColor |
| TextLineColor |
| Title | Título del cuadro de diálogo |
| VScroll | Mostrar barra de desplazamiento vertial |
| Width | Ancho del control |
<br>
### **add_control**
---
Agrega un control al cuadro de diálogo.
```py
propiedades = {
'Type': 'label',
'Name': 'lbl_info',
'Label': 'Esta es una etiqueta.',
'Width': 100,
'Height': 15,
'Border': 1,
'X': 5,
'Y': 5,
}
dialog.add_control(propiedades)
```
<br>
## Eventos
---
Todos los eventos de todos los controles de un cuadro de diálogo se controlan por medio de una clase Python que se pasa a la propiedad `events` del cuadro de diálogo.
Cada método de esta clase que tenga en su nombre la estructura que corresponde al nombre del control más el nombre del evento, responderá a dicho evento de dicho control.
`NOMBRE_CONTROL_NOMBRE_EVENTO`
Ejemplo:
```py
import easymacro as app
class Eventos():
def __init__(self, dialog):
self.d = dialog
def cmd_cerrar_action(self, event):
self.d.close(1)
return
def main():
propiedades = dict(
Name = 'MiDialogo',
Title = 'Maldito Mundo',
Width = 200,
Height = 100,
)
dialog = app.dialog.create(propiedades)
dialog.events = Eventos
propiedades = {
'Type': 'button',
'Name': 'cmd_cerrar',
'Label': 'Cerrar',
'Width': 40,
'Height': 15,
}
dialog.add_control(propiedades)
dialog.open()
return
```
<br>
Cada control agregado al cuadro de diálogo es instanciado como una propiedad del mismo cuadro de diálogo. En el ejemplo anterior, el botón de comando `cmd_cerrar` es accesible desde cualquier variable que apunte al cuadro de diálogo, en el mismo ejemplo anterior en:
```py
dialog.cmd_cerrar
```
Como en la clase `Eventos` en:
```py
self.d.cmd_cerrar
```
<br>
## Controles
---
#### [Etiqueta (label)](label/)
#### [Botón de comando (button)](cmd/)
<br>

101
doc/docs/dialogs/label.md Normal file
View File

@ -0,0 +1,101 @@
# Etiqueta (label)
---
## Propiedades
---
### **type**
Devuelve el tipo de control.
```py
app.debug(label.type)
```
<br>
### **value**
Devuelve o establece la etiqueta del control.
```py
label.value = 'Mi etiqueta'
```
<br>
## Métodos
---
## Eventos
---
### **click**
Se ejecuta al dar click con cualquier botón del ratón.
```py
def label_click(self, event):
return
```
<br>
## Propiedades pyUNO
| Nombre | Descripción |
| ------ | ----------- |
| Align | |
| BackgroundColor | |
| Border | |
| BorderColor | |
| ContextWritingMode | |
| DefaultControl | |
| EnableVisible | |
| Enabled | |
| FontCharWidth | |
| FontCharset | |
| FontDescriptor | |
| FontEmphasisMark | |
| FontFamily | |
| FontHeight | |
| FontKerning | |
| FontName | |
| FontOrientation | |
| FontPitch | |
| FontRelief | |
| FontSlant | |
| FontStrikeout | |
| FontStyleName | |
| FontType | |
| FontUnderline | |
| FontWeight | |
| FontWidth | |
| FontWordLineMode | |
| Height | |
| HelpText | |
| HelpURL | |
| Label | |
| MultiLine | |
| Name | |
| NoLabel | |
| PositionX | |
| PositionY | |
| Printable | |
| ReferenceDevice | |
| ResourceResolver | |
| Step | |
| TabIndex | |
| Tabstop | |
| Tag | |
| TextColor | |
| TextLineColor | |
| VerticalAlign | |
| Width | |
| WritingMode | |

88
doc/docs/dialogs/link.md Normal file
View File

@ -0,0 +1,88 @@
# Hipervínculo (link)
---
## Propiedades
### **label**
Devuelve o establece la etiqueta.
<br>
### **url**
Devuelve o establece el vínculo web.
<br>
### **value**
Devuelve o establece el vínculo web y la etiqueta.
<br>
---
## Métodos
---
## Eventos
---
## Propiedades pyUNO
| Nombre | Descripción |
| ------ | ----------- |
| Align | |
| BackgroundColor | |
| Border | |
| BorderColor | |
| ContextWritingMode | |
| DefaultControl | |
| EnableVisible | |
| Enabled | |
| FontCharWidth | |
| FontCharset | |
| FontDescriptor | |
| FontEmphasisMark | |
| FontFamily | |
| FontHeight | |
| FontKerning | |
| FontName | |
| FontOrientation | |
| FontPitch | |
| FontRelief | |
| FontSlant | |
| FontStrikeout | |
| FontStyleName | |
| FontType | |
| FontUnderline | |
| FontWeight | |
| FontWidth | |
| FontWordLineMode | |
| Height | |
| HelpText | |
| HelpURL | |
| Label | |
| MultiLine | |
| Name | |
| NoLabel | |
| PositionX | |
| PositionY | |
| Printable | |
| ResourceResolver | |
| Step | |
| TabIndex | |
| Tabstop | |
| Tag | |
| TextColor | |
| TextLineColor | |
| URL | |
| VerticalAlign | |
| Width | |
| WritingMode | |
<br>

17
doc/docs/dialogs/md.md Normal file
View File

@ -0,0 +1,17 @@
# Control (label)
---
## Propiedades
---
## Métodos
---
## Eventos
---
## Propiedades pyUNO

112
doc/docs/dialogs/text.md Normal file
View File

@ -0,0 +1,112 @@
# Cuadro de texto (text)
---
## Propiedades
---
### **value**
Establece o recupera el valor del control.
```py
app.debug(text.value)
```
## Métodos
---
### **set_focus**
Envía el foco al control.
<br>
## Eventos
---
### **focus_gained**
Se produce al recibir el foco.
<br>
### **focus_lost**
Se produce al perder el foco.
<br>
### **text_changed**
Se produce al cambiar el contenido del control.
<br>
## Propiedades pyUNO
| Nombre | Descripción |
| ------ | ----------- |
| Align | |
| AutoHScroll | |
| AutoVScroll | |
| BackgroundColor | |
| Border | |
| BorderColor | |
| ContextWritingMode | |
| DefaultControl | |
| EchoChar | |
| EnableVisible | |
| Enabled | |
| FontCharWidth | |
| FontCharset | |
| FontDescriptor | |
| FontEmphasisMark | |
| FontFamily | |
| FontHeight | |
| FontKerning | |
| FontName | |
| FontOrientation | |
| FontPitch | |
| FontRelief | |
| FontSlant | |
| FontStrikeout | |
| FontStyleName | |
| FontType | |
| FontUnderline | |
| FontWeight | |
| FontWidth | |
| FontWordLineMode | |
| HScroll | |
| HardLineBreaks | |
| Height | |
| HelpText | |
| HelpURL | |
| HideInactiveSelection | |
| LineEndFormat | |
| MaxTextLen | |
| MultiLine | |
| Name | |
| PaintTransparent | |
| PositionX | |
| PositionY | |
| Printable | |
| ReadOnly | |
| ResourceResolver | |
| Step | |
| TabIndex | |
| Tabstop | |
| Tag | |
| Text | |
| TextColor | |
| TextLineColor | |
| VScroll | |
| VerticalAlign | |
| Width | |
| WritingMode | |
<br>

View File

@ -32,6 +32,13 @@ nav:
- Página de dibujo: - Página de dibujo:
- dp/drawpage.md - dp/drawpage.md
- Formas: dp/shapes.md - Formas: dp/shapes.md
- Cuadros de diálogo:
- dialogs/index.md
- Etiqueta: dialogs/label.md
- Botón de comando: dialogs/cmd.md
- Cuadro de texto: dialogs/text.md
- Hipervínculo: dialogs/link.md
- Imagen: dialogs/image.md
- Ejemplos de uso: - Ejemplos de uso:
- examples/index.md - examples/index.md
theme: theme:
@ -57,6 +64,8 @@ markdown_extensions:
- pymdownx.snippets - pymdownx.snippets
- pymdownx.tabbed: - pymdownx.tabbed:
alternate_style: true alternate_style: true
- tables
- pymdownx.keys
#~ extra: #~ extra:
#~ alternate: #~ alternate:
#~ - name: Español #~ - name: Español

View File

@ -9,7 +9,7 @@ from .easydocs import LODocuments
from .easymain import (log, TITLE, from .easymain import (log, TITLE,
BaseObject, Color, BaseObject, Color,
create_instance, set_properties) create_instance, set_properties)
from .easytools import _, LOInspect, Paths, Services from .easytools import _, LOInspect, Paths, Services, debug, mri
__all__ = [ __all__ = [
@ -18,16 +18,17 @@ __all__ = [
] ]
COLOR_ON_FOCUS = Color()('LightYellow') # ~ COLOR_ON_FOCUS = Color()('LightYellow')
SEPARATION = 5 SEPARATION = 5
MODELS = { MODELS = {
'label': 'com.sun.star.awt.UnoControlFixedTextModel', 'label': 'com.sun.star.awt.UnoControlFixedTextModel',
'text': 'com.sun.star.awt.UnoControlEditModel', 'text': 'com.sun.star.awt.UnoControlEditModel',
'button': 'com.sun.star.awt.UnoControlButtonModel', 'button': 'com.sun.star.awt.UnoControlButtonModel',
'link': 'com.sun.star.awt.UnoControlFixedHyperlinkModel', 'link': 'com.sun.star.awt.UnoControlFixedHyperlinkModel',
'image': 'com.sun.star.awt.UnoControlImageControlModel',
# ~ ToDo
'radio': 'com.sun.star.awt.UnoControlRadioButtonModel', 'radio': 'com.sun.star.awt.UnoControlRadioButtonModel',
'checkbox': 'com.sun.star.awt.UnoControlCheckBoxModel', 'checkbox': 'com.sun.star.awt.UnoControlCheckBoxModel',
'image': 'com.sun.star.awt.UnoControlImageControlModel',
'listbox': 'com.sun.star.awt.UnoControlListBoxModel', 'listbox': 'com.sun.star.awt.UnoControlListBoxModel',
'roadmap': 'com.sun.star.awt.UnoControlRoadmapModel', 'roadmap': 'com.sun.star.awt.UnoControlRoadmapModel',
'tree': 'com.sun.star.awt.tree.TreeControlModel', 'tree': 'com.sun.star.awt.tree.TreeControlModel',
@ -43,6 +44,7 @@ TYPE_CONTROL = {
'stardiv.Toolkit.UnoFixedTextControl': 'label', 'stardiv.Toolkit.UnoFixedTextControl': 'label',
'stardiv.Toolkit.UnoEditControl': 'text', 'stardiv.Toolkit.UnoEditControl': 'text',
'stardiv.Toolkit.UnoButtonControl': 'button', 'stardiv.Toolkit.UnoButtonControl': 'button',
'stardiv.Toolkit.UnoImageControlControl': 'image',
} }
IMPLEMENTATIONS = { IMPLEMENTATIONS = {
@ -50,6 +52,7 @@ IMPLEMENTATIONS = {
'link': 'stardiv.Toolkit.UnoFixedHyperlinkControl', 'link': 'stardiv.Toolkit.UnoFixedHyperlinkControl',
'roadmap': 'stardiv.Toolkit.UnoRoadmapControl', 'roadmap': 'stardiv.Toolkit.UnoRoadmapControl',
'pages': 'stardiv.Toolkit.UnoMultiPageControl', 'pages': 'stardiv.Toolkit.UnoMultiPageControl',
'text': 'stardiv.Toolkit.UnoEditControl',
} }
@ -57,8 +60,9 @@ def add_listeners(events, control):
name = control.Model.Name name = control.Model.Name
listeners = { listeners = {
'addActionListener': EventsButton, 'addActionListener': EventsButton,
# ~ 'addMouseListener': EventsMouse, 'addMouseListener': EventsMouse,
# ~ 'addFocusListener': EventsFocus, 'addFocusListener': EventsFocus,
'addTextListener': EventsText,
# ~ 'addItemListener': EventsItem, # ~ 'addItemListener': EventsItem,
# ~ 'addKeyListener': EventsKey, # ~ 'addKeyListener': EventsKey,
# ~ 'addTabListener': EventsTab, # ~ 'addTabListener': EventsTab,
@ -72,6 +76,9 @@ def add_listeners(events, control):
is_roadmap = control.ImplementationName == IMPLEMENTATIONS['roadmap'] is_roadmap = control.ImplementationName == IMPLEMENTATIONS['roadmap']
is_pages = control.ImplementationName == IMPLEMENTATIONS['pages'] is_pages = control.ImplementationName == IMPLEMENTATIONS['pages']
# ~ if control.ImplementationName == IMPLEMENTATIONS['text']:
# ~ mri(control)
for key, value in listeners.items(): for key, value in listeners.items():
if hasattr(control, key): if hasattr(control, key):
if is_grid and key == 'addMouseListener': if is_grid and key == 'addMouseListener':
@ -84,7 +91,7 @@ def add_listeners(events, control):
control.addItemListener(EventsItemRoadmap(events, name)) control.addItemListener(EventsItemRoadmap(events, name))
continue continue
getattr(control, key)(listeners[key](events, name)) getattr(control, key)(value(events, name))
if is_grid: if is_grid:
controllers = EventsGrid(events, name) controllers = EventsGrid(events, name)
@ -118,7 +125,8 @@ class UnoBaseObject(object):
@property @property
def properties(self): def properties(self):
data = LOInspect(self.obj).properties properties = self.model.PropertySetInfo.Properties
data = {p.Name: getattr(self.model, p.Name) for p in properties}
return data return data
@properties.setter @properties.setter
def properties(self, properties: dict): def properties(self, properties: dict):
@ -363,6 +371,41 @@ class UnoLabel(UnoBaseObject):
self.model.Label = value self.model.Label = value
class UnoLabelLink(UnoLabel):
def __init__(self, obj):
super().__init__(obj)
@property
def type(self):
return 'link'
@property
def value(self):
"""Get link"""
return self.model.URL
@value.setter
def value(self, value):
self.model.Label = value
self.model.URL = value
@property
def url(self):
"""Get link"""
return self.model.URL
@url.setter
def url(self, value):
self.model.URL = value
@property
def label(self):
"""Get label"""
return self.model.Label
@label.setter
def label(self, value):
self.model.Label = value
# ~ https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1awt_1_1UnoControlEditModel.html # ~ https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1awt_1_1UnoControlEditModel.html
class UnoText(UnoBaseObject): class UnoText(UnoBaseObject):
@ -418,14 +461,34 @@ class UnoButton(UnoBaseObject):
self.model.ImageURL = Paths.to_url(value) self.model.ImageURL = Paths.to_url(value)
class UnoImage(UnoBaseObject):
def __init__(self, obj):
super().__init__(obj)
@property
def type(self):
return 'button'
@property
def value(self):
return self.model.ImageURL
@value.setter
def value(self, value):
if isinstance(value, str):
self.model.ImageURL = value
else:
self.model.Graphic = value._get_graphic()
UNO_CLASSES = { UNO_CLASSES = {
'label': UnoLabel, 'label': UnoLabel,
'text': UnoText,
'button': UnoButton, 'button': UnoButton,
# ~ 'link': UnoLabelLink, 'text': UnoText,
'link': UnoLabelLink,
'image': UnoImage,
# ~ 'radio': UnoRadio, # ~ 'radio': UnoRadio,
# ~ 'checkbox': UnoCheckBox, # ~ 'checkbox': UnoCheckBox,
# ~ 'image': UnoImage,
# ~ 'listbox': UnoListBox, # ~ 'listbox': UnoListBox,
# ~ 'roadmap': UnoRoadmap, # ~ 'roadmap': UnoRoadmap,
# ~ 'tree': UnoTree, # ~ 'tree': UnoTree,
@ -441,10 +504,10 @@ class DialogBox(BaseObject):
SERVICE_DIALOG = 'com.sun.star.awt.UnoControlDialog' SERVICE_DIALOG = 'com.sun.star.awt.UnoControlDialog'
def __init__(self, properties: dict={}): def __init__(self, properties: dict={}):
self._controls = {}
obj = self._create(properties) obj = self._create(properties)
super().__init__(obj) super().__init__(obj)
self._init_controls() self._init_controls()
self._modal = False
def _create_from_path(self, path: str): def _create_from_path(self, path: str):
dp = create_instance(self.SERVICE, True) dp = create_instance(self.SERVICE, True)
@ -458,13 +521,16 @@ class DialogBox(BaseObject):
name = properties['Name'] name = properties['Name']
library = properties.get('Library', 'Standard') library = properties.get('Library', 'Standard')
location = properties.get('Location', 'application').lower() location = properties.get('Location', 'application').lower()
if location == 'user': if location == 'user':
location = 'application' location = 'application'
url = f'vnd.sun.star.script:{library}.{name}?location={location}' url = f'vnd.sun.star.script:{library}.{name}?location={location}'
if location == 'document': if location == 'document':
doc = LODocuments().active.obj doc = properties.get('Document', LODocuments().active)
if hasattr(doc, 'obj'):
doc = doc.obj
dp = create_instance(self.SERVICE, arguments=doc) dp = create_instance(self.SERVICE, arguments=doc)
else: else:
dp = create_instance(self.SERVICE, True) dp = create_instance(self.SERVICE, True)
@ -500,39 +566,30 @@ class DialogBox(BaseObject):
tipo = control.ImplementationName tipo = control.ImplementationName
name = control.Model.Name name = control.Model.Name
if not tipo in TYPE_CONTROL: if not tipo in TYPE_CONTROL:
log.debug(f'Type control: {tipo}') debug(f'Type control: {tipo}')
raise AttributeError(f"Has no class '{tipo}'") raise AttributeError(f"Has no class '{tipo}'")
control = UNO_CLASSES[TYPE_CONTROL[tipo]](control) control = UNO_CLASSES[TYPE_CONTROL[tipo]](control)
setattr(self, name, control) setattr(self, name, control)
self._controls[name] = control
return return
def execute(self): def execute(self):
return self.obj.execute() return self.obj.execute()
def open(self): def open(self, modal=False):
self._modal = modal
if modal:
self.visible = True
return
return self.execute() return self.execute()
def close(self, value=0): def close(self, value=0):
value = self.obj.endDialog(value) if self._modal:
self.visible = False
self.obj.dispose()
else:
value = self.obj.endDialog(value)
return value return value
# ~ def close(self, value=0):
# ~ if self._modal:
# ~ value = self.obj.endDialog(value)
# ~ else:
# ~ self.visible = False
# ~ self.obj.dispose()
# ~ return value
# ~ def show(self, modal=True):
# ~ self._modal = modal
# ~ if modal:
# ~ return self.obj.execute()
# ~ else:
# ~ self.visible = True
# ~ return
@property @property
def model(self): def model(self):
return self.obj.Model return self.obj.Model
@ -576,6 +633,17 @@ class DialogBox(BaseObject):
def color_on_focus(self, value): def color_on_focus(self, value):
self._color_on_focus = get_color(value) self._color_on_focus = get_color(value)
@property
def properties(self):
properties = self.model.PropertySetInfo.Properties
data = {}
for p in properties:
try:
data[p.Name] = getattr(self.model, p.Name)
except:
continue
return data
@property @property
def events(self): def events(self):
return self._events return self._events
@ -601,9 +669,14 @@ class DialogBox(BaseObject):
properties['Label'] = properties['URL'] properties['Label'] = properties['URL']
return properties return properties
if tipo == 'label':
properties['VerticalAlign'] = properties.get('VerticalAlign', 1)
return properties
if tipo == 'button': if tipo == 'button':
if 'ImageURL' in properties: if 'ImageURL' in properties:
properties['ImageURL'] = self._set_image_url(properties['ImageURL']) properties['ImageURL'] = self._set_image_url(properties['ImageURL'])
properties['ImageAlign'] = properties.get('ImageAlign', 0)
properties['FocusOnClick'] = properties.get('FocusOnClick', False) properties['FocusOnClick'] = properties.get('FocusOnClick', False)
return properties return properties
@ -659,7 +732,7 @@ class DialogBox(BaseObject):
control.events = self.events control.events = self.events
setattr(self, name, control) setattr(self, name, control)
self._controls[name] = control
return control return control

View File

@ -5,14 +5,24 @@ import unohelper
from com.sun.star.awt import XActionListener from com.sun.star.awt import XActionListener
from com.sun.star.lang import XEventListener from com.sun.star.lang import XEventListener
from com.sun.star.awt import XFocusListener
from com.sun.star.util import XModifyListener
from com.sun.star.awt import XMouseListener
from com.sun.star.awt import XMouseMotionListener
from com.sun.star.awt import XTextListener
from com.sun.star.sheet import XRangeSelectionListener from com.sun.star.sheet import XRangeSelectionListener
from .easymain import Macro, dict_to_property from .easymain import Macro, Color, dict_to_property
__all__ = [ __all__ = [
'EventsButton', 'EventsButton',
'EventsFocus',
'EventsModify',
'EventsMouse',
'EventsMouseLink',
'EventsRangeSelectionListener', 'EventsRangeSelectionListener',
'EventsText',
] ]
@ -93,6 +103,9 @@ class EventsRangeSelectionListener(EventsListenerBase, XRangeSelectionListener):
class EventsButton(EventsListenerBase, XActionListener): class EventsButton(EventsListenerBase, XActionListener):
"""
See: https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1awt_1_1XActionListener.html
"""
def __init__(self, controller, name): def __init__(self, controller, name):
super().__init__(controller, name) super().__init__(controller, name)
@ -102,3 +115,96 @@ class EventsButton(EventsListenerBase, XActionListener):
if hasattr(self._controller, event_name): if hasattr(self._controller, event_name):
getattr(self._controller, event_name)(event) getattr(self._controller, event_name)(event)
return return
class EventsMouse(EventsListenerBase, XMouseListener, XMouseMotionListener):
def __init__(self, controller, name):
super().__init__(controller, name)
def mousePressed(self, event):
event_name = f'{self._name}_click'
if event.ClickCount == 2:
event_name = f'{self._name}_double_click'
if hasattr(self._controller, event_name):
getattr(self._controller, event_name)(event)
return
def mouseReleased(self, event):
pass
def mouseEntered(self, event):
pass
def mouseExited(self, event):
pass
# ~ XMouseMotionListener
def mouseMoved(self, event):
pass
def mouseDragged(self, event):
pass
class EventsMouseLink(EventsMouse):
def mouseEntered(self, event):
obj = event.Source.Model
obj.TextColor = Color()('blue')
return
def mouseExited(self, event):
obj = event.Source.Model
obj.TextColor = 0
return
class EventsFocus(EventsListenerBase, XFocusListener):
def __init__(self, controller, name):
super().__init__(controller, name)
def focusGained(self, event):
service = event.Source.Model.ImplementationName
if service == 'stardiv.Toolkit.UnoControlListBoxModel':
return
event_name = f'{self._name}_focus_gained'
if hasattr(self._controller, event_name):
getattr(self._controller, event_name)(event)
# ~ obj = event.Source.ModelBackgroundColor = 16777184
return
def focusLost(self, event):
event_name = f'{self._name}_focus_lost'
if hasattr(self._controller, event_name):
getattr(self._controller, event_name)(event)
# ~ event.Source.Model.BackgroundColor = -1
return
class EventsModify(EventsListenerBase, XModifyListener):
def __init__(self, controller, name):
super().__init__(controller, name)
def modified(self, event):
event_name = f'{self._name}_modified'
if hasattr(self._controller, event_name):
getattr(self._controller, event_name)(event)
return
class EventsText(EventsListenerBase, XTextListener):
def __init__(self, controller, name):
super().__init__(controller, name)
def textChanged(self, event):
event_name = f'{self._name}_text_changed'
if hasattr(self._controller, event_name):
getattr(self._controller, event_name)(event)
return