require "phi" ; include Phi form = Phi::Form.new :form, "大きさを指定する(1)" label = Phi::Label.new form, :label, "Hello!" label.height = 50 label.width = 70 label.color = Phi::CL_RED form.show Phi.mainloop # by take_tk
require "phi" ; include Phi form = Phi::Form.new :form, "大きさを指定する(2)" label = Phi::Label.new form, :label, "Hello!" label.align = Phi::AL_CLIENT label.color = Phi::CL_RED form.height = 200 form.width = 300 form.show Phi.mainloop # by take_tk
require "phi" ; include Phi form = Phi::Form.new :form, "大きさを取得する。フォームの大きさを変えてください。" label = Phi::Label.new form, :label, "Hello!" label.align = Phi::AL_CLIENT form.on_resize = proc{ label.caption = "height = %d, width = %d" % [form.height, form.width] } form.show Phi.mainloop # by take_tk
require "phi" ; include Phi require"rgui" form = RGUI::Form.new :form, "Widget 間の間隔(余白)を設定する" form.add ( hbox1 = RGUI::Hbox.new(true,10).add(*[ vbox1 = RGUI::Vbox.new(true,10).add(*[ button1 = Button.new( form , :button1, "横に広げる"), button2 = Button.new( form , :button2, "横に狭める") ]), vbox2 = RGUI::Vbox.new(true,10).add(*[ button3 = Button.new( form , :button3, "縦に広げる"), button4 = Button.new( form , :button4, "縦に狭める") ]), ]) ) button1.on_click = proc{ hbox1.space += 1 ; form.layout } button2.on_click = proc{ hbox1.space -= 1 ; form.layout } button3.on_click = proc{ vbox2.space = vbox1.space += 1 ; form.layout } button4.on_click = proc{ vbox2.space = vbox1.space -= 1 ; form.layout } form.on_resize = proc{ form.layout } form.show mainloop
require 'phi' include Phi form = Form.new form.font.name = 'MS ゴシック' i = Button.new form, :btn, 'hello' i.align = Phi::AL_CLIENT def i.on_click self.caption = Time.now.to_s print "clicked\n" end form.show Phi.mainloop
font.color = CL_RED
font.size = 20
require "phi" puts Phi::SCREEN.fonts.sort #=> @Batang #=> @BatangChe #=> …… #=> @Terminal #=> @MS Pゴシック #=> @MS P明朝 #=> @MS ゴシック #=> @MS 明朝 #=> Arial #=> …… #=> Wingdings #=> MS Pゴシック #=> MS P明朝 #=> MS ゴシック #=> MS 明朝
by take_tk
require 'dialog' :
Phi.message_dlg( Usage , Phi::MT_CONFIRMATION, [Phi::MB_OK])
Phi::Form から継承して作りましょう。 そして form.show_modal します。
dlg = Phi::OpenDialog.new if dlg.execute : end
require 'phi' include Phi prompt = 'Select a directory' root = 'C:/apollo/src' result_path='' if Phi.select_dir prompt, root, result_path print "You selected [%s]\n" % result_path else print "You canceled to select directory.\n" end
dlg = Phi::ColorDialog.new if dlg.execute : end
form = Form.new Image.new form, :image form.image.picture.load file_name
JPEG は require 'jpeg' で扱えます。
?
?
ウィンドウを閉じるっていう意味?
exit
とか?
すぐには終了しません。 全てのウィンドウを閉じると Phi.mainloop を抜けます。
form.caption = 'タイトル'
あるいは Form 生成時に
form = Form.new :form1, 'タイトル'
Phi::APPLICATION.icon = Phi::Icon.new.load('foo.ico')
#!ruby -Ks require "phi" ; include Phi form = Form.new :form, "フォームのアイコンを設定する" button = Button.new form, :button, "フォームのアイコンを設定します" button.on_click = proc{ form.icon = Icon.new.load 'c:/apollo/sample/arima.ico' button.caption = "フォームのアイコンを変更しました" } button.align = AL_CLIENT form.show mainloop
#!ruby -Ks require "phi" ; include Phi form = Form.new :form, "アプリケーションのアイコンを設定する" button = Button.new form, :button, "アプリケーションのアイコンを設定します" button.on_click = proc{ APPLICATION.icon = Icon.new.load 'c:/apollo/sample/arima.ico' button.caption = "アプリケーションのアイコンを変更しました" } button.align = AL_CLIENT form.show mainloop
form.caption = 'hello' # by moriq
form = Phi::Form.new form.show # by moriq
form.close # by moriq
form.hide # by moriq
form.position = Phi::PO_SCREEN_CENTER # by moriq
form.top = top form.left = left form.rect = Rect.new(left, top, right, bottom) form.set_bounds(left, top, width, height) # by moriq
p Phi::SCREEN.width p Phi::SCREEN.height # by moriq
form.border_style = Phi::BS_DIALOG # or BS_SINGLE, BS_NONE # by moriq
form.show_modal # by moriq
Sys.beep # by moriq # SysUtils Unit 関係は Sys module を使うつもりだったんだけど、ややこしいから Phi にまとめようか?
動く
# by moriq
基本的に Delphi は SJIS のみ
# by moriq
edit.set_focus form.focus_control = edit # by moriq
p Phi::VERSION # by moriq
?
# by moriq
p $: # by moriq
?
# by moriq
#! ruby # cf: # Delphi4 プログラミングバイブル p.215 # 5.1.5. コンポーネント間のドラッグ require 'phi' include Phi form = Form.new form.caption = $0 i = Edit.new form, :edit i.align = Phi::AL_TOP i.text = 'hello' def i.on_mouse_down(btn, shift, x, y) begin_drag false, 10 end i = ListBox.new form, :lbox i.align = Phi::AL_CLIENT def i.on_drag_over(accept, src, x, y, state) src != parent.edit || items.index_of(parent.edit.text) < 0 end def i.on_drag_drop(src, x, y) case src when parent.edit items.add src.text end end form.show Phi.mainloop # sample/drag_drop.rb # by moriq
#-- $(apollo)/sample/Application_on_idle.rb require "phi" ; include Phi form = Form.new form.show APPLICATION.on_idle = proc{ @idle_cnt ||= 0 @idle_cnt += 1 form.caption = @idle_cnt.to_s } mainloop
take_tk
#-- $(apollo)/sapmle/Timer_interval.rb #-- (B) Timer require "phi" ; include Phi form = Form.new form.show timer = Timer.new timer.interval = 100 ## 100/1000 sec timer.on_timer = proc{ @idle_cnt ||= 0 @idle_cnt += 1 form.caption = @idle_cnt.to_s } mainloop
take_tk