Hello everyone,
Is there a possibility of catching and disabling messages such as the one below? Is there any event that I could register, and if so at what level?
Hello everyone,
Is there a possibility of catching and disabling messages such as the one below? Is there any event that I could register, and if so at what level?
I am pretty sure that such possibility does not exist. A workaround is to install a Top window listener, which automatically closes this message when it pops up. But the user would always see a flickerā¦
Thus, essentially, this is hard coded without any option available to have it disabled. Unfortunately, as much as I wish that would not be the case, way above my abilities and comprehension. There is no way Iād even make an attempt to alter the original code.
What @ms777 is proposing looks definitely more straight forward. Although, when you say ātop window listenerā are you referring to one of the Calc listeners or spreadsheet?
Thank you both for your offered assistance.
Hi,
the below python code installs a TopWindowListener, which checks title and message text of all newly opened windows.
If they match (title: āInformationā, message: āProtected cells can not be modified.ā) the OK-button is pressed through its AccessibleContext.
There are some caveats:
It goes for title and message, so it is UI language dependent.
AFAIK the code cannot be replicated in LO Basic. One needs to press the OK button in a separate thread with a (very small) delay, which is impossible in Basic. Pressing the OK button directly in windowOpened leaves some orphaned window elements. Maybe this is a LO bug.
Good luck,
ms777
import unohelper
import time
import threading
from com.sun.star.awt import XTopWindowListener # type:ignore
from com.sun.star.lang import EventObject # type:ignore
def hasUnoInterfaces(obj, *interfaces):
return set(interfaces).issubset(t.typeName for t in obj.Types)
def closeDialog(oAcOK):
time.sleep(0.01)
oAcOK.doAccessibleAction(0)
class CTopWindowListener(XTopWindowListener, unohelper.Base):
def windowActivated(self, e: EventObject):
pass
def windowClosed(self, e: EventObject):
pass
def windowClosing(self, e: EventObject):
pass
def windowDeactivated(self, e: EventObject):
pass
def windowMinimized(self, e: EventObject):
pass
def windowMaximized(self, e: EventObject):
pass
def windowNormalized(self, e: EventObject):
pass
def windowOpened(self, e: EventObject):
if hasUnoInterfaces(e.Source, 'com.sun.star.awt.XDialog2') :
title = e.Source.Title
if title == 'Information':
try:
oAcOK = e.Source.AccessibleContext.getAccessibleChild(0).AccessibleContext.getAccessibleChild(1).AccessibleContext.getAccessibleChild(0).AccessibleContext
if oAcOK.AccessibleName == 'OK':
sText = e.Source.AccessibleContext.getAccessibleChild(0).AccessibleContext.getAccessibleChild(0).AccessibleContext.getAccessibleChild(0).AccessibleContext.getAccessibleChild(0).AccessibleContext.Text
if sText == "Protected cells can not be modified.":
t = threading.Thread(target = closeDialog, args = (oAcOK, ))
t.start()
except:
pass
def disposing(self, e: EventObject):
pass
def InstallTopWindowListener(*args):
doc = XSCRIPTCONTEXT.getDocument() # type: ignore
myTopWindowListener = CTopWindowListener()
oToolkit = doc.CurrentController.Frame.ComponentWindow.Toolkit
oToolkit.addTopWindowListener(myTopWindowListener)
Thanks amazing, thank you very much for your help.