12from sys
import modules
13from sys
import path
as syspath
19from com.sun.star.awt.WindowClass
import TOP, SIMPLE
20from com.sun.star.awt.PushButtonType
import STANDARD
as standard
21from com.sun.star.awt.PushButtonType
import OK
as ok
22from com.sun.star.awt.PushButtonType
import CANCEL
as cancel
23from com.sun.star.awt.PushButtonType
import HELP
as help
24from com.sun.star.awt.TextAlign
import CENTER
as center
25from com.sun.star.awt.TextAlign
import LEFT
as left
26from com.sun.star.awt.TextAlign
import RIGHT
as right
32 """Inspect UNO object, link to sdk and recursive calls"""
35 """acontext : a Valid UNO context
40 self.
smgr = aContext.ServiceManager
66 numberOfLines = len(self.
message.split(chr(10)))
70 numberOfButtons = len(self.
Buttons)
74 size = (2 * self.
boxSize) / (3 * numberOfButtons + 1)
83 dialog_model = self.
smgr.createInstanceWithContext(
84 'com.sun.star.awt.UnoControlDialogModel',
86 dialog_model.PositionX = 50
88 dialog_model.TabIndex = 7
89 dialog_model.Width = self.
boxSize
91 dialog_model.Height = 10 + self.
lineHeight * numberOfLines + 10 + 12 + 10
92 dialog_model.PositionY = 63
93 dialog_model.Sizeable =
True
94 dialog_model.Closeable =
False
96 dialog = self.
smgr.createInstanceWithContext(
97 'com.sun.star.awt.UnoControlDialog', self.
ctx)
100 label = dialog_model.createInstance(
101 'com.sun.star.awt.UnoControlFixedTextModel')
104 label.Width = dialog_model.Width - label.PositionX
108 label.MultiLine =
True
110 dialog_model.insertByName(
'Label0', label)
113 for buttonName
in self.
Buttons:
115 button = dialog_model.createInstance(
116 'com.sun.star.awt.UnoControlButtonModel')
121 button.PositionY = 10 + label.Height + 10
122 button.PushButtonType = standard
124 button.DefaultButton =
True
126 button.DefaultButton =
False
127 button.Label = buttonName
128 dialog_model.insertByName(
'Btn' + str(nb), button )
130 if not dialog.getModel():
131 dialog.setModel(dialog_model)
134 toolkit = self.
smgr.createInstanceWithContext(
'com.sun.star.awt.Toolkit', self.
ctx)
137 dialog.setTitle ( self.
title )
142 win_descriptor.Type = TOP
143 win_descriptor.ParentIndex = -1
144 win_descriptor.Bounds = a_rect
145 peer = toolkit.createWindow( win_descriptor )
146 dialog.createPeer( toolkit, peer )
151 """Add listeners to dialog"""
153 for buttonName
in self.
Buttons:
155 a_control = self.
dialog.getControl(
'Btn'+str(nb))
157 a_control.addActionListener(the_listener)
162 """ remove listeners on exiting"""
164 for buttonName
in self.
Buttons:
166 a_control = self.
dialog.getControl(
'Btn'+str(nb))
167 a_control.removeActionListener(self.
lst_listeners[
'Btn'+str(nb)])
170 def show(self, message, decoration, title):
199 """Stops the MessageBox, sets the button label as returned value"""
207 button = actionEvent.Source
208 self.caller.Response = button.Model.Label
209 self.caller.dialog.endExecute()
213if __name__ ==
'__main__':
218 resolver = localContext.ServiceManager.createInstanceWithContext(
219 "com.sun.star.bridge.UnoUrlResolver", localContext )
224 ctx = resolver.resolve(
"uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
226 myBox.addButton(
"Yes")
227 myBox.addButton(
"No")
228 myBox.addButton(
"May be")
229 myBox.renderFromBoxSize(150)
230 myBox.numberOflines = 2
232 print(myBox.show(
"A very long message A very long message A very long message A very long message A very long message A very long message A very long message A very long message A very long message A very long message " + chr(10)+chr(10)+
"Do you agree ?",0,
"Dialog title"))
235 myBox.addButton(
"oK")
236 myBox.renderFromButtonSize()
237 myBox.numberOflines = 2
239 print(myBox.show(
"A small message",0,
"Dialog title"))
def renderFromBoxSize(self, size=150)
def addButton(self, caption)
def show(self, message, decoration, title)
def _createBox(self)
GUI definition #.
def renderFromButtonSize(self, size=50)
def __init__(self, aContext)
def _removeListeners(self)
def getComponentContext()
def createUnoStruct(typeName, *args, **kwargs)