LibreOffice Pythhon 매크로로 대화상자 만들기

13611 단어 LibreOfficePython

Interface-oriented programming in OpenOffice / LibreOffice : automate your office tasks with Python Macros



ListBox, Button, Label에서 ListBox는 제작만 할 뿐 조작할 수 없습니다.
Click Me 버튼을 클릭할 때마다 Clicks1, 2... 숫자가 늘어납니다.
dialogBox.py
import uno
import unohelper
from com.sun.star.awt import XActionListener

class MyActionListener( unohelper.Base, XActionListener ):
  def __init__(self, labelControl, prefix ):
    self.nCount = 0
    self.labelControl = labelControl
    self.prefix = prefix
  def actionPerformed(self, actionEvent):
    # increase click counter
    self.nCount = self.nCount + 1
    self.labelControl.setText( self.prefix + str( self.nCount ) )

def createDialog():
  # create dialog
  ctx = uno.getComponentContext()
  smgr = ctx.ServiceManager
  dialogModel = smgr.createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", ctx)
  dialogModel.PositionX = 10
  dialogModel.PositionY = 10
  dialogModel.Width = 200
  dialogModel.Height = 100
  dialogModel.Title = "Runtime Dialog Demo"

  # create listbox
  listBoxModel = dialogModel.createInstance("com.sun.star.awt.UnoControlListBoxModel" )
  listBoxModel.PositionX = 10
  listBoxModel.PositionY = 5
  listBoxModel.Width = 100
  listBoxModel.Height = 40
  listBoxModel.Name = "myListBoxName"
  listBoxModel.StringItemList = ('a','b','c')

  # create the button model and set the properties
  buttonModel = dialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel" )
  buttonModel.PositionX = 50
  buttonModel.PositionY  = 50
  buttonModel.Width = 50
  buttonModel.Height = 14
  buttonModel.Name = "myButtonName"
  buttonModel.Label = "Click Me"

  # create the label model and set the properties
  labelModel = dialogModel.createInstance( "com.sun.star.awt.UnoControlFixedTextModel" )
  labelModel.PositionX = 10
  labelModel.PositionY = 70
  labelModel.Width  = 100
  labelModel.Height = 14
  labelModel.Name = "myLabelName"
  labelModel.Label = "Clicks "

  # insert the control models into the dialog model
  dialogModel.insertByName( "myButtonName", buttonModel)
  dialogModel.insertByName( "myLabelName", labelModel)
  dialogModel.insertByName( "myListBoxName", listBoxModel)

  # create the dialog control and set the model
  controlContainer = smgr.createInstanceWithContext("com.sun.star.awt.UnoControlDialog", ctx)
  controlContainer.setModel(dialogModel)

  oBox = controlContainer.getControl("myListBoxName")
  oLabel = controlContainer.getControl("myLabelName")
  oButton = controlContainer.getControl("myButtonName")
  oBox.addItem('d',4)

  # create a peer
  toolkit = smgr.createInstanceWithContext( "com.sun.star.awt.ExtToolkit", ctx)  

  controlContainer.setVisible(False)
  controlContainer.createPeer(toolkit, None)

  # add the action listener
  oButton.addActionListener(MyActionListener( oLabel,labelModel.Label ))
  oBox.addActionListener(MyActionListener( oLabel,labelModel.Label ))

  # execute again
  controlContainer.execute()
  controlContainer.dispose()
  return None

g_exportedScripts = createDialog,
위의 매크로 열기
/home/사용자 이름/.config/libreoffice/4/user/Scripts/pythhon/(Ubuntu의 경우)
C:\Users\사용자 이름\AppData\Roaming\LibreOffice\4\user\Scripts\python(Windows의 경우)
구문을 생성합니다.
기타 참조 사이트
Python에서 Open Office 매크로
대화상자 편집기를 사용하여 코드의 이벤트와 관련
http://psyto.s26.xrea.com/python/ooomacro_dialog.html
Apache OpenOffice wiki
List Box
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Basic/List_Box
Apache OpenOffice
service UnoControlListBox
http://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/UnoControlListBox.html
Apache OpenOffice
interface XListBox
http://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/XListBox.html

좋은 웹페이지 즐겨찾기