オプション型
Option クラスは、ツールおよび形式プラグインのダイアログで UI コントロールを生成する、型付きで永続的なオプションを定義するためのファクトリメソッドを提供します。
共通パラメーター
すべてのオプションファクトリは、以下のパラメーターを受け取ります。
| パラメーター | 型 | 説明 |
|---|---|---|
label | str | 表示ラベル(最初の位置引数) |
default | varies | デフォルト値 |
tooltip | str | ツールチップテキスト |
enabled_when | callable | bool を返すコールバック——表示可否を制御します |
Option.integer()
整数値用のスピンボックスです。
count = Option.integer("Count", default=1, min=0, max=1000)| パラメーター | 型 | デフォルト | 説明 |
|---|---|---|---|
default | int | 0 | デフォルト値 |
min | int | None | 最小値 |
max | int | None | 最大値 |
Option.real()
浮動小数点値用のダブルスピンボックスです。
scale = Option.real("Scale Factor", default=1.0, min=0.001, max=1e6, decimals=4)| パラメーター | 型 | デフォルト | 説明 |
|---|---|---|---|
default | float | 0.0 | デフォルト値 |
min | float | None | 最小値 |
max | float | None | 最大値 |
decimals | int | 2 | 表示する小数桁数 |
Option.boolean()
true/false 値用のチェックボックスです。
flatten = Option.boolean("Flatten hierarchy", default=False)| パラメーター | 型 | デフォルト | 説明 |
|---|---|---|---|
default | bool | False | デフォルト値 |
Option.string()
1 行テキストフィールドです。
name = Option.string("Output name", default="output")| パラメーター | 型 | デフォルト | 説明 |
|---|---|---|---|
default | str | "" | デフォルト値 |
Option.choice()
ドロップダウンセレクターです。
mode = Option.choice("Mode", choices=["Fast", "Precise", "Custom"], default="Fast")| パラメーター | 型 | デフォルト | 説明 |
|---|---|---|---|
choices | list[str] | required | 使用可能なオプション |
default | str | first choice | デフォルト選択 |
Option.path()
参照ボタン付きのファイルパスピッカーです。
output = Option.path("Output file", file_filter="CSV Files (*.csv)")| パラメーター | 型 | デフォルト | 説明 |
|---|---|---|---|
default | str | "" | デフォルトパス |
file_filter | str | "" | ファイルタイプフィルター文字列 |
Option.color()
カラーピッカーボタンです。
fill = Option.color("Fill color", default="#FF0000")| パラメーター | 型 | デフォルト | 説明 |
|---|---|---|---|
default | str | "#000000" | デフォルト色(16 進) |
Option.cell_choice()
現在の図面にあるすべてのセル名で埋められるドロップダウンです。
target = Option.cell_choice("Target cell")| パラメーター | 型 | デフォルト | 説明 |
|---|---|---|---|
default | str | "" | デフォルトセル名 |
Option.table()
型付き列を持つ編集可能グリッドです。パネルアセンブリチュートリアルも参照してください。
entries = Option.table( "My Table", columns=[ TableColumn(key="name", label="Name", col_type="string"), TableColumn(key="value", label="Value", col_type="real", decimals=3), ],)| パラメーター | 型 | デフォルト | 説明 |
|---|---|---|---|
columns | list[TableColumn] | required | 列定義 |
default | list[dict] | [] | デフォルト行 |
値は list[dict] で、各辞書は列キーを値に対応付けます。
TableColumn
| プロパティ | 型 | 説明 |
|---|---|---|
key | str | この列の辞書キー |
label | str | 列見出し |
col_type | str | string、integer、real、choice、cell_choice |
default | Any | 新しい行のデフォルト値 |
choices | list[str] | choice 列のオプション |
decimals | int | real 列の小数桁数 |
min_value | int|float | 数値列の最小値 |
max_value | int|float | 数値列の最大値 |
条件付き表示
enabled_when を使用して、オプションを動的に有効/無効にします。
class MyTool(Tool): mode = Option.choice("Mode", choices=["Simple", "Advanced"]) threshold = Option.real( "Threshold", default=0.5, enabled_when=lambda self: self.mode == "Advanced", ) iterations = Option.integer( "Iterations", default=10, enabled_when=lambda self: self.mode == "Advanced", )mode が “Simple” の場合、threshold と iterations フィールドはグレーアウトされます。