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

init error dialog

parent fd20e820
...@@ -29,6 +29,9 @@ from .window import TuneitWindow ...@@ -29,6 +29,9 @@ from .window import TuneitWindow
def get_main_window(): def get_main_window():
return _application.props.active_window return _application.props.active_window
def get_error():
return _application.props.active_window.error
class TuneitApplication(Adw.Application): class TuneitApplication(Adw.Application):
"""The main application singleton class.""" """The main application singleton class."""
......
import traceback
from .module import Module from .module import Module
from .page import Page from .page import Page
from .sections import SectionFactory from .sections import SectionFactory
...@@ -24,54 +25,63 @@ def init_settings_stack(stack, listbox, split_view): ...@@ -24,54 +25,63 @@ def init_settings_stack(stack, listbox, split_view):
print("First init...") print("First init...")
for module_data in yaml_data: for module_data in yaml_data:
deps_results = dep_manager.verify_deps(module_data.get('deps', {}))
conflicts_results = dep_manager.verify_conflicts(module_data.get('conflicts', {}))
deps_message = dep_manager.format_results(deps_results)
conflicts_message = dep_manager.format_results(conflicts_results)
all_deps_ok = all(r['success'] for r in deps_results)
all_conflicts_ok = all(r['success'] for r in conflicts_results)
if all_deps_ok and all_conflicts_ok:
print("Deps: OK")
else:
dialog = TuneItDepsAlertDialog()
dialog.set_body(module_data['name'])
dialog.deps_message_textbuffer.set_text(
f"{deps_message}\n{conflicts_message}"
)
response = dialog.user_question(listbox.get_root())
print(f"RESPONSE: {response}")
if response == "skip":
break
module = Module(module_data) module = Module(module_data)
modules_dict[module.name] = module
for section_data in module_data.get('sections', []): try:
page_name = module.get_translation(section_data.get('page', 'Default')) deps_results = dep_manager.verify_deps(module_data.get('deps', {}))
module_page_name = section_data.get('page', 'Default') conflicts_results = dep_manager.verify_conflicts(module_data.get('conflicts', {}))
print(module_page_name)
if page_name not in pages_dict: deps_message = dep_manager.format_results(deps_results)
conflicts_message = dep_manager.format_results(conflicts_results)
page_info = ( all_deps_ok = all(r['success'] for r in deps_results)
module.pages.get(f"_{module_page_name}", {}) all_conflicts_ok = all(r['success'] for r in conflicts_results)
or module.pages.get(module_page_name, {})
) if all_deps_ok and all_conflicts_ok:
print("Deps: OK")
else:
dialog = TuneItDepsAlertDialog()
dialog.set_body(module_data['name'])
page = Page( dialog.deps_message_textbuffer.set_text(
name=page_name, f"{deps_message}\n{conflicts_message}"
icon=page_info.get('icon'),
) )
pages_dict[page_name] = page
response = dialog.user_question(listbox.get_root())
print(f"RESPONSE: {response}")
if response == "skip":
break
modules_dict[module.name] = module
for section_data in module_data.get('sections', []):
page_name = module.get_translation(section_data.get('page', 'Default'))
module_page_name = section_data.get('page', 'Default')
print(module_page_name)
if page_name not in pages_dict:
page_info = (
module.pages.get(f"_{module_page_name}", {})
or module.pages.get(module_page_name, {})
)
page = Page(
name=page_name,
icon=page_info.get('icon'),
)
pages_dict[page_name] = page
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}"
section = section_factory.create_section(section_data, module) error(e)
pages_dict[page_name].add_section(section)
pages = list(pages_dict.values()) pages = list(pages_dict.values())
for page in pages: 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 @@ ...@@ -4,6 +4,7 @@
<file preprocess="xml-stripblanks">window.ui</file> <file preprocess="xml-stripblanks">window.ui</file>
<file preprocess="xml-stripblanks">settings/widgets/panel_row.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/deps_alert_dialog.ui</file>
<file preprocess="xml-stripblanks">settings/widgets/error_dialog.ui</file>
<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file> <file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
</gresource> </gresource>
</gresources> </gresources>
...@@ -17,11 +17,13 @@ ...@@ -17,11 +17,13 @@
# #
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
import threading import threading, traceback
from gi.repository import GObject, Adw, Gtk, GLib from gi.repository import GObject, Adw, Gtk, GLib
from .settings.main import init_settings_stack from .settings.main import init_settings_stack
from .settings.widgets.error_dialog import TuneItErrorDialog
@Gtk.Template(resource_path='/ru.ximperlinux.TuneIt/window.ui') @Gtk.Template(resource_path='/ru.ximperlinux.TuneIt/window.ui')
class TuneitWindow(Adw.ApplicationWindow): class TuneitWindow(Adw.ApplicationWindow):
__gtype_name__ = 'TuneitWindow' __gtype_name__ = 'TuneitWindow'
...@@ -36,6 +38,8 @@ class TuneitWindow(Adw.ApplicationWindow): ...@@ -36,6 +38,8 @@ class TuneitWindow(Adw.ApplicationWindow):
def __init__(self, **kwargs): def __init__(self, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
self.error_dialog = TuneItErrorDialog()
self.connect('settings_page_update', self.update_settings_page) self.connect('settings_page_update', self.update_settings_page)
self.update_settings_page() self.update_settings_page()
...@@ -49,8 +53,15 @@ class TuneitWindow(Adw.ApplicationWindow): ...@@ -49,8 +53,15 @@ class TuneitWindow(Adw.ApplicationWindow):
Можно вызвать вот так, благодаря сигналу: Можно вызвать вот так, благодаря сигналу:
self.settings_pagestack.get_root().emit("settings_page_update") self.settings_pagestack.get_root().emit("settings_page_update")
""" """
init_settings_stack( try:
self.settings_pagestack, init_settings_stack(
self.settings_listbox, self.settings_pagestack,
self.settings_split_view, 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