Source code for tagit.view.sidebox.db_management
"""
Part of the tagit module.
A copy of the license is provided with the project.
Author: Matthias Baumgartner, 2016
"""
# IMPORTS
from os.path import join, dirname
from kivy.lang import Builder
from kivy.uix.gridlayout import GridLayout
from kivy.logger import Logger
# INNER-MODULE IMPORTS
from sidebox import VSidebox
from ...controller.sidebox import CSidebox_DB_Management
from ..dialogues import LabelDialogue, FilePickerDialogue, ErrorDialogue, FileCreatorDialogue, DirPickerDialogue
# EXPORTS
__all__ = ('VSidebox_DB_Management', )
# LOAD KV
Builder.load_file(join(dirname(__file__), 'db_management.kv'))
# CLASSES
[docs]class VSidebox_DB_Management(GridLayout, VSidebox):
"""A bunch of buttons to control the database."""
def on_widget_change(self, instance, widget):
self.controller = widget.get_controller(CSidebox_DB_Management, wx=self)
def load(self):
Logger.debug("Loading...")
self.controller.request_load()
def load_new(self):
Logger.debug("New database")
self.controller.request_new()
def save(self):
Logger.debug("Saving the database")
self.controller.request_save()
def save_as(self):
Logger.debug("Saving the database")
self.controller.request_save_as()
def reload(self):
Logger.debug("Reloading the database")
self.controller.request_reload()
def index(self):
Logger.debug("Indexing some files")
self.controller.request_index()
def load_file_dialogue(self, callback):
dlg = FilePickerDialogue(text='Select a database file to load')
dlg.bind(on_ok=lambda obj: callback(obj.path))
dlg.open()
def save_file_dialogue(self, callback):
dlg = FileCreatorDialogue(text='Select a file to save the database to.')
dlg.bind(on_ok=lambda obj: callback(obj.path))
dlg.open()
def load_dir_dialogue(self, callback):
dlg = DirPickerDialogue(text='Select a directory to index')
dlg.bind(on_ok=lambda obj: callback(obj.path))
dlg.open()
def confirm_dialogue(self, text, on_ok, on_cancel=None):
dlg = LabelDialogue(text=text)
dlg.bind(on_ok=lambda obj: on_ok())
if on_cancel is not None:
dlg.bind(on_cancel=lambda obj: on_cancel())
dlg.open()
def error(self, text):
dlg = ErrorDialogue(text=text)
dlg.open()
## EOF ##