graphviz-code-viewer 0.1.0__py3-none-any.whl
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/__init__.py +1 -0
- graphviz_code_viewer/about.py +12 -0
- graphviz_code_viewer/desktop.py +98 -0
- graphviz_code_viewer/icons/logo.png +0 -0
- graphviz_code_viewer/modules/__init__.py +1 -0
- graphviz_code_viewer/modules/configure.py +33 -0
- graphviz_code_viewer/modules/wabout.py +108 -0
- graphviz_code_viewer/program.old.py +12 -0
- graphviz_code_viewer/program.py +519 -0
- graphviz_code_viewer-0.1.0.dist-info/METADATA +59 -0
- graphviz_code_viewer-0.1.0.dist-info/RECORD +15 -0
- graphviz_code_viewer-0.1.0.dist-info/WHEEL +5 -0
- graphviz_code_viewer-0.1.0.dist-info/entry_points.txt +2 -0
- graphviz_code_viewer-0.1.0.dist-info/licenses/LICENSE +674 -0
- graphviz_code_viewer-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
#!/usr/bin/python3
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
import subprocess
|
|
5
|
+
import tempfile
|
|
6
|
+
import os
|
|
7
|
+
import signal
|
|
8
|
+
|
|
9
|
+
from PyQt5.QtWidgets import (
|
|
10
|
+
QApplication, QMainWindow, QPlainTextEdit, QLabel, QSplitter, QToolBar,
|
|
11
|
+
QAction, QVBoxLayout, QWidget, QProgressBar, QFileDialog, QScrollArea, QMessageBox, QSizePolicy
|
|
12
|
+
)
|
|
13
|
+
from PyQt5.QtGui import QSyntaxHighlighter, QTextCharFormat, QColor, QFont, QPixmap, QIcon, QDesktopServices
|
|
14
|
+
from PyQt5.QtCore import Qt, QThread, pyqtSignal, QUrl
|
|
15
|
+
|
|
16
|
+
from PyQt5.QtSvg import QSvgRenderer
|
|
17
|
+
from PyQt5.QtGui import QPainter
|
|
18
|
+
from PyQt5.QtCore import QSize
|
|
19
|
+
|
|
20
|
+
import graphviz_code_viewer.about as about
|
|
21
|
+
import graphviz_code_viewer.modules.configure as configure
|
|
22
|
+
from graphviz_code_viewer.desktop import create_desktop_file, create_desktop_directory, create_desktop_menu
|
|
23
|
+
from graphviz_code_viewer.modules.wabout import show_about_window
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# Path to config file
|
|
27
|
+
CONFIG_PATH = os.path.join(os.path.expanduser("~"),".config",about.__package__,"config.json")
|
|
28
|
+
|
|
29
|
+
DEFAULT_CONTENT={ "error_loading_svg": "Error loading SVG file",
|
|
30
|
+
"font_size": 11,
|
|
31
|
+
"font_name": "Courier",
|
|
32
|
+
"window_width": 1200,
|
|
33
|
+
"window_height": 700,
|
|
34
|
+
"action_compile":"Compile",
|
|
35
|
+
"action_compile_tooltip": "Compile the DOT file",
|
|
36
|
+
"action_open":"Open",
|
|
37
|
+
"action_open_tooltip": "Open the DOT file",
|
|
38
|
+
"action_save":"Save",
|
|
39
|
+
"action_save_tooltip": "Save the DOT file",
|
|
40
|
+
"action_saveas":"Save as",
|
|
41
|
+
"action_saveas_tooltip": "Save the DOT file as",
|
|
42
|
+
"action_saveimg":"Save image",
|
|
43
|
+
"action_saveimg_tooltip": "Save the output image",
|
|
44
|
+
"action_configure": "Configure",
|
|
45
|
+
"action_configure_tooltip": "Open the configure Json file",
|
|
46
|
+
"action_about": "About",
|
|
47
|
+
"action_about_tooltip": "About the program",
|
|
48
|
+
"action_coffee": "Coffee",
|
|
49
|
+
"action_coffee_tooltip": "Buy me a coffee (TrucomanX)",
|
|
50
|
+
"warning":"Warning",
|
|
51
|
+
"no_image_available":"No image available to save. Compile the code first.",
|
|
52
|
+
"save_image":"Save image",
|
|
53
|
+
"image_save_in":"Image saves in:",
|
|
54
|
+
"open_dot_file":"Open DOT file",
|
|
55
|
+
"loaded_file":"Loaded file:",
|
|
56
|
+
"error_opening_dot_file":"Error opening DOT file:",
|
|
57
|
+
"exist_dot_file":"The file already exists and will not be overcrowded:",
|
|
58
|
+
"save_dot_file": "Save DOT file",
|
|
59
|
+
"dot_file_dot": "DOT File (*.dot)",
|
|
60
|
+
"saved_file":"Saved file:",
|
|
61
|
+
"error":"Error",
|
|
62
|
+
"error_saving_file":"It was not possible to save the file:",
|
|
63
|
+
"error_compilation":"Error in graphviz compilation."
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
configure.verify_default_config(CONFIG_PATH,default_content=DEFAULT_CONTENT)
|
|
67
|
+
|
|
68
|
+
CONFIG=configure.load_config(CONFIG_PATH)
|
|
69
|
+
|
|
70
|
+
# ---------------------------
|
|
71
|
+
# Syntax Highlighter
|
|
72
|
+
# ---------------------------
|
|
73
|
+
class GraphvizHighlighter(QSyntaxHighlighter):
|
|
74
|
+
def __init__(self, parent, rules_dict):
|
|
75
|
+
super().__init__(parent)
|
|
76
|
+
self.rules = []
|
|
77
|
+
for key, data in rules_dict.items():
|
|
78
|
+
fmt = QTextCharFormat()
|
|
79
|
+
fmt.setForeground(QColor(data["color"]))
|
|
80
|
+
if data["bold"]:
|
|
81
|
+
fmt.setFontWeight(QFont.Bold)
|
|
82
|
+
self.rules.append((key, fmt))
|
|
83
|
+
|
|
84
|
+
def highlightBlock(self, text):
|
|
85
|
+
for keyword, fmt in self.rules:
|
|
86
|
+
index = text.find(keyword)
|
|
87
|
+
while index != -1:
|
|
88
|
+
length = len(keyword)
|
|
89
|
+
self.setFormat(index, length, fmt)
|
|
90
|
+
index = text.find(keyword, index + length)
|
|
91
|
+
|
|
92
|
+
# ---------------------------
|
|
93
|
+
# Worker thread para compilar Graphviz
|
|
94
|
+
# ---------------------------
|
|
95
|
+
class CompileThread(QThread):
|
|
96
|
+
progress = pyqtSignal(int)
|
|
97
|
+
finished = pyqtSignal(str)
|
|
98
|
+
|
|
99
|
+
def __init__(self, dot_code, output_file):
|
|
100
|
+
super().__init__()
|
|
101
|
+
self.dot_code = dot_code
|
|
102
|
+
self.output_file = output_file
|
|
103
|
+
|
|
104
|
+
def run(self):
|
|
105
|
+
self.progress.emit(10)
|
|
106
|
+
|
|
107
|
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".dot")
|
|
108
|
+
tmp_dot = temp_file.name
|
|
109
|
+
temp_file.close()
|
|
110
|
+
|
|
111
|
+
with open(tmp_dot, "w") as f:
|
|
112
|
+
f.write(self.dot_code)
|
|
113
|
+
self.progress.emit(50)
|
|
114
|
+
try:
|
|
115
|
+
subprocess.run(
|
|
116
|
+
["dot", "-Tsvg", tmp_dot, "-o", self.output_file],
|
|
117
|
+
check=True
|
|
118
|
+
)
|
|
119
|
+
self.progress.emit(100)
|
|
120
|
+
self.finished.emit(self.output_file)
|
|
121
|
+
except subprocess.CalledProcessError:
|
|
122
|
+
self.finished.emit("")
|
|
123
|
+
|
|
124
|
+
if os.path.exists(tmp_dot):
|
|
125
|
+
os.remove(tmp_dot)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
# ---------------------------
|
|
129
|
+
# Widget da imagem com zoom/move
|
|
130
|
+
# ---------------------------
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
class SvgViewer(QScrollArea):
|
|
134
|
+
def __init__(self):
|
|
135
|
+
super().__init__()
|
|
136
|
+
self.label = QLabel()
|
|
137
|
+
self.label.setAlignment(Qt.AlignCenter)
|
|
138
|
+
self.setWidget(self.label)
|
|
139
|
+
self.setWidgetResizable(True)
|
|
140
|
+
self.renderer = None
|
|
141
|
+
self.zoom = 1.0
|
|
142
|
+
self.offset = None
|
|
143
|
+
|
|
144
|
+
def load_image(self, path):
|
|
145
|
+
self.renderer = QSvgRenderer(path)
|
|
146
|
+
if not self.renderer.isValid():
|
|
147
|
+
print(CONFIG["error_loading_svg"])
|
|
148
|
+
return
|
|
149
|
+
self.zoom = 1.0
|
|
150
|
+
self.update_display()
|
|
151
|
+
|
|
152
|
+
def update_display(self):
|
|
153
|
+
if self.renderer:
|
|
154
|
+
# calcular o tamanho do SVG considerando o zoom
|
|
155
|
+
size = self.renderer.defaultSize() * self.zoom
|
|
156
|
+
size = QSize(max(1, size.width()), max(1, size.height()))
|
|
157
|
+
|
|
158
|
+
# criar um pixmap transparente do tamanho desejado
|
|
159
|
+
pixmap = QPixmap(size)
|
|
160
|
+
pixmap.fill(Qt.transparent)
|
|
161
|
+
|
|
162
|
+
# renderizar o SVG diretamente no pixmap
|
|
163
|
+
painter = QPainter(pixmap)
|
|
164
|
+
self.renderer.render(painter)
|
|
165
|
+
painter.end()
|
|
166
|
+
|
|
167
|
+
self.label.setPixmap(pixmap)
|
|
168
|
+
self.label.resize(pixmap.size())
|
|
169
|
+
|
|
170
|
+
def wheelEvent(self, event):
|
|
171
|
+
angle = event.angleDelta().y()
|
|
172
|
+
factor = 1.1 if angle > 0 else 0.9
|
|
173
|
+
self.zoom *= factor
|
|
174
|
+
self.update_display()
|
|
175
|
+
|
|
176
|
+
def mousePressEvent(self, event):
|
|
177
|
+
if event.button() == Qt.LeftButton:
|
|
178
|
+
self.offset = event.pos()
|
|
179
|
+
|
|
180
|
+
def mouseMoveEvent(self, event):
|
|
181
|
+
if self.offset:
|
|
182
|
+
delta = event.pos() - self.offset
|
|
183
|
+
self.horizontalScrollBar().setValue(self.horizontalScrollBar().value() - delta.x())
|
|
184
|
+
self.verticalScrollBar().setValue(self.verticalScrollBar().value() - delta.y())
|
|
185
|
+
self.offset = event.pos()
|
|
186
|
+
|
|
187
|
+
def mouseReleaseEvent(self, event):
|
|
188
|
+
self.offset = None
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
# ---------------------------
|
|
193
|
+
# Editor de texto com zoom
|
|
194
|
+
# ---------------------------
|
|
195
|
+
class TextEditor(QPlainTextEdit):
|
|
196
|
+
def __init__(self):
|
|
197
|
+
super().__init__()
|
|
198
|
+
self.setFont(QFont(CONFIG["font_name"], CONFIG["font_size"]))
|
|
199
|
+
self.zoom_factor = 1.0
|
|
200
|
+
|
|
201
|
+
def wheelEvent(self, event):
|
|
202
|
+
if event.modifiers() & Qt.ControlModifier:
|
|
203
|
+
angle = event.angleDelta().y()
|
|
204
|
+
factor = 1.1 if angle > 0 else 0.9
|
|
205
|
+
self.zoom_factor *= factor
|
|
206
|
+
font = self.font()
|
|
207
|
+
font.setPointSizeF(CONFIG["font_size"] * self.zoom_factor)
|
|
208
|
+
self.setFont(font)
|
|
209
|
+
else:
|
|
210
|
+
super().wheelEvent(event)
|
|
211
|
+
|
|
212
|
+
# ---------------------------
|
|
213
|
+
# Main Window
|
|
214
|
+
# ---------------------------
|
|
215
|
+
class MainWindow(QMainWindow):
|
|
216
|
+
def __init__(self, filepath):
|
|
217
|
+
super().__init__()
|
|
218
|
+
self.setWindowTitle(about.__program_name__)
|
|
219
|
+
self.resize(CONFIG["window_width"], CONFIG["window_height"])
|
|
220
|
+
|
|
221
|
+
# input file path
|
|
222
|
+
if os.path.exists(filepath):
|
|
223
|
+
self.input_filepath=str(filepath)
|
|
224
|
+
else:
|
|
225
|
+
self.input_filepath=""
|
|
226
|
+
|
|
227
|
+
# Criar um arquivo temporário único para o SVG
|
|
228
|
+
temp_svg = tempfile.NamedTemporaryFile(delete=False, suffix=".svg")
|
|
229
|
+
self.temp_svg_path = temp_svg.name
|
|
230
|
+
temp_svg.close() # fecha o arquivo, vamos escrever nele depois
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
## Icon
|
|
234
|
+
# Get base directory for icons
|
|
235
|
+
base_dir_path = os.path.dirname(os.path.abspath(__file__))
|
|
236
|
+
self.icon_path = os.path.join(base_dir_path, 'icons', 'logo.png')
|
|
237
|
+
self.setWindowIcon(QIcon(self.icon_path))
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
# Toolbar
|
|
241
|
+
self.func_toolbar()
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
# Criar status bar
|
|
245
|
+
self.status = self.statusBar()
|
|
246
|
+
|
|
247
|
+
# Editor e visualizador
|
|
248
|
+
self.editor = TextEditor()
|
|
249
|
+
syntax_rules = {
|
|
250
|
+
"digraph": {"color": "blue", "bold": True},
|
|
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)
|
|
261
|
+
self.viewer = SvgViewer()
|
|
262
|
+
|
|
263
|
+
splitter = QSplitter(Qt.Horizontal)
|
|
264
|
+
splitter.addWidget(self.editor)
|
|
265
|
+
splitter.addWidget(self.viewer)
|
|
266
|
+
splitter.setSizes([int(CONFIG["window_width"]/2), int(CONFIG["window_width"]-CONFIG["window_width"]/2)])
|
|
267
|
+
|
|
268
|
+
# Barra de progresso
|
|
269
|
+
self.progress = QProgressBar()
|
|
270
|
+
self.progress.setValue(0)
|
|
271
|
+
|
|
272
|
+
# Layout central
|
|
273
|
+
central = QWidget()
|
|
274
|
+
layout = QVBoxLayout()
|
|
275
|
+
layout.addWidget(splitter)
|
|
276
|
+
layout.addWidget(self.progress)
|
|
277
|
+
central.setLayout(layout)
|
|
278
|
+
self.setCentralWidget(central)
|
|
279
|
+
|
|
280
|
+
if os.path.exists(self.input_filepath):
|
|
281
|
+
self.load_dot(filepath=self.input_filepath)
|
|
282
|
+
|
|
283
|
+
def func_toolbar(self):
|
|
284
|
+
toolbar = QToolBar()
|
|
285
|
+
self.addToolBar(toolbar)
|
|
286
|
+
toolbar.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextUnderIcon)
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
# Compile
|
|
290
|
+
compile_action = QAction(QIcon.fromTheme("media-playback-start"),CONFIG["action_compile"], self)
|
|
291
|
+
compile_action.setToolTip(CONFIG["action_compile_tooltip"])
|
|
292
|
+
compile_action.triggered.connect(self.compile_dot)
|
|
293
|
+
toolbar.addAction(compile_action)
|
|
294
|
+
|
|
295
|
+
# Load
|
|
296
|
+
load_action = QAction(QIcon.fromTheme("document-open"),CONFIG["action_open"], self)
|
|
297
|
+
load_action.setToolTip(CONFIG["action_open_tooltip"])
|
|
298
|
+
load_action.triggered.connect(lambda: self.load_dot(filepath=""))
|
|
299
|
+
toolbar.addAction(load_action)
|
|
300
|
+
|
|
301
|
+
# Save
|
|
302
|
+
save_action = QAction(QIcon.fromTheme("document-save"),CONFIG["action_save"], self)
|
|
303
|
+
save_action.setToolTip(CONFIG["action_save_tooltip"])
|
|
304
|
+
save_action.triggered.connect(lambda: self.save_dot(from_input=True,exist_ok=True))
|
|
305
|
+
toolbar.addAction(save_action)
|
|
306
|
+
|
|
307
|
+
# Save as
|
|
308
|
+
saveas_action = QAction(QIcon.fromTheme("document-save-as"),CONFIG["action_saveas"], self)
|
|
309
|
+
saveas_action.setToolTip(CONFIG["action_saveas_tooltip"])
|
|
310
|
+
saveas_action.triggered.connect(lambda: self.save_dot(from_input=False,exist_ok=False))
|
|
311
|
+
toolbar.addAction(saveas_action)
|
|
312
|
+
|
|
313
|
+
# Save Image
|
|
314
|
+
save_image_action = QAction(QIcon.fromTheme("image-x-generic"), CONFIG["action_saveimg"], self)
|
|
315
|
+
save_image_action.setToolTip(CONFIG["action_saveimg_tooltip"])
|
|
316
|
+
save_image_action.triggered.connect(self.save_image)
|
|
317
|
+
toolbar.addAction(save_image_action)
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
# Adicionar o espaçador
|
|
321
|
+
spacer = QWidget()
|
|
322
|
+
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
|
|
323
|
+
toolbar.addWidget(spacer)
|
|
324
|
+
|
|
325
|
+
#
|
|
326
|
+
self.configure_action = QAction(QIcon.fromTheme("document-properties"), CONFIG["action_configure"], self)
|
|
327
|
+
self.configure_action.setToolTip(CONFIG["action_configure_tooltip"])
|
|
328
|
+
self.configure_action.triggered.connect(self.open_configure_editor)
|
|
329
|
+
toolbar.addAction(self.configure_action)
|
|
330
|
+
|
|
331
|
+
#
|
|
332
|
+
self.about_action = QAction(QIcon.fromTheme("help-about"), CONFIG["action_about"], self)
|
|
333
|
+
self.about_action.setToolTip(CONFIG["action_about_tooltip"])
|
|
334
|
+
self.about_action.triggered.connect(self.open_about)
|
|
335
|
+
toolbar.addAction(self.about_action)
|
|
336
|
+
|
|
337
|
+
# Coffee
|
|
338
|
+
self.coffee_action = QAction(QIcon.fromTheme("emblem-favorite"), CONFIG["action_coffee"], self)
|
|
339
|
+
self.coffee_action.setToolTip(CONFIG["action_coffee_tooltip"])
|
|
340
|
+
self.coffee_action.triggered.connect(self.on_coffee_action_click)
|
|
341
|
+
toolbar.addAction(self.coffee_action)
|
|
342
|
+
|
|
343
|
+
def on_coffee_action_click(self):
|
|
344
|
+
QDesktopServices.openUrl(QUrl("https://ko-fi.com/trucomanx"))
|
|
345
|
+
|
|
346
|
+
def open_configure_editor(self):
|
|
347
|
+
if os.name == 'nt': # Windows
|
|
348
|
+
os.startfile(CONFIG_PATH)
|
|
349
|
+
elif os.name == 'posix': # Linux/macOS
|
|
350
|
+
subprocess.run(['xdg-open', CONFIG_PATH])
|
|
351
|
+
|
|
352
|
+
def open_about(self):
|
|
353
|
+
data={
|
|
354
|
+
"version": about.__version__,
|
|
355
|
+
"package": about.__package__,
|
|
356
|
+
"program_name": about.__program_name__,
|
|
357
|
+
"author": about.__author__,
|
|
358
|
+
"email": about.__email__,
|
|
359
|
+
"description": about.__description__,
|
|
360
|
+
"url_source": about.__url_source__,
|
|
361
|
+
"url_doc": about.__url_doc__,
|
|
362
|
+
"url_funding": about.__url_funding__,
|
|
363
|
+
"url_bugs": about.__url_bugs__
|
|
364
|
+
}
|
|
365
|
+
show_about_window(data,self.icon_path)
|
|
366
|
+
|
|
367
|
+
def save_image(self):
|
|
368
|
+
# Verifica se existe uma imagem carregada
|
|
369
|
+
if not self.viewer.renderer or not self.viewer.renderer.isValid():
|
|
370
|
+
QMessageBox.warning(self, CONFIG["warning"], CONFIG["no_image_available"])
|
|
371
|
+
return
|
|
372
|
+
|
|
373
|
+
# Pergunta onde salvar
|
|
374
|
+
path, _ = QFileDialog.getSaveFileName(
|
|
375
|
+
self,
|
|
376
|
+
CONFIG["save_image"],
|
|
377
|
+
"",
|
|
378
|
+
"SVG File (*.svg);;PNG File (*.png)"
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
if not path:
|
|
382
|
+
return # cancelado
|
|
383
|
+
|
|
384
|
+
# Se for PNG, renderizar e salvar
|
|
385
|
+
if path.lower().endswith(".png"):
|
|
386
|
+
size = self.viewer.renderer.defaultSize()
|
|
387
|
+
pixmap = QPixmap(size)
|
|
388
|
+
pixmap.fill(Qt.transparent)
|
|
389
|
+
painter = QPainter(pixmap)
|
|
390
|
+
self.viewer.renderer.render(painter)
|
|
391
|
+
painter.end()
|
|
392
|
+
pixmap.save(path, "PNG")
|
|
393
|
+
else: # SVG
|
|
394
|
+
# Copia o arquivo temporário para o destino
|
|
395
|
+
import shutil
|
|
396
|
+
shutil.copyfile(self.temp_svg_path, path)
|
|
397
|
+
|
|
398
|
+
self.status.showMessage(CONFIG["image_save_in"]+" "+path, 5000)
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def load_dot(self, filepath=""):
|
|
402
|
+
|
|
403
|
+
if not os.path.exists(filepath):
|
|
404
|
+
# Abre uma caixa de diálogo para selecionar arquivos .dot
|
|
405
|
+
filepath, _ = QFileDialog.getOpenFileName(
|
|
406
|
+
self,
|
|
407
|
+
CONFIG["open_dot_file"],
|
|
408
|
+
"",
|
|
409
|
+
CONFIG["dot_file_dot"]
|
|
410
|
+
)
|
|
411
|
+
|
|
412
|
+
if filepath:
|
|
413
|
+
try:
|
|
414
|
+
with open(filepath, "r", encoding="utf-8") as f:
|
|
415
|
+
content = f.read()
|
|
416
|
+
self.editor.setPlainText(content) # carrega o conteúdo no QPlainTextEdit
|
|
417
|
+
self.input_filepath=str(filepath)
|
|
418
|
+
self.status.showMessage(CONFIG["loaded_file"]+" "+self.input_filepath, 5000)
|
|
419
|
+
except Exception as e:
|
|
420
|
+
print(CONFIG["error_opening_dot_file"]+f"{e}")
|
|
421
|
+
|
|
422
|
+
def save_dot(self, from_input=True, exist_ok=True):
|
|
423
|
+
path=None
|
|
424
|
+
if from_input:
|
|
425
|
+
path = self.input_filepath
|
|
426
|
+
|
|
427
|
+
# Se o path foi fornecido e já existe, não sobrescreve
|
|
428
|
+
if path and os.path.exists(path) and exist_ok==False:
|
|
429
|
+
QMessageBox.warning(self, CONFIG["warning"], CONFIG["exist_dot_file"] + "\n" + path)
|
|
430
|
+
return
|
|
431
|
+
|
|
432
|
+
# Se path não foi fornecido ou não existe, abre diálogo para salvar
|
|
433
|
+
if not path or len(path)==0:
|
|
434
|
+
path, _ = QFileDialog.getSaveFileName(
|
|
435
|
+
self,
|
|
436
|
+
CONFIG["save_dot_file"],
|
|
437
|
+
"",
|
|
438
|
+
CONFIG["dot_file_dot"]
|
|
439
|
+
)
|
|
440
|
+
|
|
441
|
+
if not path: # usuário cancelou
|
|
442
|
+
return
|
|
443
|
+
|
|
444
|
+
# Garantir que o arquivo termine com .dot
|
|
445
|
+
if not path.lower().endswith(".dot"):
|
|
446
|
+
path += ".dot"
|
|
447
|
+
|
|
448
|
+
try:
|
|
449
|
+
with open(path, "w", encoding="utf-8") as f:
|
|
450
|
+
content = self.editor.toPlainText()
|
|
451
|
+
f.write(content)
|
|
452
|
+
self.status.showMessage(CONFIG["saved_file"]+" "+path, 5000)
|
|
453
|
+
except Exception as e:
|
|
454
|
+
QMessageBox.critical(self, CONFIG["erro"], CONFIG["error_saving_file"]+"\n"+ e)
|
|
455
|
+
|
|
456
|
+
def compile_dot(self):
|
|
457
|
+
dot_code = self.editor.toPlainText()
|
|
458
|
+
self.progress.setValue(0)
|
|
459
|
+
|
|
460
|
+
self.thread = CompileThread(dot_code, self.temp_svg_path)
|
|
461
|
+
self.thread.progress.connect(self.progress.setValue)
|
|
462
|
+
self.thread.finished.connect(self.show_image)
|
|
463
|
+
self.thread.start()
|
|
464
|
+
|
|
465
|
+
def show_image(self, path):
|
|
466
|
+
if path:
|
|
467
|
+
self.viewer.load_image(path)
|
|
468
|
+
else:
|
|
469
|
+
print(CONFIG["error_compilation"])
|
|
470
|
+
|
|
471
|
+
# ---------------------------
|
|
472
|
+
# Run
|
|
473
|
+
# ---------------------------
|
|
474
|
+
def main():
|
|
475
|
+
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
|
476
|
+
|
|
477
|
+
create_desktop_directory()
|
|
478
|
+
create_desktop_menu()
|
|
479
|
+
create_desktop_file('~/.local/share/applications')
|
|
480
|
+
|
|
481
|
+
filepath = ""
|
|
482
|
+
if(len(sys.argv)==2):
|
|
483
|
+
if sys.argv[1] == "--autostart":
|
|
484
|
+
create_desktop_directory(overwrite = True)
|
|
485
|
+
create_desktop_menu(overwrite = True)
|
|
486
|
+
create_desktop_file('~/.config/autostart', overwrite=True)
|
|
487
|
+
return
|
|
488
|
+
|
|
489
|
+
if sys.argv[1] == "--applications":
|
|
490
|
+
create_desktop_directory(overwrite = True)
|
|
491
|
+
create_desktop_menu(overwrite = True)
|
|
492
|
+
create_desktop_file('~/.local/share/applications', overwrite=True)
|
|
493
|
+
return
|
|
494
|
+
|
|
495
|
+
if os.path.exists(sys.argv[1]):
|
|
496
|
+
filepath = sys.argv[1]
|
|
497
|
+
else:
|
|
498
|
+
for n in range(len(sys.argv)):
|
|
499
|
+
if sys.argv[n] == "--autostart":
|
|
500
|
+
create_desktop_directory(overwrite = True)
|
|
501
|
+
create_desktop_menu(overwrite = True)
|
|
502
|
+
create_desktop_file('~/.config/autostart', overwrite=True)
|
|
503
|
+
return
|
|
504
|
+
if sys.argv[n] == "--applications":
|
|
505
|
+
create_desktop_directory(overwrite = True)
|
|
506
|
+
create_desktop_menu(overwrite = True)
|
|
507
|
+
create_desktop_file('~/.local/share/applications', overwrite=True)
|
|
508
|
+
return
|
|
509
|
+
|
|
510
|
+
app = QApplication(sys.argv)
|
|
511
|
+
app.setApplicationName(about.__package__)
|
|
512
|
+
|
|
513
|
+
window = MainWindow(filepath)
|
|
514
|
+
window.show()
|
|
515
|
+
sys.exit(app.exec_())
|
|
516
|
+
|
|
517
|
+
if __name__ == "__main__":
|
|
518
|
+
main()
|
|
519
|
+
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: graphviz_code_viewer
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Program to edit and view Graphviz code.
|
|
5
|
+
Author-email: Fernando Pujaico Rivera <fernando.pujaico.rivera@gmail.com>
|
|
6
|
+
Maintainer-email: Fernando Pujaico Rivera <fernando.pujaico.rivera@gmail.com>
|
|
7
|
+
License-Expression: GPL-3.0-only WITH Classpath-exception-2.0 OR BSD-3-Clause
|
|
8
|
+
Project-URL: Bug Reports, https://github.com/trucomanx/GraphvizCodeViewer/issues
|
|
9
|
+
Project-URL: Funding, https://trucomanx.github.io/en/funding.html
|
|
10
|
+
Project-URL: Documentation, https://github.com/trucomanx/GraphvizCodeViewer/tree/main/doc
|
|
11
|
+
Project-URL: Source, https://github.com/trucomanx/GraphvizCodeViewer
|
|
12
|
+
Keywords: writing,translate
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Requires-Python: >=3.8
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: PyQt5
|
|
19
|
+
Requires-Dist: deep-consultation
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# graphviz-code-viewer
|
|
23
|
+
|
|
24
|
+
Program to edit and view Graphviz code.
|
|
25
|
+
|
|
26
|
+

|
|
27
|
+
|
|
28
|
+
## 1. Installing
|
|
29
|
+
|
|
30
|
+
To install the package from [PyPI](https://pypi.org/project/graphviz-code-viewer/), follow the instructions below:
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pip install --upgrade graphviz-code-viewer
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Execute `which graphviz-code-viewer` to see where it was installed, probably in `/home/USERNAME/.local/bin/graphviz-code-viewer`.
|
|
38
|
+
|
|
39
|
+
### Using
|
|
40
|
+
|
|
41
|
+
To start, use the command below:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
graphviz-code-viewer
|
|
45
|
+
```
|
|
46
|
+
## 2. More information
|
|
47
|
+
|
|
48
|
+
If you want more information go to [doc](https://github.com/trucomanx/GraphvizCodeViewer/blob/main/doc) directory.
|
|
49
|
+
|
|
50
|
+
## 3. Buy me a coffee
|
|
51
|
+
|
|
52
|
+
If you find this tool useful and would like to support its development, you can buy me a coffee!
|
|
53
|
+
Your donations help keep the project running and improve future updates.
|
|
54
|
+
|
|
55
|
+
[☕ Buy me a coffee](https://ko-fi.com/trucomanx)
|
|
56
|
+
|
|
57
|
+
## 4. License
|
|
58
|
+
|
|
59
|
+
This project is licensed under the GPL license. See the `LICENSE` file for more details.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
graphviz_code_viewer/__init__.py,sha256=ruULPQI7A5xxFhCYlc2-Yak7eGnabqCYTahYYvxbPtc,19
|
|
2
|
+
graphviz_code_viewer/about.py,sha256=A7DxHYLV4YatV80MogErhxjMO_TM_TR3r_Af-wwJje0,548
|
|
3
|
+
graphviz_code_viewer/desktop.py,sha256=cQmD5nYq-69CPyl3Lpw-nHy4mlogYoMdxKzJbXGqNEU,3405
|
|
4
|
+
graphviz_code_viewer/program.old.py,sha256=WITEa9nGhdxyHgTEv5CW5n-X7WUqEHLqOBOz4Hf6K1U,390
|
|
5
|
+
graphviz_code_viewer/program.py,sha256=5gpoBAwpkMlyKajX_RxQR-DIlS3IJHzhSjUV4ugzw3c,19153
|
|
6
|
+
graphviz_code_viewer/icons/logo.png,sha256=-OliUiEwNgg0XrAy730RYvYGHS91sg9VQXdTu8jaD4Y,13867
|
|
7
|
+
graphviz_code_viewer/modules/__init__.py,sha256=ruULPQI7A5xxFhCYlc2-Yak7eGnabqCYTahYYvxbPtc,19
|
|
8
|
+
graphviz_code_viewer/modules/configure.py,sha256=8lRKvTMQooUP11gs8DhiyLf-1nLzYNw6nAxKqZn08vA,1075
|
|
9
|
+
graphviz_code_viewer/modules/wabout.py,sha256=a8WOE9FJ9AdmbFioK17lqbR0cWavBSKhTzjrhsMJn10,4455
|
|
10
|
+
graphviz_code_viewer-0.1.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
11
|
+
graphviz_code_viewer-0.1.0.dist-info/METADATA,sha256=zpses8j8HF0xK1B83ODJcBb0avCajlSX3pxYyy6UI-s,1987
|
|
12
|
+
graphviz_code_viewer-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
13
|
+
graphviz_code_viewer-0.1.0.dist-info/entry_points.txt,sha256=NNGfKE-wV0STU-Nqg4c3AwHSEZJTTd7YvXjbORljShk,75
|
|
14
|
+
graphviz_code_viewer-0.1.0.dist-info/top_level.txt,sha256=ugiV_3C6-J4ci2Vx6a9LG97-30z-TcbRlS51p6KBwE4,21
|
|
15
|
+
graphviz_code_viewer-0.1.0.dist-info/RECORD,,
|