1717#
1818# SPDX-License-Identifier: GPL-3.0-or-later
1919
20- from gi .repository import Adw , Gtk , Gio , GObject
20+ import logging
21+ from gi .repository import Adw , Gtk , Gio
2122from scriptorium .models import Chapter
2223from scriptorium .globals import BASE
23- import logging
24+
25+ try :
26+ from gi .repository import WebKit
27+ HAVE_WEBKIT = True
28+ except ImportError :
29+ HAVE_WEBKIT = False
2430
2531logger = logging .getLogger (__name__ )
2632
@@ -33,7 +39,7 @@ class ScrptFormattingPanel(Adw.NavigationPage):
3339 __icon_name__ = "open-book-symbolic"
3440 __description__ = "Preview and modify the formatting"
3541
36- web_view = Gtk .Template .Child ()
42+ web_view_placeholder = Gtk .Template .Child ()
3743 button_next = Gtk .Template .Child ()
3844 button_previous = Gtk .Template .Child ()
3945 chapters_drop_down = Gtk .Template .Child ()
@@ -42,6 +48,29 @@ def __init__(self, editor, **kwargs):
4248 super ().__init__ (** kwargs )
4349 self ._editor = editor
4450
51+ # If we have WebKit set the component, otherwise show placeholder
52+ if HAVE_WEBKIT :
53+ logger .info ("Webkit is available" )
54+ self .web_view = WebKit .WebView ()
55+ self .web_view .set_zoom_level (1 )
56+ self .web_view .set_margin_start (6 )
57+ self .web_view .set_margin_end (6 )
58+ self .web_view .set_margin_top (6 )
59+ self .web_view .set_margin_bottom (6 )
60+ self .web_view .set_vexpand (True )
61+ self .web_view .set_hexpand (True )
62+ self .web_view_placeholder .append (self .web_view )
63+ else :
64+ widget = Adw .StatusPage (
65+ title = "Not available" ,
66+ icon_name = "process-stop-symbolic" ,
67+ description = "This feature is not available on your operating system"
68+ )
69+ widget .set_vexpand (True )
70+ widget .set_hexpand (True )
71+ self .web_view_placeholder .append (widget )
72+
73+
4574 self .chapters_drop_down .connect (
4675 "notify::selected-item" ,
4776 self .on_selected_item
@@ -57,6 +86,7 @@ def __init__(self, editor, **kwargs):
5786
5887 self ._position = 0
5988
89+
6090 def on_selected_item (self , _drop_down , _selected_item ):
6191 selected_chapter = _drop_down .get_selected_item ()
6292 if selected_chapter is None :
@@ -77,7 +107,8 @@ def on_selected_item(self, _drop_down, _selected_item):
77107 html_content = html_content .replace ("{content}" , content )
78108
79109 # Load the content
80- self .web_view .load_html (html_content )
110+ if HAVE_WEBKIT :
111+ self .web_view .load_html (html_content )
81112
82113 # Find the position of the chapter
83114 chapters = self ._editor .project .manuscript .chapters
0 commit comments