graphviz-code-viewer 0.1.0__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/PKG-INFO +1 -1
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/about.py +1 -1
- graphviz_code_viewer-0.1.2/graphviz_code_viewer/modules/configure.py +76 -0
- graphviz_code_viewer-0.1.2/graphviz_code_viewer/modules/resources.py +15 -0
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/modules/wabout.py +7 -3
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/program.py +274 -53
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer.egg-info/PKG-INFO +1 -1
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer.egg-info/SOURCES.txt +1 -0
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/pyproject.toml +1 -1
- graphviz_code_viewer-0.1.0/graphviz_code_viewer/modules/configure.py +0 -33
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/LICENSE +0 -0
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/README.md +0 -0
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/__init__.py +0 -0
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/desktop.py +0 -0
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/icons/logo.png +0 -0
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/modules/__init__.py +0 -0
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/program.old.py +0 -0
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer.egg-info/dependency_links.txt +0 -0
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer.egg-info/entry_points.txt +0 -0
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer.egg-info/requires.txt +0 -0
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer.egg-info/top_level.txt +0 -0
- {graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: graphviz_code_viewer
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Program to edit and view Graphviz code.
|
|
5
5
|
Author-email: Fernando Pujaico Rivera <fernando.pujaico.rivera@gmail.com>
|
|
6
6
|
Maintainer-email: Fernando Pujaico Rivera <fernando.pujaico.rivera@gmail.com>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def merge_defaults(config, defaults):
|
|
6
|
+
"""
|
|
7
|
+
Adiciona valores de defaults que não existam em config.
|
|
8
|
+
Funciona recursivamente para dicionários aninhados.
|
|
9
|
+
"""
|
|
10
|
+
changed = False
|
|
11
|
+
|
|
12
|
+
for key, value in defaults.items():
|
|
13
|
+
if key not in config:
|
|
14
|
+
config[key] = value
|
|
15
|
+
changed = True
|
|
16
|
+
elif isinstance(value, dict) and isinstance(config[key], dict):
|
|
17
|
+
if merge_defaults(config[key], value):
|
|
18
|
+
changed = True
|
|
19
|
+
|
|
20
|
+
return changed
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def verify_default_config(path, default_content=None):
|
|
24
|
+
"""
|
|
25
|
+
Garante que o arquivo JSON exista e contenha todas as chaves
|
|
26
|
+
definidas em default_content.
|
|
27
|
+
Se faltar alguma chave, adiciona com valor padrão.
|
|
28
|
+
"""
|
|
29
|
+
if default_content is None:
|
|
30
|
+
default_content = {}
|
|
31
|
+
|
|
32
|
+
# Garante que os diretórios existam
|
|
33
|
+
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
34
|
+
|
|
35
|
+
config = {}
|
|
36
|
+
|
|
37
|
+
# Se o arquivo existir, tenta carregar
|
|
38
|
+
if os.path.exists(path):
|
|
39
|
+
try:
|
|
40
|
+
with open(path, 'r', encoding='utf-8') as f:
|
|
41
|
+
config = json.load(f)
|
|
42
|
+
except json.JSONDecodeError:
|
|
43
|
+
print("Arquivo corrompido. Recriando com defaults.")
|
|
44
|
+
config = {}
|
|
45
|
+
else:
|
|
46
|
+
print("Arquivo não existe. Criando com defaults.")
|
|
47
|
+
|
|
48
|
+
# Verifica e adiciona chaves faltantes
|
|
49
|
+
changed = merge_defaults(config, default_content)
|
|
50
|
+
|
|
51
|
+
# Se arquivo não existia ou houve mudança, salva
|
|
52
|
+
if not os.path.exists(path) or changed:
|
|
53
|
+
with open(path, 'w', encoding='utf-8') as f:
|
|
54
|
+
json.dump(config, f, ensure_ascii=False, indent=4)
|
|
55
|
+
|
|
56
|
+
return config
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def load_config(config_path, default_content=None):
|
|
60
|
+
"""
|
|
61
|
+
Carrega o JSON de configuração garantindo defaults.
|
|
62
|
+
"""
|
|
63
|
+
return verify_default_config(config_path, default_content)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def save_config(path, content):
|
|
67
|
+
"""
|
|
68
|
+
Cria o arquivo JSON no caminho especificado com conteúdo padrão,
|
|
69
|
+
criando diretórios intermediários se necessário.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
# Garante que os diretórios existam
|
|
73
|
+
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
74
|
+
with open(path, 'w', encoding='utf-8') as f:
|
|
75
|
+
json.dump(content, f, ensure_ascii=False, indent=4)
|
|
76
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
# self.icon_path = resource_path("icons", "logo.png")
|
|
5
|
+
|
|
6
|
+
def resource_path(*parts):
|
|
7
|
+
if hasattr(sys, "_MEIPASS"):
|
|
8
|
+
base = sys._MEIPASS
|
|
9
|
+
else:
|
|
10
|
+
# sobe de modules → stock_viewer
|
|
11
|
+
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
12
|
+
|
|
13
|
+
return os.path.join(base, *parts)
|
|
14
|
+
|
|
15
|
+
|
{graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/modules/wabout.py
RENAMED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from PyQt5.QtWidgets import QDialog, QLabel, QPushButton, QVBoxLayout
|
|
2
2
|
from PyQt5.QtGui import QPixmap
|
|
3
3
|
from PyQt5.QtCore import Qt
|
|
4
|
+
import os
|
|
4
5
|
|
|
5
6
|
class AboutWindow(QDialog):
|
|
6
7
|
"""About dialog window"""
|
|
@@ -14,9 +15,12 @@ class AboutWindow(QDialog):
|
|
|
14
15
|
|
|
15
16
|
# Logo
|
|
16
17
|
logo_label = QLabel()
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
if os.path.exists(logo_path):
|
|
19
|
+
pixmap = QPixmap(logo_path)
|
|
20
|
+
pixmap = pixmap.scaled(100, 100, Qt.KeepAspectRatio, Qt.SmoothTransformation)
|
|
21
|
+
logo_label.setPixmap(pixmap)
|
|
22
|
+
else:
|
|
23
|
+
logo_label.setText(logo_path)
|
|
20
24
|
logo_label.setAlignment(Qt.AlignCenter)
|
|
21
25
|
layout.addWidget(logo_label)
|
|
22
26
|
|
|
@@ -5,10 +5,11 @@ import subprocess
|
|
|
5
5
|
import tempfile
|
|
6
6
|
import os
|
|
7
7
|
import signal
|
|
8
|
+
import shutil
|
|
8
9
|
|
|
9
10
|
from PyQt5.QtWidgets import (
|
|
10
|
-
QApplication, QMainWindow, QPlainTextEdit, QLabel, QSplitter, QToolBar,
|
|
11
|
-
QAction, QVBoxLayout, QWidget, QProgressBar, QFileDialog, QScrollArea, QMessageBox, QSizePolicy
|
|
11
|
+
QApplication, QMainWindow, QPlainTextEdit, QLabel, QSplitter, QToolBar, QHBoxLayout,
|
|
12
|
+
QAction, QVBoxLayout, QWidget, QProgressBar, QFileDialog, QScrollArea, QMessageBox, QSizePolicy, QLineEdit
|
|
12
13
|
)
|
|
13
14
|
from PyQt5.QtGui import QSyntaxHighlighter, QTextCharFormat, QColor, QFont, QPixmap, QIcon, QDesktopServices
|
|
14
15
|
from PyQt5.QtCore import Qt, QThread, pyqtSignal, QUrl
|
|
@@ -16,19 +17,21 @@ from PyQt5.QtCore import Qt, QThread, pyqtSignal, QUrl
|
|
|
16
17
|
from PyQt5.QtSvg import QSvgRenderer
|
|
17
18
|
from PyQt5.QtGui import QPainter
|
|
18
19
|
from PyQt5.QtCore import QSize
|
|
20
|
+
from PyQt5.QtWidgets import QShortcut
|
|
21
|
+
from PyQt5.QtGui import QKeySequence, QTextDocument
|
|
22
|
+
|
|
19
23
|
|
|
20
24
|
import graphviz_code_viewer.about as about
|
|
21
25
|
import graphviz_code_viewer.modules.configure as configure
|
|
22
26
|
from graphviz_code_viewer.desktop import create_desktop_file, create_desktop_directory, create_desktop_menu
|
|
23
27
|
from graphviz_code_viewer.modules.wabout import show_about_window
|
|
28
|
+
from graphviz_code_viewer.modules.resources import resource_path
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
# ------------------------------------------------------------------------------
|
|
26
31
|
# Path to config file
|
|
27
32
|
CONFIG_PATH = os.path.join(os.path.expanduser("~"),".config",about.__package__,"config.json")
|
|
28
33
|
|
|
29
34
|
DEFAULT_CONTENT={ "error_loading_svg": "Error loading SVG file",
|
|
30
|
-
"font_size": 11,
|
|
31
|
-
"font_name": "Courier",
|
|
32
35
|
"window_width": 1200,
|
|
33
36
|
"window_height": 700,
|
|
34
37
|
"action_compile":"Compile",
|
|
@@ -40,13 +43,16 @@ DEFAULT_CONTENT={ "error_loading_svg": "Error loading SVG file",
|
|
|
40
43
|
"action_saveas":"Save as",
|
|
41
44
|
"action_saveas_tooltip": "Save the DOT file as",
|
|
42
45
|
"action_saveimg":"Save image",
|
|
43
|
-
"action_saveimg_tooltip": "Save the output image",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
+
"action_saveimg_tooltip": "Save the output as binary or vector image (SVG,PNG,PDF)",
|
|
47
|
+
"action_configure_window": "Conf. window",
|
|
48
|
+
"action_configure_window_tooltip": "Open the configure window Json file",
|
|
49
|
+
"action_configure_editor": "Conf. Editor",
|
|
50
|
+
"action_configure_editor_tooltip": "Open the configure editor Json file",
|
|
46
51
|
"action_about": "About",
|
|
47
52
|
"action_about_tooltip": "About the program",
|
|
48
53
|
"action_coffee": "Coffee",
|
|
49
54
|
"action_coffee_tooltip": "Buy me a coffee (TrucomanX)",
|
|
55
|
+
"file_path": "File path:",
|
|
50
56
|
"warning":"Warning",
|
|
51
57
|
"no_image_available":"No image available to save. Compile the code first.",
|
|
52
58
|
"save_image":"Save image",
|
|
@@ -64,12 +70,35 @@ DEFAULT_CONTENT={ "error_loading_svg": "Error loading SVG file",
|
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
configure.verify_default_config(CONFIG_PATH,default_content=DEFAULT_CONTENT)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
CONFIG=configure.load_config(CONFIG_PATH,default_content=DEFAULT_CONTENT)
|
|
74
|
+
|
|
75
|
+
# ------------------------------------------------------------------------------
|
|
76
|
+
|
|
77
|
+
CONFIG_EDITOR_PATH = os.path.join(os.path.expanduser("~"),".config",about.__package__,"config_editor.json")
|
|
78
|
+
|
|
79
|
+
DEFAULT_EDITOR_CONTENT= { "font_size": 11,
|
|
80
|
+
"font_name": "Monospace",
|
|
81
|
+
"save_file": "Ctrl+S",
|
|
82
|
+
"find_text": "Ctrl+F",
|
|
83
|
+
"syntax_rules": {
|
|
84
|
+
"digraph": {"color": "blue", "bold": True},
|
|
85
|
+
"->": {"color": "darkRed", "bold": True},
|
|
86
|
+
"=": {"color": "darkGreen", "bold": True},
|
|
87
|
+
"\"": {"color": "darkMagenta", "bold": True},
|
|
88
|
+
"[": {"color": "black", "bold": True},
|
|
89
|
+
"]": {"color": "black", "bold": True},
|
|
90
|
+
"{": {"color": "darkGreen", "bold": True},
|
|
91
|
+
"}": {"color": "darkGreen", "bold": True},
|
|
92
|
+
";": {"color": "darkGray", "bold": True}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
configure.verify_default_config(CONFIG_EDITOR_PATH,default_content=DEFAULT_EDITOR_CONTENT)
|
|
97
|
+
CONFIG_EDITOR=configure.load_config(CONFIG_EDITOR_PATH,default_content=DEFAULT_EDITOR_CONTENT)
|
|
98
|
+
|
|
99
|
+
# ------------------------------------------------------------------------------
|
|
71
100
|
# Syntax Highlighter
|
|
72
|
-
#
|
|
101
|
+
# ------------------------------------------------------------------------------
|
|
73
102
|
class GraphvizHighlighter(QSyntaxHighlighter):
|
|
74
103
|
def __init__(self, parent, rules_dict):
|
|
75
104
|
super().__init__(parent)
|
|
@@ -89,12 +118,12 @@ class GraphvizHighlighter(QSyntaxHighlighter):
|
|
|
89
118
|
self.setFormat(index, length, fmt)
|
|
90
119
|
index = text.find(keyword, index + length)
|
|
91
120
|
|
|
92
|
-
#
|
|
121
|
+
# ------------------------------------------------------------------------------
|
|
93
122
|
# Worker thread para compilar Graphviz
|
|
94
|
-
#
|
|
123
|
+
# ------------------------------------------------------------------------------
|
|
95
124
|
class CompileThread(QThread):
|
|
96
125
|
progress = pyqtSignal(int)
|
|
97
|
-
finished = pyqtSignal(str)
|
|
126
|
+
finished = pyqtSignal(str, str) # (output_file, error_message)
|
|
98
127
|
|
|
99
128
|
def __init__(self, dot_code, output_file):
|
|
100
129
|
super().__init__()
|
|
@@ -111,24 +140,28 @@ class CompileThread(QThread):
|
|
|
111
140
|
with open(tmp_dot, "w") as f:
|
|
112
141
|
f.write(self.dot_code)
|
|
113
142
|
self.progress.emit(50)
|
|
143
|
+
|
|
114
144
|
try:
|
|
115
|
-
subprocess.run(
|
|
145
|
+
result = subprocess.run(
|
|
116
146
|
["dot", "-Tsvg", tmp_dot, "-o", self.output_file],
|
|
117
|
-
check=True
|
|
147
|
+
check=True,
|
|
148
|
+
capture_output=True,
|
|
149
|
+
text=True
|
|
118
150
|
)
|
|
119
151
|
self.progress.emit(100)
|
|
120
|
-
self.finished.emit(self.output_file)
|
|
121
|
-
except subprocess.CalledProcessError:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
os.
|
|
152
|
+
self.finished.emit(self.output_file, "") # sucesso, sem erro
|
|
153
|
+
except subprocess.CalledProcessError as e:
|
|
154
|
+
error_msg = e.stderr if e.stderr else "Erro desconhecido ao rodar o Graphviz"
|
|
155
|
+
self.finished.emit("", error_msg)
|
|
156
|
+
finally:
|
|
157
|
+
if os.path.exists(tmp_dot):
|
|
158
|
+
os.remove(tmp_dot)
|
|
126
159
|
|
|
127
160
|
|
|
128
|
-
# ---------------------------
|
|
129
|
-
# Widget da imagem com zoom/move
|
|
130
|
-
# ---------------------------
|
|
131
161
|
|
|
162
|
+
# ------------------------------------------------------------------------------
|
|
163
|
+
# Widget da imagem com zoom/move
|
|
164
|
+
# ------------------------------------------------------------------------------
|
|
132
165
|
|
|
133
166
|
class SvgViewer(QScrollArea):
|
|
134
167
|
def __init__(self):
|
|
@@ -195,9 +228,57 @@ class SvgViewer(QScrollArea):
|
|
|
195
228
|
class TextEditor(QPlainTextEdit):
|
|
196
229
|
def __init__(self):
|
|
197
230
|
super().__init__()
|
|
198
|
-
self.setFont(QFont(
|
|
231
|
+
self.setFont(QFont(CONFIG_EDITOR["font_name"], CONFIG_EDITOR["font_size"]))
|
|
199
232
|
self.zoom_factor = 1.0
|
|
200
233
|
|
|
234
|
+
# Não quebrar linhas
|
|
235
|
+
self.setLineWrapMode(QPlainTextEdit.NoWrap)
|
|
236
|
+
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
|
|
237
|
+
|
|
238
|
+
# Filtro de busca
|
|
239
|
+
self.search_bar = QLineEdit(self)
|
|
240
|
+
self.search_bar.setPlaceholderText("Buscar...")
|
|
241
|
+
self.search_bar.setFixedHeight(24)
|
|
242
|
+
self.search_bar.hide()
|
|
243
|
+
self.search_bar.textChanged.connect(self.highlight_search)
|
|
244
|
+
self.search_bar.installEventFilter(self) # Para capturar Enter/Esc na barra
|
|
245
|
+
|
|
246
|
+
self.search_format = QTextCharFormat()
|
|
247
|
+
self.search_format.setBackground(QColor("yellow"))
|
|
248
|
+
|
|
249
|
+
self.setAcceptDrops(True)
|
|
250
|
+
|
|
251
|
+
def dragEnterEvent(self, event):
|
|
252
|
+
if event.mimeData().hasUrls():
|
|
253
|
+
event.acceptProposedAction()
|
|
254
|
+
else:
|
|
255
|
+
super().dragEnterEvent(event)
|
|
256
|
+
|
|
257
|
+
def dropEvent(self, event):
|
|
258
|
+
mime = event.mimeData()
|
|
259
|
+
|
|
260
|
+
if mime.hasUrls():
|
|
261
|
+
for url in mime.urls():
|
|
262
|
+
path = url.toLocalFile()
|
|
263
|
+
|
|
264
|
+
if os.path.isfile(path):
|
|
265
|
+
try:
|
|
266
|
+
# Tenta abrir como texto
|
|
267
|
+
with open(path, "r", encoding="utf-8") as f:
|
|
268
|
+
content = f.read()
|
|
269
|
+
#self.insertPlainText(content)
|
|
270
|
+
self.setPlainText(content)
|
|
271
|
+
except Exception:
|
|
272
|
+
# Se falhar (provável binário), insere o path
|
|
273
|
+
#self.insertPlainText(path)
|
|
274
|
+
self.setPlainText(path)
|
|
275
|
+
else:
|
|
276
|
+
self.insertPlainText(path)
|
|
277
|
+
|
|
278
|
+
event.acceptProposedAction()
|
|
279
|
+
else:
|
|
280
|
+
super().dropEvent(event)
|
|
281
|
+
|
|
201
282
|
def wheelEvent(self, event):
|
|
202
283
|
if event.modifiers() & Qt.ControlModifier:
|
|
203
284
|
angle = event.angleDelta().y()
|
|
@@ -209,6 +290,64 @@ class TextEditor(QPlainTextEdit):
|
|
|
209
290
|
else:
|
|
210
291
|
super().wheelEvent(event)
|
|
211
292
|
|
|
293
|
+
def keyPressEvent(self, event):
|
|
294
|
+
# Cria a representação textual do atalho pressionado
|
|
295
|
+
key_seq = QKeySequence(event.modifiers() | event.key()).toString()
|
|
296
|
+
|
|
297
|
+
# Lê o atalho do seu config ou usa literal
|
|
298
|
+
search_shortcut = CONFIG_EDITOR["find_text"]
|
|
299
|
+
|
|
300
|
+
if key_seq == search_shortcut:
|
|
301
|
+
self.toggle_search_bar()
|
|
302
|
+
return
|
|
303
|
+
|
|
304
|
+
super().keyPressEvent(event)
|
|
305
|
+
|
|
306
|
+
def toggle_search_bar(self):
|
|
307
|
+
if self.search_bar.isVisible():
|
|
308
|
+
self.search_bar.hide()
|
|
309
|
+
self.setFocus()
|
|
310
|
+
self.highlight_search("") # remove highlights
|
|
311
|
+
else:
|
|
312
|
+
self.search_bar.show()
|
|
313
|
+
self.search_bar.setFocus()
|
|
314
|
+
|
|
315
|
+
def highlight_search(self, text):
|
|
316
|
+
# Remove highlights anteriores
|
|
317
|
+
cursor = self.textCursor()
|
|
318
|
+
fmt_clear = QTextCharFormat()
|
|
319
|
+
cursor.select(cursor.Document)
|
|
320
|
+
cursor.setCharFormat(fmt_clear)
|
|
321
|
+
cursor.clearSelection()
|
|
322
|
+
|
|
323
|
+
if not text:
|
|
324
|
+
return
|
|
325
|
+
|
|
326
|
+
# Aplicar destaque
|
|
327
|
+
cursor = self.document().find(text, 0, QTextDocument.FindCaseSensitively)
|
|
328
|
+
while not cursor.isNull():
|
|
329
|
+
cursor.mergeCharFormat(self.search_format)
|
|
330
|
+
cursor = self.document().find(text, cursor.position(), QTextDocument.FindCaseSensitively)
|
|
331
|
+
|
|
332
|
+
def eventFilter(self, obj, event):
|
|
333
|
+
if hasattr(self, "search_bar") and obj == self.search_bar:
|
|
334
|
+
if event.type() == event.KeyPress:
|
|
335
|
+
if event.key() == Qt.Key_Escape:
|
|
336
|
+
self.toggle_search_bar()
|
|
337
|
+
return True # consome o evento
|
|
338
|
+
elif event.key() in (Qt.Key_Return, Qt.Key_Enter):
|
|
339
|
+
# Seleciona próxima ocorrência
|
|
340
|
+
text = self.search_bar.text()
|
|
341
|
+
if text:
|
|
342
|
+
cursor = self.textCursor()
|
|
343
|
+
pos = cursor.position()
|
|
344
|
+
next_cursor = self.document().find(text, pos, QTextDocument.FindCaseSensitively)
|
|
345
|
+
if not next_cursor.isNull():
|
|
346
|
+
self.setTextCursor(next_cursor)
|
|
347
|
+
return True
|
|
348
|
+
return super().eventFilter(obj, event)
|
|
349
|
+
|
|
350
|
+
|
|
212
351
|
# ---------------------------
|
|
213
352
|
# Main Window
|
|
214
353
|
# ---------------------------
|
|
@@ -232,8 +371,7 @@ class MainWindow(QMainWindow):
|
|
|
232
371
|
|
|
233
372
|
## Icon
|
|
234
373
|
# Get base directory for icons
|
|
235
|
-
|
|
236
|
-
self.icon_path = os.path.join(base_dir_path, 'icons', 'logo.png')
|
|
374
|
+
self.icon_path = resource_path("icons", "logo.png")
|
|
237
375
|
self.setWindowIcon(QIcon(self.icon_path))
|
|
238
376
|
|
|
239
377
|
|
|
@@ -244,20 +382,27 @@ class MainWindow(QMainWindow):
|
|
|
244
382
|
# Criar status bar
|
|
245
383
|
self.status = self.statusBar()
|
|
246
384
|
|
|
385
|
+
|
|
386
|
+
# --- File path bar ---
|
|
387
|
+
self.file_label = QLabel(CONFIG["file_path"])
|
|
388
|
+
self.file_path_edit = QLineEdit()
|
|
389
|
+
self.file_path_edit.setReadOnly(True)
|
|
390
|
+
|
|
391
|
+
file_bar = QWidget()
|
|
392
|
+
file_bar.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
|
|
393
|
+
#file_bar.setMaximumHeight(28)
|
|
394
|
+
file_layout = QHBoxLayout()
|
|
395
|
+
file_layout.setContentsMargins(5, 2, 5, 2)
|
|
396
|
+
|
|
397
|
+
file_layout.addWidget(self.file_label)
|
|
398
|
+
file_layout.addWidget(self.file_path_edit)
|
|
399
|
+
|
|
400
|
+
file_bar.setLayout(file_layout)
|
|
401
|
+
|
|
247
402
|
# Editor e visualizador
|
|
248
403
|
self.editor = TextEditor()
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
"->": {"color": "darkRed", "bold": True},
|
|
252
|
-
"=": {"color": "darkRed", "bold": True},
|
|
253
|
-
"\"": {"color": "darkMagenta", "bold": True},
|
|
254
|
-
"[": {"color": "black", "bold": True},
|
|
255
|
-
"]": {"color": "black", "bold": True},
|
|
256
|
-
"{": {"color": "darkGreen", "bold": True},
|
|
257
|
-
"}": {"color": "darkGreen", "bold": True},
|
|
258
|
-
";": {"color": "darkGray", "bold": True}
|
|
259
|
-
}
|
|
260
|
-
self.highlighter = GraphvizHighlighter(self.editor.document(), syntax_rules)
|
|
404
|
+
|
|
405
|
+
self.highlighter = GraphvizHighlighter(self.editor.document(), CONFIG_EDITOR["syntax_rules"])
|
|
261
406
|
self.viewer = SvgViewer()
|
|
262
407
|
|
|
263
408
|
splitter = QSplitter(Qt.Horizontal)
|
|
@@ -272,6 +417,7 @@ class MainWindow(QMainWindow):
|
|
|
272
417
|
# Layout central
|
|
273
418
|
central = QWidget()
|
|
274
419
|
layout = QVBoxLayout()
|
|
420
|
+
layout.addWidget(file_bar) # 🔥 NOVO (logo abaixo da toolbar)
|
|
275
421
|
layout.addWidget(splitter)
|
|
276
422
|
layout.addWidget(self.progress)
|
|
277
423
|
central.setLayout(layout)
|
|
@@ -279,7 +425,33 @@ class MainWindow(QMainWindow):
|
|
|
279
425
|
|
|
280
426
|
if os.path.exists(self.input_filepath):
|
|
281
427
|
self.load_dot(filepath=self.input_filepath)
|
|
428
|
+
|
|
429
|
+
save_shortcut = QShortcut(QKeySequence(CONFIG_EDITOR["save_file"]), self)
|
|
430
|
+
save_shortcut.activated.connect(lambda: self.save_dot(from_input=True, exist_ok=True))
|
|
431
|
+
|
|
432
|
+
if not self.check_graphviz():
|
|
433
|
+
sys.exit(1) # encerra o app se não tiver dot
|
|
282
434
|
|
|
435
|
+
def check_graphviz(self):
|
|
436
|
+
dot_path = shutil.which("dot")
|
|
437
|
+
|
|
438
|
+
if dot_path is None:
|
|
439
|
+
QMessageBox.critical(
|
|
440
|
+
self,
|
|
441
|
+
"Graphviz not found",
|
|
442
|
+
"The executable 'dot' (Graphviz) was not found on the system.\n\n"
|
|
443
|
+
"Install Graphviz and make sure the 'dot' command is in the PATH.\n\n"
|
|
444
|
+
"Example:\n"
|
|
445
|
+
" Linux: sudo apt install graphviz\n"
|
|
446
|
+
" Windows: add Graphviz to PATH\n"
|
|
447
|
+
)
|
|
448
|
+
return False
|
|
449
|
+
|
|
450
|
+
return True
|
|
451
|
+
|
|
452
|
+
def update_filepath_ui(self):
|
|
453
|
+
self.file_path_edit.setText(self.input_filepath if self.input_filepath else "")
|
|
454
|
+
|
|
283
455
|
def func_toolbar(self):
|
|
284
456
|
toolbar = QToolBar()
|
|
285
457
|
self.addToolBar(toolbar)
|
|
@@ -323,9 +495,15 @@ class MainWindow(QMainWindow):
|
|
|
323
495
|
toolbar.addWidget(spacer)
|
|
324
496
|
|
|
325
497
|
#
|
|
326
|
-
self.
|
|
327
|
-
self.
|
|
328
|
-
self.
|
|
498
|
+
self.configure_editor_action = QAction(QIcon.fromTheme("document-properties"), CONFIG["action_configure_editor"], self)
|
|
499
|
+
self.configure_editor_action.setToolTip(CONFIG["action_configure_editor_tooltip"])
|
|
500
|
+
self.configure_editor_action.triggered.connect(self.open_configure_editor)
|
|
501
|
+
toolbar.addAction(self.configure_editor_action)
|
|
502
|
+
|
|
503
|
+
#
|
|
504
|
+
self.configure_action = QAction(QIcon.fromTheme("document-properties"), CONFIG["action_configure_window"], self)
|
|
505
|
+
self.configure_action.setToolTip(CONFIG["action_configure_window_tooltip"])
|
|
506
|
+
self.configure_action.triggered.connect(self.open_configure_window)
|
|
329
507
|
toolbar.addAction(self.configure_action)
|
|
330
508
|
|
|
331
509
|
#
|
|
@@ -344,6 +522,12 @@ class MainWindow(QMainWindow):
|
|
|
344
522
|
QDesktopServices.openUrl(QUrl("https://ko-fi.com/trucomanx"))
|
|
345
523
|
|
|
346
524
|
def open_configure_editor(self):
|
|
525
|
+
if os.name == 'nt': # Windows
|
|
526
|
+
os.startfile(CONFIG_PATH)
|
|
527
|
+
elif os.name == 'posix': # Linux/macOS
|
|
528
|
+
subprocess.run(['xdg-open', CONFIG_EDITOR_PATH])
|
|
529
|
+
|
|
530
|
+
def open_configure_window(self):
|
|
347
531
|
if os.name == 'nt': # Windows
|
|
348
532
|
os.startfile(CONFIG_PATH)
|
|
349
533
|
elif os.name == 'posix': # Linux/macOS
|
|
@@ -370,12 +554,19 @@ class MainWindow(QMainWindow):
|
|
|
370
554
|
QMessageBox.warning(self, CONFIG["warning"], CONFIG["no_image_available"])
|
|
371
555
|
return
|
|
372
556
|
|
|
557
|
+
# Nome sugerido baseado no .dot
|
|
558
|
+
if self.input_filepath:
|
|
559
|
+
base = os.path.splitext(os.path.basename(self.input_filepath))[0]
|
|
560
|
+
default_name = base + ".svg"
|
|
561
|
+
else:
|
|
562
|
+
default_name = "graph.svg"
|
|
563
|
+
|
|
373
564
|
# Pergunta onde salvar
|
|
374
565
|
path, _ = QFileDialog.getSaveFileName(
|
|
375
566
|
self,
|
|
376
567
|
CONFIG["save_image"],
|
|
377
|
-
|
|
378
|
-
"SVG File (*.svg);;PNG File (*.png)"
|
|
568
|
+
default_name,
|
|
569
|
+
"SVG File (*.svg);;PNG File (*.png);;PDF File (*.pdf)"
|
|
379
570
|
)
|
|
380
571
|
|
|
381
572
|
if not path:
|
|
@@ -390,9 +581,33 @@ class MainWindow(QMainWindow):
|
|
|
390
581
|
self.viewer.renderer.render(painter)
|
|
391
582
|
painter.end()
|
|
392
583
|
pixmap.save(path, "PNG")
|
|
584
|
+
|
|
585
|
+
elif path.lower().endswith(".pdf"):
|
|
586
|
+
# gerar PDF diretamente com graphviz (vetorial real)
|
|
587
|
+
dot_code = self.editor.toPlainText()
|
|
588
|
+
|
|
589
|
+
temp_dot = tempfile.NamedTemporaryFile(delete=False, suffix=".dot")
|
|
590
|
+
tmp_dot_path = temp_dot.name
|
|
591
|
+
temp_dot.close()
|
|
592
|
+
|
|
593
|
+
with open(tmp_dot_path, "w") as f:
|
|
594
|
+
f.write(dot_code)
|
|
595
|
+
|
|
596
|
+
try:
|
|
597
|
+
subprocess.run(
|
|
598
|
+
["dot", "-Tpdf", tmp_dot_path, "-o", path],
|
|
599
|
+
check=True
|
|
600
|
+
)
|
|
601
|
+
finally:
|
|
602
|
+
if os.path.exists(tmp_dot_path):
|
|
603
|
+
os.remove(tmp_dot_path)
|
|
604
|
+
|
|
393
605
|
else: # SVG
|
|
394
606
|
# Copia o arquivo temporário para o destino
|
|
395
|
-
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
if not path.lower().endswith(".svg"):
|
|
610
|
+
path = path + ".svg"
|
|
396
611
|
shutil.copyfile(self.temp_svg_path, path)
|
|
397
612
|
|
|
398
613
|
self.status.showMessage(CONFIG["image_save_in"]+" "+path, 5000)
|
|
@@ -415,6 +630,7 @@ class MainWindow(QMainWindow):
|
|
|
415
630
|
content = f.read()
|
|
416
631
|
self.editor.setPlainText(content) # carrega o conteúdo no QPlainTextEdit
|
|
417
632
|
self.input_filepath=str(filepath)
|
|
633
|
+
self.update_filepath_ui()
|
|
418
634
|
self.status.showMessage(CONFIG["loaded_file"]+" "+self.input_filepath, 5000)
|
|
419
635
|
except Exception as e:
|
|
420
636
|
print(CONFIG["error_opening_dot_file"]+f"{e}")
|
|
@@ -452,6 +668,10 @@ class MainWindow(QMainWindow):
|
|
|
452
668
|
self.status.showMessage(CONFIG["saved_file"]+" "+path, 5000)
|
|
453
669
|
except Exception as e:
|
|
454
670
|
QMessageBox.critical(self, CONFIG["erro"], CONFIG["error_saving_file"]+"\n"+ e)
|
|
671
|
+
|
|
672
|
+
self.input_filepath = str(path)
|
|
673
|
+
|
|
674
|
+
self.update_filepath_ui()
|
|
455
675
|
|
|
456
676
|
def compile_dot(self):
|
|
457
677
|
dot_code = self.editor.toPlainText()
|
|
@@ -462,12 +682,13 @@ class MainWindow(QMainWindow):
|
|
|
462
682
|
self.thread.finished.connect(self.show_image)
|
|
463
683
|
self.thread.start()
|
|
464
684
|
|
|
465
|
-
def show_image(self, path):
|
|
466
|
-
if
|
|
467
|
-
|
|
685
|
+
def show_image(self, path, error_msg):
|
|
686
|
+
if error_msg: # deu erro
|
|
687
|
+
QMessageBox.critical(None, CONFIG["error_compilation"], error_msg)
|
|
468
688
|
else:
|
|
469
|
-
|
|
470
|
-
|
|
689
|
+
if path:
|
|
690
|
+
self.viewer.load_image(path)
|
|
691
|
+
self.progress.setValue(0)
|
|
471
692
|
# ---------------------------
|
|
472
693
|
# Run
|
|
473
694
|
# ---------------------------
|
{graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: graphviz_code_viewer
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Program to edit and view Graphviz code.
|
|
5
5
|
Author-email: Fernando Pujaico Rivera <fernando.pujaico.rivera@gmail.com>
|
|
6
6
|
Maintainer-email: Fernando Pujaico Rivera <fernando.pujaico.rivera@gmail.com>
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "graphviz_code_viewer"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.2"
|
|
8
8
|
description = "Program to edit and view Graphviz code."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [{name = "Fernando Pujaico Rivera", email = "fernando.pujaico.rivera@gmail.com"}]
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import json
|
|
3
|
-
|
|
4
|
-
def verify_default_config(path,default_content={}):
|
|
5
|
-
"""
|
|
6
|
-
Cria o arquivo JSON no caminho especificado com conteúdo padrão,
|
|
7
|
-
criando diretórios intermediários se necessário.
|
|
8
|
-
"""
|
|
9
|
-
|
|
10
|
-
# Se o arquivo não existir, cria com o conteúdo padrão
|
|
11
|
-
if not os.path.exists(path):
|
|
12
|
-
# Garante que os diretórios existam
|
|
13
|
-
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
14
|
-
with open(path, 'w', encoding='utf-8') as f:
|
|
15
|
-
json.dump(default_content, f, ensure_ascii=False, indent=4)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
# Lê o JSON no início do programa
|
|
19
|
-
def load_config(config_path):
|
|
20
|
-
with open(config_path, 'r', encoding='utf-8') as f:
|
|
21
|
-
return json.load(f)
|
|
22
|
-
|
|
23
|
-
def save_config(path,content):
|
|
24
|
-
"""
|
|
25
|
-
Cria o arquivo JSON no caminho especificado com conteúdo padrão,
|
|
26
|
-
criando diretórios intermediários se necessário.
|
|
27
|
-
"""
|
|
28
|
-
|
|
29
|
-
# Garante que os diretórios existam
|
|
30
|
-
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
31
|
-
with open(path, 'w', encoding='utf-8') as f:
|
|
32
|
-
json.dump(content, f, ensure_ascii=False, indent=4)
|
|
33
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/icons/logo.png
RENAMED
|
File without changes
|
{graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/modules/__init__.py
RENAMED
|
File without changes
|
{graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/program.old.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{graphviz_code_viewer-0.1.0 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer.egg-info/requires.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|