Linux Mint 21 x64 Cinnamon X11
Version: 7.5.4.2 (X86_64) / LibreOffice Community
Build ID: 50(Build:2)
CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: pt-BR (pt_BR.UTF-8); UI: en-US
Ubuntu package version: 4:7.5.4~rc2-0ubuntu0.22.04.1~lo1
Calc: threaded
Using macro in python I create a dialog that contains a PatternField widget, when I set the StrictFormat property to True. Hotkeys no longer work on this widget. (Ctrl+A, Ctrl+C, Ctrl+V … etc …).
I tested on Windows these shortcut keys work, on Linux if StrictFormat is False, the shortcuts work.
Complement:
I need to be more precise in my question. The error happens when I set a value for these three properties together
'EditMask': 'NNNLNNNLNNNLNN', 'LiteralMask': ' . . - ', 'StrictFormat': True
None of the conventional shortcuts present in the menu below work in linux if StrictFormat = True
Am I doing something wrong or is this a bug?
import uno
from com.sun.star.awt import MessageBoxButtons as MSG_BUTTONS
from com.sun.star.awt.PosSize import POS, SIZE, POSSIZE
from com.sun.star.awt.PushButtonType import OK, CANCEL
from com.sun.star.util.MeasureUnit import TWIP
import re
def create_instance(name, with_context=False):
ctx = XSCRIPTCONTEXT.getComponentContext()
sm = ctx.ServiceManager
if with_context:
instance = sm.createInstanceWithContext(name, ctx)
else:
instance = sm.createInstance(name)
return instance
def msg(message, title='LibreOffice', buttons=MSG_BUTTONS.BUTTONS_OK, type_msg='INFOBOX'):
toolkit = create_instance('com.sun.star.awt.Toolkit')
parent = toolkit.getDesktopWindow()
mb = toolkit.createMessageBox(parent, type_msg, buttons, title, str(message)+'\n\n')
return mb.execute()
def dialog_test(message, title='', default='', x=None, y=None):
#https://api.libreoffice.org/docs/idl/ref/structcom_1_1sun_1_1star_1_1awt_1_1FontDescriptor.html
#https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1awt_1_1UnoControlPatternFieldModel.html
#https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1awt_1_1UnoControlButtonModel.html
#https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1awt_1_1UnoControlFixedTextModel.html
WIDTH = 520
MARGIN = 8
BUTTON_WIDTH = 100
BUTTON_HEIGHT = 26
SEP = 8
LBL_HEIGHT = 16
EDIT_HEIGHT = 26
HEIGHT = MARGIN * 2 + LBL_HEIGHT + SEP + EDIT_HEIGHT + SEP + BUTTON_HEIGHT + SEP + LBL_HEIGHT
dialog = create_instance('com.sun.star.awt.UnoControlDialog', True)
dialog_model = create_instance('com.sun.star.awt.UnoControlDialogModel', True)
dialog.setModel(dialog_model)
dialog.setVisible(False)
dialog.setTitle(title)
dialog.setPosSize(0, 0, WIDTH, HEIGHT, SIZE)
def add_widget(name, type, x_, y_, width_, height_, props):
model = dialog_model.createInstance(f'''com.sun.star.awt.UnoControl{type}Model''')
dialog_model.insertByName(name, model)
control = dialog.getControl(name)
control.setPosSize(x_, y_, width_, height_, POSSIZE)
for key, value in props.items():
if key == 'FontDescriptor':
font_descriptor = uno.createUnoStruct('com.sun.star.awt.FontDescriptor')
for k, v in value.items():
setattr(font_descriptor, k, v)
setattr(model, key, font_descriptor)
else:
setattr(model, key, value)
# Adding widgets to the dialog
add_widget('label', 'FixedText', MARGIN, MARGIN, WIDTH - MARGIN * 2, LBL_HEIGHT, {'Label': str(message), 'NoLabel': True})
add_widget('edit', 'PatternField', MARGIN, MARGIN + LBL_HEIGHT + SEP, WIDTH - MARGIN * 2, EDIT_HEIGHT,
{'Text': default, 'EditMask': 'NNNLNNNLNNNLNN', 'LiteralMask': ' . . - ', 'StrictFormat': True})
add_widget('lbl_error', 'FixedText', MARGIN, MARGIN + LBL_HEIGHT + SEP + EDIT_HEIGHT + SEP, WIDTH - MARGIN * 2, LBL_HEIGHT, {'Label': '', 'NoLabel': True, 'MultiLine': True, 'TextColor': int('ff0000', 16), 'FontDescriptor': {'Weight': 200}})
add_widget('btn_ok', 'Button', WIDTH - BUTTON_WIDTH - MARGIN, HEIGHT - MARGIN - BUTTON_HEIGHT, BUTTON_WIDTH,
BUTTON_HEIGHT, {'PushButtonType': OK, 'DefaultButton': True})
add_widget('btn_cancel', 'Button', WIDTH - BUTTON_WIDTH - MARGIN * 2 - SEP - BUTTON_WIDTH,
HEIGHT - MARGIN - BUTTON_HEIGHT, BUTTON_WIDTH, BUTTON_HEIGHT, {'PushButtonType': CANCEL})
frame = create_instance('com.sun.star.frame.Desktop', True).getCurrentFrame()
window = frame.getContainerWindow() if frame else None
dialog.createPeer(create_instance('com.sun.star.awt.Toolkit', True), window)
# Defining the position of the dialog
if x is not None and y is not None:
ps = dialog.convertSizeToPixel(uno.createUnoStruct('com.sun.star.awt.Size', x, y), TWIP)
_x, _y = ps.Width, ps.Height
elif window:
ps = window.getPosSize()
_x = ps.Width / 2 - WIDTH / 2
_y = ps.Height / 2 - HEIGHT / 2
dialog.setPosSize(_x, _y, 0, 0, POS)
# Loop to display the dialog until a valid value is entered
while True:
# Display the dialog and get the result
if dialog.execute():
value = dialog.getControl('edit').getText()
# Check if the entered value is valid
if not re.match(r'^\d{3}\.\d{3}\.\d{3}-\d{2}$', value):
error_label = dialog.getControl('lbl_error')
error_label.setText('The entered Code is invalid. Please enter a correct Code.')
#error_label_model = dialog_model.getByName('lbl_error')
#error_label_model.TextColor = int('0000ff', 16)
else:
# Valid value, break the loop
break
else:
# Cancel button pressed, break the loop
value = ''
break
# Close the dialog and return the entered value
dialog.dispose()
return value
def test():
result = dialog_test('Enter only numbers:', 'Title')
if result != '':
msg(result)
return