| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
ソッドをクラスに追加するmix-in。 |
| 5 |
ドと、値が変更された時に呼ばれる[]=メソッドを定義すること。 |
| 6 |
idでなければならない. |
| 7 |
|
| 8 |
module Gtk::FormDSL |
| 9 |
using MUI::ColorConverter |
| 10 |
|
| 11 |
class Chainable |
| 12 |
def initialize(widget) |
| 13 |
@widget = widget |
| 14 |
end |
| 15 |
|
| 16 |
def tooltip(text) |
| 17 |
@widget.tooltip_text = text |
| 18 |
self |
| 19 |
end |
| 20 |
|
| 21 |
def native |
| 22 |
@widget |
| 23 |
end |
| 24 |
end |
| 25 |
|
| 26 |
extend Memoist |
| 27 |
|
| 28 |
PIXBUF_PHOTO_FILTER = GdkPixbuf::Pixbuf.formats.to_h { |f| |
| 29 |
[ |
| 30 |
"#{f.description} (#{f.name})", |
| 31 |
f.extensions.flat_map { |x| |
| 32 |
[x.downcase.freeze, x.upcase.freeze] |
| 33 |
}.freeze |
| 34 |
] |
| 35 |
}.freeze |
| 36 |
PHOTO_FILTER = {'All images' => PIXBUF_PHOTO_FILTER.values.flatten}.merge(PIXBUF_PHOTO_FILTER).merge('All files' => ['*']) |
| 37 |
|
| 38 |
def initialize(*_, &block) |
| 39 |
super |
| 40 |
|
| 41 |
type_strict self => Gtk::Grid |
| 42 |
|
| 43 |
block and instance_eval(&block) |
| 44 |
end |
| 45 |
|
| 46 |
行テキスト |
| 47 |
|
| 48 |
ルテキスト |
| 49 |
キー |
| 50 |
def multitext(text, key) |
| 51 |
label = Gtk::Label.new text |
| 52 |
label.halign = :start |
| 53 |
|
| 54 |
text_view = Gtk::TextView.new |
| 55 |
text_view.halign = :fill |
| 56 |
text_view.hexpand = true |
| 57 |
text_view.wrap_mode = :char |
| 58 |
text_view.border_width = 6 |
| 59 |
text_view.accepts_tab = false |
| 60 |
text_view.editable = true |
| 61 |
text_view.buffer.text = self[key] || '' |
| 62 |
text_view.buffer.ssc :changed do |
| 63 |
self[key] = text_view.buffer.text |
| 64 |
false |
| 65 |
end |
| 66 |
|
| 67 |
attach_next_to label, nil, :bottom, 1, 1 |
| 68 |
attach_next_to text_view, label, :right, 2, 1 |
| 69 |
|
| 70 |
Chainable.new text_view |
| 71 |
end |
| 72 |
|
| 73 |
囲の数値入力 |
| 74 |
|
| 75 |
ルテキスト |
| 76 |
定のキー |
| 77 |
小さい数字は入力できないようになる |
| 78 |
大きい数字は入力できないようになる |
| 79 |
def adjustment(text, key, lower, upper) |
| 80 |
label = Gtk::Label.new text |
| 81 |
label.halign = :start |
| 82 |
label.hexpand = true |
| 83 |
|
| 84 |
value = (self[key] || lower).to_f |
| 85 |
lower, upper = lower.to_f, upper.to_f |
| 86 |
step = 1.0 |
| 87 |
page, page_size = 5.0, 0.0 |
| 88 |
adj = Gtk::Adjustment.new value, lower, upper, step, page, page_size |
| 89 |
adj.ssc :value_changed do |
| 90 |
self[key] = adj.value.to_i |
| 91 |
false |
| 92 |
end |
| 93 |
spinner = Gtk::SpinButton.new adj, 0, 0 |
| 94 |
spinner.halign = :end |
| 95 |
|
| 96 |
attach_next_to label, nil, :bottom, 1, 1 |
| 97 |
attach_next_to spinner, label, :right, 1, 1 |
| 98 |
|
| 99 |
Chainable.new spinner |
| 100 |
end |
| 101 |
|
| 102 |
偽値入力 |
| 103 |
|
| 104 |
ックスのラベルテキスト |
| 105 |
キー |
| 106 |
def boolean(text, key, switch: false) |
| 107 |
if switch |
| 108 |
label = Gtk::Label.new text |
| 109 |
label.halign = :start |
| 110 |
|
| 111 |
switch = Gtk::Switch.new |
| 112 |
switch.active = self[key] |
| 113 |
switch.halign = :end |
| 114 |
switch.ssc 'notify::active' do |
| 115 |
self[key] = switch.active? |
| 116 |
end |
| 117 |
|
| 118 |
attach_next_to label, nil, :bottom, 1, 1 |
| 119 |
attach_next_to switch, label, :right, 1, 1 |
| 120 |
|
| 121 |
Chainable.new switch |
| 122 |
else |
| 123 |
check = Gtk::CheckButton.new text |
| 124 |
check.active = self[key] |
| 125 |
check.ssc :toggled do |
| 126 |
self[key] = check.active? |
| 127 |
false |
| 128 |
end |
| 129 |
|
| 130 |
attach_next_to check, nil, :bottom, 2, 1 |
| 131 |
|
| 132 |
Chainable.new check |
| 133 |
end |
| 134 |
end |
| 135 |
|
| 136 |
ルを選択する |
| 137 |
|
| 138 |
ルテキスト |
| 139 |
キー |
| 140 |
ディレクトリ |
| 141 |
アログのタイトル(String) |
| 142 |
バーに表示しておくディレクトリの絶対パスの配列(Array) |
| 143 |
ボックスに表示するラベル(String)、値は拡張子の配列(Array)。拡張子はStringで指定する。 |
| 144 |
ューを表示するか。 _true_ なら表示する。 (_true_ or _false_) |
| 145 |
def fileselect(text, key, _current=nil, dir: _current, title: text.to_s, shortcuts: nil, filters: nil, use_preview: false) |
| 146 |
label = Gtk::Label.new text |
| 147 |
label.hexpand = true |
| 148 |
label.halign = :start |
| 149 |
|
| 150 |
file_chooser = Gtk::FileChooserButton.new title, :open |
| 151 |
(self[key] && ! self[key].empty?) and file_chooser.filename = self[key] |
| 152 |
file_chooser.ssc :file_set do |
| 153 |
self[key] = file_chooser.filename |
| 154 |
end |
| 155 |
|
| 156 |
dir and file_chooser.current_folder = dir |
| 157 |
|
| 158 |
shortcuts&.each(&file_chooser.method(:add_shortcut_folder)) |
| 159 |
|
| 160 |
filters&.each do |k, v| |
| 161 |
filter = Gtk::FileFilter.new |
| 162 |
filter.name = k |
| 163 |
v.each { |ext| filter.add_pattern "*.#{ext}" } |
| 164 |
file_chooser.add_filter filter |
| 165 |
end |
| 166 |
|
| 167 |
if use_preview |
| 168 |
file_chooser.preview_widget = Gtk::Image.new |
| 169 |
file_chooser.ssc :update_preview do |
| 170 |
filename = file_chooser.preview_filename |
| 171 |
pixbuf = GdkPixbuf::Pixbuf.new file: filename, width: 128, height: 128 |
| 172 |
pixbuf and file_chooser.preview_widget.pixbuf = pixbuf |
| 173 |
file_chooser.preview_widget_active = !!pixbuf |
| 174 |
rescue |
| 175 |
file_chooser.preview_widget_active = false |
| 176 |
end |
| 177 |
end |
| 178 |
|
| 179 |
button = Gtk::Button.new icon_name: 'edit-clear-symbolic' |
| 180 |
button.ssc :clicked do |
| 181 |
file_chooser.unselect_all |
| 182 |
self[key] = nil |
| 183 |
end |
| 184 |
|
| 185 |
box = Gtk::Box.new :horizontal |
| 186 |
box.halign = :end |
| 187 |
box.style_context.add_class 'linked' |
| 188 |
box << file_chooser << button |
| 189 |
|
| 190 |
attach_next_to label, nil, :bottom, 1, 1 |
| 191 |
attach_next_to box, label, :right, 1, 1 |
| 192 |
|
| 193 |
Chainable.new file_chooser |
| 194 |
end |
| 195 |
|
| 196 |
ルを選択する |
| 197 |
|
| 198 |
ルテキスト |
| 199 |
キー |
| 200 |
アログのタイトル(String) |
| 201 |
バーに表示しておくディレクトリの絶対パスの配列(Array) |
| 202 |
ボックスに表示するラベル(String)、値は拡張子の配列(Array)。拡張子はStringで指定する。 |
| 203 |
ューを表示するか。 _true_ なら表示する。 (_true_ or _false_) |
| 204 |
def photoselect(text, key, _current=nil, dir: _current, title: text.to_s, shortcuts: nil, filters: PHOTO_FILTER, use_preview: true) |
| 205 |
label = Gtk::Label.new text |
| 206 |
label.hexpand = true |
| 207 |
label.halign = :start |
| 208 |
|
| 209 |
size = [18, 18] |
| 210 |
|
| 211 |
preview_button = Gtk::Button.new |
| 212 |
preview_button.always_show_image = true |
| 213 |
photo = fs_photo_thumbnail self[key] |
| 214 |
preview_button.image = Gtk::WebIcon.new photo, *size |
| 215 |
preview_button.ssc :clicked do |
| 216 |
Plugin.call(:open, fs_photo_thumbnail(self[key]) || self[key]) |
| 217 |
true |
| 218 |
end |
| 219 |
|
| 220 |
entry = Gtk::Entry.new |
| 221 |
entry.secondary_icon_name = 'document-open-symbolic' |
| 222 |
self[key] and entry.text = self[key] |
| 223 |
entry.ssc :changed do |
| 224 |
filename = self[key] = entry.text |
| 225 |
rect = Gdk::Rectangle.new 0, 0, *size |
| 226 |
preview_button.image.load_model fs_photo_thumbnail(filename), rect |
| 227 |
end |
| 228 |
entry.ssc :icon_press do |
| 229 |
file_chooser = Gtk::FileChooserDialog.new( |
| 230 |
title: title, parent: get_ancestor(Gtk::Window), action: :open, |
| 231 |
buttons: [[Gtk::Stock::CANCEL, Gtk::ResponseType::CANCEL], |
| 232 |
[Gtk::Stock::OPEN, Gtk::Dialog::RESPONSE_ACCEPT]] |
| 233 |
) |
| 234 |
dir and file_chooser.current_folder = dir |
| 235 |
|
| 236 |
if use_preview |
| 237 |
file_chooser.preview_widget = Gtk::Image.new |
| 238 |
file_chooser.ssc :update_preview do |
| 239 |
filename = file_chooser.preview_filename |
| 240 |
pixbuf = GdkPixbuf::Pixbuf.new file: filename, width: 128, height: 128 |
| 241 |
pixbuf and file_chooser.preview_widget.pixbuf = pixbuf |
| 242 |
file_chooser.preview_widget_active = !!pixbuf |
| 243 |
rescue |
| 244 |
file_chooser.preview_widget_active = false |
| 245 |
end |
| 246 |
end |
| 247 |
file_chooser.ssc :response do |_, response_id| |
| 248 |
case response_id |
| 249 |
when Gtk::ResponseType::ACCEPT |
| 250 |
self[key] = entry.text = file_chooser.filename |
| 251 |
photo = fs_photo_thumbnail self[key] |
| 252 |
preview_button.image = Gtk::WebIcon.new photo, *size |
| 253 |
end |
| 254 |
file_chooser.destroy |
| 255 |
end |
| 256 |
|
| 257 |
dir and file_chooser.current_folder = dir |
| 258 |
|
| 259 |
shortcuts&.each(&file_chooser.method(:add_shortcut_folder)) |
| 260 |
|
| 261 |
filters&.each do |k, v| |
| 262 |
filter = Gtk::FileFilter.new |
| 263 |
filter.name = k |
| 264 |
v.each { |ext| filter.add_pattern "*.#{ext}" } |
| 265 |
file_chooser.add_filter filter |
| 266 |
end |
| 267 |
|
| 268 |
file_chooser.show_all |
| 269 |
end |
| 270 |
|
| 271 |
box = Gtk::Box.new :horizontal |
| 272 |
box.halign = :fill |
| 273 |
box.hexpand = true |
| 274 |
box.style_context.add_class 'linked' |
| 275 |
box << preview_button |
| 276 |
box.pack_start entry, fill: true, expand: true |
| 277 |
|
| 278 |
attach_next_to label, nil, :bottom, 1, 1 |
| 279 |
attach_next_to box, label, :right, 1, 1 |
| 280 |
|
| 281 |
Chainable.new entry |
| 282 |
end |
| 283 |
|
| 284 |
クトリを選択する |
| 285 |
|
| 286 |
ベル |
| 287 |
定のキー |
| 288 |
ディレクトリ |
| 289 |
アログのタイトル(String) |
| 290 |
バーに表示しておくディレクトリの絶対パスの配列(Array) |
| 291 |
def dirselect(text, key, _current=nil, dir: _current, title: text.to_s, shortcuts: nil) |
| 292 |
|
| 293 |
|
| 294 |
label = Gtk::Label.new text |
| 295 |
label.hexpand = true |
| 296 |
label.halign = :start |
| 297 |
|
| 298 |
file_chooser = Gtk::FileChooserButton.new title, :select_folder |
| 299 |
file_chooser.halign = :end |
| 300 |
(self[key] && ! self[key].empty?) and file_chooser.filename = self[key] |
| 301 |
file_chooser.ssc :file_set do |
| 302 |
self[key] = file_chooser.filename |
| 303 |
end |
| 304 |
|
| 305 |
dir and file_chooser.current_folder = dir |
| 306 |
|
| 307 |
shortcuts&.each(&file_chooser.method(:add_shortcut_folder)) |
| 308 |
|
| 309 |
attach_next_to label, nil, :bottom, 1, 1 |
| 310 |
attach_next_to file_chooser, label, :right, 1, 1 |
| 311 |
|
| 312 |
Chainable.new file_chooser |
| 313 |
end |
| 314 |
|
| 315 |
キストボックス |
| 316 |
|
| 317 |
ルテキスト |
| 318 |
キー |
| 319 |
def input(text, key, action=nil) |
| 320 |
widget_right = entry = build_entry(key) |
| 321 |
|
| 322 |
if action |
| 323 |
|
| 324 |
button = Gtk::Button.new |
| 325 |
button.image = Gtk::Image.new icon_name: 'edit-paste-symbolic' |
| 326 |
button.ssc :clicked do |
| 327 |
get_clipboard(Gdk::Selection::CLIPBOARD) |
| 328 |
.request_text { |_, text| entry.text = text } |
| 329 |
end |
| 330 |
|
| 331 |
box = Gtk::Box.new(:horizontal) |
| 332 |
box.style_context.add_class(:linked) |
| 333 |
box.add(entry, expand: true) |
| 334 |
box.add(button) |
| 335 |
widget_right = box |
| 336 |
end |
| 337 |
|
| 338 |
widget_right.halign = :fill |
| 339 |
widget_right.hexpand = true |
| 340 |
|
| 341 |
if text |
| 342 |
label = Gtk::Label.new text |
| 343 |
label.halign = :start |
| 344 |
|
| 345 |
|
| 346 |
attach_next_to label, nil, :bottom, 1, 1 |
| 347 |
attach_next_to widget_right, label, :right, 1, 1 |
| 348 |
else |
| 349 |
|
| 350 |
attach_next_to widget_right, nil, :bottom, 2, 1 |
| 351 |
end |
| 352 |
|
| 353 |
Chainable.new widget_right |
| 354 |
end |
| 355 |
|
| 356 |
トボックス(非表示) |
| 357 |
|
| 358 |
ルテキスト |
| 359 |
定のキー |
| 360 |
def inputpass(text, key) |
| 361 |
entry = build_entry(key) |
| 362 |
entry.visibility = false |
| 363 |
entry.halign = :fill |
| 364 |
entry.hexpand = true |
| 365 |
|
| 366 |
if text |
| 367 |
label = Gtk::Label.new text |
| 368 |
label.halign = :start |
| 369 |
|
| 370 |
attach_next_to label, nil, :bottom, 1, 1 |
| 371 |
attach_next_to entry, label, :right, 1, 1 |
| 372 |
else |
| 373 |
attach_next_to entry, nil, :bottom, 2, 1 |
| 374 |
end |
| 375 |
|
| 376 |
Chainable.new entry |
| 377 |
end |
| 378 |
|
| 379 |
キストボックス |
| 380 |
入力させて、配列で受け取る。 |
| 381 |
|
| 382 |
ルテキスト |
| 383 |
定のキー |
| 384 |
def multi(text, key) |
| 385 |
settings(text) do |
| 386 |
grid = Gtk::Grid.new |
| 387 |
grid.orientation = :vertical |
| 388 |
grid.row_spacing = 6 |
| 389 |
grid.halign = :fill |
| 390 |
grid.hexpand = true |
| 391 |
|
| 392 |
update_config = lambda do |
| 393 |
self[key] = grid.children.map do |box| |
| 394 |
box.children.find { |w| w.is_a? Gtk::Entry }.text |
| 395 |
end.select { |s| ! s.empty? } |
| 396 |
end |
| 397 |
|
| 398 |
build_box = lambda do |s| |
| 399 |
box = Gtk::Box.new :horizontal |
| 400 |
box.halign = :fill |
| 401 |
box.hexpand = true |
| 402 |
box.style_context.add_class 'linked' |
| 403 |
|
| 404 |
entry = Gtk::Entry.new |
| 405 |
entry.text = s |
| 406 |
entry.sensitive = false |
| 407 |
|
| 408 |
button = Gtk::Button.new icon_name: 'list-remove-symbolic' |
| 409 |
button.ssc :clicked do |
| 410 |
grid.remove box |
| 411 |
update_config.() |
| 412 |
end |
| 413 |
|
| 414 |
box.pack_start(entry, fill: true, expand: true).pack_start(button) |
| 415 |
end |
| 416 |
|
| 417 |
entry = Gtk::Entry.new |
| 418 |
button = Gtk::Button.new icon_name: 'list-add-symbolic' |
| 419 |
button.sensitive = false |
| 420 |
|
| 421 |
entry.ssc :changed do |
| 422 |
button.sensitive = ! entry.text.empty? |
| 423 |
false |
| 424 |
end |
| 425 |
entry.ssc :activate do |
| 426 |
button.clicked |
| 427 |
true |
| 428 |
end |
| 429 |
|
| 430 |
button.ssc :clicked do |
| 431 |
entry.text.empty? and next false |
| 432 |
|
| 433 |
(grid << build_box.(entry.text)).show_all |
| 434 |
|
| 435 |
entry.text = '' |
| 436 |
button.sensitive = false |
| 437 |
|
| 438 |
update_config.() |
| 439 |
|
| 440 |
true |
| 441 |
end |
| 442 |
|
| 443 |
box = Gtk::Box.new :horizontal |
| 444 |
box.halign = :fill |
| 445 |
box.hexpand = true |
| 446 |
box.style_context.add_class 'linked' |
| 447 |
box.pack_start(entry, fill: true, expand: true).pack_start(button) |
| 448 |
|
| 449 |
grid << box |
| 450 |
(self[key] || []).each do |s| |
| 451 |
grid << build_box.(s) |
| 452 |
end |
| 453 |
|
| 454 |
attach_next_to grid, nil, :bottom, 2, 1 |
| 455 |
end |
| 456 |
end |
| 457 |
|
| 458 |
関連の強い設定をカテゴライズできる。 |
| 459 |
|
| 460 |
ベル |
| 461 |
ロック |
| 462 |
def settings(title, &block) |
| 463 |
group = Gtk::Frame.new.set_border_width(1) |
| 464 |
if(title.is_a?(Gtk::Widget)) |
| 465 |
group.set_label_widget(title) |
| 466 |
else |
| 467 |
group.set_label(title) |
| 468 |
end |
| 469 |
box = create_inner_setting.set_border_width(4) |
| 470 |
box.instance_eval(&block) |
| 471 |
group.add(box) |
| 472 |
attach_next_to group, nil, :bottom, 2, 1 |
| 473 |
|
| 474 |
Chainable.new group |
| 475 |
end |
| 476 |
|
| 477 |
出すためのボタン。押すとダイアログが出てくる |
| 478 |
|
| 479 |
ルテキスト |
| 480 |
|
| 481 |
下のキーを含むハッシュ。 |
| 482 |
トウェア名 |
| 483 |
ージョン |
| 484 |
ーライト |
| 485 |
メント |
| 486 |
イセンス |
| 487 |
ージ |
| 488 |
か、GdkPixbuf::Pixbufを指定する |
| 489 |
odonのAcct(Array) |
| 490 |
通常MastodonのAcct(Array) |
| 491 |
の名前。通常MastodonのAcct(Array) |
| 492 |
def about(text, options={}) |
| 493 |
name_mapper = Hash.new{|h,k| k } |
| 494 |
name_mapper[:name] = :program_name |
| 495 |
|
| 496 |
button = Gtk::Button.new label: text |
| 497 |
button.hexpand = true |
| 498 |
button.signal_connect(:clicked){ |
| 499 |
dialog = Gtk::AboutDialog.new.show |
| 500 |
options.each { |key, value| |
| 501 |
dialog.__send__("#{name_mapper[key]}=", about_converter[key][value]) |
| 502 |
} |
| 503 |
dialog.signal_connect(:response){ |
| 504 |
dialog.destroy |
| 505 |
false |
| 506 |
} |
| 507 |
} |
| 508 |
|
| 509 |
attach_next_to button, nil, :bottom, 2, 1 |
| 510 |
|
| 511 |
Chainable.new button |
| 512 |
end |
| 513 |
|
| 514 |
すとフォント、サイズを設定するダイアログが出てくる。 |
| 515 |
|
| 516 |
ルテキスト |
| 517 |
定のキー |
| 518 |
def font(text, key) |
| 519 |
label = Gtk::Label.new text |
| 520 |
label.halign = :start |
| 521 |
font = build_font(key) |
| 522 |
font.halign = :end |
| 523 |
|
| 524 |
attach_next_to label, nil, :bottom, 1, 1 |
| 525 |
attach_next_to font, label, :right, 1, 1 |
| 526 |
|
| 527 |
Chainable.new font |
| 528 |
end |
| 529 |
|
| 530 |
すと色を設定するダイアログが出てくる。 |
| 531 |
|
| 532 |
ルテキスト |
| 533 |
定のキー |
| 534 |
def color(text, key) |
| 535 |
label = Gtk::Label.new text |
| 536 |
label.halign = :start |
| 537 |
color = build_color(key) |
| 538 |
color.halign = :end |
| 539 |
|
| 540 |
attach_next_to label, nil, :bottom, 1, 1 |
| 541 |
attach_next_to color, label, :right, 1, 1 |
| 542 |
|
| 543 |
Chainable.new color |
| 544 |
end |
| 545 |
|
| 546 |
と色を決定させる。 |
| 547 |
|
| 548 |
ルテキスト |
| 549 |
トの設定のキー |
| 550 |
設定のキー |
| 551 |
def fontcolor(text, font_key, color_key) |
| 552 |
label = Gtk::Label.new text |
| 553 |
label.halign = :start |
| 554 |
right_container = Gtk::Grid.new.tap do |grid| |
| 555 |
grid.column_spacing = 6 |
| 556 |
grid << (build_font font_key) |
| 557 |
grid << (build_color color_key) |
| 558 |
end |
| 559 |
right_container.halign = :end |
| 560 |
|
| 561 |
attach_next_to label, nil, :bottom, 1, 1 |
| 562 |
attach_next_to right_container, label, :right, 1, 1 |
| 563 |
|
| 564 |
Chainable.new right_container |
| 565 |
end |
| 566 |
|
| 567 |
ューを表示する。 |
| 568 |
|
| 569 |
定のキー |
| 570 |
|
| 571 |
タイトル(String), カラムの表示文字を返すProc] |
| 572 |
|
| 573 |
ドロップによる並び替えを許可する |
| 574 |
内容 |
| 575 |
def listview(config, columns:, edit: true, reorder: edit, object_initializer: :itself.to_proc, &generate) |
| 576 |
listview = Gtk::FormDSL::ListView.new( |
| 577 |
self, columns, config, object_initializer, |
| 578 |
create: edit, |
| 579 |
update: edit, |
| 580 |
delete: edit, |
| 581 |
reorder: reorder, |
| 582 |
&generate) |
| 583 |
listview.hexpand = true |
| 584 |
|
| 585 |
grid = Gtk::Grid.new |
| 586 |
grid.orientation = :vertical |
| 587 |
grid.row_spacing = 6 |
| 588 |
grid << (Gtk::Grid.new.tap do |grid| |
| 589 |
grid.column_spacing = 6 |
| 590 |
grid << listview << listview.buttons |
| 591 |
end) |
| 592 |
|
| 593 |
attach_next_to grid, nil, :bottom, 2, 1 |
| 594 |
|
| 595 |
Chainable.new grid |
| 596 |
end |
| 597 |
|
| 598 |
1つ選択させる |
| 599 |
|
| 600 |
ルテキスト |
| 601 |
定のキー |
| 602 |
|
| 603 |
ル_ の形式で、デフォルト値を与える。 |
| 604 |
の値が先に入って、 _block_ は後に入る。 |
| 605 |
内容 |
| 606 |
def select(text, key, default = {}, mode: :auto, **kwrest, &block) |
| 607 |
builder = SelectBuilder.new self, text, key, default.merge(kwrest), mode: mode |
| 608 |
block and builder.instance_eval(&block) |
| 609 |
widgets = builder.build |
| 610 |
|
| 611 |
if widgets.size == 1 |
| 612 |
list, = widgets |
| 613 |
|
| 614 |
attach_next_to list, nil, :bottom, 2, 1 |
| 615 |
|
| 616 |
Chainable.new list |
| 617 |
else |
| 618 |
label, combo = widgets |
| 619 |
label.halign = :start |
| 620 |
label.hexpand = true |
| 621 |
|
| 622 |
attach_next_to label, nil, :bottom, 1, 1 |
| 623 |
attach_next_to combo, label, :right, 1, 1 |
| 624 |
|
| 625 |
Chainable.new combo |
| 626 |
end |
| 627 |
end |
| 628 |
|
| 629 |
複数個選択させる |
| 630 |
|
| 631 |
ルテキスト |
| 632 |
定のキー |
| 633 |
|
| 634 |
ル_ の形式で、デフォルト値を与える。 |
| 635 |
の値が先に入って、 _block_ は後に入る。 |
| 636 |
内容 |
| 637 |
def multiselect(text, key, default = {}, mode: :auto, &block) |
| 638 |
builder = MultiSelectBuilder.new self, text, key, default |
| 639 |
block and builder.instance_eval(&block) |
| 640 |
list, = builder.build |
| 641 |
|
| 642 |
attach_next_to list, nil, :bottom, 2, 1 |
| 643 |
|
| 644 |
Chainable.new list |
| 645 |
end |
| 646 |
|
| 647 |
def keybind(title, config) |
| 648 |
keyconfig = Gtk::KeyConfig.new(title, self[config] || "") |
| 649 |
container = Gtk::Box.new(:horizontal, 0) |
| 650 |
container.pack_start(Gtk::Label.new(title), expand: false, fill: true, padding: 0) |
| 651 |
container.pack_start(Gtk::Alignment.new(1.0, 0.5, 0, 0).add(keyconfig), expand: true, fill: true, padding: 0) |
| 652 |
keyconfig.change_hook = ->(modify) { self[config] = modify } |
| 653 |
pack_start(container, expand: false) |
| 654 |
container |
| 655 |
end |
| 656 |
|
| 657 |
キストを表示する。 |
| 658 |
def label(text) |
| 659 |
Gtk::Label.new(text).tap do |label| |
| 660 |
label.halign = :start |
| 661 |
label.wrap = true |
| 662 |
label.xalign = 0 |
| 663 |
attach_next_to(label, nil, :bottom, 2, 1) |
| 664 |
end |
| 665 |
end |
| 666 |
|
| 667 |
キストを表示する。 |
| 668 |
def markup(text) |
| 669 |
Gtk::Label.new.tap do |label| |
| 670 |
label.halign = :start |
| 671 |
label.wrap = true |
| 672 |
label.markup = text |
| 673 |
label.xalign = 0 |
| 674 |
attach_next_to(label, nil, :bottom, 2, 1) |
| 675 |
end |
| 676 |
end |
| 677 |
|
| 678 |
を表示する。 |
| 679 |
され、クリックするとopenイベントが発生する。 |
| 680 |
して値を更新する機能はない。 |
| 681 |
|
| 682 |
のいずれか |
| 683 |
表示する |
| 684 |
|
| 685 |
ベルになる。 |
| 686 |
返す場合は、それも表示する。 |
| 687 |
def link(target) |
| 688 |
case target |
| 689 |
when String, URI, Addressable::URI, Diva::URI |
| 690 |
button = Gtk::Button.new(label: target.to_s, use_underline: false) |
| 691 |
button. |
| 692 |
set_tooltip_text(target.to_s). |
| 693 |
set_alignment(0.0, 0.5). |
| 694 |
ssc(:clicked, &model_opener(target)) |
| 695 |
attach_next_to(button, nil, :bottom, 2, 1) |
| 696 |
when Diva::Model |
| 697 |
button = Gtk::Button.new |
| 698 |
box = Gtk::Box.new(:horizontal, 0) |
| 699 |
if target.respond_to?(:icon) |
| 700 |
icon = Gtk::WebIcon.new(target.icon, 48, 48) |
| 701 |
box.pack_start(icon, expand: false) |
| 702 |
end |
| 703 |
button. |
| 704 |
set_tooltip_text(target.title). |
| 705 |
add(box.add(Gtk::Label.new(target.title))). |
| 706 |
ssc(:clicked, &model_opener(target)) |
| 707 |
attach_next_to(button, nil, :bottom, 2, 1) |
| 708 |
end |
| 709 |
end |
| 710 |
|
| 711 |
def native(widget) |
| 712 |
widget.hexpand = true |
| 713 |
attach_next_to widget, nil, :bottom, 2, 1 |
| 714 |
end |
| 715 |
|
| 716 |
るメソッド。Groupの中に入れるGtkウィジェットを返す。 |
| 717 |
x-inをロードしている必要がある。 |
| 718 |
def create_inner_setting |
| 719 |
self.new() |
| 720 |
end |
| 721 |
|
| 722 |
def method_missing(*args, &block) |
| 723 |
@plugin.__send__(*args, &block) |
| 724 |
end |
| 725 |
|
| 726 |
private |
| 727 |
|
| 728 |
def build_entry(key) |
| 729 |
entry = Gtk::Entry.new |
| 730 |
entry.text = self[key] || '' |
| 731 |
entry.ssc :changed do |
| 732 |
self[key] = entry.text |
| 733 |
false |
| 734 |
end |
| 735 |
entry |
| 736 |
end |
| 737 |
|
| 738 |
def about_converter |
| 739 |
Hash.new(ret_nth).merge!( |
| 740 |
logo: -> value { |
| 741 |
case value |
| 742 |
when GdkPixbuf::Pixbuf |
| 743 |
value |
| 744 |
when Diva::Model |
| 745 |
value.pixbuf(width: 48, height: 48) |
| 746 |
else |
| 747 |
Plugin.collect(:photo_filter, value, Pluggaloid::COLLECT).first.pixbuf(width: 48, height: 48) rescue nil |
| 748 |
end |
| 749 |
} |
| 750 |
) |
| 751 |
end |
| 752 |
memoize :about_converter |
| 753 |
|
| 754 |
def build_font(key) |
| 755 |
s = self[key] |
| 756 |
font = Gtk::FontButton.new(*(s ? [s] : [])) |
| 757 |
font.ssc(:font_set) { self[key] = font.font_name } |
| 758 |
font |
| 759 |
end |
| 760 |
|
| 761 |
def build_color(key) |
| 762 |
color = Gtk::ColorButton.new(self[key].rgba) |
| 763 |
color.ssc(:color_set) { self[key] = color.rgba.to_color_array } |
| 764 |
color |
| 765 |
end |
| 766 |
|
| 767 |
def fs_photo_thumbnail(path) |
| 768 |
Plugin.collect(:photo_filter, path, Pluggaloid::COLLECT).first |
| 769 |
end |
| 770 |
|
| 771 |
def model_opener(model) |
| 772 |
->(*args) do |
| 773 |
Plugin.call(:open, model) |
| 774 |
true |
| 775 |
end |
| 776 |
end |
| 777 |
end |
| 778 |
|
| 779 |
require 'mui/gtk_form_dsl_select' |
| 780 |
require 'mui/gtk_form_dsl_multi_select' |
| 781 |
require 'mui/gtk_form_dsl_listview' |