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


Hi,

I don´t know where the master is and how the scp2-directory works. Here
is a diff from debians mailmerge.py. mailmerge.py.diff is licensed under
LGPLv3+. The license text for MsgBox is inside the file.
Within debian libreoffice obviously never uses the built in python. 
Note that now python errors are displayed twice on the GNU OS. I suggest
that libreoffice shall be modified so that there will be only one
message. Also once upon a time an error box shall be implemented in
pythonscript.py so that it can be used for python errors from all
plugins. 


regards,

Timo




Am Mittwoch, den 20.04.2011, 15:48 +0100 schrieb Michael Meeks:
Hi Timo,

On Thu, 2011-04-14 at 17:50 +0200, Timo wrote:
Maybe this task should be moved to “completed”?
http://wiki.documentfoundation.org/Easy_Hacks#Make_python_.2F_mail-merge_debuggable

      I read your last mail, and I was not certain that it is working :-) so
sadly the code didn't get merged.

      Do you think you could re-send your code as a patch vs. master: with
the new msgbox.py file added ? we should also have a patch for scp2/ to
install the new python file too (git grep for mailmerge.py in there).
Also good to add [PATCH] to the Subject to get some priority review :-)
[ also confirm the LGPLv3+/MPL license ].

MessageBoxButtons as well as XSCRIPTCONTEXT do not exist for me. Python
doesn´t find them and they are documented as “not published” [1]. 

      Did you get over this ? presumably you are running this using the
python embedded with libreoffice, rather than some external python ?

[3] see screenshot Bildschirmfoto.png

      Looks nice :-)

      Great work,

              Michael.


43a45,49
from com.sun.star.awt import WindowDescriptor
from com.sun.star.awt.WindowClass import MODALTOP
import MsgBox

47a54,69
def showError(ctx,text):
              box = MsgBox.MsgBox(ctx)
              box.addButton("OK")
              box.renderFromBoxSize(400)
              box.numberOfLines = 10
              box.show(text,0,"Error")
              exit(1) 

225,226c247,257
< 
<               self.server.sendmail(sendermail, truerecipients, msg.as_string())
---
              
              try:
                      self.server.sendmail(sendermail, truerecipients, msg.as_string())
              except smtplib.SMTPRecipientsRefused as inst:
                      msg = ""
                      for key,val in inst.recipients.iteritems():
                              msg+=val[1]+"\n"
                      showError(self.ctx,msg)
              except Exception as inst:
                      showError(self.ctx,str(inst))
              #except smtplib.SMTPException:
# -*- encoding: iso-8859-15 -*-
#
#   The Contents of this file are made available subject to the terms of
#   the following license
#
#          - GNU Lesser General Public License Version 2.1
#
#   GNU Lesser General Public License Version 2.1
#   =============================================
#   Copyright 2005 by Sun Microsystems, Inc.
#   901 San Antonio Road, Palo Alto, CA 94303, USA
#
#   This library is free software; you can redistribute it and/or
#   modify it under the terms of the GNU Lesser General Public
#   License version 2.1, as published by the Free Software Foundation.
#
#   This library is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#   Lesser General Public License for more details.
#
#   You should have received a copy of the GNU Lesser General Public
#   License along with this library; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston,
#   MA  02111-1307  USA
#
#
#   The Initial Developer of the Original Code is: Laurent Godard <lgodard@indesko.com>
#   All Rights Reserved.
#
#   Contributor(s): 
#   
#*************************************************************************

#prepare pythoin environnement - Add the path of this class
from os import path
from sys import modules
from sys import path as syspath
#print modules
#the_path = path.dirname (path.abspath (modules["__main__"].__file__))
#print the_path
#print syspath

#pyUNO program itself
import uno, unohelper

