Table Of Contents

Previous topic

Ruby On Rails

Next topic

Python

This Page

VisualRuby

install

に同梱されているのを使うべし。

sample

basic

require 'vr/vruby'

# Windowを作る(VForm)
frm=VRLocalScreen.newform
# frmはVRForm型
p frm
# fromを弄る
frm.move 100,100,300,300
frm.caption="sample1"
frm.create.show
# main loop開始
# VRLocalScreenはVRScreen型の定数
VRLocalScreen.messageloop

moduleを拡張する書き方

require 'vr/vruby'

module MyForm
  def construct
    caption="sample1"
  end
end

frm=VRLocalScreen.newform
frm.extend MyForm
frm.move 100,100,300,300
frm.create.show
VRLocalScreen.messageloop

最後の部分は次の書き方ができる

frm=VRLocalScreen.showForm(MyForm, 100, 100, 300, 300)
VRLocalScreen.messageloop

さらに

VRLocalScreen.start(MyForm)

とできる

VRFormを継承する書き方

こっちの方がわかりやすい?

require 'vr/vruby'

class MyForm < VRForm
  def construct
    caption="sample1"
  end
end

VRLocalScreen.start(MyForm, 100, 100, 300, 300)

layout

require "vr/vrcontrol"
require "vr/vrlayout"

class MyForm < VRForm
  include VRVertLayoutManager
  def construct
    addControl(VRButton,"btn1","これ")
    addControl(VRButton,"btn2","これも",  0)
    addControl(VRButton,"btn3","あれ")
    addControl(VRButton,"btn4","あれも",  0)
  end
end

VRLocalScreen.start(MyForm, 100, 100, 300, 300)

listview

require "vr/vrcontrol"
require "vr/vrlayout"
require "vr/vrcomctl"
require "pathname"

class BaseListView < VRListview
  def on_dblclick
    item=focusedItem
    if focused? item then
      dblclick_action item
    end
  end
end

class DirListview < BaseListView
  HERE=Pathname.new(".")
  PARENT=Pathname.new("..")

  def vrinit
    super
    addColumn("name",120)
    addColumn("ext",50)
    addColumn("size",80)
    addColumn("atime",120)
    set_path(Pathname.new Dir.pwd)
  end

  def set_path(path)
    @current=path.realpath

    clearItems
    @files=[]

    @current.entries.each { |e|
      case e
      when HERE
      when PARENT
        e=@current+e
        @files.push e
        addItem(["..", "", e.size, e.atime])
      else
        e=@current+e
        @files.push e
        case e.ftype
        when "file"
          addItem([e.basename(".*"), e.extname, e.size, e.atime])
        when "directory"
          addItem([e.basename, "", e.size, e.atime])
        else
          puts "UNKNOWN TYPE: "+e.ftype
        end
      end
    }
  end

  def get_path
    @current
  end

  def dblclick_action(index)
    e=@files[index]
    case e.ftype
    when "file"
    when "directory"
      set_path e
    end
  end
end

class MyForm < VRForm
  include VRVertLayoutManager
  def construct
    addControl(DirListview, "list", "LIST")
  end

  def list_dblclicked
    @list.on_dblclick
    self.caption=@list.get_path
  end
end

VRLocalScreen.start(MyForm, 100, 100, 300, 300)
inserted by FC2 system