mall cleanup; added initial plugin structure for markdown preview

This commit is contained in:
itdominator 2023-10-28 14:53:42 -05:00
parent fe28aaafb5
commit 35bc3faa70
7 changed files with 203 additions and 3 deletions

View File

@ -0,0 +1,3 @@
"""
Pligin Module
"""

View File

@ -0,0 +1,3 @@
"""
Pligin Package
"""

View File

@ -0,0 +1,13 @@
{
"manifest": {
"name": "Markdown Preview",
"author": "ITDominator",
"version": "0.0.1",
"support": "",
"requests": {
"pass_events": "true",
"pass_ui_objects": ["separator_right"],
"bind_keys": ["Markdown Preview||tggle_markdown_preview:<Shift><Control>m"]
}
}
}

View File

@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<requires lib="webkit2gtk" version="2.28"/>
<object class="GtkImage" id="settings_img">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="stock">gtk-justify-fill</property>
</object>
<object class="WebKitSettings" type-func="webkit_settings_get_type" id="web_view_settings">
<property name="enable-offline-web-application-cache">False</property>
<property name="enable-html5-local-storage">False</property>
<property name="enable-html5-database">False</property>
<property name="enable-xss-auditor">False</property>
<property name="enable-hyperlink-auditing">False</property>
<property name="enable-tabs-to-links">False</property>
<property name="enable-fullscreen">False</property>
<property name="print-backgrounds">False</property>
<property name="enable-webaudio">False</property>
<property name="enable-page-cache">False</property>
<property name="user-agent">Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Safari/605.1.15</property>
<property name="enable-accelerated-2d-canvas">True</property>
<property name="allow-file-access-from-file-urls">True</property>
<property name="allow-universal-access-from-file-urls">True</property>
<property name="enable-webrtc">True</property>
</object>
<object class="GtkPopover" id="markdown_preview_dialog">
<property name="can-focus">False</property>
<property name="modal">False</property>
<property name="transitions-enabled">False</property>
<property name="constrain-to">none</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkButtonBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="layout-style">start</property>
<child>
<object class="GtkButton">
<property name="label">gtk-media-play</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-stock">True</property>
<property name="always-show-image">True</property>
<signal name="clicked" handler="_resume_preview_updates" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label">gtk-media-pause</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-stock">True</property>
<property name="always-show-image">True</property>
<signal name="clicked" handler="_pause_preview_updates" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Settings</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">settings_img</property>
<signal name="clicked" handler="_handle_ettings" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="WebKitWebView" type-func="webkit_web_view_get_type" id="markdown_view">
<property name="width-request">200</property>
<property name="height-request">400</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="settings">web_view_settings</property>
<property name="is-ephemeral">True</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

View File

@ -0,0 +1,65 @@
# Python imports
import os
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('WebKit2', '4.0')
from gi.repository import Gtk
from gi.repository import WebKit2
# Application imports
from plugins.plugin_base import PluginBase
class Plugin(PluginBase):
def __init__(self):
super().__init__()
self.name = "Markdown Preview" # NOTE: Need to remove after establishing private bidirectional 1-1 message bus
# where self.name should not be needed for message comms
self.path = os.path.dirname(os.path.realpath(__file__))
self._GLADE_FILE = f"{self.path}/markdown_preview.glade"
WebKit2.WebView() # Need one initialized for webview to work from glade file
def run(self):
self._builder = Gtk.Builder()
self._builder.add_from_file(self._GLADE_FILE)
self._connect_builder_signals(self, self._builder)
separator_right = self._ui_objects[0]
self._markdown_dialog = self._builder.get_object("markdown_preview_dialog")
self._web_view_settings = self._builder.get_object("web_view_settings")
def generate_reference_ui_element(self):
...
def subscribe_to_events(self):
self._event_system.subscribe("tggle_markdown_preview", self._tggle_markdown_preview)
def _set_active_src_view(self, source_view):
self._active_src_view = source_view
self._buffer = self._active_src_view.get_buffer()
def _pause_preview_updates(self):
...
def _resume_preview_updates(self):
...
def _handle_ettings(self):
...
def _tggle_markdown_preview(self, widget = None, eve = None):
is_visible = self._markdown_dialog.is_visible()
buffer = self._active_src_view.get_buffer()
data = None
if not is_visible:
self._markdown_dialog.popup();
elif not data and is_visible:
self._markdown_dialog.popdown()

View File

@ -38,8 +38,6 @@ if __name__ == "__main__":
# Read arguments (If any...) # Read arguments (If any...)
args, unknownargs = parser.parse_known_args() args, unknownargs = parser.parse_known_args()
print(args)
print(unknownargs)
if args.debug == "true": if args.debug == "true":
settings_manager.set_debug(True) settings_manager.set_debug(True)

View File

@ -20,7 +20,6 @@ class Controller(SignalsMixins, ControllerData):
def __init__(self, args, unknownargs): def __init__(self, args, unknownargs):
messages = [] messages = []
for arg in unknownargs + [args.new_tab,]: for arg in unknownargs + [args.new_tab,]:
logger.debug(f"{arg}")
# NOTE: If passing line number with file split against : # NOTE: If passing line number with file split against :
if os.path.isfile(arg.replace("file://", "").split(":")[0]): if os.path.isfile(arg.replace("file://", "").split(":")[0]):
messages.append(f"FILE|{arg.replace('file://', '')}") messages.append(f"FILE|{arg.replace('file://', '')}")