# UNO GUI toolkit
from com.sun.star.awt.WindowClass import TOP, SIMPLE
from com.sun.star.awt.PushButtonType import STANDARD as standard
from com.sun.star.awt.PushButtonType import OK as ok
from com.sun.star.awt.PushButtonType import CANCEL as cancel
from com.sun.star.awt.PushButtonType import HELP as help
from com.sun.star.awt.TextAlign import CENTER as center
from com.sun.star.awt.TextAlign import LEFT as left
from com.sun.star.awt.TextAlign import RIGHT as right

# used UNO listeners
from com.sun.star.awt import XActionListener

class MsgBox(unohelper.Base):
    """Inspect UNO object, link to sdk and recusrsive calls"""

    def __init__(self, aContext):
        """acontext : a Valid UNO context
        """
        
        self.VERSION = '0.1'
        self.ctx = aContext
        self.smgr = aContext.ServiceManager
        # UI Dialog object
        self.dialog=None
        # List of openned Listeners
        self.lst_listeners={}
        #UI parameters
        self.ButtonSize = 50
        self.boxSize = 200
        self.lineHeight = 10
        self.fromBroxSize = False
        self.numberOfLines = -1

        self.Buttons = []
        self.Response = ''
                
        return
        
    #####################################################
    #                 GUI definition                    #
    #####################################################
    def _createBox(self):
        """Create the Box"""
        
    #computes parameters of the message dialog
        if self.numberOfLines == -1:
            #calculate
            numberOfLines = len(self.message.split(chr(10)))
        else:
            numberOfLines = self.numberOfLines    
            
        numberOfButtons = len(self.Buttons)#2 
        self.ButtonSpace = self.ButtonSize/2   
        if self.fromBroxSize:
            #button size is calculated from boxsize
            size = (2 * self.boxSize) / (3 * numberOfButtons + 1)
            self.ButtonSize = size
            self.ButtonSpace = self.ButtonSize/2   
        else:
            #boxsize i calculated form buttonsize
            self.boxSize = numberOfButtons * (self.ButtonSize + 
                                            self.ButtonSpace) + self.ButtonSpace
  
                                                  
    #create the dialog model and set the properties
        dialog_model = self.smgr.createInstanceWithContext(
                                    'com.sun.star.awt.UnoControlDialogModel',
                                    self.ctx)
        dialog_model.PositionX = 50
        dialog_model.Step = 1
        dialog_model.TabIndex = 7
        dialog_model.Width = self.boxSize#numberOfButtons * (self.ButtonSize + 
                             #               self.ButtonSpace) + 25
        dialog_model.Height = 10 + self.lineHeight * numberOfLines + 10 + 12  + 10
        dialog_model.PositionY = 63
        dialog_model.Sizeable = True
        dialog_model.Closeable = False

        dialog = self.smgr.createInstanceWithContext(
                                'com.sun.star.awt.UnoControlDialog',
                                self.ctx)

    # label Label0
        label = dialog_model.createInstance(
                                'com.sun.star.awt.UnoControlFixedTextModel')
        label.PositionX =  10
        label.TabIndex = 9
        label.Width = dialog_model.Width - label.PositionX 
        label.Height = self.lineHeight* numberOfLines
        label.PositionY = 10
        label.Align = left
        label.MultiLine = True
        label.Label = self.message
        dialog_model.insertByName('Label0', label)
        
        nb = 0
        for buttonName in self.Buttons:
            nb +=1
            button = dialog_model.createInstance(
                                    'com.sun.star.awt.UnoControlButtonModel')
            button.PositionX = nb * self.ButtonSpace + (nb-1)* self.ButtonSize
            button.TabIndex = 8
            button.Height = 12
            button.Width = self.ButtonSize
            button.PositionY = 10 + label.Height + 10
            button.PushButtonType =  standard
            if nb == 1:
                button.DefaultButton =  True
            else:
                button.DefaultButton =  False                
            button.Label = buttonName
            dialog_model.insertByName('Btn' + str(nb), button )

        if not dialog.getModel():
            dialog.setModel(dialog_model)

    #UNO toolkit definition
        toolkit = self.smgr.createInstanceWithContext(
                                'com.sun.star.awt.Toolkit',
                                self.ctx)
        a_rect = uno.createUnoStruct( 'com.sun.star.awt.Rectangle' )
        a_rect.X = 50
        dialog.setTitle ( self.title )
        a_rect.Width = 270
        a_rect.Height = 261
        a_rect.Y = 63
        win_descriptor = uno.createUnoStruct('com.sun.star.awt.WindowDescriptor')
        win_descriptor.Type = TOP
        win_descriptor.ParentIndex = -1
        win_descriptor.Bounds = a_rect
        peer = toolkit.createWindow( win_descriptor )
        dialog.createPeer( toolkit, peer )

        return dialog

