| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
from PyQt6.QtWidgets import * |
| 9 |
from PyQt6.QtGui import * |
| 10 |
from PyQt6.QtCore import * |
| 11 |
|
| 12 |
class GenericResItem(QTreeWidgetItem): |
| 13 |
def __init__(self, li): |
| 14 |
QTreeWidgetItem.__init__(self, li) |
| 15 |
def column_val(self, col): |
| 16 |
return str(self.data(col, Qt.ItemDataRole.DisplayRole).toString()) |
| 17 |
def line_val(self): |
| 18 |
return (int(self.column_val(1))) |
| 19 |
|
| 20 |
class GenericRes(QTreeWidget): |
| 21 |
def __init__(self, parent=None): |
| 22 |
QTreeWidget.__init__(self) |
| 23 |
|
| 24 |
self.setColumnCount(1) |
| 25 |
self.setHeaderLabels(['Result']) |
| 26 |
|
| 27 |
|
| 28 |
self.setMinimumWidth(50) |
| 29 |
|
| 30 |
self.setFont(QFont("San Serif", 8)) |
| 31 |
|
| 32 |
self.setIndentation(-2) |
| 33 |
|
| 34 |
self.setAllColumnsShowFocus(True) |
| 35 |
|
| 36 |
def add_result(self, res): |
| 37 |
for line in res: |
| 38 |
item = GenericResItem([line]) |
| 39 |
self.addTopLevelItem(item) |
| 40 |
|
| 41 |
class GenericFileCmdPage(QWidget): |
| 42 |
sig_goto_line = pyqtSignal(int) |
| 43 |
|
| 44 |
def __init__(self, parent=None): |
| 45 |
QWidget.__init__(self) |
| 46 |
self.ct = GenericRes(self) |
| 47 |
vlay = QVBoxLayout() |
| 48 |
|
| 49 |
|
| 50 |
vlay.addWidget(self.ct) |
| 51 |
self.setLayout(vlay) |
| 52 |
|
| 53 |
self.ct.itemActivated.connect(self.ct_itemActivated) |
| 54 |
|
| 55 |
def ct_itemActivated(self, item): |
| 56 |
try: |
| 57 |
line = int(str(item.data(1, Qt.ItemDataRole.DisplayRole).toString())) |
| 58 |
except: |
| 59 |
return |
| 60 |
self.sig_goto_line.emit(line) |
| 61 |
|
| 62 |
@staticmethod |
| 63 |
def run_plugin(cmd, filename, parent): |
| 64 |
if '%f' in cmd: |
| 65 |
args = cmd.replace('%f', filename) |
| 66 |
args = args.strip().split() |
| 67 |
else: |
| 68 |
args = cmd.strip().split() |
| 69 |
args.append(filename) |
| 70 |
import subprocess |
| 71 |
try: |
| 72 |
proc = subprocess.Popen(args, stdout=subprocess.PIPE) |
| 73 |
(res, err_data) = proc.communicate() |
| 74 |
res = res.decode() |
| 75 |
except Exception as e: |
| 76 |
res = '%s\n%s' % (' '.join(args), str(e)) |
| 77 |
import re |
| 78 |
res = [ x.strip() for x in re.split(r'\r?\n', res.strip()) ] |
| 79 |
|
| 80 |
page = GenericFileCmdPage(parent) |
| 81 |
page.cmd = cmd |
| 82 |
|
| 83 |
page.ct.add_result(res) |
| 84 |
parent.add_page(page, cmd) |
| 85 |
|
| 86 |
def cmd_name(): |
| 87 |
cmd_list = [ |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
] |
| 92 |
import os |
| 93 |
cmd = os.getenv('SEASCOPE_FC_CUSTOM_CMD') |
| 94 |
if cmd: |
| 95 |
cmd_list += [ x.strip() for x in cmd.split(';') ] |
| 96 |
return list(set(cmd_list)) |
| 97 |
|
| 98 |
def run(filename, parent, cmd=None): |
| 99 |
if cmd: |
| 100 |
cmd_list = [ cmd ] |
| 101 |
else: |
| 102 |
cmd_list = cmd_name() |
| 103 |
for cmd in cmd_list: |
| 104 |
GenericFileCmdPage.run_plugin(cmd, filename, parent) |