Hi everyone,

I posted a similar question a few months back, but now I'm more or less
running around the same problem. I've done some extra research, so I
hope someone will be able to help.

I want to create and show a non-modal dialog from one macro (I'm using
Python) and once it's open I want to access and modify its controls from
another macro. I haven't found a way to store a global reference to the
dialog window, so I'm trying to access it through the frame hierarchy.
It's almost there, but I'm finally stuck.

First I create and display the dialog in one macro -- pretty standard
stuff except that I pass the current frame's container window as the peer:

smgr = XSCRIPTCONTEXT.getComponentContext().ServiceManager
ctx = XSCRIPTCONTEXT.getComponentContext()
dialogModel = smgr.createInstanceWithContext(
              "com.sun.star.awt.UnoControlDialogModel", ctx)
dialogModel.Title = "FooBar"
controlContainer = smgr.createInstanceWithContext(
                   "com.sun.star.awt.UnoControlDialog", ctx)
controlContainer.setModel(dialogModel)
toolkit = smgr.createInstanceWithContext(
          "com.sun.star.awt.Toolkit", ctx)
containerWin = XSCRIPTCONTEXT.getDocument().getCurrentController()
               .getFrame().getContainerWindow()
controlContainer.createPeer(toolkit, containerWin)
controlContainer.setVisible(True)

Now the dialog is displayed (non-modally, because I used setVisible()
instead of execute()), I want to access it via the frame hierarchy from
another macro. Using through the same frame's toolkit and going through
its TopWindows, in a separate macro I've managed to get hold of what
seems to be the dialog's container window (it's the only one with a
Title, and it's the same Title as for my dialog):

tk = XSCRIPTCONTEXT.getDocument().getCurrentController().getFrame()
     .getContainerWindow().getToolkit()
for i in range(0, tk.getTopWindowCount()):
    currWin = tk.getTopWindow(i)
    if "Title" in dir(currWin) and currWin.Title == "FooBar":
        dialogRef = currWin
        break

(For non-Python speakers, dir() returns a sequence of available
attributes). Now dialogRef is an XTopWindow and XDialog, and a call to
its getWindows() shows an XWindow and XButton (presumably the dialog
window and default close button). However, I can't find a way of getting
the dialog model from dialogRef nor its inner XWindow, which is what I
really need.

So my question: is it at all possible to achieve what I'm doing, i.e.
access the controls of an open dialog window through the frame
hierarchy? If so, am I going the right way? And if not, what could I do
to get a similar effect (maybe abandon dialogs and create a window some
other way)? For my original question, Mathias Bauer suggested
implementing a singleton UNO service for the dialog, but I was hoping
for some simpler way. I'm basically trying to create a glossary window
for my app, acting something like the OOo Stylist (non-modal,
always-on-top) and fully accessible to macros from the API.

Bit long for a question, but it seems to me a useful problem to resolve.
Hope someone can help me out here.

Thanks in advance,

Zbigniew Banach

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to