diff --git a/noted/database.py b/noted/database.py index 5bfa3aa..6882fe8 100644 --- a/noted/database.py +++ b/noted/database.py @@ -1,14 +1,17 @@ +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import GLib from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from database_tables import Notebook, Note, Base -import getpass import os import subprocess class Database(object): def start_database(self): - db_path = "/home/{}/Noted/sqlitedatabase.db".format(getpass.getuser()) + path = GLib.get_user_data_dir() + db_path = "{}/Noted/sqlitedatabase.db".format(path) if not os.path.exists(db_path): self.engine = create_engine('sqlite:///{}'.format(db_path),echo=False) Base.metadata.create_all(self.engine) diff --git a/noted/editor.py b/noted/editor.py index 5d5ff25..f0912d8 100644 --- a/noted/editor.py +++ b/noted/editor.py @@ -18,7 +18,6 @@ def __init__(self,parent): self.scrolled_window.set_hexpand(True) self.parent = parent - self.current_indent_level = 1 self.offset_after_tab_deletion = None # TextView diff --git a/noted/main.py b/noted/main.py index 1c32b55..01dea1a 100644 --- a/noted/main.py +++ b/noted/main.py @@ -1,6 +1,6 @@ import gi gi.require_version('Gtk', '3.0') -from gi.repository import Gtk, Gdk +from gi.repository import Gtk, Gdk, GLib import sidebar as sb import headerbar as hb import editor @@ -8,7 +8,6 @@ from dialogs import notebook_dialog as nd from dialogs import delete_dialog as dd from database import Database -import getpass import os import subprocess @@ -122,10 +121,10 @@ def save_note(self, event): self.sidebar.modify_item(path, title) def start_database(self): - path = "/home/{}/Noted".format(getpass.getuser()) + path = "{}/Noted".format(GLib.get_user_data_dir()) if not os.path.exists(path): subprocess.call(['mkdir', path]) - db = shelve.open("/home/{}/Noted/database.db".format(getpass.getuser())) + db = shelve.open("{}/database.db".format(path)) self.database = Database() self.database.start_database() if not db: @@ -142,7 +141,8 @@ def start_database(self): db.close() def close_database(self, event): - db = shelve.open("/home/{}/Noted/database.db".format(getpass.getuser())) + path = GLib.get_user_data_dir() + db = shelve.open("{}/Noted/database.db".format(path)) db['note_id'] = self.id db['notebook_id'] = self.notebook_id db.close()