[Python] dialog whose content can be selected and copied
[Python] dialog whose content can be selected and copied
Hello *,
How to make a dialog whose content can be selected and copied?
I noticed that some part of the LibreOffice About dialog can be selected and copied, but no idea how to do this.
How to make a dialog whose content can be selected and copied?
I noticed that some part of the LibreOffice About dialog can be selected and copied, but no idea how to do this.
LibreOffice 6.4 • Windows 10
Re: [Python] dialog whose content can be selected and copied
Code: Select all
import uno
from com.sun.star.awt.MessageBoxType import MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX
from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK, BUTTONS_OK_CANCEL, BUTTONS_ABORT_IGNORE_RETRY, BUTTONS_YES_NO_CANCEL, BUTTONS_YES_NO, BUTTONS_RETRY_CANCEL, DEFAULT_BUTTON_OK, DEFAULT_BUTTON_CANCEL, DEFAULT_BUTTON_RETRY, DEFAULT_BUTTON_YES, DEFAULT_BUTTON_NO, DEFAULT_BUTTON_IGNORE
from com.sun.star.awt.MessageBoxResults import CANCEL, OK, YES, NO, RETRY, IGNORE
def hello_world_msgbox(*args):
ctx = uno.getComponentContext()
smgr = ctx.getServiceManager()
tk = smgr.createInstance('com.sun.star.awt.Toolkit')
dtp = smgr.createInstance('com.sun.star.frame.Desktop')
frame = dtp.getCurrentFrame()
win = frame.getComponentWindow()
mtyp = INFOBOX
btn = BUTTONS_YES_NO_CANCEL + DEFAULT_BUTTON_YES
title = 'HELLO WORLD TEST'
msg = '"Hello World" from Python via com.sun.star.awt.Toolkit'
mb = tk.createMessageBox(win,mtyp,btn,title,msg)
return mb.execute()
Edit: If you set mtyp = QUERYBOX, all the buttons appear. INFOBOX implies a simple message with on OK button. |
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: [Python] dialog whose content can be selected and copied
Thanks a lot for the answer.
But I realize I should have been more specific. I already have a dialog with a lot of “fixed” texts (this is a conjugation tool), and I’d like to be able to copy and select the content of this dialog.
I saw nothing in the LibreOffice API to make fixed texts selectable.
What it looks like: Here the code of this dialog (I cut most the irrelevant parts):
But I realize I should have been more specific. I already have a dialog with a lot of “fixed” texts (this is a conjugation tool), and I’d like to be able to copy and select the content of this dialog.
I saw nothing in the LibreOffice API to make fixed texts selectable.
What it looks like: Here the code of this dialog (I cut most the irrelevant parts):
Code: Select all
class Conjugueur (unohelper.Base, XActionListener, XTopWindowListener, XJobExecutor):
def __init__ (self, ctx):
self.ctx = ctx
self.xSvMgr = self.ctx.ServiceManager
self.xContainer = None
self.xDialog = None
self.lDropDown = ["être", "avoir", "aller", "vouloir", "pouvoir", "devoir", "acquérir", "connaître", "dire", "faire", \
"mettre", "partir", "prendre", "répondre", "savoir", "sentir", "tenir", "vaincre", "venir", "voir", \
"appeler", "envoyer", "commencer", "manger", "trouver", "accomplir", "agir", "finir", "haïr", "réussir"]
self.sWarning = "Verbe non vérifié.\nOptions “pronominal” et “temps composés” désactivées."
def _addWidget (self, name, wtype, x, y, w, h, **kwargs):
xWidget = self.xDialog.createInstance('com.sun.star.awt.UnoControl%sModel' % wtype)
xWidget.Name = name
xWidget.PositionX = x
xWidget.PositionY = y
xWidget.Width = w
xWidget.Height = h
for k, w in kwargs.items():
setattr(xWidget, k, w)
self.xDialog.insertByName(name, xWidget)
return xWidget
def run (self, sArgs=""):
## dialog
self.xDialog = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialogModel', self.ctx)
self.xDialog.Width = 300
self.xDialog.Title = "Grammalecte · Conjugueur"
## widgets
nWidth = (self.xDialog.Width-30) // 2
nHeight = 10
nHeightCj = 8
nTitleColor = 0x660000
nSubTitleColor = 0x000033
# grid
nX1 = 10; nX2 = nX1+145;
nY0 = 5; nY1 = nY0+17; nY2 = nY1+2; nY3 = nY2+30; nY4 = nY3+46; nY5 = nY4+55; nY6 = nY5+55; nY7 = nY6+55; nY6b = nY6+13; nY7b = nY6b+55
# input field + button
self.input = self._addWidget('input', 'ComboBox', nX1, nY0, 85, 14, TextColor = 0x666666, Dropdown = True, LineCount = 30)
for n, s in enumerate(self.lDropDown):
self.input.insertItemText(n, s)
# button
self.cbutton = self._addWidget('cbutton', 'Button', nX1+90, nY0, 50, 14, Label = "Conjuguer")
... some other widgets ...
# group box // indicatif
gb_infi = self._addWidget('groupbox_infi', 'FixedLine', nX1, nY2, nWidth, 10, Label = "Infinitif", \
FontRelief = 0, TextColor = nTitleColor)
self.infi = self._addWidget('infi', 'FixedText', nX1, nY2+10, nWidth, nHeight, Label = "")
... a lot more of fixed text widgets here ...
# dialog height
self.xDialog.Height = 350
xWindowSize = helpers.getWindowSize()
self.xDialog.PositionX = int((xWindowSize.Width / 2) - (self.xDialog.Width / 2))
self.xDialog.PositionY = int((xWindowSize.Height / 2) - (self.xDialog.Height / 2))
## container
self.xContainer = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.UnoControlDialog', self.ctx)
self.xContainer.setModel(self.xDialog)
self.xContainer.setVisible(True) # True for non modal dialog
self.xContainer.getControl('cbutton').addActionListener(self)
self.xContainer.getControl('cbutton').setActionCommand('New')
... other listeners and action commands here ...
self.xContainer.addTopWindowListener(self) # listener with XTopWindowListener methods
#self.xContainer.execute() # for modal dialog only
xToolkit = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.ExtToolkit', self.ctx)
self.xContainer.createPeer(xToolkit, None)
LibreOffice 6.4 • Windows 10
Re: [Python] dialog whose content can be selected and copied
Instead of FixedText you could use a read-only EditBox with same color as the background.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: [Python] dialog whose content can be selected and copied
Looking at the LibreOffice about box... the bit that can be selected the "Version: 6.1.5.2 (x64)..." bit... has a right click popup menu that's the same as a textbox and that's what it might be - though there's something very strange about it in that it flickers a lot and there is no caret, so it might not be.
You can use textboxes - or one textbox only positioned over the right fixed text - if you only need to select from one at a time.
Or you could use fixedtext controls (labels) and simulate a selection by changing the background color to blue. If you were happy with the whole fixed text being selected or not selected that would be easy. If you needed character by character selection then you could overlay another fixed text with a blue background for the selected portions.
You can use textboxes - or one textbox only positioned over the right fixed text - if you only need to select from one at a time.
Or you could use fixedtext controls (labels) and simulate a selection by changing the background color to blue. If you were happy with the whole fixed text being selected or not selected that would be easy. If you needed character by character selection then you could overlay another fixed text with a blue background for the selected portions.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [Python] dialog whose content can be selected and copied
The problem with EditBox is that you can select the content only one by one.
Selection is a request from one of my user, but I assume that copying all relevant data to the clipboard might be good enough.
Thank you for the help.
Selection is a request from one of my user, but I assume that copying all relevant data to the clipboard might be good enough.
Thank you for the help.
LibreOffice 6.4 • Windows 10
Re: [Python] dialog whose content can be selected and copied
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: [Python] dialog whose content can be selected and copied
No, does not support multiple selections of snippets
Last edited by Villeroy on Fri Apr 24, 2020 11:14 am, edited 1 time in total.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: [Python] dialog whose content can be selected and copied
If anyone wanted to implement the label idea above you'd use this interface:
https://www.openoffice.org/api/docs/com ... ssibleText
There is selectedtext and so on in that interface - but it doesn't apply when its a fixed text/label control
It gives you all the information you need such as the character at the mouse point (on a mouse down/move event) so you can position another label over it for the highlight. You could actually write a textbox control using labels (something i've done in OOBasic) because you have enough information there to do it.
For a multiselection you'd need two extra labels to represent the part of the first and last fixed texts that are selected. The selection of the ones in between can be indicated by setting the background color to the highlight color.
https://www.openoffice.org/api/docs/com ... ssibleText
There is selectedtext and so on in that interface - but it doesn't apply when its a fixed text/label control
It gives you all the information you need such as the character at the mouse point (on a mouse down/move event) so you can position another label over it for the highlight. You could actually write a textbox control using labels (something i've done in OOBasic) because you have enough information there to do it.
For a multiselection you'd need two extra labels to represent the part of the first and last fixed texts that are selected. The selection of the ones in between can be indicated by setting the background color to the highlight color.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)