generated from itdominator/Python-With-Gtk-Template
addeed dialogs
This commit is contained in:
parent
bc7577a725
commit
8c26fe544e
|
@ -12,6 +12,7 @@ from gi.repository import GLib
|
||||||
# Application imports
|
# Application imports
|
||||||
from .mixins.signals_mixins import SignalsMixins
|
from .mixins.signals_mixins import SignalsMixins
|
||||||
from .controller_data import ControllerData
|
from .controller_data import ControllerData
|
||||||
|
from .widgets.dialogs.message_widget import MessageWidget
|
||||||
from .widgets.create_notebook_widget import CreateNotebookWidget
|
from .widgets.create_notebook_widget import CreateNotebookWidget
|
||||||
from .widgets.sections.sections_widget import Sections
|
from .widgets.sections.sections_widget import Sections
|
||||||
|
|
||||||
|
@ -58,6 +59,7 @@ class Controller(SignalsMixins, ControllerData):
|
||||||
event_system.subscribe("load_notebook_data", self._load_notebook_data)
|
event_system.subscribe("load_notebook_data", self._load_notebook_data)
|
||||||
|
|
||||||
def _load_widgets(self):
|
def _load_widgets(self):
|
||||||
|
MessageWidget()
|
||||||
CreateNotebookWidget()
|
CreateNotebookWidget()
|
||||||
|
|
||||||
def load_glade_file(self):
|
def load_glade_file(self):
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
"""
|
||||||
|
Dialogs module
|
||||||
|
"""
|
|
@ -0,0 +1,49 @@
|
||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
gi.require_version('Gtk', '3.0')
|
||||||
|
from gi.repository import Gtk
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class AboutWidget:
|
||||||
|
"""docstring for AboutWidget."""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(AboutWidget, self).__init__()
|
||||||
|
|
||||||
|
_GLADE_FILE = f"{settings.get_ui_widgets_path()}/about_ui.glade"
|
||||||
|
self._builder = Gtk.Builder()
|
||||||
|
self._builder.add_from_file(_GLADE_FILE)
|
||||||
|
|
||||||
|
self._setup_styling()
|
||||||
|
self._setup_signals()
|
||||||
|
self._load_widgets()
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_styling(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _setup_signals(self):
|
||||||
|
event_system.subscribe("show_about_page", self.show_about_page)
|
||||||
|
event_system.subscribe("hide_about_page", self.hide_about_page)
|
||||||
|
settings.register_signals_to_builder([self,], self._builder)
|
||||||
|
|
||||||
|
def _load_widgets(self):
|
||||||
|
builder = settings.get_builder()
|
||||||
|
|
||||||
|
self.about_page = self._builder.get_object("about_page")
|
||||||
|
builder.expose_object(f"about_page", self.about_page)
|
||||||
|
|
||||||
|
|
||||||
|
def show_about_page(self, widget=None, eve=None):
|
||||||
|
response = self.about_page.run()
|
||||||
|
if response in [Gtk.ResponseType.CANCEL, Gtk.ResponseType.DELETE_EVENT]:
|
||||||
|
self.hide_about_page()
|
||||||
|
|
||||||
|
def hide_about_page(self, widget=None, eve=None):
|
||||||
|
self.about_page.hide()
|
|
@ -0,0 +1,87 @@
|
||||||
|
# Python imports
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
gi.require_version('Gtk', '3.0')
|
||||||
|
from gi.repository import Gtk
|
||||||
|
from gi.repository import Gio
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MessageWidget(Gtk.MessageDialog):
|
||||||
|
"""docstring for MessageWidget."""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(MessageWidget, self).__init__()
|
||||||
|
|
||||||
|
self._setup_styling()
|
||||||
|
self._setup_signals()
|
||||||
|
self._subscribe_to_events()
|
||||||
|
self._load_widgets()
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_styling(self):
|
||||||
|
self.type = Gtk.MessageType.WARNING
|
||||||
|
|
||||||
|
def _setup_signals(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _subscribe_to_events(self):
|
||||||
|
event_system.subscribe("delete_files", self.delete_files)
|
||||||
|
|
||||||
|
def _load_widgets(self):
|
||||||
|
message_area = self.get_message_area()
|
||||||
|
message_area.get_children()[0].set_label("Alert!")
|
||||||
|
message_area.show_all()
|
||||||
|
|
||||||
|
self.set_image( Gtk.Image.new_from_icon_name("user-alert", 16) )
|
||||||
|
self.add_buttons(Gtk.STOCK_NO, Gtk.ResponseType.NO)
|
||||||
|
self.add_buttons(Gtk.STOCK_YES, Gtk.ResponseType.YES)
|
||||||
|
|
||||||
|
def delete_files(self, widget = None, eve = None, uris = None, msg = f"Do you really want to delete the file(s)?"):
|
||||||
|
response = None
|
||||||
|
|
||||||
|
self.format_secondary_text(msg)
|
||||||
|
for uri in uris:
|
||||||
|
file = Gio.File.new_for_path(uri)
|
||||||
|
|
||||||
|
if not response:
|
||||||
|
response = self.run()
|
||||||
|
self.hide()
|
||||||
|
|
||||||
|
if response == Gtk.ResponseType.YES:
|
||||||
|
type = file.query_file_type(flags=Gio.FileQueryInfoFlags.NONE)
|
||||||
|
|
||||||
|
if type == Gio.FileType.DIRECTORY:
|
||||||
|
self.delete_file( file.get_path() )
|
||||||
|
else:
|
||||||
|
file.delete(cancellable = None)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
def delete_file(self, to_delete_file):
|
||||||
|
try:
|
||||||
|
logger.debug(f"Deleting: {to_delete_file}")
|
||||||
|
if os.path.exists(to_delete_file):
|
||||||
|
if os.path.isfile(to_delete_file):
|
||||||
|
os.remove(to_delete_file)
|
||||||
|
elif os.path.isdir(to_delete_file):
|
||||||
|
shutil.rmtree(to_delete_file)
|
||||||
|
else:
|
||||||
|
logger.debug("An error occured deleting the file:")
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
logger.debug("The folder/file does not exist")
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
logger.debug("An error occured deleting the file:")
|
||||||
|
logger.debug( repr(e) )
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
|
@ -35,7 +35,6 @@ class Page(Gtk.ScrolledWindow):
|
||||||
...
|
...
|
||||||
|
|
||||||
def _subscribe_to_events(self):
|
def _subscribe_to_events(self):
|
||||||
# event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
|
|
||||||
...
|
...
|
||||||
|
|
||||||
def _load_widgets(self):
|
def _load_widgets(self):
|
||||||
|
@ -51,6 +50,9 @@ class Page(Gtk.ScrolledWindow):
|
||||||
def get_tab_widget(self):
|
def get_tab_widget(self):
|
||||||
return self._tab_widget
|
return self._tab_widget
|
||||||
|
|
||||||
|
def get_manifest_pth(self):
|
||||||
|
return self._manifest_pth
|
||||||
|
|
||||||
def _load_page_manifest(self, manifest_pth = None):
|
def _load_page_manifest(self, manifest_pth = None):
|
||||||
if manifest_pth:
|
if manifest_pth:
|
||||||
self._manifest_pth = manifest_pth
|
self._manifest_pth = manifest_pth
|
||||||
|
|
|
@ -66,8 +66,14 @@ class Pages(Gtk.Notebook):
|
||||||
return
|
return
|
||||||
|
|
||||||
page_num = self.page_num(page)
|
page_num = self.page_num(page)
|
||||||
|
manifest_pth = os.path.dirname( page.get_manifest_pth() )
|
||||||
|
msg = f"Do you really want to delete the Section Page?"
|
||||||
|
response = event_system.emit_and_await("delete_files", (None, None, [manifest_pth,], msg))
|
||||||
|
|
||||||
|
if response == -8:
|
||||||
self.remove_page(page_num)
|
self.remove_page(page_num)
|
||||||
|
|
||||||
|
|
||||||
def create_page_view(self, widget = None, eve = None, manifest_pth = None):
|
def create_page_view(self, widget = None, eve = None, manifest_pth = None):
|
||||||
page = Page(self._close_tab, self._section_pth, manifest_pth)
|
page = Page(self._close_tab, self._section_pth, manifest_pth)
|
||||||
page_num = self.append_page(page, page.get_tab_widget())
|
page_num = self.append_page(page, page.get_tab_widget())
|
||||||
|
@ -81,6 +87,9 @@ class Pages(Gtk.Notebook):
|
||||||
def get_tab_widget(self):
|
def get_tab_widget(self):
|
||||||
return self._tab_widget
|
return self._tab_widget
|
||||||
|
|
||||||
|
def get_section_pth(self):
|
||||||
|
return self._section_pth
|
||||||
|
|
||||||
def _text_search(self, widget = None, eve = None):
|
def _text_search(self, widget = None, eve = None):
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,10 @@ class Sections(Gtk.Notebook):
|
||||||
return
|
return
|
||||||
|
|
||||||
page_num = self.page_num(pages)
|
page_num = self.page_num(pages)
|
||||||
|
msg = f"Do you really want to delete the Notebook Section?"
|
||||||
|
response = event_system.emit_and_await("delete_files", (None, None, [pages.get_section_pth(),], msg))
|
||||||
|
|
||||||
|
if response == -8:
|
||||||
self.remove_page(page_num)
|
self.remove_page(page_num)
|
||||||
|
|
||||||
def create_section_view(self, widget = None, eve = None, manifest_pth = None):
|
def create_section_view(self, widget = None, eve = None, manifest_pth = None):
|
||||||
|
|
Loading…
Reference in New Issue