Thanks,
Sachin
Code: Select all
def inputbox(message, title="", default="", x=None, y=None):
""" Shows dialog with input box.
@param message message to show on the dialog
@param title window title
@param default default value
@param x dialog positio in twips, pass y also
@param y dialog position in twips, pass y also
@return string if OK button pushed, otherwise zero length string
"""
WIDTH = 300
HORI_MARGIN = VERT_MARGIN = 8
BUTTON_WIDTH = 100
BUTTON_HEIGHT = 26
HORI_SEP = VERT_SEP = 8
LABEL_HEIGHT = BUTTON_HEIGHT * 2 + 5
EDIT_HEIGHT = 24
HEIGHT = 150
import uno
import unohelper
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
from com.sun.star.awt import XActionListener
from com.sun.star.awt import XItemListener
ctx = uno.getComponentContext()
def create(name):
return ctx.getServiceManager().createInstanceWithContext(name, ctx)
dialog = create("com.sun.star.awt.UnoControlDialog")
dialog_model = create("com.sun.star.awt.UnoControlDialogModel")
dialog.setModel(dialog_model)
dialog.setVisible(False)
dialog.setTitle(title)
dialog.setPosSize(0, 0, WIDTH, HEIGHT, SIZE)
def add(name, type, x_, y_, width_, height_, actListener, props):
model = dialog_model.createInstance("com.sun.star.awt.UnoControl" + type + "Model")
dialog_model.insertByName(name, model)
control = dialog.getControl(name)
control.setPosSize(x_, y_, width_, height_, POSSIZE)
if actListener != 0:
control.addItemListener(actListener(dialog, name))
for key, value in props.items():
setattr(model, key, value)
class radioListener( unohelper.Base, XItemListener ):
def __init__(self, cCont, name):
self.nCount = 0
self.cCont = cCont
self.cName = name
def itemStateChanged(self, actionEvent):
cCont = self.cCont
oCont = cCont.getControl(self.cName)
oCont.setLabel("YIPPEE")
add("Chk1", "CheckBox", 10, 5, 150, 150, 0, {"Label": "Show redeemed funds"})
add("Chk2", "CheckBox", 20, 45, 150, 150, 0, {"Label":"By Fund Subtype"})
add("Radio1", "RadioButton", 10, 25, 150, 150, radioListener, {"Label":"Fund Type", "State": 1})
add("Radio2", "RadioButton", 10, 65, 150, 150, radioListener, {"Label":"By Fund AMC", "State": 0})
"""
"""
add("btn_ok", "Button", 10, 85,
BUTTON_WIDTH, BUTTON_HEIGHT, 0, {"PushButtonType": OK})
add("btn_cancel", "Button", 160, 85,
BUTTON_WIDTH, BUTTON_HEIGHT, 0, {"PushButtonType": CANCEL})
frame = create("com.sun.star.frame.Desktop").getCurrentFrame()
window = frame.getContainerWindow() if frame else None
dialog.createPeer(create("com.sun.star.awt.Toolkit"), window)
if not x is None and not y is 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)
dialog.execute()
dialog.dispose()
return 0
#This function can be called as follows:
def inpmacro(*args):
inputbox("Please input some value", "Input", "Default value")