move the log file viewer to its own plugin
We plan to have multiple different types of tabs.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from types import ModuleType
|
||||
from typing import Dict
|
||||
from typing import Dict, Optional
|
||||
from inspect import isclass
|
||||
from pkgutil import iter_modules
|
||||
from pathlib import Path
|
||||
@@ -46,11 +46,11 @@ class PluginRegistry():
|
||||
return PluginRegistry.modules.copy()
|
||||
|
||||
@staticmethod
|
||||
def executeSingle(function_name: str, *args):
|
||||
def execute_single(function_name: str, *args) -> Optional[any]:
|
||||
return PluginRegistry._execute(function_name, True, *args)
|
||||
|
||||
@staticmethod
|
||||
def execute(function_name: str, *args) -> []:
|
||||
def execute(function_name: str, *args) -> [any]:
|
||||
return PluginRegistry._execute(function_name, False, *args)
|
||||
|
||||
@staticmethod
|
||||
|
||||
38
raven/plugins/logfileplugin.py
Normal file
38
raven/plugins/logfileplugin.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import os.path
|
||||
from typing import Callable, Optional
|
||||
|
||||
from PyQt6.QtWidgets import QMessageBox
|
||||
|
||||
from fulltabwidget import FullTabWidget
|
||||
from logFileModel import LogFileModel
|
||||
from raven.pluginbase import PluginBase
|
||||
from raven.plugins.ravenlog.Tab import Tab
|
||||
from settings import Settings
|
||||
|
||||
|
||||
class LogFilePlugin(PluginBase):
|
||||
def __init__(self):
|
||||
super(LogFilePlugin, self).__init__()
|
||||
self.settings = None
|
||||
self.tr = None
|
||||
|
||||
def set_settings(self, settings: Settings):
|
||||
self.settings = settings
|
||||
|
||||
def set_translator(self, tr: Callable[[str], str]):
|
||||
self.tr = tr
|
||||
|
||||
def create_tab(self, file: str) -> Optional[Tab]:
|
||||
if not os.path.isfile(file):
|
||||
message = QMessageBox(QMessageBox.Icon.Warning, "File not found",
|
||||
"'%s' is not a file or cannot be opened" % file)
|
||||
message.exec()
|
||||
return None
|
||||
|
||||
realpath = os.path.realpath(file)
|
||||
filename = os.path.basename(realpath)
|
||||
|
||||
model = LogFileModel(file, self.settings)
|
||||
tab = FullTabWidget(model, unique_id=realpath, title=filename)
|
||||
|
||||
return tab
|
||||
@@ -1,6 +1,6 @@
|
||||
import os
|
||||
from typing import Callable
|
||||
|
||||
from pathlib import Path
|
||||
from PyQt6.QtGui import QAction, QIcon
|
||||
from PyQt6.QtWidgets import QMenu, QFileDialog
|
||||
|
||||
@@ -41,8 +41,8 @@ class OpenFilePlugin(PluginBase):
|
||||
]
|
||||
|
||||
def _open_file_dialog(self) -> None:
|
||||
current_file = PluginRegistry.executeSingle("current_file")
|
||||
directory = os.path.dirname(current_file) if current_file else ''
|
||||
current_file = PluginRegistry.execute_single("current_file")
|
||||
directory = os.path.dirname(current_file) if current_file else os.path.join(Path.home())
|
||||
|
||||
dialog = QFileDialog()
|
||||
(selected_file, _filter) = dialog.getOpenFileName(
|
||||
@@ -53,12 +53,14 @@ class OpenFilePlugin(PluginBase):
|
||||
self._open_file(selected_file)
|
||||
|
||||
def _open_file(self, selected_file: str):
|
||||
PluginRegistry.executeSingle("create_tab", selected_file)
|
||||
self._remember_recent_file(selected_file)
|
||||
tab = PluginRegistry.execute_single("create_tab", selected_file)
|
||||
if tab:
|
||||
PluginRegistry.execute_single("add_tab", tab)
|
||||
PluginRegistry.execute("after_open_file", selected_file)
|
||||
|
||||
def _get_recent_files(self) -> [str]:
|
||||
recent_files = self.settings.session.get('general', 'recent_files', fallback='')
|
||||
print(recent_files)
|
||||
# print(recent_files)
|
||||
files = recent_files.split(os.pathsep)
|
||||
if "" in files:
|
||||
files.remove("")
|
||||
|
||||
23
raven/plugins/ravenlog/Tab.py
Normal file
23
raven/plugins/ravenlog/Tab.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from abc import abstractmethod
|
||||
|
||||
from PyQt6.QtWidgets import QWidget
|
||||
|
||||
|
||||
class Tab(QWidget):
|
||||
|
||||
def __init__(self, unique_id: str, title: str):
|
||||
super(Tab, self).__init__()
|
||||
self.unique_id = unique_id
|
||||
self.title = title
|
||||
|
||||
@abstractmethod
|
||||
def get_status_text(self) -> str:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_file(self) -> str:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def destruct(self):
|
||||
pass
|
||||
0
raven/plugins/ravenlog/__init__.py
Normal file
0
raven/plugins/ravenlog/__init__.py
Normal file
@@ -8,6 +8,7 @@ from raven.pluginbase import PluginBase
|
||||
from raven.pluginregistry import PluginRegistry
|
||||
from raven.plugins.domain.menucontribution import MenuContribution
|
||||
from raven.plugins.domain.raction import RAction
|
||||
from raven.plugins.ravenlog.Tab import Tab
|
||||
|
||||
|
||||
class RavenLogPlugin(PluginBase):
|
||||
@@ -29,9 +30,8 @@ class RavenLogPlugin(PluginBase):
|
||||
def current_file(self) -> Optional[str]:
|
||||
return self.main_window.tabs.current_file()
|
||||
|
||||
def create_tab(self, file: str):
|
||||
self.main_window.tabs.create_tab(file)
|
||||
PluginRegistry.execute("after_open_file", file)
|
||||
def add_tab(self, tab: Tab):
|
||||
self.main_window.tabs.add_tab(tab)
|
||||
|
||||
def _action_about(self) -> RAction:
|
||||
about_action = RAction(
|
||||
|
||||
Reference in New Issue
Block a user