Current code.
[capital-apms.git] / rb / mainmenu
blob59317e26fceaefd45b91d0684704023227e715ff
1 #!/usr/bin/env ruby
3 =begin
4 mainmenu - APMS Main Menu
6 Copyright (c) Andrew McMillan, 2007
7 =end
9 require 'gtk2'
10 require 'dbi'
12 $dbh = DBI.connect("DBI:Pg:apms_catalyst","general")
14 class Apms
15 def initialize
16 @window = Gtk::Window.new
17 @window.border_width = 5
18 @window.title = "APMS Main Menu"
19 menu = Gtk::VBox.new
20 @window.add(menu)
21 @tips = Gtk::Tooltips.new
24 # Add a set of buttons
25 link_id = 8
26 buttons_sql = $dbh.prepare("SELECT buttonlabel, linktype, linkcode, viewer, sortpanel, filterpanel, description, function FROM programlink WHERE source = #{link_id} AND exists( SELECT 1 FROM usrgroupmenu JOIN usrgroupmenuitem USING ( menuname ) WHERE menuname = 'Main Menu' AND programlink.linkcode = usrgroupmenuitem.linkcode);")
27 buttons_sql.execute()
28 btns_width = 0
29 btn_count = 0
30 btn_per_row = 4
31 row_width = 550
32 # buttons = Gtk::HButtonBox.new
33 buttons = Gtk::HBox.new( false, 0 )
34 while btn_row = buttons_sql.fetch do
35 btn = Gtk::Button.new(btn_row["buttonlabel"])
36 @tips.set_tip( btn, btn_row["description"], '' )
37 puts btn_row["buttonlabel"] + " added"
38 btn.signal_connect("clicked") { |handle|
39 puts handle.label + " clicked"
40 BrowseWindow.new( handle.label )
42 (width,height) = btn.size_request
43 btns_width += width
44 buttons.pack_start(btn, false, false, 0)
45 # buttons.add(btn)
46 if btns_width >= row_width then
47 puts "Button row added - width #{btns_width}"
48 menu.add(buttons)
49 # buttons = Gtk::HButtonBox.new
50 buttons = Gtk::HBox.new( false, 0 )
51 # buttons.set_layout_style(Gtk::ButtonBox::START)
52 btn_count = 0
53 btns_width = 0
54 else
55 btn_count += 1
56 end
57 end
58 if btn_count > 0 then
59 menu.add(buttons)
60 end
63 @window.signal_connect("destroy") {
64 puts "Apms destroy event handler"
65 quit
68 @window.show_all
69 end
71 def quit
72 Gtk.main_quit
73 end
75 end
77 class BrowseWindow
78 def initialize( label )
79 window = Gtk::Window.new
80 window.title = label
82 window.signal_connect("delete_event") {
83 puts "BrowseWindow delete event handler"
85 window.show_all
86 end
88 end
90 Apms.new
91 Gtk.main