graphviz-code-viewer 0.1.1__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.
Files changed (22) hide show
  1. {graphviz_code_viewer-0.1.1 → graphviz_code_viewer-0.1.2}/PKG-INFO +1 -1
  2. {graphviz_code_viewer-0.1.1 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/about.py +1 -1
  3. graphviz_code_viewer-0.1.2/graphviz_code_viewer/modules/configure.py +76 -0
  4. graphviz_code_viewer-0.1.2/graphviz_code_viewer/modules/resources.py +15 -0
  5. {graphviz_code_viewer-0.1.1 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/modules/wabout.py +7 -3
  6. {graphviz_code_viewer-0.1.1 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/program.py +112 -6
  7. {graphviz_code_viewer-0.1.1 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer.egg-info/PKG-INFO +1 -1
  8. {graphviz_code_viewer-0.1.1 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer.egg-info/SOURCES.txt +1 -0
  9. {graphviz_code_viewer-0.1.1 → graphviz_code_viewer-0.1.2}/pyproject.toml +1 -1
  10. graphviz_code_viewer-0.1.1/graphviz_code_viewer/modules/configure.py +0 -60
  11. {graphviz_code_viewer-0.1.1 → graphviz_code_viewer-0.1.2}/LICENSE +0 -0
  12. {graphviz_code_viewer-0.1.1 → graphviz_code_viewer-0.1.2}/README.md +0 -0
  13. {graphviz_code_viewer-0.1.1 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/__init__.py +0 -0
  14. {graphviz_code_viewer-0.1.1 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/desktop.py +0 -0
  15. {graphviz_code_viewer-0.1.1 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/icons/logo.png +0 -0
  16. {graphviz_code_viewer-0.1.1 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/modules/__init__.py +0 -0
  17. {graphviz_code_viewer-0.1.1 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer/program.old.py +0 -0
  18. {graphviz_code_viewer-0.1.1 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer.egg-info/dependency_links.txt +0 -0
  19. {graphviz_code_viewer-0.1.1 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer.egg-info/entry_points.txt +0 -0
  20. {graphviz_code_viewer-0.1.1 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer.egg-info/requires.txt +0 -0
  21. {graphviz_code_viewer-0.1.1 → graphviz_code_viewer-0.1.2}/graphviz_code_viewer.egg-info/top_level.txt +0 -0
  22. {graphviz_code_viewer-0.1.1 → 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.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>
@@ -1,6 +1,6 @@
1
1
  # about.py
2
2
 
3
- __version__ = "0.1.1"
3
+ __version__ = "0.1.2"
4
4
  __package__ = "graphviz_code_viewer"
5
5
  __program_name__ = "graphviz-code-viewer"
6
6
  __author__ = "Fernando Pujaico Rivera"
@@ -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
+
@@ -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
- pixmap = QPixmap(logo_path)
18
- pixmap = pixmap.scaled(100, 100, Qt.KeepAspectRatio, Qt.SmoothTransformation)
19
- logo_label.setPixmap(pixmap)
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
 
@@ -8,7 +8,7 @@ import signal
8
8
  import shutil
9
9
 
10
10
  from PyQt5.QtWidgets import (
11
- QApplication, QMainWindow, QPlainTextEdit, QLabel, QSplitter, QToolBar,
11
+ QApplication, QMainWindow, QPlainTextEdit, QLabel, QSplitter, QToolBar, QHBoxLayout,
12
12
  QAction, QVBoxLayout, QWidget, QProgressBar, QFileDialog, QScrollArea, QMessageBox, QSizePolicy, QLineEdit
13
13
  )
14
14
  from PyQt5.QtGui import QSyntaxHighlighter, QTextCharFormat, QColor, QFont, QPixmap, QIcon, QDesktopServices
@@ -25,6 +25,7 @@ import graphviz_code_viewer.about as about
25
25
  import graphviz_code_viewer.modules.configure as configure
26
26
  from graphviz_code_viewer.desktop import create_desktop_file, create_desktop_directory, create_desktop_menu
27
27
  from graphviz_code_viewer.modules.wabout import show_about_window
28
+ from graphviz_code_viewer.modules.resources import resource_path
28
29
 
29
30
  # ------------------------------------------------------------------------------
30
31
  # Path to config file
@@ -42,7 +43,7 @@ DEFAULT_CONTENT={ "error_loading_svg": "Error loading SVG file",
42
43
  "action_saveas":"Save as",
43
44
  "action_saveas_tooltip": "Save the DOT file as",
44
45
  "action_saveimg":"Save image",
45
- "action_saveimg_tooltip": "Save the output image",
46
+ "action_saveimg_tooltip": "Save the output as binary or vector image (SVG,PNG,PDF)",
46
47
  "action_configure_window": "Conf. window",
47
48
  "action_configure_window_tooltip": "Open the configure window Json file",
48
49
  "action_configure_editor": "Conf. Editor",
@@ -51,6 +52,7 @@ DEFAULT_CONTENT={ "error_loading_svg": "Error loading SVG file",
51
52
  "action_about_tooltip": "About the program",
52
53
  "action_coffee": "Coffee",
53
54
  "action_coffee_tooltip": "Buy me a coffee (TrucomanX)",
55
+ "file_path": "File path:",
54
56
  "warning":"Warning",
55
57
  "no_image_available":"No image available to save. Compile the code first.",
56
58
  "save_image":"Save image",
@@ -244,6 +246,39 @@ class TextEditor(QPlainTextEdit):
244
246
  self.search_format = QTextCharFormat()
245
247
  self.search_format.setBackground(QColor("yellow"))
246
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
+
247
282
  def wheelEvent(self, event):
248
283
  if event.modifiers() & Qt.ControlModifier:
249
284
  angle = event.angleDelta().y()
@@ -336,8 +371,7 @@ class MainWindow(QMainWindow):
336
371
 
337
372
  ## Icon
338
373
  # Get base directory for icons
339
- base_dir_path = os.path.dirname(os.path.abspath(__file__))
340
- self.icon_path = os.path.join(base_dir_path, 'icons', 'logo.png')
374
+ self.icon_path = resource_path("icons", "logo.png")
341
375
  self.setWindowIcon(QIcon(self.icon_path))
342
376
 
343
377
 
@@ -348,6 +382,23 @@ class MainWindow(QMainWindow):
348
382
  # Criar status bar
349
383
  self.status = self.statusBar()
350
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
+
351
402
  # Editor e visualizador
352
403
  self.editor = TextEditor()
353
404
 
@@ -366,6 +417,7 @@ class MainWindow(QMainWindow):
366
417
  # Layout central
367
418
  central = QWidget()
368
419
  layout = QVBoxLayout()
420
+ layout.addWidget(file_bar) # 🔥 NOVO (logo abaixo da toolbar)
369
421
  layout.addWidget(splitter)
370
422
  layout.addWidget(self.progress)
371
423
  central.setLayout(layout)
@@ -377,6 +429,29 @@ class MainWindow(QMainWindow):
377
429
  save_shortcut = QShortcut(QKeySequence(CONFIG_EDITOR["save_file"]), self)
378
430
  save_shortcut.activated.connect(lambda: self.save_dot(from_input=True, exist_ok=True))
379
431
 
432
+ if not self.check_graphviz():
433
+ sys.exit(1) # encerra o app se não tiver dot
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
+
380
455
  def func_toolbar(self):
381
456
  toolbar = QToolBar()
382
457
  self.addToolBar(toolbar)
@@ -479,12 +554,19 @@ class MainWindow(QMainWindow):
479
554
  QMessageBox.warning(self, CONFIG["warning"], CONFIG["no_image_available"])
480
555
  return
481
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
+
482
564
  # Pergunta onde salvar
483
565
  path, _ = QFileDialog.getSaveFileName(
484
566
  self,
485
567
  CONFIG["save_image"],
486
- "",
487
- "SVG File (*.svg);;PNG File (*.png)"
568
+ default_name,
569
+ "SVG File (*.svg);;PNG File (*.png);;PDF File (*.pdf)"
488
570
  )
489
571
 
490
572
  if not path:
@@ -499,6 +581,27 @@ class MainWindow(QMainWindow):
499
581
  self.viewer.renderer.render(painter)
500
582
  painter.end()
501
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
+
502
605
  else: # SVG
503
606
  # Copia o arquivo temporário para o destino
504
607
 
@@ -527,6 +630,7 @@ class MainWindow(QMainWindow):
527
630
  content = f.read()
528
631
  self.editor.setPlainText(content) # carrega o conteúdo no QPlainTextEdit
529
632
  self.input_filepath=str(filepath)
633
+ self.update_filepath_ui()
530
634
  self.status.showMessage(CONFIG["loaded_file"]+" "+self.input_filepath, 5000)
531
635
  except Exception as e:
532
636
  print(CONFIG["error_opening_dot_file"]+f"{e}")
@@ -566,6 +670,8 @@ class MainWindow(QMainWindow):
566
670
  QMessageBox.critical(self, CONFIG["erro"], CONFIG["error_saving_file"]+"\n"+ e)
567
671
 
568
672
  self.input_filepath = str(path)
673
+
674
+ self.update_filepath_ui()
569
675
 
570
676
  def compile_dot(self):
571
677
  dot_code = self.editor.toPlainText()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: graphviz_code_viewer
3
- Version: 0.1.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>
@@ -15,4 +15,5 @@ graphviz_code_viewer.egg-info/top_level.txt
15
15
  graphviz_code_viewer/icons/logo.png
16
16
  graphviz_code_viewer/modules/__init__.py
17
17
  graphviz_code_viewer/modules/configure.py
18
+ graphviz_code_viewer/modules/resources.py
18
19
  graphviz_code_viewer/modules/wabout.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "graphviz_code_viewer"
7
- version = "0.1.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,60 +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
-
19
- def merge_defaults(config, defaults):
20
- """
21
- Adiciona valores de defaults que não existam em config.
22
- Funciona recursivamente para dicionários aninhados.
23
- """
24
- for key, value in defaults.items():
25
- if key not in config:
26
- config[key] = value
27
- elif isinstance(value, dict) and isinstance(config[key], dict):
28
- merge_defaults(config[key], value)
29
- return config
30
-
31
- # Lê o JSON no início do programa
32
- def load_config(config_path, default_content=None):
33
- """
34
- Carrega o JSON de configuração e preenche com valores padrão se necessário.
35
- """
36
- config = {}
37
- if os.path.exists(config_path):
38
- with open(config_path, 'r', encoding='utf-8') as f:
39
- try:
40
- config = json.load(f)
41
- except json.JSONDecodeError:
42
- print("Erro ao ler config, usando defaults")
43
- config = {}
44
-
45
- if default_content:
46
- config = merge_defaults(config, default_content)
47
-
48
- return config
49
-
50
- def save_config(path,content):
51
- """
52
- Cria o arquivo JSON no caminho especificado com conteúdo padrão,
53
- criando diretórios intermediários se necessário.
54
- """
55
-
56
- # Garante que os diretórios existam
57
- os.makedirs(os.path.dirname(path), exist_ok=True)
58
- with open(path, 'w', encoding='utf-8') as f:
59
- json.dump(content, f, ensure_ascii=False, indent=4)
60
-