create a new page, using OOoBasic/Macros/MRI/Documentation/Macros as a template.
Front page
Search
掲示板
Reload
Help
Browse Log
掲示板の使い方
OOo 掲示板3
OOo 掲示板2
OOo 掲示板
掲示板
雑談掲示板
New
List of pages
Recent changes
Backup
簡単ヘルプ
整形ルール
Start:
* マクロ [#b1ef2b82]
MRI 1.0.0 に追加予定の機能です。
Python で書いたコードを MRI を拡張したりするためにマクロ...
MRI のマクロでは MRI の全ての機能にアクセスできますが、オ...
MRI のマクロは MRI の実装に強く依存しています。そのため、...
#contents
** マクロメニュー [#ma741df6]
MRI ウィンドウを開くと Macros メニューが MRI ウィンドウの...
マクロは以下のディレクトリに保存されていなければいけませ...
- 拡張機能のレポジトリ、これは MRI に付属のものです。
- ユーザーのレポジトリ。Tools - Configuration... で設定で...
ユーザーのレポジトリにはアクセス権限のあるディレクトリを...
** マクロのインポート [#qe524dbc]
MRI 用のマクロが含まれているファイルをユーザーのディレク...
マクロが ZIP、tar.gz、tar.bz2 アーカイブにまとめられてい...
** マクロメニュー項目のリロード [#o88667a9]
Macros メニューは動的に作成されますが、一度読み込んだ後は...
** ファイルの種類 [#efb58f98]
マクロは Python で書き、ファイルの拡張子 ".py" をつけてユ...
** マクロの種類 [#c0856cdb]
MRI で実行できるのマクロには二種類あります。一つ目は普通...
*** 普通のマクロ [#l114e69b]
普通のマクロの簡単な例を示します。
# # hello.py example
# __all__ 変数の項目がメニューに表示されます。
# 項目の順はそのままに、空文字列の項目は区切り
# となります。
__all__ = ["hello_world", "", "another_function"]
def hello_world(mri):
""" はろー
メソッドの説明 """
# ドキュメント文字列は関数のタイトルと説明として
# 利用されます。最初の行はタイトルとして利用されます。
# 二行目以降は関数の説明として利用されます。
mri.message("Hello World!")
def another_function(mri):
pass
def private_function(mri):
""" この関数は関数リストに表示されません。 """
マクロのファイルは imp.load_source 関数でモジュールとして...
関数のドキュメント文字列はメニューや他の場所でタイトルと...
__all__ モジュール変数はそのファイルからエクスポートされ...
もうひとつ例を示します。以下の例では現在のターゲットを利...
def another_example(mri):
target = mri.current.target # real value of the curre...
sheets = target.getSheets()
sheet = sheets.getSheets()
# To do something
*** アクションマクロ [#n24b5f51]
アクションマクロは API 呼び出しがコードとして記録されるも...
以下に簡単な例を示します。
def action_macro(mri):
current = mri.current # current is a Writer document...
text = current.getText()
cursor = text.createTextCursor()
getText と createTextCursor メソッドの呼び出しは自動的に...
サービスなどの新しい Entry インスタンスを利用するときには...
def macro_test(mri):
current = mri.current
transformer = mri.create_service(
"com.sun.star.util.URLTransformer")
yield current, transformer
ジェネレータでは親エントリと子エントリのタプルを返してく...
このアクションマクロにはかなり制限があります。たとえば、...
** MRI オブジェクト [#kd111181]
全てのマクロは現在の MRI インスタンスを最初の引数として受...
*** インスタンス変数 [#aa1f86f5]
MRI インスタンスは様々な値をインスタンス変数に保持してい...
|Variable|Type|Description|h
|ctx|pyuno|コンポーネントコンテキスト|
|config|mytools_Mri.config.Config|設定|
|web|mytools_Mri.web.IDL|ウェブページなどをウェブブラウザ...
|engine|mytools_Mri.engine.Engine|イントロスペクションと...
|history|mytools_Mri.node.Root|履歴の階層構造|
|current|mytools_Mri.engine.Entry|現在のエントリ|
|cg|mytools_Mri.cg.CodeGenerator|コードジェネレータを管理|
|mode|bool|ノーマルモードのとき True、False ではマクロモ...
|open_new|bool|True のとき次のターゲーットを新規ウィンド...
|macros|mytools_Mri.macros.Macros|マクロを管理|
|ui|mytools_Mri.ui.MRIUi|ユーザーインターフェース|
*** メソッド [#t90bff33]
*** ComponentContext [#ebcc7b8c]
css.uno.XComponentContext インターフェースを ctx インスタ...
*** Current エントリ [#wa3d9ac3]
MRI は現在のターゲーットを current インスタンス変数に保持...
*** Engine オブジェクト [#lfc167ae]
エンジンは UNO オブジェクトの情報を取得するためのコアオブ...
def use_engine(mri):
""" Shows type name of the current target. """
engine = mri.engine
current = mri.current
mri.ui.message(engine.get_type_name(current))
** Web オブジェクト [#cfcfc1a5]
ウェブオブジェクトは設定で指定されたウェブブラウザを開く...
def open_url(mri):
""" URL をウェブブラウザで開く """
url = "http://example.com/"
mri.web.open_url(url)
def open_ref(mri):
""" IDL リファレンスを開きます。
二番目の引数はオプションです。 """
idl = "com.sun.star.awt.Rectangle"
name = "X"
mri.web.open_idl_reference(idl, name)
** MRI UI オブジェクト [#x0756b95]
mytools_Mri.ui.MRIUi クラスは MRI のウィンドウを管理しま...
|Variable|Type|Description|h
|ctx|pyuno|コンポーネントコンテキスト|
|main|mytools_Mri.MRI|MRI インスタンス|
|desktop|pyuno|デスクトップインスタンス|
|listeners|dict|リスナー|
|property_mode|bool|True のときプロパティを取得。False で...
|tree|mytools_Mri.ui.pages.HistoryTreeUi|ツリー構造の履歴|
|dlgs|mytools_Mri.ui.dialogs.Dialogs|ダイアログを提供しま...
|status_eraser|threading.Timer|ステータス文字列を消去する...
|frame|pyuno|MRI ウィンドウの入ったフレーム|
|cont|pyuno|コンテナウィンドウ|
|pages|mytools_Mri.ui.pages.InfoUi/GridUi|コントロールへ...
*** ダイアログ [#d02d0f73]
mytools_Mri.ui.dialogs.Dialogs クラスが提供するダイアログ...
def dialog_select(mri):
items = ("Item 1", "Item 2", "Item 3", "Item 1")
item = mri.ui.dlgs.dialog_select(items, "Title")
mri.ui.dlgs.dialog_info("%s is selected. " % item)
dialog_select メソッドの二番目の引数はダイアログのタイト...
ユーザーに入力させたいときには dialog_input メソッドを利...
def dialog_input(mri):
text = mri.ui.dlgs.dialog_input(
"Service Name", "Input a service name.",
"com.sun.star.awt.")
mri.ui.message(text)
全ての引数は省略可能です。
履歴から項目を選択させるダイアログがあります。
def history_selector(mri):
entry = mri.ui.dlgs.history_selector("Select Entry")
if entry:
mri.ui.message(entry.name)
返り値は mytools_Mri.engine.Entry クラスのインスタンスで...
メッセージを表示したり、ユーザーの反応が必要なときには me...
def message(self, message, title="", type="messbox", but...
** エントリ [#q45546b3]
Entry クラスは現在またはそれ以外のターゲットを保持するた...
mytools_Mri.engine.Entry <
(mytools_Mri.engine.EntryBase, mytools_Mri.node.Node)
Entry クラスは二つの親クラスを継承していますが、自身では...
次の表では Entry クラスのインスンタンス変数を説明します。
|Variable|Type|Description|h
|target|object|インスタンスがラップしている実際の値|
|inspected|pyuno|css.beans.XIntrospectionAccess インター...
|type|pyuno|css.reflection.CoreReflection による IDL 型情...
|mri|mytools_Mri.MRI|MRI への参照|
|code_entry|mytools_Mri.cg.CodeEntry|コード生成用の情報|
次の表に示したメソッドも提供しています。
|Method|Description|h
|get_target()|target インスタンス変数を利用してください|
|has_interface(name)|ターゲットが指定したインターフェース...
|supports_service(name)|ターゲットが指定したサービスをサ...
|append(obj)|obj をリストに追加します。このメソッドは MRI...
** ページ [#a2272a6d]
MRIUi の pages インスタンス変数は mytools_Mri.pages.InfoU...
InfoUi < (Ui, PageStatus,
Pages < PagesBase)
GridUi < (Ui, PageStatus,
GridPages < GridPagesBase < PagesBase)
Ui クラスは型や実装名、検索と履歴のコントロールへのアクセ...
|Method|Description|h
|get_type_name()|型名を返します|
|set_type_name(name)|型名を設定します|
|get_imple_name()|実装名を返します|
|set_imple_name(name)|実装名を設定します|
|get_code()|現在のコードのテキストを返します|
|set_code(txt)|コードのテキストを設定します|
PageStatus クラスは情報ページのステータスを保持しています。
PagesBase クラスはその子クラスで定義するべきクラスを定義...
|Method|Description|h
|get_selected(index=None)|選択されているテキストを返します|
|get_current_line(index=None)|現在の行のテキストを返します|
|get_first_word(index=None)|現在の行の最初の単語を返します|
|activate(index)|アクティブなページを設定します|
|get_active()|アクティブなページを設定します|
|search(search_text, index=None)|検索します|
これらのコントロールの内容は最初にアクティブになったとき...
** MRI ウィンドウのコントローラ [#n06feac2]
MRI はウィンドウのフレームに接続される独自のコントローラ...
def do_something_with(mri):
# デスクトップから MRI ウィンドウを探す
found = None
frames = mri.ui.desktop.getFrames()
for i in range(frames.getCount()):
frame = frames.getByIndex(i)
if frame.getTitle() == "MRI":
found = frame
break
if found:
controller = found.getController()
# もうひとつの MRI の MRIUi インスタンス
ui = controller.ui
mri2 = ui.main # instance of mytools_Mri.MRI
この方法はオフィースの同じ Python インスタンスで動作して...
** MRI ウィンドウの構造 [#b3197135]
MRI ウィンドウの構造を示します。
frame: css.frame.Frame
- Controller: mytools_Mri.ui.controller.Controller
- Model: always None
- Container Window: general window
- Component Window: css.awt.UnoControlContainer
- splitter: does not added in the container
- label_status: FixedText keeps status text.
- edit_type: Edit shows type information.
- edit_in: Edit shows implementation name.
- list_hist: List of history.
- btn_back: Back button.
- btn_forward: Forward button.
- edit_search: Search edit.
- btn_search: Search Button.
- btn_tree: Open tree button.
- btn_index_acc: Index button.
- btn_name_acc: Name button.
- subcont: css.awt.UnoControlContainer (without tab)
- info_0:
- info_1:
- info_2:
- info_3:
- subcont: css.awt.UnoControlContainer (with tab)
- page_0
- info_0
- page_1
- info_1
- page_2
- info_2
- page_3
- info_3
subcont の構造はタブコントロールを利用しているかどうかで...
** 例 [#i8ddd1ea]
拡張機能パッケージの Macros ディレクトリにある bundle.py ...
*** 例1 [#g7f78c4f]
以下の短いコードで現在の図形描写コレクションから子図形描...
def inspect_shapes(mri):
""" Inspect Shapes
Inspect all shapes in this container. """
shape = mri.current # current target
# check current shape is correct type
if shape.supports_service("com.sun.star.drawing.Shap...
# getCount call is not collected to code
for i in range(shape.target.getCount()):
child = shape.getByIndex(i)
Entry クラスの supports_service メソッドはそのターゲット...
*** 例2 [#zd9dabef]
Entry インスタンスは実際の値をラップしています。ターゲッ...
def show_property_value(mri):
current = mri.current
ui = mri.ui
ui.message(current.target)
End:
* マクロ [#b1ef2b82]
MRI 1.0.0 に追加予定の機能です。
Python で書いたコードを MRI を拡張したりするためにマクロ...
MRI のマクロでは MRI の全ての機能にアクセスできますが、オ...
MRI のマクロは MRI の実装に強く依存しています。そのため、...
#contents
** マクロメニュー [#ma741df6]
MRI ウィンドウを開くと Macros メニューが MRI ウィンドウの...
マクロは以下のディレクトリに保存されていなければいけませ...
- 拡張機能のレポジトリ、これは MRI に付属のものです。
- ユーザーのレポジトリ。Tools - Configuration... で設定で...
ユーザーのレポジトリにはアクセス権限のあるディレクトリを...
** マクロのインポート [#qe524dbc]
MRI 用のマクロが含まれているファイルをユーザーのディレク...
マクロが ZIP、tar.gz、tar.bz2 アーカイブにまとめられてい...
** マクロメニュー項目のリロード [#o88667a9]
Macros メニューは動的に作成されますが、一度読み込んだ後は...
** ファイルの種類 [#efb58f98]
マクロは Python で書き、ファイルの拡張子 ".py" をつけてユ...
** マクロの種類 [#c0856cdb]
MRI で実行できるのマクロには二種類あります。一つ目は普通...
*** 普通のマクロ [#l114e69b]
普通のマクロの簡単な例を示します。
# # hello.py example
# __all__ 変数の項目がメニューに表示されます。
# 項目の順はそのままに、空文字列の項目は区切り
# となります。
__all__ = ["hello_world", "", "another_function"]
def hello_world(mri):
""" はろー
メソッドの説明 """
# ドキュメント文字列は関数のタイトルと説明として
# 利用されます。最初の行はタイトルとして利用されます。
# 二行目以降は関数の説明として利用されます。
mri.message("Hello World!")
def another_function(mri):
pass
def private_function(mri):
""" この関数は関数リストに表示されません。 """
マクロのファイルは imp.load_source 関数でモジュールとして...
関数のドキュメント文字列はメニューや他の場所でタイトルと...
__all__ モジュール変数はそのファイルからエクスポートされ...
もうひとつ例を示します。以下の例では現在のターゲットを利...
def another_example(mri):
target = mri.current.target # real value of the curre...
sheets = target.getSheets()
sheet = sheets.getSheets()
# To do something
*** アクションマクロ [#n24b5f51]
アクションマクロは API 呼び出しがコードとして記録されるも...
以下に簡単な例を示します。
def action_macro(mri):
current = mri.current # current is a Writer document...
text = current.getText()
cursor = text.createTextCursor()
getText と createTextCursor メソッドの呼び出しは自動的に...
サービスなどの新しい Entry インスタンスを利用するときには...
def macro_test(mri):
current = mri.current
transformer = mri.create_service(
"com.sun.star.util.URLTransformer")
yield current, transformer
ジェネレータでは親エントリと子エントリのタプルを返してく...
このアクションマクロにはかなり制限があります。たとえば、...
** MRI オブジェクト [#kd111181]
全てのマクロは現在の MRI インスタンスを最初の引数として受...
*** インスタンス変数 [#aa1f86f5]
MRI インスタンスは様々な値をインスタンス変数に保持してい...
|Variable|Type|Description|h
|ctx|pyuno|コンポーネントコンテキスト|
|config|mytools_Mri.config.Config|設定|
|web|mytools_Mri.web.IDL|ウェブページなどをウェブブラウザ...
|engine|mytools_Mri.engine.Engine|イントロスペクションと...
|history|mytools_Mri.node.Root|履歴の階層構造|
|current|mytools_Mri.engine.Entry|現在のエントリ|
|cg|mytools_Mri.cg.CodeGenerator|コードジェネレータを管理|
|mode|bool|ノーマルモードのとき True、False ではマクロモ...
|open_new|bool|True のとき次のターゲーットを新規ウィンド...
|macros|mytools_Mri.macros.Macros|マクロを管理|
|ui|mytools_Mri.ui.MRIUi|ユーザーインターフェース|
*** メソッド [#t90bff33]
*** ComponentContext [#ebcc7b8c]
css.uno.XComponentContext インターフェースを ctx インスタ...
*** Current エントリ [#wa3d9ac3]
MRI は現在のターゲーットを current インスタンス変数に保持...
*** Engine オブジェクト [#lfc167ae]
エンジンは UNO オブジェクトの情報を取得するためのコアオブ...
def use_engine(mri):
""" Shows type name of the current target. """
engine = mri.engine
current = mri.current
mri.ui.message(engine.get_type_name(current))
** Web オブジェクト [#cfcfc1a5]
ウェブオブジェクトは設定で指定されたウェブブラウザを開く...
def open_url(mri):
""" URL をウェブブラウザで開く """
url = "http://example.com/"
mri.web.open_url(url)
def open_ref(mri):
""" IDL リファレンスを開きます。
二番目の引数はオプションです。 """
idl = "com.sun.star.awt.Rectangle"
name = "X"
mri.web.open_idl_reference(idl, name)
** MRI UI オブジェクト [#x0756b95]
mytools_Mri.ui.MRIUi クラスは MRI のウィンドウを管理しま...
|Variable|Type|Description|h
|ctx|pyuno|コンポーネントコンテキスト|
|main|mytools_Mri.MRI|MRI インスタンス|
|desktop|pyuno|デスクトップインスタンス|
|listeners|dict|リスナー|
|property_mode|bool|True のときプロパティを取得。False で...
|tree|mytools_Mri.ui.pages.HistoryTreeUi|ツリー構造の履歴|
|dlgs|mytools_Mri.ui.dialogs.Dialogs|ダイアログを提供しま...
|status_eraser|threading.Timer|ステータス文字列を消去する...
|frame|pyuno|MRI ウィンドウの入ったフレーム|
|cont|pyuno|コンテナウィンドウ|
|pages|mytools_Mri.ui.pages.InfoUi/GridUi|コントロールへ...
*** ダイアログ [#d02d0f73]
mytools_Mri.ui.dialogs.Dialogs クラスが提供するダイアログ...
def dialog_select(mri):
items = ("Item 1", "Item 2", "Item 3", "Item 1")
item = mri.ui.dlgs.dialog_select(items, "Title")
mri.ui.dlgs.dialog_info("%s is selected. " % item)
dialog_select メソッドの二番目の引数はダイアログのタイト...
ユーザーに入力させたいときには dialog_input メソッドを利...
def dialog_input(mri):
text = mri.ui.dlgs.dialog_input(
"Service Name", "Input a service name.",
"com.sun.star.awt.")
mri.ui.message(text)
全ての引数は省略可能です。
履歴から項目を選択させるダイアログがあります。
def history_selector(mri):
entry = mri.ui.dlgs.history_selector("Select Entry")
if entry:
mri.ui.message(entry.name)
返り値は mytools_Mri.engine.Entry クラスのインスタンスで...
メッセージを表示したり、ユーザーの反応が必要なときには me...
def message(self, message, title="", type="messbox", but...
** エントリ [#q45546b3]
Entry クラスは現在またはそれ以外のターゲットを保持するた...
mytools_Mri.engine.Entry <
(mytools_Mri.engine.EntryBase, mytools_Mri.node.Node)
Entry クラスは二つの親クラスを継承していますが、自身では...
次の表では Entry クラスのインスンタンス変数を説明します。
|Variable|Type|Description|h
|target|object|インスタンスがラップしている実際の値|
|inspected|pyuno|css.beans.XIntrospectionAccess インター...
|type|pyuno|css.reflection.CoreReflection による IDL 型情...
|mri|mytools_Mri.MRI|MRI への参照|
|code_entry|mytools_Mri.cg.CodeEntry|コード生成用の情報|
次の表に示したメソッドも提供しています。
|Method|Description|h
|get_target()|target インスタンス変数を利用してください|
|has_interface(name)|ターゲットが指定したインターフェース...
|supports_service(name)|ターゲットが指定したサービスをサ...
|append(obj)|obj をリストに追加します。このメソッドは MRI...
** ページ [#a2272a6d]
MRIUi の pages インスタンス変数は mytools_Mri.pages.InfoU...
InfoUi < (Ui, PageStatus,
Pages < PagesBase)
GridUi < (Ui, PageStatus,
GridPages < GridPagesBase < PagesBase)
Ui クラスは型や実装名、検索と履歴のコントロールへのアクセ...
|Method|Description|h
|get_type_name()|型名を返します|
|set_type_name(name)|型名を設定します|
|get_imple_name()|実装名を返します|
|set_imple_name(name)|実装名を設定します|
|get_code()|現在のコードのテキストを返します|
|set_code(txt)|コードのテキストを設定します|
PageStatus クラスは情報ページのステータスを保持しています。
PagesBase クラスはその子クラスで定義するべきクラスを定義...
|Method|Description|h
|get_selected(index=None)|選択されているテキストを返します|
|get_current_line(index=None)|現在の行のテキストを返します|
|get_first_word(index=None)|現在の行の最初の単語を返します|
|activate(index)|アクティブなページを設定します|
|get_active()|アクティブなページを設定します|
|search(search_text, index=None)|検索します|
これらのコントロールの内容は最初にアクティブになったとき...
** MRI ウィンドウのコントローラ [#n06feac2]
MRI はウィンドウのフレームに接続される独自のコントローラ...
def do_something_with(mri):
# デスクトップから MRI ウィンドウを探す
found = None
frames = mri.ui.desktop.getFrames()
for i in range(frames.getCount()):
frame = frames.getByIndex(i)
if frame.getTitle() == "MRI":
found = frame
break
if found:
controller = found.getController()
# もうひとつの MRI の MRIUi インスタンス
ui = controller.ui
mri2 = ui.main # instance of mytools_Mri.MRI
この方法はオフィースの同じ Python インスタンスで動作して...
** MRI ウィンドウの構造 [#b3197135]
MRI ウィンドウの構造を示します。
frame: css.frame.Frame
- Controller: mytools_Mri.ui.controller.Controller
- Model: always None
- Container Window: general window
- Component Window: css.awt.UnoControlContainer
- splitter: does not added in the container
- label_status: FixedText keeps status text.
- edit_type: Edit shows type information.
- edit_in: Edit shows implementation name.
- list_hist: List of history.
- btn_back: Back button.
- btn_forward: Forward button.
- edit_search: Search edit.
- btn_search: Search Button.
- btn_tree: Open tree button.
- btn_index_acc: Index button.
- btn_name_acc: Name button.
- subcont: css.awt.UnoControlContainer (without tab)
- info_0:
- info_1:
- info_2:
- info_3:
- subcont: css.awt.UnoControlContainer (with tab)
- page_0
- info_0
- page_1
- info_1
- page_2
- info_2
- page_3
- info_3
subcont の構造はタブコントロールを利用しているかどうかで...
** 例 [#i8ddd1ea]
拡張機能パッケージの Macros ディレクトリにある bundle.py ...
*** 例1 [#g7f78c4f]
以下の短いコードで現在の図形描写コレクションから子図形描...
def inspect_shapes(mri):
""" Inspect Shapes
Inspect all shapes in this container. """
shape = mri.current # current target
# check current shape is correct type
if shape.supports_service("com.sun.star.drawing.Shap...
# getCount call is not collected to code
for i in range(shape.target.getCount()):
child = shape.getByIndex(i)
Entry クラスの supports_service メソッドはそのターゲット...
*** 例2 [#zd9dabef]
Entry インスタンスは実際の値をラップしています。ターゲッ...
def show_property_value(mri):
current = mri.current
ui = mri.ui
ui.message(current.target)
Page: