Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


Hi Joost,

On Tue, 2012-06-05 at 19:37 +0200, Joost Eekhoorn wrote:
There is UnoDialog2.py in wizards/com/sun/star/wizards/ui.

        Right :-)

I made a new example using UnoDialog2: example-using-unodialog2.py.
...
The attached new example has this header.
...
As a demo would be nice.

        I agree - creating dialogs is infernally difficult with the AWT code,
and it'd be great to have this so people can do build these things more
easily.

Where is the place for such a demo ?

        I massaged it a bit into a patch in your name (attached).
This makes it part of the default install and set of samples.

        Unfortunately - as I run it in master I get the attached error.

        I'd love to get it in for 3.7 with a bit of fixing, any chance of some
debugging help from a pythonista :-)

        Thanks !

                Michael.

-- 
michael.meeks@suse.com  <><, Pseudo Engineer, itinerant idiot
From e6a49ff037bcf6c918ab3716c1919e4a8e8a280a Mon Sep 17 00:00:00 2001
From: Joost Wezenbeek <joost.eekhoorn@gmail.com>
Date: Wed, 13 Jun 2012 13:42:45 +0100
Subject: [PATCH] Add an UnoDialog example

Change-Id: I54a869feddc77ad61a3e7f099af70935101e3c96
---
 scripting/Zip_ScriptsPython.mk         |    1 +
 scripting/examples/python/UnoDialog.py |  231 ++++++++++++++++++++++++++++++++
 2 files changed, 232 insertions(+), 0 deletions(-)
 create mode 100644 scripting/examples/python/UnoDialog.py

