1# 2# tkextlib/bwidget/selectfont.rb 3# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) 4# 5 6require 'tk' 7require 'tkextlib/bwidget.rb' 8require 'tkextlib/bwidget/messagedlg' 9 10module Tk 11 module BWidget 12 class SelectFont < Tk::BWidget::MessageDlg 13 class Dialog < Tk::BWidget::SelectFont 14 end 15 class Toolbar < TkWindow 16 end 17 end 18 end 19end 20 21class Tk::BWidget::SelectFont 22 extend Tk 23 24 TkCommandNames = ['SelectFont'.freeze].freeze 25 WidgetClassName = 'SelectFont'.freeze 26 WidgetClassNames[WidgetClassName] ||= self 27 28 def __strval_optkeys 29 super() << 'sampletext' << 'title' 30 end 31 private :__strval_optkeys 32 33 def __boolval_optkeys 34 super() << 'nosizes' 35 end 36 private :__boolval_optkeys 37 38 def __font_optkeys 39 [] # without fontobj operation 40 end 41 private :__font_optkeys 42 43 def create 44 tk_call(self.class::TkCommandNames[0], @path, *hash_kv(@keys)) 45 end 46 47 def self.load_font 48 tk_call('SelectFont::loadfont') 49 end 50end 51 52class Tk::BWidget::SelectFont::Dialog 53 def __font_optkeys 54 [] # without fontobj operation 55 end 56 57 def create_self(keys) 58 super(keys) 59 @keys['type'] = 'dialog' 60 end 61 62 def configure(slot, value=None) 63 if slot.kind_of?(Hash) 64 slot.delete['type'] 65 slot.delete[:type] 66 return self if slot.empty? 67 else 68 return self if slot == 'type' || slot == :type 69 end 70 super(slot, value) 71 end 72 73 def create 74 @keys['type'] = 'dialog' # 'dialog' type returns font name 75 tk_call(Tk::BWidget::SelectFont::TkCommandNames[0], @path, *hash_kv(@keys)) 76 end 77end 78 79class Tk::BWidget::SelectFont::Toolbar 80 def __font_optkeys 81 [] # without fontobj operation 82 end 83 84 def create_self(keys) 85 keys = {} unless keys 86 keys = _symbolkey2str(keys) 87 keys['type'] = 'toolbar' # 'toolbar' type returns widget path 88 window(tk_call(Tk::BWidget::SelectFont::TkCommandNames[0], 89 @path, *hash_kv(keys))) 90 end 91end 92