wxRuby 를 이용한 간단한 프로그램

require "wxruby"

class Array
def shuffle
ret, org = Array.new, self.dup
ret<<org.delete_at(rand(org.length)) while org.length > 0
return ret
end
end

class RandomGenApp < Wx::App
def on_init
$xrc = Wx::XmlResource.get
$xrc.init_all_handlers
$xrc.load("_RandomNumber.xrc")

RandomGenDialog.new(self).show(true)
end
end

class RandomGenDialog < Wx::Dialog
def initialize(parent)
@coupons = (1..300).to_a

super()
$xrc.load_dialog_subclass(self, parent, 'ID_DIALOG')

@number = Wx::Window.find_window_by_id(Wx::xrcid('wxID_STATIC'))
@btn_select = Wx::Window.find_window_by_id(Wx::xrcid('ID_BUTTON_SELECT'))

evt_button(@btn_select.get_id) { onBtnPop }
evt_close() { Wx::get_app.exit_main_loop }
end
def onBtnPop
50.times { @number.set_label(@coupons.shuffle[0].to_s) }
@number.set_label(@coupons.shuffle.shift.to_s)
end
end

RandomGenApp.new.main_loop


작년 2학기 동아리 세미나때 Ruby 를 소개하면서 예제로 만들어봤던 프로그램. 경품 추첨을 위해 사용되었던, 배열을 섞고 첫번째 값을 뽑아내는 프로그램이다. 40줄짜리 간단한 프로그램이지만 Ruby 에 대한 설명과 wxWindows 에 대한 설명을 병행하면서 시연하다보니 예상시간을 훌쩍 넘어버렸었다. 다 짜고 나니까 청중들 반이 자고 있더라.

그리고 이번에는, 특정 대역의 번호만 줄줄이 나와버리는 기현상이 나타나서 우리 학교가 경품을 싹쓸이해가는 사태가 발생해 버렸다.-_-;

by cypher | 2006/05/22 05:39 | 마이너 잡담 | 트랙백 | 덧글(2)
트랙백 주소 : http://cypher.egloos.com/tb/2438795
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
Commented by 슬레이드 at 2006/05/23 19:05
쿨스에 한장만 주세요 ㅠㅠ
한글쓰고 싶어요 ㅠㅠ
Commented by cypher at 2006/05/24 01:38
나는 못받았다.
※ 로그인 사용자만 덧글을 남길 수 있습니다.
< 이전페이지 다음페이지 >