#    ##########################

    def _addListeners(self):
        """Add listeners to dialog"""
        nb = 0
        for buttonName in self.Buttons:
            nb +=1
            a_control = self.dialog.getControl('Btn'+str(nb))
            the_listener = ButtonListener(self)
            a_control.addActionListener(the_listener)
            self.lst_listeners['Btn'+str(nb)] = the_listener

        return

#    ###########################

    def _removeListeners(self):
        """ remove listeners on exiting"""
        nb = 0
        for buttonName in self.Buttons:
            nb +=1
            a_control = self.dialog.getControl('Btn'+str(nb))
            a_control.removeActionListener(self.lst_listeners['Btn'+str(nb)])

        return        

#    ###########################
                
    def show(self, message, decoration, title):
        self.message = message
        self.decoration = decoration
        self.title = title
        # Create GUI
        self.dialog = self._createBox()
        self._addListeners()
        #execute the dialog --> blocking call
        self.dialog.execute()
        #end --> release listeners and dispose dialog
        self._removeListeners()
        self.dialog.dispose()
        return self.Response        
       
    def addButton(self, caption):
        self.Buttons.append(caption)
        return
    
    def renderFromBoxSize(self, size = 150):
        self.boxSize = size
        self.fromBroxSize = True
        return
        
    def renderFromButtonSize(self, size = 50):
        self.ButtonSize = size
        self.fromBroxSize = False
        return        

        
class ButtonListener(unohelper.Base, XActionListener):
    """Stops the MessageBox, sets the button label as returned value"""
    def __init__(self, caller):
        self.caller = caller

    def disposing(self, eventObject):
        pass

    def actionPerformed(self, actionEvent):
        button = actionEvent.Source
        self.caller.Response = button.Model.Label
        self.caller.dialog.endExecute()
        return

### TEST
if __name__ == '__main__':       
    # get the uno component context from the PyUNO runtime
    localContext = uno.getComponentContext()
    
    # create the UnoUrlResolver
    resolver = localContext.ServiceManager.createInstanceWithContext(
                    "com.sun.star.bridge.UnoUrlResolver", localContext )
    
    # connect to the running office
    # OOo has to be launched in listen mode as 
    # ./soffice "-accept=socket,host=localhost,port=2002;urp;"
    
    ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
    
    myBox = MsgBox(ctx)  
    myBox.addButton("Oui")
    myBox.addButton("Non")
    myBox.addButton("Peut-Etre")
    myBox.renderFromBoxSize(150)
    myBox.numberOflines = 2
    
    print myBox.show("Un message sur une ligneUn message sur une ligneUn message sur une ligneUn 
message sur une ligneUn message sur une ligneUn message sur une ligneUn message sur une ligneUn 
message sur une ligne" + chr(10)+chr(10)+"�tes-vous d'accord ?",0,"Titre de la boite")        

    myBox = MsgBox(ctx)  
    myBox.addButton("oK")
    myBox.renderFromButtonSize()
    myBox.numberOflines = 2
    
    print myBox.show("Un message sur une ligne",0,"Titre de la boite")        
    



        
        

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.