Class: Clevic::Browser
- Defined in:
- lib/clevic/qt/browser.rb,
lib/clevic/swing/browser.rb
Overview
The main application class. Display one tabs for each descendant of Clevic::View in Clevic::View.order. DefaultView classes created by Clevic::Record are included.
Instance Attribute Summary collapse
-
#menu_edit ⇒ Object
readonly
Returns the value of attribute menu_edit.
-
#menu_search ⇒ Object
readonly
Returns the value of attribute menu_search.
-
#menu_table ⇒ Object
readonly
Returns the value of attribute menu_table.
-
#tables_tab ⇒ Object
readonly
Returns the value of attribute tables_tab.
Class Method Summary collapse
Instance Method Summary collapse
-
#current_changed ⇒ Object
slot to handle the currentChanged signal from tables_tab, and set focus on the grid.
-
#database_name ⇒ Object
Set the main window title to the name of the database, if we can find it.
-
#dump ⇒ Object
activated by Ctrl-Shift-D for debugging.
- #icon ⇒ Object
- #init_connections(tab) ⇒ Object
-
#initialize ⇒ Browser
constructor
A new instance of Browser.
-
#load_views ⇒ Object
Create the tabs, each with a collection for a particular entity class.
- #menu_bar ⇒ Object
-
#next_tab ⇒ Object
slot to handle Ctrl-Tab and move to next tab, or wrap around.
-
#previous_tab ⇒ Object
slot to handle Ctrl-Backtab and move to previous tab, or wrap around.
-
#save_all ⇒ Object
make sure all outstanding records are saved.
- #status_bar ⇒ Object
- #status_bar_timer ⇒ Object
-
#table_view ⇒ Object
return the Clevic::TableView object in the currently displayed tab.
- #title_string ⇒ Object
-
#translate(st) ⇒ Object
shortcut for the Qt translate call.
-
#update_menus ⇒ Object
called by current_changed to update the Edit menu to the menus defined by the currently selected view.
Constructor Details
#initialize ⇒ Browser
Returns a new instance of Browser.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/clevic/qt/browser.rb', line 18 def initialize( main_window ) super( main_window ) # do menus and widgets @layout = Ui::Browser.new @layout.setup_ui( main_window ) # set icon. MUST come after call to setup_ui icon_path = Pathname.new( __FILE__ ).parent + "../icons/icon.png" Kernel::raise "icon.png not found" unless icon_path.file? main_window.window_icon = Qt::Icon.new( icon_path.realpath.to_s ) # add the tables tab @tables_tab = Qt::TabWidget.new( @layout. ) @layout..layout. @tables_tab @tables_tab..focus_policy = Qt::NoFocus # hide the file menu, for now @layout..remove_action( @layout.. ) # tab navigation @layout.action_next.connect SIGNAL( 'triggered()' ), &method( :next_tab ) @layout.action_previous.connect SIGNAL( 'triggered()' ), &method( :previous_tab ) # dump model for current tab @layout.action_dump.visible = $options[:debug] @layout.action_dump.connect SIGNAL( 'triggered()' ), &method( :dump ) tables_tab.connect SIGNAL( 'currentChanged(int)' ), &method( :current_changed ) load_views main_window.window_title = [database_name, 'Clevic'].compact.join ' ' end |
Instance Attribute Details
#menu_edit ⇒ Object (readonly)
Returns the value of attribute menu_edit.
12 13 14 |
# File 'lib/clevic/swing/browser.rb', line 12 def @menu_edit end |
#menu_search ⇒ Object (readonly)
Returns the value of attribute menu_search.
12 13 14 |
# File 'lib/clevic/swing/browser.rb', line 12 def @menu_search end |
#menu_table ⇒ Object (readonly)
Returns the value of attribute menu_table.
12 13 14 |
# File 'lib/clevic/swing/browser.rb', line 12 def @menu_table end |
#tables_tab ⇒ Object (readonly)
Returns the value of attribute tables_tab.
16 17 18 |
# File 'lib/clevic/qt/browser.rb', line 16 def tables_tab @tables_tab end |
Class Method Details
.run(args) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/clevic/qt/browser.rb', line 175 def self.run( args ) # load model files raise "no model definition file specified" if args.empty? args.each { |arg| load_models( Pathname.new( arg ) ) } app = Qt::Application.new( args ) # show UI main_window = Qt::MainWindow.new browser = Clevic::Browser.new( main_window ) # this must come after Clevic::Browser.new main_window.show # make sure any partially edited records are saved when the window is closed app.connect( SIGNAL('lastWindowClosed()') ) { browser.save_all } begin app.exec rescue puts $!. puts $!.backtrace end end |
Instance Method Details
#current_changed ⇒ Object
slot to handle the currentChanged signal from tables_tab, and set focus on the grid
112 113 114 115 |
# File 'lib/clevic/qt/browser.rb', line 112 def current_changed( current_tab_index ) tables_tab..set_focus end |
#database_name ⇒ Object
Set the main window title to the name of the database, if we can find it.
54 55 56 |
# File 'lib/clevic/qt/browser.rb', line 54 def database_name table_view.model.entity_class.db.url rescue '' end |
#dump ⇒ Object
activated by Ctrl-Shift-D for debugging
80 81 82 83 |
# File 'lib/clevic/qt/browser.rb', line 80 def dump puts "table_view.model: #{table_view.model.inspect}" puts "table_view.model.entity_class: #{table_view.model.entity_class.inspect}" end |
#icon ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/clevic/swing/browser.rb', line 89 def icon @icon ||= begin icon_path = Pathname.new( __FILE__ ).parent.parent + "icons/icon.png" raise "icon.png not found" unless icon_path.file? javax.swing.ImageIcon.new( icon_path.realpath.to_s ).image end end |
#init_connections(tab) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/clevic/swing/browser.rb', line 234 def init_connections( tab ) tab.emit_status_text do |msg| .text = msg # hide the message after a while. .start end # handle filter status changed, so we can provide a visual indication tab.emit_filter_status do |status| # update the tab, so there's a visual indication of filtering filter_title = ( tab.filtered? ? '| ' : '' ) + tab.title tables_tab.set_title_at( tables_tab.selected_index, filter_title ) tables_tab.set_tool_tip_text_at( tables_tab.selected_index, tab. ) end end |
#load_views ⇒ Object
Create the tabs, each with a collection for a particular entity class. views come from Clevic::View.order
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/clevic/qt/browser.rb', line 124 def load_views views = Clevic::View.order.uniq Kernel.raise "no views to display" if views.empty? # Add all existing model objects as tabs, one each views.each do |view_class| begin view = view_class.new # This will raise an exception if we can't talk to the # table. Returns nil if there is an empty table, which is # also fine. view.entity_class.first # create the the table_view and the table_model for the entity_class tab = Clevic::TableView.new( view ) # show status messages tab.connect( SIGNAL( 'status_text_signal(QString)' ) ) { |msg| @layout..( msg, 10000 ) } # add a new tab tables_tab.add_tab( tab, translate( tab.title ) ) # add the table to the Table menu action = Qt::Action.new( @layout. ) action.text = translate( tab.title ) action.connect SIGNAL( 'triggered()' ) do tables_tab. = tab end @layout..add_action( action ) # handle filter status changed, so we can provide a visual indication tab.connect SIGNAL( 'filter_status_signal(bool)' ) do |status| # update the tab, so there's a visual indication of filtering filter_title = ( tab.filtered? ? '| ' : '' ) + translate( tab.title ) tables_tab.set_tab_text( tables_tab.current_index, filter_title ) end rescue Exception => e puts puts "UI from #{view} will not be available: #{e.}" puts e.backtrace #if $options[:debug] puts end end end |
#menu_bar ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/clevic/swing/browser.rb', line 38 def javax.swing.JMenuBar.new.tap do || << javax.swing.JMenu.new( 'File' ).tap do || .mnemonic = java.awt.event.KeyEvent::VK_F << "Open" << "Close" end @menu_edit = javax.swing.JMenu.new( 'Edit' ).tap {|m| m.mnemonic = java.awt.event.KeyEvent::VK_E} << @menu_search = javax.swing.JMenu.new( 'Search' ).tap {|m| m.mnemonic = java.awt.event.KeyEvent::VK_S} << @menu_table = javax.swing.JMenu.new( 'Table' ).tap do || .mnemonic = java.awt.event.KeyEvent::VK_T << Action.new( self ) do |action| action.name = :next_tab action.text = "&Next" action.shortcut = "Ctrl+Tab" action.handler do |event| puts "next tab" next_tab end end << Action.new( self ) do |action| action.name = :previous_tab action.text = "&Previous" action.shortcut = "Shift+Ctrl+Tab" action.handler do |event| puts "previous tab" previous_tab end end if $options[:debug] << Action.new( self ) do |action| action.name = :dump action.text = "&Dump" action.shortcut = "Ctrl+D" action.handler do |event| dump end end end end << @menu_table end end |
#next_tab ⇒ Object
slot to handle Ctrl-Tab and move to next tab, or wrap around
91 92 93 94 95 96 97 98 |
# File 'lib/clevic/qt/browser.rb', line 91 def next_tab tables_tab.current_index = if tables_tab.current_index >= tables_tab.count - 1 0 else tables_tab.current_index + 1 end end |
#previous_tab ⇒ Object
slot to handle Ctrl-Backtab and move to previous tab, or wrap around
101 102 103 104 105 106 107 108 |
# File 'lib/clevic/qt/browser.rb', line 101 def previous_tab tables_tab.current_index = if tables_tab.current_index <= 0 tables_tab.count - 1 else tables_tab.current_index - 1 end end |
#save_all ⇒ Object
make sure all outstanding records are saved
171 172 173 |
# File 'lib/clevic/qt/browser.rb', line 171 def save_all tables_tab.tabs.each {|x| x.save_row( x.current_index ) } end |
#status_bar ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/clevic/swing/browser.rb', line 111 def @status_bar ||= javax.swing.JLabel.new.tap do || .horizontal_alignment = javax.swing.SwingConstants::RIGHT # just so the bar actually displays .text = "Welcome to Clevic" end end |
#status_bar_timer ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/clevic/swing/browser.rb', line 119 def @status_bar_timer ||= javax.swing.Timer.new( 15000, nil ).tap do |timer| timer.repeats = false # This is only for 1.6 #~ timer.action_command = 'hide_status_message' timer.add_action_listener do |event| .text = nil timer.stop end end end |
#table_view ⇒ Object
return the Clevic::TableView object in the currently displayed tab
86 87 88 |
# File 'lib/clevic/qt/browser.rb', line 86 def table_view tables_tab. end |
#title_string ⇒ Object
34 35 36 |
# File 'lib/clevic/swing/browser.rb', line 34 def title_string [database_name, 'Clevic'].compact.join ' ' end |
#translate(st) ⇒ Object
shortcut for the Qt translate call
118 119 120 |
# File 'lib/clevic/qt/browser.rb', line 118 def translate( st ) Qt::Application.translate("Browser", st, nil, Qt::Application::UnicodeUTF8) end |
#update_menus ⇒ Object
called by current_changed to update the Edit menu to the menus defined by the currently selected view
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/clevic/swing/browser.rb', line 138 def # update edit menu @layout..clear # do the model-specific menu items first table_view.model_actions.each do |action| @layout..add_action( action ) end # now do the generic edit items table_view.edit_actions.each do |action| @layout..add_action( action ) end # update search menu @layout..clear table_view.search_actions.each do |action| @layout..add_action( action ) end end |