spiceditor 0.0.4__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.

Potentially problematic release.


This version of spiceditor might be problematic. Click here for more details.

Files changed (51) hide show
  1. pyspice/__init__.py +0 -0
  2. pyspice/dialogs.py +103 -0
  3. pyspice/editor_widget.py +196 -0
  4. pyspice/file_browser.py +143 -0
  5. pyspice/highlighter.py +74 -0
  6. pyspice/line_number_text_edit.py +54 -0
  7. pyspice/magic_scrollbar.py +11 -0
  8. pyspice/main.py +435 -0
  9. pyspice/resources.py +1120 -0
  10. pyspice/spice_console.py +282 -0
  11. pyspice/spice_magic_editor.py +389 -0
  12. pyspice/splitter.py +118 -0
  13. pyspice/term.py +63 -0
  14. pyspice/textract.py +597 -0
  15. pyspice/utils.py +33 -0
  16. spiceditor/__init__.py +0 -0
  17. spiceditor/dialogs.py +103 -0
  18. spiceditor/editor_widget.py +196 -0
  19. spiceditor/file_browser.py +143 -0
  20. spiceditor/highlighter.py +74 -0
  21. spiceditor/line_number_text_edit.py +54 -0
  22. spiceditor/magic_scrollbar.py +11 -0
  23. spiceditor/main.py +435 -0
  24. spiceditor/resources.py +1120 -0
  25. spiceditor/spice_console.py +282 -0
  26. spiceditor/spice_magic_editor.py +389 -0
  27. spiceditor/splitter.py +118 -0
  28. spiceditor/term.py +63 -0
  29. spiceditor/textract.py +597 -0
  30. spiceditor/utils.py +33 -0
  31. spiceditor-0.0.4.dist-info/LICENSE +674 -0
  32. spiceditor-0.0.4.dist-info/METADATA +31 -0
  33. spiceditor-0.0.4.dist-info/RECORD +51 -0
  34. spiceditor-0.0.4.dist-info/WHEEL +5 -0
  35. spiceditor-0.0.4.dist-info/entry_points.txt +2 -0
  36. spiceditor-0.0.4.dist-info/top_level.txt +1 -0
  37. spyce/__init__.py +0 -0
  38. spyce/dialogs.py +103 -0
  39. spyce/editor_widget.py +196 -0
  40. spyce/file_browser.py +143 -0
  41. spyce/highlighter.py +74 -0
  42. spyce/line_number_text_edit.py +54 -0
  43. spyce/magic_scrollbar.py +11 -0
  44. spyce/main.py +435 -0
  45. spyce/resources.py +1120 -0
  46. spyce/spice_console.py +282 -0
  47. spyce/spice_magic_editor.py +389 -0
  48. spyce/splitter.py +118 -0
  49. spyce/term.py +63 -0
  50. spyce/textract.py +597 -0
  51. spyce/utils.py +33 -0
