From: Ed Page Date: Fri, 19 Mar 2010 00:36:44 +0000 (-0500) Subject: TIny cleanups X-Git-Url: http://git.maemo.org/git/?p=multilist;a=commitdiff_plain;h=72ad61a95566a8a5c220b3a190c94af4831d3da2 TIny cleanups --- diff --git a/src/__init__.py b/src/__init__.py index 105eaaf..d34b733 100755 --- a/src/__init__.py +++ b/src/__init__.py @@ -1,21 +1,21 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- - + """ - This file is part of Multilist. +This file is part of Multilist. + +Multilist 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, either version 3 of the License, or +(at your option) any later version. - Multilist 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, either version 3 of the License, or - (at your option) any later version. +Multilist 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. - Multilist 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 Multilist. If not, see . - You should have received a copy of the GNU General Public License - along with Multilist. If not, see . - - Copyright (C) 2008 Christoph Würstle -""" +Copyright (C) 2008 Christoph Würstle +""" diff --git a/src/copydb.py b/src/copydb.py index 8361cf3..b489344 100755 --- a/src/copydb.py +++ b/src/copydb.py @@ -11,22 +11,22 @@ def copydb(db): cur = conn.cursor() sql = "UPDATE sync SET syncpartner=? WHERE syncpartner=?" - cur.execute(sql,(str(uuid.uuid4()),"self")) #Eigene Id ändern feststellen + cur.execute(sql, (str(uuid.uuid4()), "self")) #Eigene Id ändern feststellen conn.commit() sql = "DELETE FROM sync WHERE syncpartner=?" - cur.execute(sql,("self",)) + cur.execute(sql, ("self", )) conn.commit() sql = "INSERT INTO sync (syncpartner,uuid,pcdatum) VALUES (?,?,?)" - cur.execute(sql,("self",str(uuid.uuid4()),int(time.time()))) + cur.execute(sql, ("self", str(uuid.uuid4()), int(time.time()))) sql = "UPDATE sync SET pcdatum=?" - cur.execute(sql,(int(time.time()),)) + cur.execute(sql, (int(time.time()), )) conn.commit() if __name__ == "__main__": - db = "/home/chris/Documents/Schule/Schule/schulplaner/schuljahr200708enni.s3db" - copydb(db) + dbPath = "/home/chris/Documents/Schule/Schule/schulplaner/schuljahr200708enni.s3db" + copydb(dbPath) diff --git a/src/libsqldialog.py b/src/libsqldialog.py deleted file mode 100755 index 65d45f9..0000000 --- a/src/libsqldialog.py +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -""" -This file is part of Multilist. - -Multilist 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, either version 3 of the License, or -(at your option) any later version. - -Multilist 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 Multilist. If not, see . - -Copyright (C) 2008 Christoph Würstle -""" - -import time -import gtk -import logging - - -try: - _ -except NameError: - _ = lambda x: x - - -_moduleLogger = logging.getLogger(__name__) - - -class sqlDialog(gtk.Dialog): - - def __init__(self,db): - self.db=db - - _moduleLogger.info("sqldialog, init") - - gtk.Dialog.__init__(self,_("SQL History (the past two days):"),None,gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) - - self.add_button(_("Export"), 444) - self.set_position(gtk.WIN_POS_CENTER) - - self.liststore = gtk.ListStore(str, str, str) - - # create the TreeView using liststore - self.treeview = gtk.TreeView(self.liststore) - - # create a CellRenderers to render the data - self.cell1 = gtk.CellRendererText() - self.cell2 = gtk.CellRendererText() - self.cell3 = gtk.CellRendererText() - #self.cell1.set_property('markup', 1) - - # create the TreeViewColumns to display the data - self.tvcolumn1 = gtk.TreeViewColumn(_('Date')) - self.tvcolumn2 = gtk.TreeViewColumn(_('SQL')) - self.tvcolumn3 = gtk.TreeViewColumn(_('Parameter')) - - # add columns to treeview - self.treeview.append_column(self.tvcolumn1) - self.treeview.append_column(self.tvcolumn2) - self.treeview.append_column(self.tvcolumn3) - - self.tvcolumn1.pack_start(self.cell1, True) - self.tvcolumn2.pack_start(self.cell2, True) - self.tvcolumn3.pack_start(self.cell3, True) - - self.tvcolumn1.set_attributes(self.cell1, text=0) #Spalten setzten hier!!!! - self.tvcolumn2.set_attributes(self.cell2, text=1) - self.tvcolumn3.set_attributes(self.cell3, text=2) - - # make treeview searchable - #self.treeview.set_search_column(0) - #self.tvcolumn.set_sort_column_id(0) - - # Allow NOT drag and drop reordering of rows - self.treeview.set_reorderable(False) - - scrolled_window = gtk.ScrolledWindow() - scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) - scrolled_window.add(self.treeview) - #self.pack_start(scrolled_window, expand=True, fill=True, padding=0) - - self.vbox.pack_start(scrolled_window, True, True, 0) - - self.vbox.show_all() - - msgstring="" - sql="SELECT pcdatum,sql,param FROM logtable WHERE pcdatum>? ORDER BY pcdatum DESC" - rows=db.ladeSQL(sql,(time.time()-3*24*3600,)) - i=0 - for row in rows: - pcdatum,sql,param = row - datum=str(time.strftime("%d.%m.%y %H:%M:%S ", (time.localtime(pcdatum)))) - if len(param)>100: - param=param[:20]+_(" (Reduced parameter) ")+param[20:] - self.liststore.append([datum, sql,param]) - i+=1 - if (i>50): - break - - self.set_size_request(500,400) - - def exportSQL(self,filename): - f = open(filename, 'w') - msgstring="" - sql="SELECT pcdatum,sql,param FROM logtable WHERE pcdatum>? ORDER BY pcdatum DESC" - rows=self.db.ladeSQL(sql,(time.time()-2*24*3600,)) - for row in rows: - pcdatum,sql,param = row - datum=str(time.strftime("%d.%m.%y %H:%M:%S ", (time.localtime(pcdatum)))) - f.write( datum +"\t" + sql + "\t\t" + param+ "\n") - - f.close() diff --git a/src/multilist_gtk.py b/src/multilist_gtk.py index 6e32044..5368345 100755 --- a/src/multilist_gtk.py +++ b/src/multilist_gtk.py @@ -47,7 +47,7 @@ import constants import hildonize import libspeichern -import libsqldialog +import sqldialog import libselection import libview import libliststorehandler @@ -236,45 +236,45 @@ class Multilist(hildonize.get_app_class()): else: self.window_in_fullscreen = False - def speichereAlles(self,data=None,data2=None): + def speichereAlles(self, data=None, data2=None): logging.info("Speichere alles") - def ladeAlles(self,data=None,data2=None): + def ladeAlles(self, data=None, data2=None): logging.info("Lade alles") - def beforeSync(self,data=None,data2=None): + def beforeSync(self, data=None, data2=None): logging.info("Lade alles") - def sync_finished(self,data=None,data2=None): + def sync_finished(self, data=None, data2=None): self.selection.comboList_changed() self.selection.comboCategory_changed() self.liststorehandler.update_list() def prepare_sync_dialog(self): - self.sync_dialog = gtk.Dialog(_("Sync"),None,gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) + self.sync_dialog = gtk.Dialog(_("Sync"), None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) self.sync_dialog.set_position(gtk.WIN_POS_CENTER) - sync=libsync.Sync(self.db,self.window,50503) - sync.connect("syncFinished",self.sync_finished) + sync=libsync.Sync(self.db, self.window, 50503) + sync.connect("syncFinished", self.sync_finished) self.sync_dialog.vbox.pack_start(sync, True, True, 0) - self.sync_dialog.set_size_request(500,350) + self.sync_dialog.set_size_request(500, 350) self.sync_dialog.vbox.show_all() - sync.connect("syncFinished",self.sync_finished) + sync.connect("syncFinished", self.sync_finished) - def sync_notes(self,widget=None,data=None): + def sync_notes(self, widget=None, data=None): if self.sync_dialog==None: self.prepare_sync_dialog() self.sync_dialog.run() self.sync_dialog.hide() - def show_columns_dialog(self,widget=None,data=None): - col_dialog = gtk.Dialog(_("Choose columns"),self.window,gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) + def show_columns_dialog(self, widget=None, data=None): + col_dialog = gtk.Dialog(_("Choose columns"), self.window, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)) col_dialog.set_position(gtk.WIN_POS_CENTER) - cols=libview.Columns_dialog(self.db,self.liststorehandler) + cols=libview.Columns_dialog(self.db, self.liststorehandler) col_dialog.vbox.pack_start(cols, True, True, 0) - col_dialog.set_size_request(500,350) + col_dialog.set_size_request(500, 350) col_dialog.vbox.show_all() resp=col_dialog.run() @@ -308,10 +308,10 @@ class Multilist(hildonize.get_app_class()): #print "delete event occurred" return False - def dlg_delete(self,widget,event,data=None): + def dlg_delete(self, widget, event, data=None): return False - def show_about(self, widget=None,data=None): + def show_about(self, widget=None, data=None): dialog = gtk.AboutDialog() dialog.set_position(gtk.WIN_POS_CENTER) dialog.set_name(constants.__pretty_app_name__) @@ -324,14 +324,17 @@ class Multilist(hildonize.get_app_class()): dialog.run() dialog.destroy() - def on_info1_activate(self,menuitem): + def on_info1_activate(self, menuitem): self.show_about(menuitem) - def view_sql_history(self,widget=None,data=None,data2=None): - sqldiag=libsqldialog.sqlDialog(self.db) - res=sqldiag.run() + def view_sql_history(self, widget=None, data=None, data2=None): + sqldiag = sqldialog.SqlDialog(self.db) + res = sqldiag.run() sqldiag.hide() - if res==444: + + try: + if res != gtk.RESPONSE_OK: + return logging.info("exporting sql") if not isHildon: @@ -342,24 +345,24 @@ class Multilist(hildonize.get_app_class()): dlg.add_button( gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) dlg.add_button( gtk.STOCK_OK, gtk.RESPONSE_OK) else: - #dlg = hildon.FileChooserDialog(parent = self.window, action = gtk.FILE_CHOOSER_ACTION_SAVE) - dlg=hildon.FileChooserDialog(self.window, gtk.FILE_CHOOSER_ACTION_SAVE) + dlg = hildon.FileChooserDialog(self.window, gtk.FILE_CHOOSER_ACTION_SAVE) dlg.set_title(_("Select SQL export file")) - if dlg.run() == gtk.RESPONSE_OK: - fileName = dlg.get_filename() - dlg.destroy() - sqldiag.exportSQL(fileName) - else: + exportFileResponse = dlg.run() + try: + if exportFileResponse == gtk.RESPONSE_OK: + fileName = dlg.get_filename() + sqldiag.exportSQL(fileName) + finally: dlg.destroy() + finally: + sqldiag.destroy() - sqldiag.destroy() - - def optimizeSQL(self,widget=None,data=None,data2=None): + def optimizeSQL(self, widget=None, data=None, data2=None): #optimiere sql - self.db.speichereSQL("VACUUM",log=False) + self.db.speichereSQL("VACUUM", log=False) - def select_db_dialog(self,widget=None,data=None,data2=None): + def select_db_dialog(self, widget=None, data=None, data2=None): if (isHildon==False): dlg = gtk.FileChooserDialog(parent = self.window, action = gtk.FILE_CHOOSER_ACTION_SAVE) dlg.add_button( gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) @@ -373,7 +376,7 @@ class Multilist(hildonize.get_app_class()): dlg.set_title(_("Choose your database file")) if dlg.run() == gtk.RESPONSE_OK: fileName = dlg.get_filename() - self.db.speichereDirekt('datenbank',fileName) + self.db.speichereDirekt('datenbank', fileName) self.speichereAlles() self.db.openDB() self.ladeAlles() diff --git a/src/sqldialog.py b/src/sqldialog.py new file mode 100755 index 0000000..e9cc814 --- /dev/null +++ b/src/sqldialog.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +This file is part of Multilist. + +Multilist 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, either version 3 of the License, or +(at your option) any later version. + +Multilist 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 Multilist. If not, see . + +Copyright (C) 2008 Christoph Würstle +""" + +from __future__ import with_statement + +import time +import gtk +import logging + + +try: + _ +except NameError: + _ = lambda x: x + + +_moduleLogger = logging.getLogger(__name__) + + +class SqlDialog(gtk.Dialog): + + def __init__(self, db): + self.db = db + + _moduleLogger.info("sqldialog, init") + + gtk.Dialog.__init__( + self, + _("SQL History (the past two days):"), + None, + gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, + (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE) + ) + + self.add_button(_("Export"), gtk.RESPONSE_OK) + self.set_position(gtk.WIN_POS_CENTER) + + self.liststore = gtk.ListStore(str, str, str) + + # create the TreeView using liststore + self.treeview = gtk.TreeView(self.liststore) + + # create a CellRenderers to render the data + self.cell1 = gtk.CellRendererText() + self.cell2 = gtk.CellRendererText() + self.cell3 = gtk.CellRendererText() + #self.cell1.set_property('markup', 1) + + # create the TreeViewColumns to display the data + self.tvcolumn1 = gtk.TreeViewColumn(_('Date')) + self.tvcolumn2 = gtk.TreeViewColumn(_('SQL')) + self.tvcolumn3 = gtk.TreeViewColumn(_('Parameter')) + + # add columns to treeview + self.treeview.append_column(self.tvcolumn1) + self.treeview.append_column(self.tvcolumn2) + self.treeview.append_column(self.tvcolumn3) + + self.tvcolumn1.pack_start(self.cell1, True) + self.tvcolumn2.pack_start(self.cell2, True) + self.tvcolumn3.pack_start(self.cell3, True) + + self.tvcolumn1.set_attributes(self.cell1, text=0) #Spalten setzten hier!!!! + self.tvcolumn2.set_attributes(self.cell2, text=1) + self.tvcolumn3.set_attributes(self.cell3, text=2) + + # make treeview searchable + #self.treeview.set_search_column(0) + #self.tvcolumn.set_sort_column_id(0) + + # Allow NOT drag and drop reordering of rows + self.treeview.set_reorderable(False) + + scrolled_window = gtk.ScrolledWindow() + scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + scrolled_window.add(self.treeview) + #self.pack_start(scrolled_window, expand=True, fill=True, padding=0) + + self.vbox.pack_start(scrolled_window, True, True, 0) + + self.vbox.show_all() + + msgstring="" + sql="SELECT pcdatum,sql,param FROM logtable WHERE pcdatum>? ORDER BY pcdatum DESC" + rows=db.ladeSQL(sql, (time.time()-3*24*3600, )) + for i, row in enumerate(rows): + if (i>50): + break + + pcdatum, sql, param = row + datum = str(time.strftime("%d.%m.%y %H:%M:%S ", (time.localtime(pcdatum)))) + if 100 < len(param): + param=param[:20]+_(" (Reduced parameter) ")+param[20:] + self.liststore.append([datum, sql,param]) + + self.set_size_request(500,400) + + def exportSQL(self,filename): + with open(filename, 'w') as f: + msgstring="" + sql="SELECT pcdatum,sql,param FROM logtable WHERE pcdatum>? ORDER BY pcdatum DESC" + rows=self.db.ladeSQL(sql,(time.time()-2*24*3600,)) + for row in rows: + pcdatum,sql,param = row + datum=str(time.strftime("%d.%m.%y %H:%M:%S ", (time.localtime(pcdatum)))) + f.write( datum +"\t" + sql + "\t\t" + param+ "\n")