Sziasztok!
Elkezdtem egy egyszeru terminalprogit irni Ruby/Gtk-ban, mivel ez eleg konnyu, a peldak kozt is van ilyen. Amde elakadtam. A kerdes nem annyira Ruby-s mint inkabb Gtk-s.
Szoval, a terv: adott egy ComboBoxEntry, ebbe tarolodnak a szerverek cimei. Attol fuggoen, hogy az user milyen protokollt valaszt, dol el, hogy milyen history-t mutatok neki.
A kod (kihagyva az irrelevans reszek)
require 'gtk2'
require 'mterm/glade'
module MTerm
class ConnectWindow
attr :rsp
def initialize
glade = Glade.new.glade
@dlgConn = glade['dlgConn']
@cbServer = glade['cbServer']
@btConn = glade['btConn']
@btCancel = glade['btCancel']
@rbtTelnet = glade['rbtTelnet']
@rbtTN = glade['rbtTN']
@rbtSSH = glade['rbtSSH']
@btConn.signal_connect('clicked') { btConn_click }
@btCancel.signal_connect('clicked') do
@rsp = nil
@dlgConn.hide
end
collect_servers
@rbtSSH.signal_connect('toggled') { fill_combo @ssh_servers }
@rbtTelnet.signal_connect('toggled') { fill_combo @telnet_servers }
@rbtTN.signal_connect('toggled') { fill_combo @tn_servers }
@rbtSSH.active = true
fill_combo @ssh_servers
end
def run
@dlgConn.run
end
private
def collect_servers
@ssh_servers = []
@telnet_servers = []
@tn_servers = []
File.open(File.expand_path "~/.ssh/known_hosts").readlines.each do |line|
line.strip!
hosts = line.split(/\ /)[0]
hosts.split(/,/).each do |host|
if host.include? ':'
host, port = host.split /:/
else
port = 22
end
#puts host
host = host.scan(/\[([^\]]*)\]/)[0][0] if host.include? '['
@ssh_servers << { :host => host, :port => port.to_i }
end
end
@ssh_servers.sort! { |a,b| a[:host] <=> b[:host] }
end
def fill_combo(hlist)
puts hlist.inspect
#if @cbServer.model.nil?
# @cbServer.model = Gtk::ListStore.new String
#end
unless hlist.empty?
@cbServer.model = Gtk::ListStore.new String
ls = @cbServer.model
hlist.each do |s|
it = ls.append
it[0] = s[:host]
end
@cbServer.text_column = 0
else
puts "#empty"
@cbServer.model = nil
@cbServer.text_column = -1
end
end
def save_history
end
end
end
# vim: ts=2 et
A problema a fill_combo-nal jon valahol elo, a hiba:
#empty
/usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb: line 31
Gtk-CRITICAL **:gtk_combo_box_entry_set_text_column: assertion `text_column >= 0' failed
vagy
/usr/lib64/ruby/site_ruby/1.8/rubygems/custom_require.rb: line 31
Gtk-CRITICAL **:gtk_combo_box_entry_set_text_column: assertion `entry_box->priv->text_column == -1' failed
Ez inkabb valami Gtk hulyeseg, de nem jovok ra, micsoda. Az lehet gond, hogy a combo maga glade-bol van elobanyaszva?
PS: az mterm/glade.rb az a ruby-glade-create-template altal generalt osztaly, aminek csak a neve van atirva, egyebkent az van benne, amit a template keszito belerakott.
- 1064 megtekintés