Debian Codegraph @

core/mui/gtk_form_dsl.rb

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 =begin rdoc
4 UIを定義するためのDSLメソッドをクラスに追加するmix-in。
5 現在の値(初期値)を返す[]メソッドと、値が変更された時に呼ばれる[]=メソッドを定義すること。
6 includeするクラスはGtk::Gridでなければならない.
7 =end
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 # ==== Args
48 # [text] ラベルテキスト
49 # [key] キー
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 # ==== Args
75 # [text] ラベルテキスト
76 # [key] 設定のキー
77 # [lower] 最低値。これより小さい数字は入力できないようになる
78 # [upper] 最高値。これより大きい数字は入力できないようになる
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 # ==== Args
104 # [text] チェックボックスのラベルテキスト
105 # [key] キー
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 # ==== Args
138 # [text] ラベルテキスト
139 # [key] キー
140 # [dir:] 初期のディレクトリ
141 # [title:] ファイル選択ダイアログのタイトル(String)
142 # [shortcuts:] ファイル選択ダイアログのサイドバーに表示しておくディレクトリの絶対パスの配列(Array)
143 # [filters:] ファイル選択ダイアログの拡張子フィルタ(Hash)。キーはコンボボックスに表示するラベル(String)、値は拡張子の配列(Array)。拡張子はStringで指定する。
144 # [use_preview:] ファイル選択ダイアログで、ファイルのプレビューを表示するか。 _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 # ==== Args
198 # [text] ラベルテキスト
199 # [key] キー
200 # [title:] ファイル選択ダイアログのタイトル(String)
201 # [shortcuts:] ファイル選択ダイアログのサイドバーに表示しておくディレクトリの絶対パスの配列(Array)
202 # [filters:] ファイル選択ダイアログの拡張子フィルタ(Hash)。キーはコンボボックスに表示するラベル(String)、値は拡張子の配列(Array)。拡張子はStringで指定する。
203 # [use_preview:] ファイル選択ダイアログで、ファイルのプレビューを表示するか。 _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 # stop propagation
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 # ==== Args
286 # [text] ラベル
287 # [key] 設定のキー
288 # [dir:] 初期のディレクトリ
289 # [title:] ファイル選択ダイアログのタイトル(String)
290 # [shortcuts:] ファイル選択ダイアログのサイドバーに表示しておくディレクトリの絶対パスの配列(Array)
291 def dirselect(text, key, _current=nil, dir: _current, title: text.to_s, shortcuts: nil)
292 # fsselect(label, config, dir: dir, action: Gtk::FileChooser::ACTION_SELECT_FOLDER, title: title, shortcuts: shortcuts)
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 # ==== Args
317 # [text] ラベルテキスト
318 # [key] キー
319 def input(text, key, action=nil)
320 widget_right = entry = build_entry(key)
321
322 if action
323 # TODO; gtk3 case action
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 # attach to a new row of the grid
346 attach_next_to label, nil, :bottom, 1, 1
347 attach_next_to widget_right, label, :right, 1, 1
348 else
349 # attach to a new row of the grid
350 attach_next_to widget_right, nil, :bottom, 2, 1
351 end
352
353 Chainable.new widget_right
354 end
355
356 # 一行テキストボックス(非表示)
357 # ==== Args
358 # [text] ラベルテキスト
359 # [key] 設定のキー
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 # ==== Args
382 # [text] ラベルテキスト
383 # [key] 設定のキー
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 # ==== Args
460 # [title] ラベル
461 # [&block] ブロック
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 # ==== Args
479 # [text] ラベルテキスト
480 # [options]
481 # 設定値。以下のキーを含むハッシュ。
482 # _:name_ :: ソフトウェア名
483 # _:version_ :: バージョン
484 # _:copyright_ :: コピーライト
485 # _:comments_ :: コメント
486 # _:license_ :: ライセンス
487 # _:website_ :: Webページ
488 # _:logo_ :: ロゴ画像。 フルパス(String)か、Photo Modelか、GdkPixbuf::Pixbufを指定する
489 # _:authors_ :: 作者の名前。通常MastodonのAcct(Array)
490 # _:artists_ :: デザイナとかの名前。通常MastodonのAcct(Array)
491 # _:documenters_ :: ドキュメントかいた人とかの名前。通常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 # ==== Args
516 # [text] ラベルテキスト
517 # [key] 設定のキー
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 # ==== Args
532 # [text] ラベルテキスト
533 # [key] 設定のキー
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 # ==== Args
548 # [text] ラベルテキスト
549 # [font_key] フォントの設定のキー
550 # [color_key] 色の設定のキー
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 # ==== Args
569 # [config] 設定のキー
570 # [columns:]
571 # 配列の配列で、各要素は[カラムのタイトル(String), カラムの表示文字を返すProc]
572 # [reorder:]
573 # _true_ なら、ドラッグ&ドロップによる並び替えを許可する
574 # [&block] 内容
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 # ==== Args
600 # [text] ラベルテキスト
601 # [key] 設定のキー
602 # [default]
603 # 連想配列で、 _値_ => _ラベル_ の形式で、デフォルト値を与える。
604 # _block_ と同時に与えれられたら、 _default_ の値が先に入って、 _block_ は後に入る。
605 # [&block] 内容
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 # ==== Args
631 # [text] ラベルテキスト
632 # [key] 設定のキー
633 # [default]
634 # 連想配列で、 _値_ => _ラベル_ の形式で、デフォルト値を与える。
635 # _block_ と同時に与えれられたら、 _default_ の値が先に入って、 _block_ は後に入る。
636 # [&block] 内容
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 # Diva::Model の内容を表示する。
679 # 通常はボタンとして描画され、クリックするとopenイベントが発生する。
680 # エレメントとして値を更新する機能はない。
681 # ==== Args
682 # 以下のいずれか
683 # [String | Diva::URI] URLを表示する
684 # [Diva::Model]
685 # _target.title_ がラベルになる。
686 # _target.icon_ が呼び出せてPhotoModelを返す場合は、それも表示する。
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 # settingsメソッドとSelectから内部的に呼ばれるメソッド。Groupの中に入れるGtkウィジェットを返す。
717 # 戻り値は同時にこのmix-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'