- サマリ: 拡張機能オプション設定ダイアログ (OOo 2.3)
- 環境: General
- 状態: 投稿
- 投稿者: はにゃ??
- 投稿日: 2007-09-26 (水) 03:25:11
質問 
2.3 から拡張機能の設定を行うためにオプションダイアログを利用できます。新しい Developers Guide に詳細が載っていますのでここではちょっと試してみる程度にしておきます。
これは新たに専用のダイアログを追加することで行います。
必要なもの
- オプションダイアログ設定ファイル
- ダイアログ
- イベントハンドル用サービス
パッケージ 
MaximumPageSize.oxt
オプションダイアログ設定ファイル 
まず、OpenOffice.org/share/registry/schema/org/openoffice/Office/OptionDialog.xcs にしたがってオプションダイアログ用の設定ファイルを作成します。このファイルでは、オプション設定ダイアログの左側に表示されているツリーコントロールのどの位置に新たに項目を追加するか指定します。追加項目設定には表示するラベル、項目に対応したダイアログ、イベントハンドル用サービスなども設定します。
OptionsDialog.xcu
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| |
<!DOCTYPE oor:component-data SYSTEM "../../../../component-update.dtd">
<oor:component-data oor:name="OptionsDialog" oor:package="org.openoffice.Office"
xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<node oor:name="Nodes">
<node oor:name="mytools.Extensions" oor:op="fuse">
<prop oor:name="Label">
<value xml:lang="en-US">Extensions</value>
<value xml:lang="ja-JP">拡張機能</value>
</prop>
<prop oor:name="OptionsPage">
<value>%origin%/dialogs/node/mytools_Extensions_Node.xdl</value>
</prop>
<prop oor:name="AllModules">
<value>true</value>
</prop>
<node oor:name="Leaves">
<node oor:name="mytools.Extensions.MaximumPaperSize" oor:op="fuse">
<prop oor:name="Id">
<value>mytools.Extensions.MaximumPaperSize</value>
</prop>
<prop oor:name="Label">
<value xml:lang="en-US">Maximum Paper Size</value>
<value xml:lang="ja-JP">最大用紙サイズ</value>
</prop>
<prop oor:name="OptionsPage">
<value>%origin%/dialogs/MaximumPaperSize/mytools_Extensions_MaximumPaperSize.xdl</value>
</prop>
<prop oor:name="EventHandlerService">
<value>mytools.MaximumPaperSize.DialogHandler</value>
</prop>
</node>
</node>
</node>
</node>
</oor:component-data>
|
お試しなので Nodes に項目を追加、Leaves に一つ項目を追加しています。
- Nodes の項目にはハンドラは指定できない
- 位置を指定しないときには一番下に表示される
- Leavs の項目を特定のコンテキストに表示することも可 (普通はこちら)。
- ラベルのローカライズ
- ダイアログパス OptionsPage
- ハンドラ用サービス名 EventHandlerService
Leaves の Id を拡張機能 ID と同じにすると拡張機能マネージャにあるオプションボタンからオプションページを開くことができます。
ダイアログ 
オプション設定ダイアログの右側に表示されるコントロール類は OOo のダイアログエディタで作成します。
ダイアログはタイトルバーをなし (2.3) に設定して作成、ダイアログのみをエクスポートします (2.3)。ダイアログはローカライズされたものも利用できる (はず)。
丁度オプションダイアログにぴったり収まるサイズ:
- Width: 185, Height: 260 (確認中)
- Title bar: No
イベントハンドル用サービス 
Developers Guide には Java で書かれた例が記載されています。
一方、ここでは Python-UNO によるコンポーネントでハンドラサービスを作成します。
サービスは XContainerWindowEventHandler インターフェースを実装している必要があります。オプションダイアログのイベントで (ブロードキャスタにより) callHandlerMethod が呼ばれます。
DialogHandler.py
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
| | #!
# -*- coding: utf_8 -*-
import uno
import unohelper
#interfaces
from com.sun.star.awt import XContainerWindowEventHandler
from com.sun.star.lang import XServiceInfo
# listeners
from com.sun.star.awt import XActionListener
# push button listener
class ButtonListener(unohelper.Base,XActionListener):
DEFAULTMAXIMUM = 30000
def __init__(self,cast,dialog):
self.cast = cast
self.dialog = dialog
def disposing(self,eventObject):
pass
def actionPerformed(self,actionEvent):
cmd = str(actionEvent.ActionCommand)
if cmd == "width":
self.dialog.getControl("nf_width").Value = self.DEFAULTMAXIMUM / 100
elif cmd == "height":
self.dialog.getControl("nf_height").Value = self.DEFAULTMAXIMUM / 100
return
# main class
class DilaogHandler(unohelper.Base,XServiceInfo,XContainerWindowEventHandler):
def __init__(self,ctx):
self.ctx = ctx;
self.smgr = ctx.ServiceManager
self.CFGNODE = "/org.openoffice.Office.Common/Drawinglayer"
self.cp = self.smgr.createInstanceWithContext(
"com.sun.star.configuration.ConfigurationProvider",self.ctx)
node = uno.createUnoStruct("com.sun.star.beans.PropertyValue")
node.Name = "nodepath"
node.Value = self.CFGNODE
self.node = node
self.cfg_names = ("MaximumPaperHeight","MaximumPaperWidth")
return
#XContainerWindowEventHandler
def callHandlerMethod(self,window,eventObject,method):
if method == "external_event":
try:
self.handleExternalEvent(window,eventObject)
except:
pass
return True
#XContainerWindowEventHandler
def getSupportedMethodNames(self):
return ("external_event",)
def supportsService(self,name):
return False
def getImplementationName(self):
return "mytools.extensions.maximumpapersize.DilaogHandler"
def getSupportedServiceNames(self):
return ()
def handleExternalEvent(self,window,eventName):
if eventName == "ok":
self.saveData(window)
elif eventName == "back":
self.loadData(window,"back")
elif eventName == "initialize":
self.loadData(window,"initialize")
return True
# load and set the data
def loadData(self,window,ev):
name = window.getModel().Name
if name != "mytools_Extensions_MaximumPaperSize":
return
settings = self.configreader()
if settings:
cfgs = self.cfg_names
nf_width = window.getControl("nf_width")
nf_height = window.getControl("nf_height")
nf_height.Value = settings[cfgs[0]] / 100
nf_width.Value = settings[cfgs[1]] / 100
if ev == "initialize":
listener = ButtonListener(self,window)
btn_width = window.getControl("btn_width")
btn_height = window.getControl("btn_height")
btn_width.ActionCommand = "width"
btn_height.ActionCommand = "height"
btn_width.addActionListener(listener)
btn_height.addActionListener(listener)
return
# making the save data
def saveData(self,window):
name = window.getModel().Name
if name != "mytools_Extensions_MaximumPaperSize":
return
nf_height = window.getControl("nf_height")
nf_width = window.getControl("nf_width")
settings = []
settings.append(long(nf_height.Value * 100))
settings.append(long(nf_width.Value * 100))
t_settings = tuple(settings)
self.configwriter(t_settings)
return
# read configuration
def configreader(self):
settings = {}
try:
ConfigReader = self.cp.createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationAccess",(self.node,))
cfg_values = ConfigReader.getPropertyValues(self.cfg_names)
for i in range(len(self.cfg_names)):
settings[self.cfg_names[i]] = cfg_values[i]
except:
raise
return settings
# write configuration, cfg_values: tuple
# keep the order of the values
def configwriter(self,cfg_values):
try:
ConfigWriter = self.cp.createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationUpdateAccess",(self.node,))
ConfigWriter.setPropertyValues(self.cfg_names,cfg_values)
ConfigWriter.commitChanges() # commits
except:
raise
###
# uno implementation
g_ImplementationHelper = unohelper.ImplementationHelper()
g_ImplementationHelper.addImplementation(
DilaogHandler,"mytools.MaximumPaperSize.DialogHandler",
("mytools.MaximumPaperSize.DialogHandler",),)
###
|
manifest.xml 
拡張機能パッケージの登録に必要な manifest.xml ファイルを作成します。
<?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest>
<manifest:file-entry manifest:full-path="OptionsDialog.xcu"
manifest:media-type="application/vnd.sun.star.configuration-data"/>
<manifest:file-entry manifest:full-path="DialogHandler.py"
manifest:media-type="application/vnd.sun.star.uno-component;type=Python"/>
</manifest:manifest>
パッケージ構成 
今回作成するパッケージファイル構成
-package
--META-INF
---manifest.xml
--dialogs
---MaximumPaperSize
----mytoolsExtensionsMaximumPaperSize.xdl
----mytoolsExtensionsMaximumPaperSize_en_US.default
----mytoolsExtensionsMaximumPaperSize_en_US.properties
----mytoolsExtensionsMaximumPaperSize_ja_JP.properties
----node
----mytoolsExtensionsNode.xdl
----mytoolsExtensionsNode_en_US.default
----mytoolsExtensionsNode_en_US.properties
----mytoolsExtensionsNode_ja_JP.properties
--OptionsDialog.xcu
--DialogHandler.py
拡張機能パッケージを作成する手順と同じように ZIP 圧縮して .oxt に拡張子を変更す。ダイアログはリソースをまとめて同じディレクトリに保存する。
インストール方法 
ツール - パッケージマネージャからインストールします。サービスの実装に Py-UNO を利用しているため、パッケージインストール後に一度完全に OpenOffice.org を再起動してください。クイック起動も終了させる必要があります。
アンインストールもツール - パッケージマネージャから行います。
使い方 
ツール - オプションメニューを選択して表示されるダイアログに次のように項目が追加されます。

回答 
感想,コメント,メモ 