Way too much stuff, I need to commit more often >_<
[tablebottom.git] / tttk.rb
blobbaa6c5061fb458146c8a6508b1112b3076a25a4b
1 require 'tk'
2 require 'tkextlib/tile'
3 require 'ttsock'
4 require 'ttdefs'
6 class TTTk
7   def initialize(host, room, username)
8     @ttsock = TTSock.new(host, room, username)
9     @ttcmd = TTCommander.new(@ttsock)
10     
11     root = TkRoot.new() { title "Tablebottom" }
12     frame = Tk::Tile::Frame.new(root)
13     frame.grid(:sticky => "nsew")
14     TkGrid.columnconfigure root, 0, :weight => 1; TkGrid.rowconfigure root, 0, :weight => 1
15     
16     @tkout = TkText.new(frame) { width 80; height 20;}
17     @tkout.grid( :row => 0, :column => 0, :sticky => "nsew")
18     TkGrid.columnconfigure frame, 0, :weight => 1; TkGrid.rowconfigure frame, 0, :weight => 1
19     
20     @tkout.value = "Welcome to Tablebottom"
21     
22     @tkin = Tk::Tile::Entry.new(frame) { width 80; }
23     @tkin.grid( :row => 1, :column => 0, :sticky => "nsew")
24     @invar = TkVariable.new("")
25     @tkin.textvariable(@invar)
26     
27     root.bind("Return") { return_pressed(@invar.value); @invar.value = "" }
28     Tk.after(10) { do_network() }
29   end
30   
31   def return_pressed(str)
32     @ttcmd.xyzzy_do_cmd(str)
33   end
34   
35   def out_line(str)
36     @tkout.value = @tkout.value + str + "\n"
37   end
38   
39   def do_network()
40     msg = @ttsock.get_msg
41     
43     
44     if msg and ((msg[0] == :lPresent) or (msg[0] == :mSay) or (msg[0] == :mOSay) or (msg[0] == :mCalc) or (msg[0] == :mRoll) or (msg[0] == :mFact) or (msg[0] == :mCheck))
45       out_line(msg.to_s)
46     end
47     
48     Tk.after(10) { do_network() }
49   end
50 end
52 if __FILE__ == $0
53   print "Host (None for Dare's system) : "
54   host = gets.strip
55   if host == ""
56     host = TTDefs::HOST
57   end
58   
59   print "Room : "
60   room = gets.strip
61   
62   print "Name : "
63   name = gets.strip
64   
65   foo = TTTk.new(host, room, name)
66   
67   Tk.mainloop()
68 end