/sqlite3manager.rb
Ruby | 215 lines | 163 code | 24 blank | 28 comment | 8 complexity | 3e339abe142cf099c45686bc4fbe6598 MD5 | raw file
- #!/usr/bin/env ruby
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, version 3 of the License.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- #
- # Copyright: (C) 2004-2010 Rafal Kotusiewicz aka 'jjhop'. All rights reserved.
- #
- # http://bitbucket.org/jjhop/sqlite3manager/overview/
- # http://bitbucket.org/jjhop/sqlite3manager/wiki/Home
- #
- require 'rubygems'
- require 'fox16'
- require 'sqlite3'
-
- include Fox
-
- class SQLite3ManagerApp < FXApp
- def initialize
- super("sqlite3manager", "sqlite3manager")
- main_window = MainWindow.new(self)
- self.addSignal("SIGINT", main_window.method(:cmd_quit))
- self.create()
- main_window.create()
- end
- end
-
- class SchemaUtils
-
- def self.show_database_table(dbh)
- table_names = []
- dbh.execute("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name ASC") do |r|
- table_names<< r[0]
- end
- table_names
- end
-
- end
-
-
- class MainWindow < FXMainWindow
-
- def initialize(app)
- super(app, "SQLite3Manager 0.1", nil, nil, DECOR_ALL, 0, 0, 800, 600)
- FXToolTip.new(getApp())
- menubar = FXMenuBar.new(self, LAYOUT_SIDE_TOP|LAYOUT_FILL_X|FRAME_RAISED)
- @status_bar = FXStatusBar.new(self, LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|STATUSBAR_WITH_DRAGCORNER)
- FXHorizontalSeparator.new(self, LAYOUT_SIDE_TOP, LAYOUT_FILL_X, SEPARATOR_GROOVE)
-
- FXVerticalFrame.new(self, LAYOUT_SIDE_TOP|FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y) do |contents|
- FXSplitter.new(contents, LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y|SPLITTER_TRACKING|SPLITTER_HORIZONTAL) do |splitter|
- FXGroupBox.new(splitter, "Relacje", LAYOUT_FILL_Y|FRAME_GROOVE, 0, 0, 200) do |groupbox|
- FXHorizontalFrame.new(groupbox, LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THICK,0, 0, 0, 0, 0, 0, 0, 0) do |frame|
- FXList.new(frame, nil, 0, LIST_SINGLESELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_RIGHT) do |list|
- list.appendItem("Hello")
- end
- end
- end
- FXGroupBox.new(splitter,nil) do |group_right|
- @table = FXTable.new(group_right, nil, 0, TABLE_COL_SIZABLE|TABLE_NO_COLSELECT|LAYOUT_FILL, 0,0,0,0, 2,2,2,2) do |t|
- t.setTableSize(0, 50)
- t.setColumnText( 0, "Pierwsze pole")
- t.setColumnText( 1, "Drugie pole")
- t.setColumnText( 2, "Trzecie pole")
- t.setColumnText( 3, "Czwarte pole")
- t.setColumnText( 4, "Piate pole")
-
- t.rowHeaderMode = LAYOUT_FIX_WIDTH
- t.rowHeaderWidth = 0
-
- t.editable = false
-
- t.setColumnWidth(0, 100)
- t.setColumnWidth(1, 100)
- t.setColumnWidth(2, 100)
- t.setColumnWidth(3, 100)
- t.setColumnWidth(4, 100)
- 50.times do |idx|
- t.insertRows(t.numRows, 1, true)
- t.setRowText(idx, "#{idx+1}")
- t.setItemText(idx, 0, " Linux. Programowanie.");
- t.setItemText(idx, 1, " 83-7243-020-9");
- t.setItemText(idx, 2, " ReadMe");
- t.setItemText(idx, 3, " 1999");
- t.setItemText(idx, 4, " DOM");
- end
- t.connect(SEL_RIGHTBUTTONRELEASE) do |sender, sel, evt|
- col = sender.colAtX(evt.click_x)
- row = sender.rowAtY(evt.click_y)
- begin
- #selectedItem = sender.getItem(col, row)
- #puts "#{selectedItem.class}\n"
- #unless selectedItem.nil?
- FXMenuPane.new(self) do |menuPane|
- FXMenuCommand.new(menuPane, "Pokaz szczegoly")
- FXMenuCommand.new(menuPane, "usun w diably")
- menuPane.create()
- t.selectRow(t.rowAtY(evt.click_y))
- menuPane.popup(nil, evt.root_x, evt.root_y)
- end
- #else
- # puts "nil?"
- #end
- rescue IndexError => ex
- puts ex
- end
- end
- end
- end
- end
- end
-
- filemenu = FXMenuPane.new(self) do |menu|
-
- FXMenuCommand.new(menu, "Nowa baza...\tCtrl-N\tNowa baza...", self.get_icon('db_new.gif')) do |c|
- #c.connect(SEL_COMMAND, method(:not_yet_implemented))
- end
- FXMenuCommand.new(menu, "Otworz baze...\tCtrl-O\tOtwiera baze...", self.get_icon('db_open.gif')) do |c|
- c.connect(SEL_COMMAND, method(:cmd_open_database))
- end
- FXMenuCommand.new(menu, "Zamknij baze\tCtrl-W\tZamyka baze", self.get_icon('db_close.gif')) do |c|
- #c.connect(SEL_COMMAND, method(:not_yet_implemented))
- c.disable
- end
- FXMenuSeparator.new(menu)
- FXMenuCommand.new(menu, "Wyjscie\tAlt-F4\t\tZamykam program", self.get_icon('app_close.gif')) do |c|
- c.connect(SEL_COMMAND, method(:cmd_quit))
- end
- end
- helpmenu = FXMenuPane.new(self) do |menu|
- FXMenuCommand.new(menu, "Pomoc\tF1\tShowing help.", nil).connect(SEL_COMMAND, method(:cmd_help))
- FXMenuCommand.new(menu, "O programie\tCtrl-F1\tPokazuje okno z informacjami o programie.", nil).connect(SEL_COMMAND, method(:cmd_about))
- if RUBY_PLATFORM == 'i386-mswin32'
- FXMenuSeparator.new(menu)
- FXMenuCommand.new(menu, "Strona domowa\tCtrl-Shift-F1\tOtwiera w przegladarce Internet Explorer strone domowa programu.", nil) do |cmd|
- cmd.connect(SEL_COMMAND) do
- begin
- Thread.new do
- require 'win32ole'
- ie = WIN32OLE.new('InternetExplorer.Application')
- ie.visible = true
- ie.navigate('http://bitbucket.org/jjhop/sqlite3manager/')
- end
- rescue; end
- end
- end
- end
- end
- FXMenuTitle.new(menubar, "&Plik", nil, filemenu)
- FXMenuTitle.new(menubar, "Pomoc", nil, helpmenu, LAYOUT_RIGHT)
- end
-
- def create
- super()
- show(PLACEMENT_SCREEN)
- end
-
- def cmd_open_database(sender, sel, ptr)
- dialog = FXFileDialog.new(self, "Otworz baze danych...")
- dialog.patternList = [
- "All files (*)",
- "SQLite3 .db (.db)",
- "SQLite3 .sqlite (.sqlite)"
- ]
- dialog.selectMode = SELECTFILE_EXISTING
- if dialog.execute != 0
- self.load_database(dialog.filename)
- end
- end
-
- def cmd_quit(sender, sel, ptr)
- if MBOX_CLICKED_YES == FXMessageBox.question(self, MBOX_YES_NO, "Potwierdzenie zamkniecia", "Czy jestes pewien, ze chcesz zamknac program?")
- # jeszcze trzeba zamkna? ewentualnie otwarta baze danych...
- unless @dbh.nil?
- @dbh.close()
- end
- getApp().exit(0)
- end
- end
-
- def cmd_help(sender, sel, ptr)
- end
-
- def cmd_about(sender, sel, ptr)
- end
-
- def get_icon(file)
- begin
- FXGIFIcon.new(getApp(),File.open(File.join(File.dirname(__FILE__), "./ico/#{file}"),"rb").read)
- rescue
- nil
- end
- end
-
- def load_database(db_filename)
- @dbh = SQLite3::Database.new(db_filename)
- SchemaUtils.show_database_table(@dbh).each do |n|
- puts "#{n}"
- end
- end
-
- end
-
-
- if __FILE__ == $0
- SQLite3ManagerApp.new.run
- end