diff --git a/scripting/Zip_ScriptsPython.mk b/scripting/Zip_ScriptsPython.mk
index e86785c..abbe3d1 100644
--- a/scripting/Zip_ScriptsPython.mk
+++ b/scripting/Zip_ScriptsPython.mk
@@ -29,6 +29,7 @@
 $(eval $(call gb_Zip_Zip,ScriptsPython,$(SRCDIR)/scripting/examples))
 
 $(eval $(call gb_Zip_add_files,ScriptsPython,\
+       python/UnoDialog.py \
        python/Capitalise.py \
        python/HelloWorld.py \
        python/pythonSamples/TableSample.py \
diff --git a/scripting/examples/python/UnoDialog.py b/scripting/examples/python/UnoDialog.py
new file mode 100644
index 0000000..d8c4aa7
--- /dev/null
+++ b/scripting/examples/python/UnoDialog.py
@@ -0,0 +1,231 @@
+#!/usr/bin/python
+
+# A sample showing how to create UNO dialogs
+
+#
+# Copyright 2012 LibreOffice contributors.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# vim:set shiftwidth=4 softtabstop=4 expandtab:
+
+# Use uno, which uses pyuno
+import uno, unohelper
+import time
+
+import wizards.ui.UIConsts
+from wizards.ui.UnoDialog2 import *
+
+from wizards.common.SystemDialog import SystemDialog
+from com.sun.star.awt.VclWindowPeerAttribute import OK, YES_NO, DEF_YES
+
+uno_ALIGN_LEFT  = uno.getConstantByName("com.sun.star.awt.TextAlign.LEFT")
+uno_ALIGN_RIGHT = uno.getConstantByName("com.sun.star.awt.TextAlign.RIGHT")
+
+import dialogbox
+
+
+# Get some uno constants
+from com.sun.star.awt.WindowClass import TOP, SIMPLE
+
+
+# ## These 4 global objects must be moved!
+ctx    = uno.getComponentContext()
+res    = ctx.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver",ctx)
+cxt    = res.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
+desktop= cxt.ServiceManager.createInstance("com.sun.star.frame.Desktop")
+
+
+# Those control properties that will be used in the "insert" methods
+class MyProps():
+    PROPNAMES_STANDARD = (
+        PropertyNames.PROPERTY_HEIGHT,
+        PropertyNames.PROPERTY_NAME,
+        PropertyNames.PROPERTY_POSITION_X,
+        PropertyNames.PROPERTY_POSITION_Y,
+        PropertyNames.PROPERTY_STEP,
+        PropertyNames.PROPERTY_TABINDEX,
+        PropertyNames.PROPERTY_WIDTH)
+
+    PROPNAMES_LBL = (
+        "Align",
+        PropertyNames.PROPERTY_LABEL,) + PROPNAMES_STANDARD
+
+    PROPNAMES_TXT = (
+        PropertyNames.PROPERTY_HELPURL,) + PROPNAMES_STANDARD
+
+    PROPNAMES_BUTTON = (
+        PropertyNames.PROPERTY_LABEL,
+        PropertyNames.PROPERTY_HELPURL,) + PROPNAMES_STANDARD
+
+    PROPNAMES_CHKBOX = (
+        "State",) + PROPNAMES_BUTTON
+
+    PROPNAMES_LIST = (
+        "Dropdown",
+        "MultiSelection",
+        "LineCount",
+        PropertyNames.PROPERTY_HELPURL,) + PROPNAMES_STANDARD
+
+    PROPNAMES_NUM = (
+        "Value",
+        "ValueMin",
+        "ValueMax",
+        "DecimalAccuracy",
+        "Align",
+        PropertyNames.PROPERTY_HELPURL,) + PROPNAMES_STANDARD
+
+
+# Using the UnoDialog2
+class CustomDialog(UnoDialog2):
+
+    def __init__(self, xMSF):
+        super(CustomDialog, self).__init__(xMSF)
+        #set dialog properties...
+        Helper.setUnoPropertyValues(self.xDialogModel,
+            ("Closeable",
+            PropertyNames.PROPERTY_HEIGHT,
+            PropertyNames.PROPERTY_HELPURL, "Moveable",
+            PropertyNames.PROPERTY_NAME,
+            PropertyNames.PROPERTY_POSITION_X,
+            PropertyNames.PROPERTY_POSITION_Y,
+            PropertyNames.PROPERTY_STEP,
+            PropertyNames.PROPERTY_TABINDEX, "Title",
+            PropertyNames.PROPERTY_WIDTH),
+            (True, 170, "", True,
+            "CustomDialog", 102, 52, 1, 6,
+            "Example Custom Dialog", 150))
+
+    def showCustomDialog(self, xParentWindow, propSet):
+        self.xDialogModel.BackgroundColor = 0xafd2cc
+        self.createWindowPeer(xParentWindow)
+        tabIndex = 1;
+
+        self.btnOK = self.insertButton(
+            "btnOK", "actionOK", propSet.PROPNAMES_BUTTON,
+            ("OK", "", 14, "btnOK", 38, 145, 2, tabIndex + 1, 50), self)
+
+        self.btnCancel = self.insertButton(
+            "btnCancel", "actionCancel", propSet.PROPNAMES_BUTTON,
+            ("Cancel", "", 14, "btnCancel", 91, 145, 2, tabIndex + 1, 50), self)
+
+        self.lblComment = self.insertLabel(
+            "lblComment", propSet.PROPNAMES_LBL,
+            (uno_ALIGN_RIGHT, "Comment", 8, "lblComment", 3, 10, 1, tabIndex + 1, 38))
+
+        self.txtComment = self.insertTextField(
+            "txtComment", None, propSet.PROPNAMES_TXT,
+            ("Give your comment", 12, "txtComment",
+                45, 8, 6, tabIndex + 1, 95), self)
+
+        self.lblGraphType = self.insertLabel(
+            "lblGraphType", propSet.PROPNAMES_LBL,
+            (uno_ALIGN_RIGHT, "Graph type", 8, "lblGraphType", 3, 27, 1, tabIndex + 1, 38))
+
+        self.lstGraphType = self.insertListBox(
+            "lstGraphType", None, None, propSet.PROPNAMES_LIST,
+            (True, False, 5, "", 12, "lstGraphType", 45, 25, 1, tabIndex + 1, 52), self)
+        self.lstGraphType.addItems(("Area", "Bar", "Line", "Donut", "Bubble"), 0)
+        self.selectListBoxItem(self.lstGraphType, 1)
+        itemChanged = getattr(self, "actionTypeChanged")
+        self.lstGraphType.addItemListener(ItemListenerProcAdapter(itemChanged))
+
+        self.lblOptions = self.insertLabel(
+            "lblOptions", propSet.PROPNAMES_LBL,
+            (uno_ALIGN_RIGHT, "Options", 8, "lblOptions", 3, 44, 1, tabIndex + 1, 38))
+
+        self.lstOptions = self.insertListBox(
+            "lstOptions", None, None, propSet.PROPNAMES_LIST,
+            (False, True, 5, "", 52, "lstOptions", 45, 43, 1, tabIndex + 1, 52), self)
+        self.lstOptions.addItems(("Item 1", "Item 2", "Item 3", "Item 4", "Item 5"), 0)
+
+        self.lblStart = self.insertLabel(
+            "lblStart", propSet.PROPNAMES_LBL,
+            (uno_ALIGN_RIGHT, "Start", 8, "lblStart", 3, 108, 1, tabIndex + 1, 38))
+
+        self.numStart = self.insertNumericField(
+            "numStart", None, propSet.PROPNAMES_NUM,
+            (25.1, 1, 60, 1, uno_ALIGN_RIGHT, "", 12, "numStart", 45, 106, 1, tabIndex + 1, 32), 
self)
+
+        self.chkObvious = self.insertCheckBox(
+            "chkObvious", None, propSet.PROPNAMES_CHKBOX,
+            (1, "Obvious", "", 9, "chkObvious", 45, 125, 2, tabIndex + 1, 75), self)
+
+        self.running = True
+        rectBounds = uno.createUnoStruct("com.sun.star.awt.Rectangle")
+        rectBounds.X      = 100
+        rectBounds.Y      = 200
+        rectBounds.Width  = 440
+        rectBounds.Height = 200
+        self.executeDialog(rectBounds)
+
+    def actionTypeChanged(self):
+        print "action combo GraphType changed"
+        sMsg = str(self.chkObvious.getModel().Label)
+        #print sMsg
+
+    def actionOK(self):
+        print "Action OK"
+        answer = SystemDialog.showMessageBox(self.xMSF, "MessBox", YES_NO + DEF_YES, "Show 
results?",
+            self.xUnoDialog.Peer)
+
+        if answer != 3:
+            # user said YES
+            sMsg = "Comment = " + self.txtComment.Text
+            sMsg += "\nGraph type = " + self.lstGraphType.getSelectedItem()
+
+            fieldnames = self.lstOptions.getSelectedItems()
+            if fieldnames:
+                for i in fieldnames:
+                    sMsg += "\nOption = " + i
+
+            sMsg += "\nStart = " + str(self.numStart.Value)
+
+            if self.chkObvious.getState() == 1:
+                sMsg += "\nThis is " + self.chkObvious.getModel().Label
+            else:
+                sMsg += "\nThis is not " + self.chkObvious.getModel().Label
+
+            SystemDialog.showMessageBox(self.xMSF, "MessBox", OK, sMsg, self.xUnoDialog.Peer)
+
+        self.xUnoDialog.endExecute()
+        self.running = False
+
+    def actionCancel(self):
+        print "action Cancel"
+        self.xUnoDialog.endExecute()
+        self.running = False
+
+
+def makePropertyValue(cName, uValue, nHandle, nState):
+    core = cxt.ServiceManager.createInstance("com.sun.star.reflection.CoreReflection")
+    oXIdlClass = core.forName("com.sun.star.beans.PropertyValue")
+    oRV,oStruct = oXIdlClass.createObject(None)
+    oStruct.Name   = cName
+    oStruct.Value  = uValue
+    oStruct.Handle = nHandle
+    oStruct.State  = nState
+    return oStruct
+
+
+def testTheDialog():
+    props=tuple([makePropertyValue("ReadOnly", False, 0, 0),makePropertyValue("Hidden", True, 0, 
0)])
+    doc=desktop.loadComponentFromURL("private:factory/scalc", "_blank", 0, props)
+
+    frame=doc.getCurrentController().getFrame()
+    if frame:
+        xParentWindow = frame.getContainerWindow()
+        customDlg = CustomDialog(cxt.ServiceManager)
+        propset = MyProps()
+        customDlg.showCustomDialog(xParentWindow, propset)
+    else:
+        print "frame not found"
+
+    doc.close(True)
+
+
+if __name__ == "__main__":
+    testTheDialog()
+
-- 
1.7.9

Attachment: error.png
Description: PNG image


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.