"""
import ConfigParser
+import csv
+import uuid
import logging
import gtk
except ConfigParser.NoOptionError:
pass
+ def export_data(self, filename):
+ sql = "SELECT list, category, uid, status, title, quantity, unit, price, priority, date, private, stores, note, custom1, custom2 FROM items ORDER BY list, title ASC"
+ rows = self.db.ladeSQL(sql)
+ with open(filename, "w") as f:
+ csvWriter = csv.writer(f)
+ headerRow = ["list", "category"]
+ headerRow.extend(self.collist)
+ csvWriter.writerow(headerRow)
+ csvWriter.writerows(rows)
+
+ def append_data(self, filename):
+ with open(filename, "r") as f:
+ csvReader = csv.reader(f)
+ for row in csvReader:
+ uid = str(uuid.uuid4())
+ row[2] = uid
+ sql = "INSERT INTO items (list, category, uid, status, title, quantity, unit, price, priority, date, private, stores, note, custom1, custom2) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
+ self.db.speichereSQL(sql, row, rowid = uid)
+ self.db.commitSQL()
+ self.update_list()
+
def set_filter(self, filter):
assert filter in self.ALL_FILTERS
self.__filter = filter
def get_unitsstore(self):
if self.unitsstore is None:
- self.unitsstore = gtk.ListStore(str, str, str, str, str, str, str, str, str, str, str, str, str)
+ self.unitsstore = gtk.ListStore(str, str, str, str, str, str, str, str, str, str, str, str, str)
self.unitsstore.clear()
#row(3) quantities
#row 4 units
if rows is not None:
for row in rows:
uid, status, title, quantity, unit, price, priority, date, private, stores, note, custom1, custom2 = row
- if unit == None:
- pass
- #unit = ""
+ if unit is None:
+ unit = ""
self.liststore.append([uid, status, title, quantity, unit, price, priority, date, private, stores, note, custom1, custom2])
return self.liststore
def add_row(self, title = ""):
status = self.__calculate_status()
- import uuid
uid = str(uuid.uuid4())
sql = "INSERT INTO items (uid, list, category, status, title) VALUES (?, ?, ?, ?, ?)"
self.db.speichereSQL(sql, (uid, self.selection.get_list(), self.selection.get_category(), status, title), rowid = uid)
menu_items.connect("activate", self.sync_notes, None)
fileMenu.append(menu_items)
+ menu_items = gtk.MenuItem(_("Import"))
+ menu_items.connect("activate", self._on_import, None)
+ fileMenu.append(menu_items)
+
+ menu_items = gtk.MenuItem(_("Export"))
+ menu_items.connect("activate", self._on_export, None)
+ fileMenu.append(menu_items)
+
menu_items = gtk.MenuItem(_("Quit"))
menu_items.connect("activate", self._on_destroy, None)
fileMenu.append(menu_items)
button.connect("clicked", self._on_click_menu_filter, self.liststorehandler.SHOW_COMPLETE)
button.set_mode(False)
+ button = gtk.Button(_("Import"))
+ button.connect("clicked", self._on_import)
+ menuBar.append(button)
+
+ button = gtk.Button(_("Export"))
+ button.connect("clicked", self._on_export)
+ menuBar.append(button)
+
renameListButton= gtk.Button(_("Rename List"))
renameListButton.connect("clicked", self.bottombar.rename_list)
menuBar.append(renameListButton)
self.selection.comboCategory_changed()
self.liststorehandler.update_list()
+ @gtk_toolbox.log_exception(_moduleLogger)
+ def _on_import(self, *args):
+ csvFilter = gtk.FileFilter()
+ csvFilter.set_name("Import Lists")
+ csvFilter.add_pattern("*.csv")
+ importFileChooser = gtk.FileChooserDialog(
+ title="Contacts",
+ action=gtk.FILE_CHOOSER_ACTION_OPEN,
+ parent=self.window,
+ )
+ importFileChooser.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
+ importFileChooser.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
+
+ importFileChooser.set_property("filter", csvFilter)
+ userResponse = importFileChooser.run()
+ importFileChooser.hide()
+ if userResponse == gtk.RESPONSE_OK:
+ filename = importFileChooser.get_filename()
+ self.liststorehandler.append_data(filename)
+
+ @gtk_toolbox.log_exception(_moduleLogger)
+ def _on_export(self, *args):
+ csvFilter = gtk.FileFilter()
+ csvFilter.set_name("Export Lists")
+ csvFilter.add_pattern("*.csv")
+ importFileChooser = gtk.FileChooserDialog(
+ title="Contacts",
+ action=gtk.FILE_CHOOSER_ACTION_SAVE,
+ parent=self.window,
+ )
+ importFileChooser.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
+ importFileChooser.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
+
+ importFileChooser.set_property("filter", csvFilter)
+ userResponse = importFileChooser.run()
+ importFileChooser.hide()
+ if userResponse == gtk.RESPONSE_OK:
+ filename = importFileChooser.get_filename()
+ self.liststorehandler.export_data(filename)
+
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))