Create a new method called "rename" in the Log class.

pull/61/head
Christian T. Jacobs 2017-04-15 00:55:52 +01:00
rodzic 9a6a1a24ae
commit 331d80a060
3 zmienionych plików z 32 dodań i 22 usunięć

Wyświetl plik

@ -241,6 +241,27 @@ class Log(Gtk.ListStore):
assert(removed == len(duplicates))
return (len(duplicates), removed)
def rename(self, new_name):
""" Rename the log.
:arg str new_name: The new name for the log.
:returns: True if the renaming process is successful. Otherwise returns False.
:rtype: bool
"""
try:
with self.connection:
# First try to alter the table name in the database.
c = self.connection.cursor()
query = "ALTER TABLE %s RENAME TO %s" % (self.name, new_name)
c.execute(query)
# If the table name change was successful, then change the name attribute of the Log object too.
self.name = new_name
success = True
except sqlite.Error as e:
logging.exception(e)
success = False
return success
def get_duplicates(self):
""" Find the duplicates in the log, based on the CALL, QSO_DATE, TIME_ON, FREQ and MODE fields.

Wyświetl plik

@ -493,33 +493,23 @@ class Logbook:
log_index = self.get_log_index(name=old_log_name)
exists = True
success = False
ln = LogNameDialog(self.application, title="Rename Log", name=old_log_name)
while(exists):
while(not success):
response = ln.dialog.run()
if(response == Gtk.ResponseType.OK):
new_log_name = ln.name
try:
with self.connection:
c = self.connection.cursor()
query = "ALTER TABLE %s RENAME TO %s" % (old_log_name, new_log_name)
c.execute(query)
exists = False
except sqlite.Error as e:
logging.exception(e)
# Data is not valid - inform the user.
success = self.logs[log_index].rename(new_log_name)
if(success):
ln.dialog.destroy()
else:
# Unsuccessful rename attempt. Inform the user.
error(parent=ln.dialog, message="Database error. Try another log name.")
exists = True
else:
ln.dialog.destroy()
return
ln.dialog.destroy()
# Remember to change the Log object's name...
self.logs[log_index].name = new_log_name
# ...and the page's name
# Remember to change the page's name
page.set_name(self.logs[log_index].name)
# ...and update the tab's label

Wyświetl plik

@ -19,10 +19,9 @@
from gi.repository import Gtk
import logging
from os.path import basename, getmtime, expanduser
from os import pardir
from os.path import basename, getmtime, expanduser, dirname, join, realpath
from datetime import datetime, date
import os
import os.path
try:
import configparser
except ImportError:
@ -52,7 +51,7 @@ class Summary(object):
self.application = application
self.logbook = self.application.logbook
self.builder = self.application.builder
glade_file_path = os.path.join(os.path.realpath(os.path.dirname(__file__)), os.pardir, "res/pyqso.glade")
glade_file_path = join(realpath(dirname(__file__)), pardir, "res/pyqso.glade")
self.builder.add_objects_from_file(glade_file_path, ("summary_page",))
self.summary_page = self.builder.get_object("summary_page")