Commit 8bfc8b32 authored by Roman Alifanov's avatar Roman Alifanov

init error dialog

parent fd20e820
......@@ -29,6 +29,9 @@ from .window import TuneitWindow
def get_main_window():
return _application.props.active_window
def get_error():
return _application.props.active_window.error
class TuneitApplication(Adw.Application):
"""The main application singleton class."""
......
import traceback
from .module import Module
from .page import Page
from .sections import SectionFactory
......@@ -24,6 +25,9 @@ def init_settings_stack(stack, listbox, split_view):
print("First init...")
for module_data in yaml_data:
module = Module(module_data)
try:
deps_results = dep_manager.verify_deps(module_data.get('deps', {}))
conflicts_results = dep_manager.verify_conflicts(module_data.get('conflicts', {}))
......@@ -48,8 +52,6 @@ def init_settings_stack(stack, listbox, split_view):
print(f"RESPONSE: {response}")
if response == "skip":
break
module = Module(module_data)
modules_dict[module.name] = module
for section_data in module_data.get('sections', []):
......@@ -72,6 +74,14 @@ def init_settings_stack(stack, listbox, split_view):
section = section_factory.create_section(section_data, module)
pages_dict[page_name].add_section(section)
except Exception as e:
from ..main import get_error
error = get_error()
full_traceback = traceback.format_exc()
e = f"Module '{module.name}' loading error \nError: {e}\nFull traceback:\n{full_traceback}"
error(e)
pages = list(pages_dict.values())
for page in pages:
......
using Gtk 4.0;
using Adw 1;
template $TuneItErrorDialog: Adw.AlertDialog {
heading: _("Error in Tune it!");
body: _("You can write in an official telegram chat by applying this log.");
responses [
close: _("Ignore") destructive,
copy: _("Copy the log and go to telegram chat") suggested,
]
close-response: "close";
extra-child: Gtk.ScrolledWindow {
hscrollbar-policy: never;
vscrollbar-policy: automatic;
height-request: 185;
Gtk.TextView{
wrap-mode: word_char;
buffer: Gtk.TextBuffer textbuffer {};
}
};
}
import webbrowser
from gi.repository import Adw, Gtk, Gdk
@Gtk.Template(resource_path='/ru.ximperlinux.TuneIt/settings/widgets/error_dialog.ui')
class TuneItErrorDialog(Adw.AlertDialog):
__gtype_name__ = "TuneItErrorDialog"
textbuffer = Gtk.Template.Child()
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.connect('response', self.on_response)
def on_response(self, _, response):
if response == 'copy':
self.on_copy()
def on_copy(self):
self.copy_error()
webbrowser.open("https://t.me/tuneit")
def copy_error(self):
display = Gdk.Display.get_default()
clipboard = display.get_clipboard()
clipboard.set(self.textbuffer.get_text(
self.textbuffer.get_start_iter(),
self.textbuffer.get_end_iter(),
False
))
......@@ -4,6 +4,7 @@
<file preprocess="xml-stripblanks">window.ui</file>
<file preprocess="xml-stripblanks">settings/widgets/panel_row.ui</file>
<file preprocess="xml-stripblanks">settings/widgets/deps_alert_dialog.ui</file>
<file preprocess="xml-stripblanks">settings/widgets/error_dialog.ui</file>
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
</gresource>
</gresources>
......@@ -17,11 +17,13 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later
import threading
import threading, traceback
from gi.repository import GObject, Adw, Gtk, GLib
from .settings.main import init_settings_stack
from .settings.widgets.error_dialog import TuneItErrorDialog
@Gtk.Template(resource_path='/ru.ximperlinux.TuneIt/window.ui')
class TuneitWindow(Adw.ApplicationWindow):
__gtype_name__ = 'TuneitWindow'
......@@ -36,6 +38,8 @@ class TuneitWindow(Adw.ApplicationWindow):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.error_dialog = TuneItErrorDialog()
self.connect('settings_page_update', self.update_settings_page)
self.update_settings_page()
......@@ -49,8 +53,15 @@ class TuneitWindow(Adw.ApplicationWindow):
Можно вызвать вот так, благодаря сигналу:
self.settings_pagestack.get_root().emit("settings_page_update")
"""
try:
init_settings_stack(
self.settings_pagestack,
self.settings_listbox,
self.settings_split_view,
)
except Exception as e:
self.error(traceback.format_exc())
def error(self, error):
self.error_dialog.textbuffer.set_text(str(error))
self.error_dialog.present(self)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment