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.pyimport 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
Reference
이 문제에 관하여(LibreOffice Pythhon 매크로로 대화상자 만들기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/ty21ky/items/ca8622f54c13ce56f9c5
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
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,
Reference
이 문제에 관하여(LibreOffice Pythhon 매크로로 대화상자 만들기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ty21ky/items/ca8622f54c13ce56f9c5텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)