On this page |
概要 ¶
ViewerStateMenu
クラスは、Viewer Stateのコンテキストメニューを構築することができます。
このクラスは、トップレベルのコンテキストメニューのサブメニューを表現することもできます。
現在のところ、コンテキストメニューには以下のアイテムを追加することができます。
-
トグル(チェックボックス)アイテム: 有効/無効を切り替え可能な設定を表現します。
-
ラジオストリップ: 複数の相互排他的アイテム選択を表現します。
-
アクションアイテム: 実行するアクションを表現します。Viewer StateのonMenuActionメソッドを使って、そのアクションを実装します。
-
セパレータアイテム: コンテキストメニュー内のアイテムをグループ別に分けた視覚的な区切り線を作成します。
hou.PluginHotkeyDefinitionsオブジェクトを使用して登録されているホットキーは、トグル、アクション、ラジオストリップのメニューアイテムに追加することができます。
詳細は、Viewer Stateコンテキストメニューのセットアップ方法を参照してください。
以下のサンプルは、SOP
Viewer Stateのメニューを実装して、そのメニューをそのViewer Stateにバインドさせる方法を載せています。
from __future__ import print_function import hou class ExampleState(object): def __init__(self, state_name, scene_viewer): self.state_name = state_name self.scene_viewer = scene_viewer # メニューコールバック def onMenuAction(self, kwargs): action = kwargs["menu_item"] if action == 'toggle1': print("Set toggle 1 to", kwargs["toggle1"]) elif action == 'toggle2': print("Set toggle 2 to", kwargs["toggle2"]) elif action == 'action': print("Chose action 1") elif action == 'radio_strip': print("Set the radio strip to", kwargs["radio_strip"]) elif action == 'submenu_toggle1': print("Set the submenu toggle to", kwargs["submenu_toggle1"]) def createViewerStateTemplate(state_type, state_label): template = hou.ViewerStateTemplate( state_type, state_label, hou.sopNodeTypeCategory() ) template.bindFactory(ExampleState) # ホットキー定義をいくつか追加します。 hotkey_definitions = hou.PluginHotkeyDefinitions() example_context = "h.pane.gview.state.sop.example" hotkey_definitions.addContext(example_context, "Example Operation", "These keys apply to the Example operations") example_category = "h.pane.gview.state.sop.example" hotkey_definitions.addCommandCategory(example_category, "Example Operation", "These commands apply to the Example operations") h1 = example_category + 'h1' hotkey_definitions.addCommand(h1, 'example 1', 'example 1') hotkey_definitions.addDefaultBinding(example_context, h1, ['1']) h2 = example_category + 'h2' hotkey_definitions.addCommand(h2, 'example 2', 'example 2') hotkey_definition.addDefaultBinding(example_context, h2, ['2']) h3 = example_category + 'h3' hotkey_definitions.addCommand(h3, 'example 3', 'example 3') hotkey_definitions.addDefaultBinding(example_context, h3, ['3']) h4 = example_category + 'h3' hotkey_definitions.addCommand(h4, 'example 4', 'example 4') hotkey_definitions.addDefaultBinding(example_context, h4, ['4']) # Viewer Stateのポップアップメニューを定義します。 m = hou.ViewerStateMenu('menu', 'Example') m.addSeparator() m.addToggleItem( 'toggle1', 'Toggle1', True, hotkey=h1 ) m.addToggleItem( 'toggle2', 'Toggle2', False ) m.addSeparator() m.addActionItem( 'action', 'Action1', hotkey=h2 ) m.addSeparator() m.addRadioStrip( 'radio_strip', 'Radio', "radio_item1" ) m.addRadioStripItem( 'radio_strip', 'radio_item1', 'Radio1', hotkey=h3 ) m.addRadioStripItem( 'radio_strip', 'radio_item2', 'Radio2', hotkey=h4 ) m.addSeparator() subm = hou.ViewerStateMenu('submenu', 'More Example...') subm.addToggleItem( 'submenu_toggle1', 'Sub toggle1', True ) m.addMenu( subm ) m.addSeparator() # ポップアップルメニューをViewer Stateに取り付けます。 template.bindMenu(m) # ホットキー定義をViewer Stateに取り付けます。 template.bindHotkeyDefinitions(hotkey_definitions) return t
メソッド ¶
__init__(id, label)
hou.ViewerStateMenuオブジェクトを作成します。
id
メニューの固有文字列ID。現在のところ、これはトップレベルのViewer Stateコンテキストメニューには使用されません。
label
メニューをインターフェース内に表示する際のそのメニュー名。現在のところ、これはトップレベルのViewer Stateコンテキストメニューには使用されません。
# トップメニューのIDとラベルは使用されないものの、とにかく意味のある値を設定しておくべきです。 menu = hou.ViewerStateMenu("menu", "State Menu")
addActionItem(id, label, hotkey='')
このメニューにアクションアイテムを追加します。
id
メニューアイテムを識別するための固有名。ユーザがこのアイテムを選択すると、このIDがkwargs["menu_item"]
引数辞書としてonMenuAction
メソッドに渡されます。
label
メニューに表示されるメニューアイテムラベル。
hotkey
このメニューアイテムに関連付けるオプションのホットキーID文字列。 hou.hotkeys.addCommandを使用することで、独自のホットキーを作成することができます。
menu = hou.ViewerStateMenu("menu", "State Menu") menu.addActionItem("delete", "Delete")
addToggleItem(id, label, default, hotkey='' )
このメニューにトグルメニューアイテムを追加します。
id
このアイテムの固有文字列ID。
label
メニューに表示されるメニューアイテムテキスト。
default
メニューが生成された時にデフォルトでアイテムを有効にするかどうか。
hotkey
このメニューアイテムに関連付けるオプションのホットキーID文字列。 hou.hotkeys.addCommandを使用することで、独自のホットキーを作成することができます。
menu = hou.ViewerStateMenu("menu", "State Menu") menu.addToggleItem("show_points", "Show Points", True) menu.addToggleItem("show_point_nums", "Show Point Numbers", False
addSeparator()
セパレータメニューアイテムを追加します。
menu = hou.ViewerStateMenu("menu", "State Menu") menu.addActionItem("delete", "Delete") menu.addSeparator() menu.addToggleItem("show_points", "Show Points", True) menu.addToggleItem("show_point_nums", "Show Point Numbers", False)
addRadioStrip(id, label, default)
相互排他的“ラジオボタン”アイテムのグループを受け入れるメニューを用意します。
id
ラジオストリップの固有文字列ID。
addRadioStripItem()
を使ってグループに追加されたすべてのメニューアイテムは、この文字列を最初の引数として持ちます。
label
メニュー内のグループの上部に表示されるタイトル。
default
hou.ViewerStateMenu.addRadioStripItemで指定するようなラジオアイテムIDをここに指定し、メニューが生成された時のデフォルトの選択を表現します。
menu = hou.ViewerStateMenu("menu", "State Menu") menu.addRadioStrip("deform_type", "Deformation", "bend") menu.addRadioStripItem("deform_type", "bend", "Bend") menu.addRadioStripItem("deform_type", "squash", "Squash")
addRadioStripItem(strip_id, id, label, hotkey='')
ラジオストリップメニューにメニューアイテムを追加します。
strip_id
(addRadioStrip()
で作成された)ラジオストリップの文字列ID。
同じstrip_id
を共有したすべてのアイテムが相互排他的になります。
id
このアイテムの固有文字列ID。
label
メニューに表示されるメニューアイテムテキスト。
hotkey
このメニューアイテムに関連付けるオプションのホットキーID文字列。 hou.hotkeys.addCommandを使用することで、独自のホットキーを作成することができます。
menu = hou.ViewerStateMenu("menu", "State Menu") menu.addRadioStrip("deform_type", "Deformation", "bend") menu.addRadioStripItem("deform_type", "bend", "Bend") menu.addRadioStripItem("deform_type", "squash", "Squash")
addMenu(submenu)
サブメニューとしてViewerStateMenu
オブジェクトを追加します。
menu = hou.ViewerStateMenu("menu", "State Menu") menu.addActionItem("delete", "Delete") menu.addSeparator() submenu = hou.ViwerStateMenu("options", "Options") submenu.addToggleItem("show_points", "Show Points", True) submenu.addToggleItem("show_point_nums", "Show Point Numbers", False) menu.addMenu(submenu)