_user_data = os.path.join(os.path.expanduser("~"), ".%s" % constants.__app_name__)
_user_settings = "%s/settings.ini" % _user_data
- def on_key_press(self, widget, event, *args):
- RETURN_TYPES = (gtk.keysyms.Return, gtk.keysyms.ISO_Enter, gtk.keysyms.KP_Enter)
- isCtrl = bool(event.get_state() & gtk.gdk.CONTROL_MASK)
- if (
- event.keyval == gtk.keysyms.F6 or
- event.keyval in RETURN_TYPES and isCtrl
- ):
- # The "Full screen" hardware key has been pressed
- if self.window_in_fullscreen:
- self.window.unfullscreen ()
- else:
- self.window.fullscreen ()
- return True
- #elif event.keyval == gtk.keysyms.f and isCtrl:
- # self._toggle_search()
- # return True
- elif (
- event.keyval in (gtk.keysyms.w, gtk.keysyms.q) and
- event.get_state() & gtk.gdk.CONTROL_MASK
- ):
- self._window.destroy()
- elif event.keyval == gtk.keysyms.l and event.get_state() & gtk.gdk.CONTROL_MASK:
- with open(constants._user_logpath_, "r") as f:
- logLines = f.xreadlines()
- log = "".join(logLines)
- self._clipboard.set_text(str(log))
- return True
-
- def on_window_state_change(self, widget, event, *args):
- if event.new_window_state & gtk.gdk.WINDOW_STATE_FULLSCREEN:
- self.window_in_fullscreen = True
- else:
- self.window_in_fullscreen = False
-
- def speichereAlles(self,data=None,data2=None):
- logging.info("Speichere alles")
-
- def ladeAlles(self,data=None,data2=None):
- logging.info("Lade alles")
-
- def beforeSync(self,data=None,data2=None):
- logging.info("Lade alles")
-
- 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.set_position(gtk.WIN_POS_CENTER)
- 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.vbox.show_all()
- sync.connect("syncFinished",self.sync_finished)
-
- 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))
-
- col_dialog.set_position(gtk.WIN_POS_CENTER)
- 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.vbox.show_all()
-
- resp=col_dialog.run()
- col_dialog.hide()
- if resp==gtk.RESPONSE_ACCEPT:
- logging.info("changing columns")
- cols.save_column_setting()
- self.view.reload_view()
- #children=self.vbox.get_children()
- #while len(children)>1:
- # self.vbox.remove(children[1])
-
- #self.vbox.pack_end(self.bottombar, expand=True, fill=True, padding=0)
- #self.vbox.pack_end(view, expand=True, fill=True, padding=0)
- #self.vbox.pack_end(self.selection, expand=False, fill=True, padding=0)
-
- col_dialog.destroy()
-
def __init__(self):
super(multilistclass, self).__init__()
self._clipboard = gtk.clipboard_get()
self.prepare_sync_dialog()
self.ladeAlles()
+ def on_key_press(self, widget, event, *args):
+ RETURN_TYPES = (gtk.keysyms.Return, gtk.keysyms.ISO_Enter, gtk.keysyms.KP_Enter)
+ isCtrl = bool(event.get_state() & gtk.gdk.CONTROL_MASK)
+ if (
+ event.keyval == gtk.keysyms.F6 or
+ event.keyval in RETURN_TYPES and isCtrl
+ ):
+ # The "Full screen" hardware key has been pressed
+ if self.window_in_fullscreen:
+ self.window.unfullscreen ()
+ else:
+ self.window.fullscreen ()
+ return True
+ #elif event.keyval == gtk.keysyms.f and isCtrl:
+ # self._toggle_search()
+ # return True
+ elif (
+ event.keyval in (gtk.keysyms.w, gtk.keysyms.q) and
+ event.get_state() & gtk.gdk.CONTROL_MASK
+ ):
+ self._window.destroy()
+ elif event.keyval == gtk.keysyms.l and event.get_state() & gtk.gdk.CONTROL_MASK:
+ with open(constants._user_logpath_, "r") as f:
+ logLines = f.xreadlines()
+ log = "".join(logLines)
+ self._clipboard.set_text(str(log))
+ return True
+
+ def on_window_state_change(self, widget, event, *args):
+ if event.new_window_state & gtk.gdk.WINDOW_STATE_FULLSCREEN:
+ self.window_in_fullscreen = True
+ else:
+ self.window_in_fullscreen = False
+
+ def speichereAlles(self,data=None,data2=None):
+ logging.info("Speichere alles")
+
+ def ladeAlles(self,data=None,data2=None):
+ logging.info("Lade alles")
+
+ def beforeSync(self,data=None,data2=None):
+ logging.info("Lade alles")
+
+ 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.set_position(gtk.WIN_POS_CENTER)
+ 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.vbox.show_all()
+ sync.connect("syncFinished",self.sync_finished)
+
+ 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))
+
+ col_dialog.set_position(gtk.WIN_POS_CENTER)
+ 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.vbox.show_all()
+
+ resp=col_dialog.run()
+ col_dialog.hide()
+ if resp==gtk.RESPONSE_ACCEPT:
+ logging.info("changing columns")
+ cols.save_column_setting()
+ self.view.reload_view()
+ #children=self.vbox.get_children()
+ #while len(children)>1:
+ # self.vbox.remove(children[1])
+
+ #self.vbox.pack_end(self.bottombar, expand=True, fill=True, padding=0)
+ #self.vbox.pack_end(view, expand=True, fill=True, padding=0)
+ #self.vbox.pack_end(self.selection, expand=False, fill=True, padding=0)
+
+ col_dialog.destroy()
+
def destroy(self, widget=None, data=None):
try:
self.speichereAlles()
#!/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 <http://www.gnu.org/licenses/>.
-
- Copyright (C) 2008 Christoph Würstle
+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 <http://www.gnu.org/licenses/>.
+
+Copyright (C) 2008 Christoph Würstle
"""
import gobject
-import time
import logging
import gtk
+try:
+ _
+except NameError:
+ _ = lambda x: x
+
+
+_moduleLogger = logging.getLogger(__name__)
+
+
class Selection(gtk.HBox):
-
+
__gsignals__ = {
- 'changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_STRING,gobject.TYPE_STRING)),
+ 'changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_STRING,gobject.TYPE_STRING)),
#'changedCategory': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_STRING,gobject.TYPE_STRING))
- }
+ }
def load(self):
model=self.comboList.get_model()
model.clear()
#self.comboList.remove(0)
-
-
+
sql="SELECT DISTINCT list FROM items ORDER BY list"
rows=self.db.ladeSQL(sql)
if ((rows!=None)and(len(rows)>0)):
self.comboList.append_text(row[0])
else:
self.comboList.append_text("default")
-
+
s=self.db.ladeDirekt("comboListText")
if s!="":
self.comboList.get_child().set_text(s)
#print "reload categories"
while len(self.comboCategory.get_model())>0:
self.comboCategory.remove_text(0)
-
+
sql="SELECT DISTINCT category FROM items WHERE list=? ORDER BY category"
rows=self.db.ladeSQL(sql,(self.get_list(),))
-
+
self.comboCategory.append_text(_("all"))
if ((rows!=None)and(len(rows)>0)):
for row in rows:
if (row[0]!=_("all")):
self.comboCategory.append_text(row[0])
-
+
s=self.db.ladeDirekt("comboCategoryText"+self.comboList.get_child().get_text())
if len(s)>0:
self.comboCategory.get_child().set_text(s)
else:
self.comboCategory.set_active(0)
-
+
self.emit("changed","list","")
self.db.speichereDirekt("comboListText",self.comboList.get_child().get_text())
-
-
def comboCategory_changed(self, widget=None, data=None):
- #logging.info("Klasse geaendert zu ")
+ #_moduleLogger.info("Klasse geaendert zu ")
#self.hauptRegister.set_current_page(0)
self.emit("changed","category","")
if self.comboCategory.get_active()>-1:
self.db.speichereDirekt("comboCategoryText"+self.comboList.get_child().get_text(),self.comboCategory.get_child().get_text())
-
+
def radioActive_changed(self, widget, data=None):
self.emit("changed","radio","")
if found==False:
self.comboList.append_text(self.get_list())
self.comboList.set_active(len(self.comboList.get_model())-1)
-
def lade(self):
- logging.warning("Laden der aktuellen position noch nicht implementiert")
+ _moduleLogger.warning("Laden der aktuellen position noch nicht implementiert")
-
def speichere(self):
- logging.warning("Speichern der aktuellen position noch nicht implementiert")
-
-
+ _moduleLogger.warning("Speichern der aktuellen position noch nicht implementiert")
+
def getIsHildon(self):
return self.isHildon
-
+
def get_category(self,select=False):
s=self.comboCategory.get_child().get_text()
if s==_("all"):
return s
def set_category(self,category):
self.comboCategory.get_child().set_text(category)
-
+
def set_list(self,listname):
self.comboList.get_child().set_text(listname)
-
+
def get_list(self):
return self.comboList.get_child().get_text()
-
-
def get_status(self):
#return self.comboCategory.get_child().get_text()
if self.radio_all.get_active()==True:
return "-1"
else:
return "0"
-
-
+
def __init__(self,db,isHildon):
gtk.HBox.__init__(self,homogeneous=False, spacing=3)
-
+
self.db=db
self.isHildon=isHildon
-
- logging.info("libSelection, init")
-
-
+
+ _moduleLogger.info("libSelection, init")
+
label=gtk.Label(_("List:"))
self.pack_start(label, expand=False, fill=True, padding=0)
-
+
self.comboList = gtk.combo_box_entry_new_text()
self.comboList.set_size_request(180,-1)
self.pack_start(self.comboList, expand=False, fill=True, padding=0)
-
+
label=gtk.Label(_(" Category:"))
self.pack_start(label, expand=False, fill=True, padding=0)
-
+
self.comboCategory = gtk.combo_box_entry_new_text()
self.comboCategory.set_size_request(180,-1)
self.pack_start(self.comboCategory, expand=False, fill=True, padding=0)
-
+
self.comboList.connect("changed", self.comboList_changed, None)
self.comboCategory.connect("changed", self.comboCategory_changed, None)
-
+
label=gtk.Label(_(" View:"))
self.pack_start(label, expand=False, fill=True, padding=0)
-
+
self.radio_all=gtk.RadioButton(group=None, label=_("All"), use_underline=True)
self.pack_start(self.radio_all, expand=False, fill=True, padding=0)
self.radio_active=gtk.RadioButton(group=self.radio_all, label=_("Active"), use_underline=True)
self.pack_start(self.radio_active, expand=False, fill=True, padding=0)
self.radio_all.connect("toggled",self.radioActive_changed, None)
-
-
-
#!/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 <http://www.gnu.org/licenses/>.
-
- Copyright (C) 2008 Christoph Würstle
+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 <http://www.gnu.org/licenses/>.
+
+Copyright (C) 2008 Christoph Würstle
"""
import time
import os
import logging
-class Speichern():
+try:
+ _
+except NameError:
+ _ = lambda x: x
+
+
+_moduleLogger = logging.getLogger(__name__)
+
+
+class Speichern(object):
+
+ def __init__(self):
+ home_dir = os.path.expanduser('~')
+ filename=os.path.join(home_dir, ".multilist.dat")
+ self.d = shelve.open(filename)
+ self.openDB()
+
+ def close(self):
+ try:
+ self.d.close()
+ except:
+ pass
+ try:
+ self.cur.close()
+ except:
+ pass
+ try:
+ self.conn.close()
+ except:
+ pass
+ _moduleLogger.info("Alle Daten gespeichert")
+
+ def __del__(self):
+ self.close()
+
def speichereDirekt(self,schluessel,daten):
self.d[schluessel]=daten
- logging.info("speichereDirekt "+str(schluessel)+" "+str(daten)+" lesen: "+str(self.d[schluessel]))
+ _moduleLogger.info("speichereDirekt "+str(schluessel)+" "+str(daten)+" lesen: "+str(self.d[schluessel]))
-
def ladeDirekt(self,schluessel,default=""):
#print "ladeDirekt",schluessel, "Schluessel vorhanden",self.d.has_key(schluessel)
if (self.d.has_key(schluessel)==True):
return data
else:
return default
-
-
+
def speichereSQL(self,sql,tupel=None,commit=True,host="self",log=True,pcdatum=None,rowid=""):
#print "speichereSQL:",sql,tupel
try:
self.cur.execute(sql)
else:
self.cur.execute(sql,tupel)
- programSQLError=False
-
+ programSQLError=False
+
#print int(time.time()), sql, pickle.dumps(tupel), host
if (log==True):
strtupel=[]
for t in tupel:
strtupel.append(str(t))
-
if pcdatum==None: pcdatum=int(time.time())
self.cur.execute("INSERT INTO logtable ( pcdatum,sql,param,host,rowid ) VALUES (?,?,?,?,?)",(pcdatum, sql, string.join(strtupel," <<Tren-ner>> "), host,str(rowid) ))
- if (commit==True): self.conn.commit()
-
+ if (commit==True):
+ self.conn.commit()
return True
except:
s=str(sys.exc_info())
if (s.find(" already exists")==-1):
#if len(s)>0:
if (programSQLError==True):
- logging.error("speichereSQL-Exception "+str(sys.exc_info())+" "+str(sql)+" "+str(tupel))
+ _moduleLogger.error("speichereSQL-Exception "+str(sys.exc_info())+" "+str(sql)+" "+str(tupel))
else:
- logging.error("speichereSQL-Exception in Logging!!!! :"+str(sys.exc_info())+" "+str(sql)+" "+str(tupel))
+ _moduleLogger.error("speichereSQL-Exception in Logging!!!! :"+str(sys.exc_info())+" "+str(sql)+" "+str(tupel))
return False
def commitSQL(self):
self.conn.commit()
-
-
+
def ladeSQL(self,sql,tupel=None):
#print sql,tupel
try:
self.cur.execute(sql,tupel)
return self.cur.fetchall()
except:
- logging.error("ladeSQL-Exception "+str(sys.exc_info())+" "+str(sql)+" "+str(tupel))
+ _moduleLogger.error("ladeSQL-Exception "+str(sys.exc_info())+" "+str(sql)+" "+str(tupel))
return ()
-
+
def ladeHistory(self,sql_condition,param_condition):
sql="SELECT * FROM logtable WHERE sql LIKE '%"+str(sql_condition)+"%' AND param LIKE '%"+str(param_condition)+"%'"
rows=self.ladeSQL(sql)
datum=time.strftime("%d.%m.%y %H:%M:%S", (time.localtime(rows[i][1])))
erg.append([rows[i][1],datum,rows[i][2],rows[i][3],rows[i][3].split(" <<Tren-ner>> ")])
#pcdatum #datum #sql # Param_org #param
-
+
i+=1
-
+
return erg
-
+
def delHistory(self,sql_condition,param_condition,exceptTheLastXSeconds=0):
pcdatum=int(time.time())-exceptTheLastXSeconds
sql="DELETE FROM logtable WHERE sql LIKE '%"+str(sql_condition)+"%' AND param LIKE '%"+str(param_condition)+"%' AND pcdatum<?"
self.speichereSQL(sql,(pcdatum,))
-
+
def delHistoryWithRowID(self,rowid,sql_condition=" ",exceptTheLastXSeconds=0):
pcdatum=int(time.time())-exceptTheLastXSeconds
sql="DELETE FROM logtable WHERE rowid=? AND pcdatum<? AND sql LIKE '%"+str(sql_condition)+"%'"
self.speichereSQL(sql,(rowid,pcdatum,))
-
+
def openDB(self):
try:
self.cur.close()
self.conn.close()
except:
pass
-
+
db=self.ladeDirekt("datenbank")
- if db=="":
+ if db=="":
home_dir = os.path.expanduser('~')
- db=os.path.join(home_dir, "multilist.s3db")
-
-
+ db=os.path.join(home_dir, "multilist.s3db")
+
datum=time.strftime("%Y-%m-%d--", (time.localtime(time.time())))+str(int(time.time()))+"--"
if (os.path.exists(db))and(os.path.exists(os.path.dirname(db)+os.sep+"backup/")):
try:
shutil.copyfile(db,str(os.path.dirname(db))+os.sep+"backup"+os.sep+datum+os.path.basename(db))
- #logging.debug(str(os.path.dirname(db))+os.sep+"backup"+os.sep+datum+os.path.basename(db))
+ #_moduleLogger.debug(str(os.path.dirname(db))+os.sep+"backup"+os.sep+datum+os.path.basename(db))
except:
- logging.info("Achtung Backup-Datei NICHT (!!!) angelegt!")
+ _moduleLogger.info("Achtung Backup-Datei NICHT (!!!) angelegt!")
#print db,str(os.path.dirname(db))+os.sep+"backup"+os.sep+datum+os.path.basename(db)
-
- self.conn = sqlite3.connect(db)
- self.cur = self.conn.cursor()
+
+ self.conn = sqlite3.connect(db)
+ self.cur = self.conn.cursor()
try:
sql="CREATE TABLE logtable (id INTEGER PRIMARY KEY AUTOINCREMENT, pcdatum INTEGER ,sql TEXT, param TEXT, host TEXT, rowid TEXT)"
self.cur.execute(sql)
- self.conn.commit()
+ self.conn.commit()
except:
pass
-
+
#Add rowid line (not in old versions included)
try:
sql="ALTER TABLE logtable ADD rowid TEXT"
self.cur.execute(sql)
- self.conn.commit()
- except:
- pass
-
-
- def __init__(self):
- home_dir = os.path.expanduser('~')
- filename=os.path.join(home_dir, ".multilist.dat")
- self.d = shelve.open(filename)
- self.openDB()
-
-
-
-
-
- def close(self):
- try:
- self.d.close()
- except:
- pass
- try:
- self.cur.close()
- except:
- pass
- try:
- self.conn.close()
+ self.conn.commit()
except:
pass
- logging.info("Alle Daten gespeichert")
-
- def __del__(self):
- self.close()
\ No newline at end of file
#!/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 <http://www.gnu.org/licenses/>.
-
- Copyright (C) 2008 Christoph Würstle
+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 <http://www.gnu.org/licenses/>.
+
+Copyright (C) 2008 Christoph Würstle
"""
-import gobject
import time
-import string
import gtk
-import sys
import logging
-import libspeichern
-
-
+
+try:
+ _
+except NameError:
+ _ = lambda x: x
+
+
+_moduleLogger = logging.getLogger(__name__)
+
+
class sqlDialog(gtk.Dialog):
-
- 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()
-
-
+
def __init__(self,db):
self.db=db
-
- logging.info("sqldialog, init")
-
+
+ _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.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 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.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'))
+
+ # 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)
+
+ # 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.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)
+ # 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)
-
+ 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()
-
+
+ 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+=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()
# -*- coding: utf-8 -*-
"""
- 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, either version 3 of the License, or
- (at your option) any later version.
-
- 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/>.
+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, either version 3 of the License, or
+(at your option) any later version.
+
+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/>.
"""
-import gobject
-import time
-import string
-from SimpleXMLRPCServer import SimpleXMLRPCServer
-import random
-import socket
-socket.setdefaulttimeout(60) # Timeout auf 60 sec. setzen
-import xmlrpclib
+import sys
import select
-#import fcntl
-import struct
-import gtk
import uuid
-import sys
+import time
+import string
+from SimpleXMLRPCServer import SimpleXMLRPCServer
+import socket
+import xmlrpclib
import logging
-import libspeichern
-
-
+import gobject
+import gtk
+
+
+try:
+ _
+except NameError:
+ _ = lambda x: x
+
+
+_moduleLogger = logging.getLogger(__name__)
+socket.setdefaulttimeout(60) # Timeout auf 60 sec. setzen
+
+
class ProgressDialog(gtk.Dialog):
-
- def pulse(self):
- #self.progressbar.pulse()
- pass
-
+
def __init__(self,title=_("Sync process"), parent=None):
gtk.Dialog.__init__(self,title,parent,gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,())
-
- logging.info("ProgressDialog, init")
-
+
+ _moduleLogger.info("ProgressDialog, init")
+
label=gtk.Label(_("Sync process running...please wait"))
self.vbox.pack_start(label, True, True, 0)
label=gtk.Label(_("(this can take some minutes)"))
self.vbox.pack_start(label, True, True, 0)
-
+
#self.progressbar=gtk.ProgressBar()
#self.vbox.pack_start(self.progressbar, True, True, 0)
-
+
#self.set_keep_above(True)
- self.vbox.show_all()
+ self.vbox.show_all()
self.show()
-
-class Sync(gtk.VBox):
-
+
+ def pulse(self):
+ #self.progressbar.pulse()
+ pass
+
+
+class Sync(gtk.VBox):
+
__gsignals__ = {
- 'syncFinished' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_STRING,)),
+ 'syncFinished' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_STRING,)),
'syncBeforeStart' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_STRING,)),
- }
-
+ }
+
+ def __init__(self,db,parentwindow,port):
+ gtk.VBox.__init__(self,homogeneous=False, spacing=0)
+
+ _moduleLogger.info("Sync, init")
+ self.db=db
+ self.progress=None
+ self.server=None
+ self.port=int(port)
+ self.parentwindow=parentwindow
+ self.concernedRows=None
+
+ #print "Sync, 2"
+ #sql = "DROP TABLE sync"
+ #self.db.speichereSQL(sql,log=False)
+
+ sql = "CREATE TABLE sync (id INTEGER PRIMARY KEY, syncpartner TEXT, uuid TEXT, pcdatum INTEGER)"
+ self.db.speichereSQL(sql,log=False)
+
+ #print "Sync, 3"
+
+ sql="SELECT uuid,pcdatum FROM sync WHERE syncpartner=?"
+ rows=self.db.ladeSQL(sql,("self",)) #Eigene Id feststellen
+
+ #print "Sync, 3a"
+ if (rows==None)or(len(rows)!=1):
+ sql="DELETE FROM sync WHERE syncpartner=?"
+ self.db.speichereSQL(sql,("self",),log=False)
+
+ #uuid1=uuid()
+ #print "Sync, 3b"
+
+ #print "Sync, 3bb"
+ self.sync_uuid=str(uuid.uuid4())
+ sql="INSERT INTO sync (syncpartner,uuid,pcdatum) VALUES (?,?,?)"
+ self.db.speichereSQL(sql,("self",str(self.sync_uuid),int(time.time())),log=False)
+ #print "Sync, 3c"
+ else:
+ sync_uuid,pcdatum = rows[0]
+ self.sync_uuid=sync_uuid
+ #print "x1"
+ #print "Sync, 4"
+
+ frame=gtk.Frame(_("Local SyncServer (port ")+str(self.port)+")")
+ self.comboIP=gtk.combo_box_entry_new_text()
+ self.comboIP.append_text("") #self.get_ip_address("eth0"))
+ #self.comboIP.append_text(self.get_ip_address("eth1")) #fixme
+ #self.comboIP.append_text(self.get_ip_address("eth2"))
+ #self.comboIP.append_text(self.get_ip_address("eth3"))
+ #print "Sync, 4d"
+ #self.comboIP.append_text(self.get_ip_address("wlan0"))
+ #self.comboIP.append_text(self.get_ip_address("wlan1"))
+
+ #print "Sync, 4e"
+
+ frame.add(self.comboIP)
+ serverbutton=gtk.ToggleButton(_("Start SyncServer"))
+ serverbutton.connect("clicked",self.startServer,(None,))
+ self.pack_start(frame, expand=False, fill=True, padding=1)
+ self.pack_start(serverbutton, expand=False, fill=True, padding=1)
+ self.syncServerStatusLabel=gtk.Label(_("Syncserver not running"))
+ self.pack_start(self.syncServerStatusLabel, expand=False, fill=True, padding=1)
+
+ frame=gtk.Frame(_("RemoteSync-Server (Port ")+str(self.port)+")")
+ self.comboRemoteIP=gtk.combo_box_entry_new_text()
+ self.comboRemoteIP.append_text("192.168.0.?")
+ self.comboRemoteIP.append_text("192.168.1.?")
+ self.comboRemoteIP.append_text("192.168.176.?")
+ frame.add(self.comboRemoteIP)
+ syncbutton=gtk.Button(_("Connect to remote SyncServer"))
+ syncbutton.connect("clicked",self.syncButton,(None,))
+ self.pack_start(frame, expand=False, fill=True, padding=1)
+ self.pack_start(syncbutton, expand=False, fill=True, padding=1)
+ self.syncStatusLabel=gtk.Label(_("no sync process (at the moment)"))
+ self.pack_start(self.syncStatusLabel, expand=False, fill=True, padding=1)
+
+ #self.comboRemoteIP.set_text_column("Test")
+ self.comboRemoteIP.get_child().set_text(self.db.ladeDirekt("syncRemoteIP"))
+ self.comboIP.get_child().set_text(self.db.ladeDirekt("syncServerIP"))
+
+ #load
+ if (self.db.ladeDirekt("startSyncServer",False)==True):
+ serverbutton.set_active(True)
+
def changeSyncStatus(self,active,title):
self.syncStatusLabel.set_text(title)
if active==True:
if self.progress==None:
self.progress=ProgressDialog(parent=self.parentwindow)
self.emit("syncBeforeStart","syncBeforeStart")
-
-
else:
if self.progress!=None:
- self.progress.hide()
+ self.progress.hide()
self.progress.destroy()
self.progress=None
self.emit("syncFinished","syncFinished")
-
+
def pulse(self):
if self.progress!=None:
self.progress.pulse()
#if self.server!=None:
# self.server.pulse()
-
-
+
def getUeberblickBox(self):
frame=gtk.Frame(_("Query"))
return frame
-
+
def handleRPC(self):
try:
if (self.rpcserver==None): return False
except:
return False
-
+
while (len(self.poll.poll(0))>0):
self.rpcserver.handle_request()
return True
#except:
# ip=socket.gethostbyname(socket.gethostname())
# s.close()
-
+
#return ip FixME
-
+
def getLastSyncDate(self,sync_uuid):
sql="SELECT syncpartner,pcdatum FROM sync WHERE uuid=?"
rows=self.db.ladeSQL(sql,(sync_uuid,))
- if (rows!=None)and(len(rows)==1):
+ if (rows!=None)and(len(rows)==1):
syncpartner,pcdatum = rows[0]
else:
pcdatum=-1
- logging.info("LastSyncDatum: "+str(pcdatum)+" Jetzt "+str(int(time.time())))
+ _moduleLogger.info("LastSyncDatum: "+str(pcdatum)+" Jetzt "+str(int(time.time())))
return pcdatum
-
-
+
def check4commit(self,newSQL,lastdate):
- logging.info("check4commit 1")
+ _moduleLogger.info("check4commit 1")
if self.concernedRows==None:
- logging.info("check4commit Updatung concernedRows")
+ _moduleLogger.info("check4commit Updatung concernedRows")
sql="SELECT pcdatum,rowid FROM logtable WHERE pcdatum>? ORDER BY pcdatum DESC"
self.concernedRows=self.db.ladeSQL(sql,(lastdate,))
-
-
+
if (self.concernedRows!=None)and(len(self.concernedRows)>0):
- #logging.info("check4commit 2")
+ #_moduleLogger.info("check4commit 2")
id1, pcdatum,sql, param, host, rowid = newSQL
-
+
if len(rowid)>0:
for x in self.concernedRows:
- #logging.info("check4commit 3")
+ #_moduleLogger.info("check4commit 3")
if (x[1]==rowid):
if (x[0]>pcdatum):
- logging.info("newer sync entry, ignoring old one")
- #logging.info("check4commit 9.1")
+ _moduleLogger.info("newer sync entry, ignoring old one")
+ #_moduleLogger.info("check4commit 9.1")
return False
else:
- #logging.info("check4commit 9.2")
+ #_moduleLogger.info("check4commit 9.2")
return True
-
- #logging.info("check4commit 9.3")
+
+ #_moduleLogger.info("check4commit 9.3")
return True
-
+
def writeSQLTupel(self,newSQLs,lastdate):
if (newSQLs==None):
return
-
+
self.concernedRows=None
pausenzaehler=0
- logging.info("writeSQLTupel got "+str(len(newSQLs))+" sql tupels")
+ _moduleLogger.info("writeSQLTupel got "+str(len(newSQLs))+" sql tupels")
for newSQL in newSQLs:
#print ""
#print "SQL1: ",newSQL[1]
param=string.split(newSQL[3]," <<Tren-ner>> ")
else:
param=None
-
+
if (len(newSQL)>2):
commitSQL=True
if (newSQL[5]!=None)and(len(newSQL[5])>0):
commitSQL=self.check4commit(newSQL,lastdate)
-
+
if (commitSQL==True):
self.db.speichereSQL(newSQL[2],param,commit=False,pcdatum=newSQL[1],rowid=newSQL[5])
- else:
- logging.error("writeSQLTupel: Error")
-
+ else:
+ _moduleLogger.error("writeSQLTupel: Error")
+
pausenzaehler+=1
if (pausenzaehler % 10)==0:
self.pulse()
while (gtk.events_pending()):
- gtk.main_iteration();
-
- logging.info("Alle SQLs an sqlite geschickt, commiting now")
+ gtk.main_iteration();
+
+ _moduleLogger.info("Alle SQLs an sqlite geschickt, commiting now")
self.db.commitSQL()
- logging.info("Alle SQLs commited")
-
-
+ _moduleLogger.info("Alle SQLs commited")
+
def doSync(self,sync_uuid,pcdatum,newSQLs,pcdatumjetzt):
#print uuid,pcdatum,newSQLs
- #logging.info("doSync 0")
+ #_moduleLogger.info("doSync 0")
self.changeSyncStatus(True,_("sync process running"))
self.pulse()
- #logging.info("doSync 1")
-
+ #_moduleLogger.info("doSync 1")
+
while (gtk.events_pending()):
- gtk.main_iteration();
+ gtk.main_iteration();
diff=time.time()-pcdatumjetzt
if diff<0:
diff=diff*(-1)
if diff>30:
return -1
-
- logging.info("doSync read sqls")
+
+ _moduleLogger.info("doSync read sqls")
sql="SELECT * FROM logtable WHERE pcdatum>?"
rows=self.db.ladeSQL(sql,(pcdatum,))
- logging.info("doSync read sqls")
+ _moduleLogger.info("doSync read sqls")
self.writeSQLTupel(newSQLs,pcdatum)
- logging.info("doSync wrote "+str(len(newSQLs))+" sqls")
- logging.info("doSync sending "+str(len(rows))+" sqls")
+ _moduleLogger.info("doSync wrote "+str(len(newSQLs))+" sqls")
+ _moduleLogger.info("doSync sending "+str(len(rows))+" sqls")
i=0
return rows
-
+
def getRemoteSyncUUID(self):
return self.sync_uuid
-
-
+
def startServer(self, widget, data=None):
#Starte RPCServer
self.db.speichereDirekt("syncServerIP",self.comboIP.get_child().get_text())
-
+
if (widget.get_active()==True):
- logging.info("Starting Server")
-
+ _moduleLogger.info("Starting Server")
+
try:
ip=self.comboIP.get_child().get_text()
- self.rpcserver = SimpleXMLRPCServer((ip, self.port),allow_none=True)
+ self.rpcserver = SimpleXMLRPCServer((ip, self.port),allow_none=True)
self.rpcserver.register_function(pow)
self.rpcserver.register_function(self.getLastSyncDate)
self.rpcserver.register_function(self.doSync)
self.poll.register(self.rpcserver.fileno())
gobject.timeout_add(1000, self.handleRPC)
self.syncServerStatusLabel.set_text(_("Syncserver running..."))
-
+
#save
self.db.speichereDirekt("startSyncServer",True)
-
+
except:
s=str(sys.exc_info())
- logging.error("libsync: could not start server. Error: "+s)
+ _moduleLogger.error("libsync: could not start server. Error: "+s)
mbox=gtk.MessageDialog(None,gtk.DIALOG_MODAL,gtk.MESSAGE_ERROR,gtk.BUTTONS_OK,_("Sync server could not start. Please check IP and port.")) #gtk.DIALOG_MODAL
mbox.set_modal(False)
- response=mbox.run()
- mbox.hide()
- mbox.destroy()
+ response=mbox.run()
+ mbox.hide()
+ mbox.destroy()
widget.set_active(False)
-
else:
- logging.info("Stopping Server")
+ _moduleLogger.info("Stopping Server")
try:
- del self.rpcserver
+ del self.rpcserver
except:
pass
self.syncServerStatusLabel.set_text(_("Syncserver not running..."))
#save
self.db.speichereDirekt("startSyncServer",False)
-
+
def doSaveFinalTime(self,sync_uuid,pcdatum=None):
if (pcdatum==None): pcdatum=int(time.time())
if (time.time()>pcdatum):
pcdatum=int(time.time()) #größere Zeit nehmen
-
+
self.pulse()
-
+
#fime save time+uuid
sql="DELETE FROM sync WHERE uuid=?"
self.db.speichereSQL(sql,(sync_uuid,),log=False)
self.pulse()
self.changeSyncStatus(False,_("no sync process (at the moment)"))
return (self.sync_uuid,pcdatum)
-
-
+
def syncButton(self, widget, data=None):
- logging.info("Syncing")
+ _moduleLogger.info("Syncing")
#sql="DELETE FROM logtable WHERE sql LIKE externeStundenplanung"
#self.db.speichereSQL(sql)
-
+
self.changeSyncStatus(True,_("sync process running"))
while (gtk.events_pending()):
- gtk.main_iteration();
+ gtk.main_iteration();
self.db.speichereDirekt("syncRemoteIP",self.comboRemoteIP.get_child().get_text())
try:
- self.server = xmlrpclib.ServerProxy("http://"+self.comboRemoteIP.get_child().get_text()+":"+str(self.port),allow_none=True)
+ self.server = xmlrpclib.ServerProxy("http://"+self.comboRemoteIP.get_child().get_text()+":"+str(self.port),allow_none=True)
#lastDate=server.getLastSyncDate(str(self.sync_uuid))
server_sync_uuid=self.server.getRemoteSyncUUID()
lastDate=self.getLastSyncDate(str(server_sync_uuid))
-
+
#print ("LastSyncDate: "+str(lastDate)+" Now: "+str(int(time.time())))
-
+
sql="SELECT * FROM logtable WHERE pcdatum>?"
rows=self.db.ladeSQL(sql,(lastDate,))
-
- logging.info("loaded concerned rows")
-
+
+ _moduleLogger.info("loaded concerned rows")
+
newSQLs=self.server.doSync(self.sync_uuid,lastDate,rows,time.time())
-
- logging.info("did do sync, processing sqls now")
+
+ _moduleLogger.info("did do sync, processing sqls now")
if newSQLs!=-1:
self.writeSQLTupel(newSQLs,lastDate)
-
+
sync_uuid, finalpcdatum=self.server.doSaveFinalTime(self.sync_uuid)
self.doSaveFinalTime(sync_uuid, finalpcdatum)
-
+
self.changeSyncStatus(False,_("no sync process (at the moment)"))
-
+
mbox = gtk.MessageDialog(None,gtk.DIALOG_MODAL,gtk.MESSAGE_INFO,gtk.BUTTONS_OK,_("Synchronization successfully completed"))
- response = mbox.run()
- mbox.hide()
- mbox.destroy()
+ response = mbox.run()
+ mbox.hide()
+ mbox.destroy()
else:
- logging.warning("Zeitdiff zu groß/oder anderer db-Fehler")
+ _moduleLogger.warning("Zeitdiff zu groß/oder anderer db-Fehler")
self.changeSyncStatus(False,_("no sync process (at the moment)"))
mbox = gtk.MessageDialog(None,gtk.DIALOG_MODAL,gtk.MESSAGE_INFO,gtk.BUTTONS_OK,_("The clocks are not synchronized between stations"))
- response = mbox.run()
- mbox.hide()
- mbox.destroy()
+ response = mbox.run()
+ mbox.hide()
+ mbox.destroy()
except:
- logging.warning("Sync connect failed")
+ _moduleLogger.warning("Sync connect failed")
self.changeSyncStatus(False,_("no sync process (at the moment)"))
mbox = gtk.MessageDialog(None,gtk.DIALOG_MODAL,gtk.MESSAGE_INFO,gtk.BUTTONS_OK,_("Sync failed, reason: ")+unicode(sys.exc_info()[1][1]))
- response = mbox.run()
- mbox.hide()
- mbox.destroy()
+ response = mbox.run()
+ mbox.hide()
+ mbox.destroy()
self.server=None
self.server=None
-
-
-
-
- def __init__(self,db,parentwindow,port):
- gtk.VBox.__init__(self,homogeneous=False, spacing=0)
-
- logging.info("Sync, init")
- self.db=db
- self.progress=None
- self.server=None
- self.port=int(port)
- self.parentwindow=parentwindow
- self.concernedRows=None
-
- #print "Sync, 2"
- #sql = "DROP TABLE sync"
- #self.db.speichereSQL(sql,log=False)
-
- sql = "CREATE TABLE sync (id INTEGER PRIMARY KEY, syncpartner TEXT, uuid TEXT, pcdatum INTEGER)"
- self.db.speichereSQL(sql,log=False)
-
- #print "Sync, 3"
-
- sql="SELECT uuid,pcdatum FROM sync WHERE syncpartner=?"
- rows=self.db.ladeSQL(sql,("self",)) #Eigene Id feststellen
-
- #print "Sync, 3a"
- if (rows==None)or(len(rows)!=1):
- sql="DELETE FROM sync WHERE syncpartner=?"
- self.db.speichereSQL(sql,("self",),log=False)
-
- #uuid1=uuid()
- #print "Sync, 3b"
-
- #print "Sync, 3bb"
- self.sync_uuid=str(uuid.uuid4())
- sql="INSERT INTO sync (syncpartner,uuid,pcdatum) VALUES (?,?,?)"
- self.db.speichereSQL(sql,("self",str(self.sync_uuid),int(time.time())),log=False)
- #print "Sync, 3c"
- else:
- sync_uuid,pcdatum = rows[0]
- self.sync_uuid=sync_uuid
- #print "x1"
-
-
-
- #print "Sync, 4"
-
-
- frame=gtk.Frame(_("Local SyncServer (port ")+str(self.port)+")")
-
-
-
- self.comboIP=gtk.combo_box_entry_new_text()
-
-
- self.comboIP.append_text("") #self.get_ip_address("eth0"))
- #self.comboIP.append_text(self.get_ip_address("eth1")) #fixme
- #self.comboIP.append_text(self.get_ip_address("eth2"))
- #self.comboIP.append_text(self.get_ip_address("eth3"))
- #print "Sync, 4d"
- #self.comboIP.append_text(self.get_ip_address("wlan0"))
- #self.comboIP.append_text(self.get_ip_address("wlan1"))
-
- #print "Sync, 4e"
-
- frame.add(self.comboIP)
- serverbutton=gtk.ToggleButton(_("Start SyncServer"))
- serverbutton.connect("clicked",self.startServer,(None,))
- self.pack_start(frame, expand=False, fill=True, padding=1)
- self.pack_start(serverbutton, expand=False, fill=True, padding=1)
- self.syncServerStatusLabel=gtk.Label(_("Syncserver not running"))
- self.pack_start(self.syncServerStatusLabel, expand=False, fill=True, padding=1)
-
- frame=gtk.Frame(_("RemoteSync-Server (Port ")+str(self.port)+")")
- self.comboRemoteIP=gtk.combo_box_entry_new_text()
- self.comboRemoteIP.append_text("192.168.0.?")
- self.comboRemoteIP.append_text("192.168.1.?")
- self.comboRemoteIP.append_text("192.168.176.?")
- frame.add(self.comboRemoteIP)
- syncbutton=gtk.Button(_("Connect to remote SyncServer"))
- syncbutton.connect("clicked",self.syncButton,(None,))
- self.pack_start(frame, expand=False, fill=True, padding=1)
- self.pack_start(syncbutton, expand=False, fill=True, padding=1)
- self.syncStatusLabel=gtk.Label(_("no sync process (at the moment)"))
- self.pack_start(self.syncStatusLabel, expand=False, fill=True, padding=1)
-
-
- #self.comboRemoteIP.set_text_column("Test")
- self.comboRemoteIP.get_child().set_text(self.db.ladeDirekt("syncRemoteIP"))
- self.comboIP.get_child().set_text(self.db.ladeDirekt("syncServerIP"))
-
- #load
- if (self.db.ladeDirekt("startSyncServer",False)==True):
- serverbutton.set_active(True)
-
- #print "Sync, 9"
#!/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 <http://www.gnu.org/licenses/>.
-
- Copyright (C) 2008 Christoph Würstle
+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 <http://www.gnu.org/licenses/>.
+
+Copyright (C) 2008 Christoph Würstle
"""
-
+
import gtk
import gobject
import logging
import pango
-import libliststorehandler
-
+
+
+try:
+ _
+except NameError:
+ _ = lambda x: x
+
+
+_moduleLogger = logging.getLogger(__name__)
+
class Columns_dialog(gtk.VBox):
-
- def is_col_selected(self, icol):
- children=self.framebox.get_children()
- if icol<len(children):
- return children[icol].get_active()
- else:
- return None
-
- def save_column_setting(self):
- i=1 #uid can not be shown
- while self.liststorehandler.get_colname(i)!=None:
- name=str(self.liststorehandler.get_colname(i))
- if self.is_col_selected(i-1)==True:
- self.db.speichereDirekt("showcol_"+name,"1")
- else:
- self.db.speichereDirekt("showcol_"+name,"0")
- i=i+1
-
-
-
def __init__(self,db,liststorehandler):
gtk.VBox.__init__(self,homogeneous=False, spacing=0)
-
+
self.db=db
self.liststorehandler=liststorehandler
-
+
#serverbutton=gtk.ToggleButton("SyncServer starten")
#serverbutton.connect("clicked",self.startServer,(None,))
#self.pack_start(serverbutton, expand=False, fill=True, padding=1)
#print "x1"
-
+
frame=gtk.Frame(_("Columns"))
self.framebox=gtk.VBox(homogeneous=False, spacing=0)
-
+
self.scrolled_window = gtk.ScrolledWindow()
self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
self.scrolled_window.add_with_viewport(self.framebox)
-
-
+
i=1 #uid can not be shown
while self.liststorehandler.get_colname(i)!=None:
name=str(self.liststorehandler.get_colname(i))
checkbutton=gtk.CheckButton(name)
if self.db.ladeDirekt("showcol_"+name)=="1":
checkbutton.set_active(True)
-
+
self.framebox.pack_start(checkbutton)
i=i+1
-
+
frame.add(self.scrolled_window)
self.pack_start(frame, expand=True, fill=True, padding=1)
-
-
-
-
+
+ def is_col_selected(self, icol):
+ children=self.framebox.get_children()
+ if icol<len(children):
+ return children[icol].get_active()
+ else:
+ return None
+
+ def save_column_setting(self):
+ i=1 #uid can not be shown
+ while self.liststorehandler.get_colname(i)!=None:
+ name=str(self.liststorehandler.get_colname(i))
+ if self.is_col_selected(i-1)==True:
+ self.db.speichereDirekt("showcol_"+name,"1")
+ else:
+ self.db.speichereDirekt("showcol_"+name,"0")
+ i=i+1
class CellRendererTriple(gtk.GenericCellRenderer):
__gproperties__ = {
- "status": (gobject.TYPE_STRING, "Status",
- "Status", "", gobject.PARAM_READWRITE),
- }
-
- __gsignals__ = {
- 'status_changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_INT,gobject.TYPE_STRING)),
- }
+ "status": (gobject.TYPE_STRING, "Status",
+ "Status", "", gobject.PARAM_READWRITE),
+ }
+ __gsignals__ = {
+ 'status_changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_INT,gobject.TYPE_STRING)),
+ }
def __init__(self):
#self.__gobject_init__()
- #gtk.GenericCellRenderer.__init__(self,*args,**kwargs)
+ #gtk.GenericCellRenderer.__init__(self,*args,**kwargs)
gtk.GenericCellRenderer.__init__(self)
#self.__gobject_init__()
self.status=-1
self.xpad = 2
- self.ypad = 2
+ self.ypad = 2
self.mode = gtk.CELL_RENDERER_MODE_ACTIVATABLE
self.xpad = -2; self.ypad = -2
- self.xalign = 0.5; self.yalign = 0.5
- self.active = 0
+ self.xalign = 0.5; self.yalign = 0.5
+ self.active = 0
self.widget=None
self.last_cell=None
self.connect('editing-started', self.on_clicked)
layout.set_text(' ')
- return layout
+ return layout
def on_get_size(self, widget, cell_area=None):
xpad = 2
width = width + (xpad * 2)
height = height + (ypad * 2)
-
return x_offset, y_offset, width, height
-
+
def on_clicked(self, widget, data):
print widget,data
def clicked(self, widget, data1=None):
x,y=widget.get_pointer()
widget.realize()
-
+
path=widget.get_path_at_pos(x,y)
-
+
#print "a",widget.get_cursor()
#print path
-
-
-
+
path=widget.get_cursor()[0]
-
+
if path!=None:
irow=path[0] #path[0][0]-1
rect=widget.get_cell_area(irow, widget.get_column(0)) #FixME 0 is hardcoded
self.emit("status_changed",irow,self.status)
else:
return
-
-
+
#workarround -1 means last item, because bug in treeview?!
#print "not in list"
rect=widget.get_visible_rect() #widget.get_cell_area(-1, widget.get_column(0))
rect=widget.get_cell_area(0, widget.get_column(0)) #FixME 0 is hardcoded
if x<rect.x+rect.width:
self.emit("status_changed",irow,"-1")
-
def on_render(self, window, widget, background_area, cell_area, expose_area, flags ):
if (self.widget==None):
#print widget
self.widget=widget
self.widget.connect("cursor-changed",self.clicked) #button-press-event
-
+
self.last_cell=cell_area
-
+
x=int(cell_area.x+(cell_area.width-2)/2-(cell_area.height-2)/2)
y=int(cell_area.y+1)
height=int(cell_area.height-2)
width=int(height)
if (self.status=="1"):
- widget.style.paint_check(window,gtk.STATE_NORMAL, gtk.SHADOW_IN,cell_area, widget, "cellradio",x,y,width,height)
+ widget.style.paint_check(window,gtk.STATE_NORMAL, gtk.SHADOW_IN,cell_area, widget, "cellradio",x,y,width,height)
elif (self.status=="0"):
#width=height
height=height-3
width=height
-
+
widget.style.paint_flat_box(window, gtk.STATE_NORMAL, gtk.SHADOW_NONE, cell_area, widget, "cellunselected",x,y,width,height)
-
+
widget.style.paint_hline(window, gtk.STATE_NORMAL,cell_area, widget, "cellunselected",x,x+width,y)
widget.style.paint_hline(window, gtk.STATE_NORMAL,cell_area, widget, "cellunselected",x,x+width,y+height)
widget.style.paint_vline(window, gtk.STATE_NORMAL,cell_area, widget, "cellunselected",y,y+height,x)
widget.style.paint_vline(window, gtk.STATE_NORMAL,cell_area, widget, "cellunselected",y,y+height,x+width)
-
+
else:
widget.style.paint_diamond(window, gtk.STATE_NORMAL, gtk.SHADOW_IN, cell_area, widget, "cellunselected",x,y,width,height)
-
+
#widget.show_all()
#print "render"
- pass
-
+ pass
+
def on_start_editing(self, event, widget, path, background_area, cell_area, flags):
print "on_start_editing",path
return None
-
-
+
def on_activate(self, event, widget, path, background_area, cell_area, flags):
print "activate",path
return False
-
-
+
class CellRendererCombo2(gtk.GenericCellRenderer):
__gproperties__ = {
- "text": (gobject.TYPE_STRING, "text",
- "Text", "", gobject.PARAM_READWRITE),
- }
-
- __gsignals__ = {
- 'status_changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_INT,gobject.TYPE_STRING)),
- }
+ "text": (gobject.TYPE_STRING, "text",
+ "Text", "", gobject.PARAM_READWRITE),
+ }
+ __gsignals__ = {
+ 'status_changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_INT,gobject.TYPE_STRING)),
+ }
def __init__(self):
#self.__gobject_init__()
- #gtk.GenericCellRenderer.__init__(self,*args,**kwargs)
+ #gtk.GenericCellRenderer.__init__(self,*args,**kwargs)
gtk.GenericCellRenderer.__init__(self)
#self.__gobject_init__()
self.status=-1
self.xpad = 2
- self.ypad = 2
+ self.ypad = 2
self.mode = gtk.CELL_RENDERER_MODE_ACTIVATABLE
- self.xpad = -2; self.ypad = -2
- self.xalign = 0.5; self.yalign = 0.5
- self.active = 0
+ self.xpad = -2
+ self.ypad = -2
+ self.xalign = 0.5
+ self.yalign = 0.5
+ self.active = 0
self.widget=None
self.last_cell=None
self.text="(none)"
layout.set_text(self.text)
- return layout
+ return layout
def on_get_size(self, widget, cell_area=None):
xpad = 2
width = width + (xpad * 2)
height = height + (ypad * 2)
-
return x_offset, y_offset, width, height
-
+
def on_clicked(self, widget, data):
print widget,data
return
x,y=widget.get_pointer()
widget.realize()
-
+
#path=widget.get_path_at_pos(x,y)
-
+
path=widget.get_cursor()[0]
-
+
if path!=None:
irow=path[0] #path[0][0]-1
rect=widget.get_cell_area(irow, widget.get_column(0)) #FixME 0 is hardcoded
self.emit("status_changed",irow,self.status)
else:
return
-
-
+
#workarround -1 means last item, because bug in treeview?!
#print "not in list"
rect=widget.get_visible_rect() #widget.get_cell_area(-1, widget.get_column(0))
rect=widget.get_cell_area(0, widget.get_column(0)) #FixME 0 is hardcoded
if x<rect.x+rect.width:
self.emit("status_changed",irow,"-1")
-
def on_render(self, window, widget, background_area, cell_area, expose_area, flags ):
if (self.widget==None):
self.widget=widget
self.widget.connect("cursor-changed",self.clicked) #button-press-event
-
+
self.last_cell=cell_area
-
+
x=int(cell_area.x+(cell_area.width-2)/2-(cell_area.height-2)/2)
y=int(cell_area.y+1)
height=int(cell_area.height-2)
width=int(height)
-
- widget.style.paint_layout(window,gtk.STATE_NORMAL, True, cell_area, widget, "cellradio",x,y,self.get_layout(widget))
-
+
+ widget.style.paint_layout(window,gtk.STATE_NORMAL, True, cell_area, widget, "cellradio",x,y,self.get_layout(widget))
+
#widget.show_all()
-
+
def on_start_editing(self, event, widget, path, background_area, cell_area, flags):
print "on_start_editing",path
return None
-
-
+
def on_activate(self, event, widget, path, background_area, cell_area, flags):
print "activate",path
return False
gobject.type_register(CellRendererCombo2)
gobject.type_register(CellRendererTriple)
-
-
+
class View(gtk.VBox):
+
+ def __init__(self,db,liststorehandler,parent_window):
+ self.db=db
+ self.parent_window=parent_window
+ self.liststorehandler = liststorehandler
+
+ gtk.VBox.__init__(self,homogeneous=False, spacing=0)
+
+ logging.info("libview, init")
+
+ self.scrolled_window = None
+ self.reload_view()
+
+ """
+ bearbeitenFrame=gtk.Frame("Verteilung kopieren nach")
+ bearbeitenvBox=gtk.VBox(homogeneous=False, spacing=0)
+
+ bearbeitenhBox=gtk.HBox(homogeneous=False, spacing=0)
+ self.comboKlassen = gtk.combo_box_new_text()
+ bearbeitenhBox.pack_start(self.comboKlassen, expand=False, fill=True, padding=0)
+ button=gtk.Button("Kopieren")
+ button.connect("clicked", self.kopiereStoffverteilung, None)
+ bearbeitenhBox.pack_start(button, expand=False, fill=True, padding=0)
+
+ label=gtk.Label(" ")
+ bearbeitenhBox.pack_start(label, expand=False, fill=True, padding=0)
+
+ button=gtk.Button("Export in CSV-Datei")
+ button.connect("clicked", self.exportStoffverteilung, None)
+ bearbeitenhBox.pack_start(button, expand=False, fill=True, padding=0)
+
+ bearbeitenvBox.pack_start(bearbeitenhBox, expand=False, fill=True, padding=0)
+
+ bearbeitenFrame.add(bearbeitenvBox)
+ self.pack_start(bearbeitenFrame, expand=False, fill=True, padding=0)
+ """
+
+ #self.connect("unmap", self.speichere)
+ #self.connect("map", self.ladeWirklich)
+
+ #self.show_all()
+
+ #print "libstoffverteilung 9: ",time.clock()
+
def loadList(self):
ls=self.liststorehandler.get_liststore()
self.treeview.set_model(ls)
#self.tvcolumn[i].add_attribute( self.cell[i], "active", 1)
#print "setup",ls
-
-
-
-
+
def col_edited(self,cell, irow, new_text,icol=None):
if (irow!=4):
self.liststorehandler.update_row(irow,icol,new_text)
else:
print cell, irow, new_text,icol
-
+
def col_toggled(self,widget,irow, status ):
#print irow,ls[irow][1],status
ls=self.treeview.get_model()
-
+
if self.liststorehandler.selection.get_status()=="0":
if ls[irow][1]=="0":
self.liststorehandler.update_row(irow,1,"1")
self.liststorehandler.update_row(irow,1,"1")
else:
self.liststorehandler.update_row(irow,1,"0")
-
+
#self.tvcolumn[i].set_attributes( self.cell[i], active=i)
-
-
-
+
def convert(self,s):
#print s
if (s=="1"):
return 1
else:
return 0
-
-
+
def del_active_row(self):
path, col = self.treeview.get_cursor()
#print path, col
row_iter=self.treeview.get_model().get_iter(path)
self.liststorehandler.del_row(irow,row_iter)
-
#treemodel.get_iter()
-
-
-
+
def sort_func_function(self,model, iter1, iter2, data=None):
print "sorting"
-
-
+
def reload_view(self):
- # create the TreeView using liststore
+ # create the TreeView using liststore
self.modelsort = gtk.TreeModelSort(self.liststorehandler.get_liststore())
self.modelsort.set_sort_column_id(2, gtk.SORT_ASCENDING)
-
- self.treeview = gtk.TreeView(self.modelsort)
+
+ self.treeview = gtk.TreeView(self.modelsort)
self.treeview.set_headers_visible(True)
-
-
+
self.cell=range(self.liststorehandler.get_colcount())
self.tvcolumn=range(self.liststorehandler.get_colcount())
-
m = self.liststorehandler.get_unitsstore()
-
+
for i in range(self.liststorehandler.get_colcount()):
-
if i>5:
default="0"
else:
self.tvcolumn[i] = gtk.TreeViewColumn(self.liststorehandler.get_colname(i),self.cell[i])
self.cell[i].connect( 'status_changed', self.col_toggled)
self.tvcolumn[i].set_attributes( self.cell[i], status=i)
-
elif (i==3)or(i==4)or(i==6):
self.cell[i] = gtk.CellRendererCombo()
self.tvcolumn[i] = gtk.TreeViewColumn(self.liststorehandler.get_colname(i),self.cell[i])
self.tvcolumn[i] = gtk.TreeViewColumn(self.liststorehandler.get_colname(i),self.cell[i])
self.cell[i].set_property('editable',True)
self.cell[i].set_property('editable-set',True)
- self.cell[i].connect("edited", self.col_edited,i)
+ self.cell[i].connect("edited", self.col_edited,i)
#self.cell[i].connect("editing-canceled", self.col_edited2,i)
self.tvcolumn[i].set_attributes(self.cell[i], text=i)
self.cell[i].set_property('cell-background', 'lightgray')
self.tvcolumn[i].set_sort_column_id(i)
self.tvcolumn[i].set_resizable(True)
-
-
+
if (i>0):
- self.treeview.append_column(self.tvcolumn[i])
-
-
- # Allow NOT drag and drop reordering of rows
- self.treeview.set_reorderable(False)
-
-
+ self.treeview.append_column(self.tvcolumn[i])
+
+ # Allow NOT drag and drop reordering of rows
+ self.treeview.set_reorderable(False)
+
if self.scrolled_window != None:
self.scrolled_window.destroy()
-
+
self.scrolled_window = gtk.ScrolledWindow()
self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
self.scrolled_window.add(self.treeview)
self.pack_start(self.scrolled_window, expand=True, fill=True, padding=0)
self.loadList()
-
- self.show_all()
-
- def __init__(self,db,liststorehandler,parent_window):
-
- self.db=db
- self.parent_window=parent_window
- self.liststorehandler = liststorehandler
-
-
- gtk.VBox.__init__(self,homogeneous=False, spacing=0)
-
- logging.info("libview, init")
-
- self.scrolled_window = None
- self.reload_view()
-
-
-
-
-
- """
- bearbeitenFrame=gtk.Frame("Verteilung kopieren nach")
- bearbeitenvBox=gtk.VBox(homogeneous=False, spacing=0)
-
- bearbeitenhBox=gtk.HBox(homogeneous=False, spacing=0)
- self.comboKlassen = gtk.combo_box_new_text()
- bearbeitenhBox.pack_start(self.comboKlassen, expand=False, fill=True, padding=0)
- button=gtk.Button("Kopieren")
- button.connect("clicked", self.kopiereStoffverteilung, None)
- bearbeitenhBox.pack_start(button, expand=False, fill=True, padding=0)
-
- label=gtk.Label(" ")
- bearbeitenhBox.pack_start(label, expand=False, fill=True, padding=0)
-
- button=gtk.Button("Export in CSV-Datei")
- button.connect("clicked", self.exportStoffverteilung, None)
- bearbeitenhBox.pack_start(button, expand=False, fill=True, padding=0)
-
- bearbeitenvBox.pack_start(bearbeitenhBox, expand=False, fill=True, padding=0)
-
-
- bearbeitenFrame.add(bearbeitenvBox)
- self.pack_start(bearbeitenFrame, expand=False, fill=True, padding=0)
- """
-
- #self.connect("unmap", self.speichere)
- #self.connect("map", self.ladeWirklich)
-
- #self.show_all()
-
-
-
- #print "libstoffverteilung 9: ",time.clock()
+ self.show_all()