|
| 1 | +import os |
| 2 | +import sys |
| 3 | +from PySide.QtCore import * |
| 4 | +from PySide.QtGui import * |
| 5 | +from ascii import Ascii |
| 6 | + |
| 7 | +def get_input_file(): |
| 8 | + in_line.setText(QFileDialog.getOpenFileName()[0]) |
| 9 | + |
| 10 | +def get_output_file(): |
| 11 | + out_line.setText(QFileDialog.getSaveFileName()[0]) |
| 12 | + |
| 13 | +def save_img(): |
| 14 | + in_file = in_line.text() |
| 15 | + out_file = out_line.text() |
| 16 | + step = step_line.text() |
| 17 | + words = words_line.text() |
| 18 | + |
| 19 | + if step.isdigit(): |
| 20 | + step = int(step) |
| 21 | + else: |
| 22 | + step = 3 |
| 23 | + |
| 24 | + if not os.path.exists(in_file): |
| 25 | + QMessageBox().warning(None, "Error", "Input file does not exist", |
| 26 | + QMessageBox.StandardButton.Ok) |
| 27 | + return |
| 28 | + |
| 29 | + if not (out_file.lower().endswith(".jpg") and |
| 30 | + out_file.lower().endswith(".png") and |
| 31 | + out_file.lower().endswith(".jpeg")): |
| 32 | + out_file += ".jpg" |
| 33 | + |
| 34 | + a = Ascii(in_file) |
| 35 | + a.artify(words, step) |
| 36 | + a.save(out_file) |
| 37 | + |
| 38 | +app = QApplication(sys.argv) |
| 39 | +root = QWidget() |
| 40 | +root.setWindowTitle("Ascii Py") |
| 41 | +root_layout = QGridLayout() |
| 42 | + |
| 43 | +# === CREATE === |
| 44 | +in_label = QLabel("From") |
| 45 | +out_label = QLabel("To") |
| 46 | +words_label = QLabel("Words to use") |
| 47 | +step_label = QLabel("Step Amount") |
| 48 | + |
| 49 | +in_line = QLineEdit() |
| 50 | +out_line = QLineEdit("out.jpg") |
| 51 | +words_line = QLineEdit("#") |
| 52 | +step_line = QLineEdit("3") |
| 53 | + |
| 54 | +open_button = QPushButton("Open File") |
| 55 | +save_button = QPushButton("Save As") |
| 56 | +save_img_button = QPushButton("Save Image") |
| 57 | +# === CREATE === |
| 58 | + |
| 59 | +# === HOOK === |
| 60 | +open_button.clicked.connect(get_input_file) |
| 61 | +save_button.clicked.connect(get_output_file) |
| 62 | +save_img_button.clicked.connect(save_img) |
| 63 | +# === HOOK === |
| 64 | + |
| 65 | +# === PLACE === |
| 66 | +root_layout.addWidget(in_label, 1,0,1,1) |
| 67 | +root_layout.addWidget(in_line, 2,0,1,1) |
| 68 | +root_layout.addWidget(open_button, 3,0,1,1) |
| 69 | + |
| 70 | +root_layout.addWidget(out_label, 1,1,1,1) |
| 71 | +root_layout.addWidget(out_line, 2,1,1,1) |
| 72 | +root_layout.addWidget(save_button, 3,1,1,1) |
| 73 | + |
| 74 | +root_layout.addWidget(words_label, 4,0,1,1) |
| 75 | +root_layout.addWidget(words_line, 5,0,1,1) |
| 76 | + |
| 77 | +root_layout.addWidget(step_label, 4,1,1,1) |
| 78 | +root_layout.addWidget(step_line, 5,1,1,1) |
| 79 | +root_layout.addWidget(save_img_button, 6,0,1,2) |
| 80 | +# === PLACE === |
| 81 | + |
| 82 | +root.setLayout(root_layout) |
| 83 | +root.show() |
| 84 | + |
| 85 | +# don't relaly see the point in resizing |
| 86 | +root.setFixedSize(root.size()) |
| 87 | + |
| 88 | +app.exec_() |
| 89 | +sys.exit() |
| 90 | + |
0 commit comments