spyce/splitter.py ADDED
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env python
2
+ import argparse
3
+ import re
4
+ from io import BytesIO
5
+
6
+ from PyPDF2 import PdfReader, PdfWriter
7
+ from reportlab.lib.colors import white, Color
8
+ from reportlab.pdfgen import canvas
9
+
10
+
11
+ def add_text_to_page(page, text, position, page_size):
12
+ packet = BytesIO()
13
+ can = canvas.Canvas(packet, pagesize=page_size)
14
+ custom_color = Color(0.894, 0.118, 0.118)
15
+
16
+ # Draw red background for text
17
+ text_width = 35 # Approximate width of the text background
18
+ text_height = 20 # Height of the text background
19
+ can.setFillColor(custom_color)
20
+ can.setStrokeColor(custom_color)
21
+ can.rect(position[0]-10 , position[1] -5, text_width, text_height, fill=1)
22
+
23
+ # Draw white text
24
+ can.setFillColor(white)
25
+ can.setFont("Helvetica-Bold", 16)
26
+ can.drawString(position[0], position[1], text)
27
+ can.save()
28
+
29
+ packet.seek(0)
30
+ new_pdf = PdfReader(packet)
31
+ overlay_page = new_pdf.pages[0]
32
+
33
+ page.merge_page(overlay_page)
34
+ return page
35
+
36
+ def process_pdf(input_path, base_output_path, suffix, exclude):
37
+ reader = PdfReader(input_path)
38
+ output_count = 0
39
+ writer = None
40
+ count = 1
41
+ filename = None
42
+
43
+ for i, page in enumerate(reader.pages):
44
+ page_text = page.extract_text()
45
+ page_size = (page.mediabox.width, page.mediabox.height)
46
+
47
+ #print(page_text)
48
+ if "Grado en Estudios para la Defensa y Seguridad".lower() in page_text.lower():
49
+ if writer is not None and len(writer.pages) > 0:
50
+ print("filename: ", filename)
51
+
52
+ if filename is None:
53
+ filename = f"{base_output_path}_{output_count}{suffix}.pdf"
54
+ else:
55
+ filename = base_output_path + filename + suffix + ".pdf"
56
+ with open(filename, "wb") as output_file:
57
+ writer.write(output_file)
58
+ filename = None
59
+
60
+ output_count += 1
61
+
62
+ writer = PdfWriter()
63
+ count = 1
64
+
65
+
66
+ if "bloque" in page_text.lower() and "tema" in page_text.lower():
67
+ for line in page_text.split("\n"):
68
+ if "BLOQUE" in line and "TEMA" in line:
69
+ matches = re.findall(r'\d+', line)
70
+ next_line = page_text.split("\n")[page_text.split("\n").index(line) + 1]
71
+ block = matches[0] # Extracts '2'
72
+ topic = matches[1] # Extracts '5'
73
+
74
+ filename = f"B{block}_T{topic}_{next_line.strip()}"
75
+
76
+
77
+
78
+ if "LAB:" in page_text:
79
+ for line in page_text.split("\n"):
80
+ if "LAB:" in line:
81
+ filename = line.strip()
82
+
83
+
84
+ if writer is not None:
85
+ if exclude is not None and exclude.lower() in page_text.lower():
86
+ continue
87
+
88
+ if count > 2:
89
+ new_page = add_text_to_page(page, str(count), (930, 6), page_size)
90
+ else:
91
+ new_page = add_text_to_page(page, "", (930, 6), page_size)
92
+ writer.add_page(new_page)
93
+ count = count + 1
94
+
95
+ if writer is not None and len(writer.pages) > 0:
96
+ if filename is None:
97
+ filename = f"{base_output_path}_{output_count}.pdf"
98
+ with open(filename, "wb") as output_file:
99
+ writer.write(output_file)
100
+
101
+ def main():
102
+ # add switches instead of positional arguments
103
+ parser = argparse.ArgumentParser()
104
+ parser.add_argument("file", help="Suffix to add to the output files", type=str)
105
+ parser.add_argument("dir", help="Suffix to add to the output files", type=str)
106
+ parser.add_argument("-s", "--suffix", help="Suffix to add to the output files", type=str, default="")
107
+ parser.add_argument("-x", "--exclude", help="Exclude pages with this text", type=str, default=None)
108
+
109
+ args = parser.parse_args()
110
+
111
+ suffix = ("_" if args.suffix != "" else "") + args.suffix
112
+
113
+ process_pdf(args.file, args.dir +"/", suffix , args.exclude)
114
+
115
+ if __name__ == "__main__":
116
+ main()
117
+
118
+
spyce/term.py ADDED
@@ -0,0 +1,63 @@
1
+ import sys
2
+ from PyQt5.QtWidgets import QApplication, QMainWindow, QTextEdit, QVBoxLayout, QWidget
3
+ from PyQt5.QtCore import QProcess, QTextStream, Qt
4
+ from PyQt5.QtGui import QTextCursor
5
+
6
+ class TerminalWidget(QMainWindow):
7
+ def __init__(self):
8
+ super().__init__()
9
+
10
+ self.process = QProcess()
11
+ self.process.setProcessChannelMode(QProcess.MergedChannels)
12
+ self.process.readyReadStandardOutput.connect(self.read_output)
13
+ self.process.finished.connect(self.process_finished)
14
+
15
+ self.text_edit = QTextEdit()
16
+ self.text_edit.setReadOnly(False)
17
+ self.text_edit.installEventFilter(self)
18
+
19
+ layout = QVBoxLayout()
20
+ layout.addWidget(self.text_edit)
21
+
22
+ container = QWidget()
23
+ container.setLayout(layout)
24
+ self.setCentralWidget(container)
25
+
26
+ self.setWindowTitle("Terminal in PyQt")
27
+ self.resize(800, 600)
28
+
29
+ # Start a shell (e.g., bash on Linux/macOS, cmd.exe on Windows)
30
+ if sys.platform == "win32":
31
+ self.process.start("cmd.exe")
32
+ else:
33
+ self.process.start("bash")
34
+
35
+ def eventFilter(self, obj, event):
36
+ if obj == self.text_edit and event.type() == event.KeyPress:
37
+ if event.key() == Qt.Key_Return:
38
+ self.send_command()
39
+ return True
40
+ return super().eventFilter(obj, event)
41
+
42
+ def send_command(self):
43
+ command = self.text_edit.textCursor().block().text() # Get the current line
44
+ self.process.write(command.encode() + b"\n") # Send the command to the process
45
+ self.text_edit.moveCursor(QTextCursor.End) # Move cursor to the end
46
+
47
+ def read_output(self):
48
+ output = self.process.readAllStandardOutput().data().decode()
49
+ self.text_append(output)
50
+
51
+ def process_finished(self):
52
+ self.text_append("\nProcess finished.")
53
+
54
+ def text_append(self, text):
55
+ self.text_edit.moveCursor(QTextCursor.End)
56
+ self.text_edit.insertPlainText(text)
57
+ self.text_edit.moveCursor(QTextCursor.End)
58
+
59
+ if __name__ == "__main__":
60
+ app = QApplication(sys.argv)
61
+ window = TerminalWidget()
62
+ window.show()
63
+ sys.exit(app.exec_())