Jul-29-2023, 04:26 PM
I am a hobby programmer and would like to write a program that supports, among other things, the scanning of double-sided paper with a one-sided feeder.
I've made good progress with the content in vb.net...
However, I would like to deepen my python knowledge and have therefore decided to write the program in python.
For this I will translate my vb functionalities into the python language...
At the moment I'm in the process of creating the GUI and linking it to functions.
The following problems occur, which I could not solve with googling:
1) When I click on the "adjustments" button, the adjustments window opens.
If I then click on the "add profile" button, the "adjustments" window appears.
The same applies to the "add profile" button when I click on the "adjustments" button after the "add profile" button.
2) in the "LineEditWindow" class in the "save_profile_in_file" function:
I would like to call the "add_profile" function of the "MainWindow" class from this function and pass the "profile_name" variable. This should add the item "profile_name" to the QListwidget "listbox_profile".
I would be very happy about constructive help on these two problems!
Thank you very much for the support!!
I've made good progress with the content in vb.net...
However, I would like to deepen my python knowledge and have therefore decided to write the program in python.
For this I will translate my vb functionalities into the python language...
At the moment I'm in the process of creating the GUI and linking it to functions.
The following problems occur, which I could not solve with googling:
1) When I click on the "adjustments" button, the adjustments window opens.
If I then click on the "add profile" button, the "adjustments" window appears.
The same applies to the "add profile" button when I click on the "adjustments" button after the "add profile" button.
2) in the "LineEditWindow" class in the "save_profile_in_file" function:
I would like to call the "add_profile" function of the "MainWindow" class from this function and pass the "profile_name" variable. This should add the item "profile_name" to the QListwidget "listbox_profile".
I would be very happy about constructive help on these two problems!
Thank you very much for the support!!
import sys from pathlib import Path from PyQt6.QtGui import QFont from PyQt6.QtWidgets import ( QApplication, QLabel, QMainWindow, QPushButton, QHBoxLayout, QVBoxLayout, QWidget, QGroupBox, QListWidget, QCheckBox, QRadioButton, QLineEdit, QFileDialog, QMessageBox, ) class LineEditWindow(QWidget): def __init__(self): super().__init__() self.setWindowTitle("abc") self.resize(300, 50) self.profile_name = "" self.i = 0 self.layout = QHBoxLayout() self.lineedit = QLineEdit() self.lineedit.setFont(QFont('Times', 12)) self.button_enter = QPushButton("save profile") self.button_enter.setFont(QFont('Times', 12)) for z in [self.lineedit, self.button_enter]: self.layout.addWidget(z) self.layout2 = QVBoxLayout() self.label = QLabel("Please enter a profile's name") self.label.setFont(QFont('Times', 12)) self.layout2.addWidget(self.label) self.layout2.addLayout(self.layout) self.setLayout(self.layout2) self.button_enter.clicked.connect(self.save_profile_in_file) def save_profile_in_file(self): profile_name = self.lineedit.text() print(profile_name) f = open("profiles.txt", "a") f.write(str(profile_name) + "\n") f.close self.lineedit.setText("") # # add to listbox main = MainWindow() main.add_profile(profile_name) class AdjustmentsWindow(QWidget): def __init__(self): super().__init__() self.setWindowTitle("abc") self.resize(300, 150) self.label = QLabel("adjustments") self.label.setFont(QFont('Times', 12)) self.button_files_to_convert = QPushButton("files to convert path") self.button_files_to_convert.setFont(QFont('Times', 12)) self.button_created_files = QPushButton("created files path") self.button_created_files.setFont(QFont('Times', 12)) self.button_donate = QPushButton("donate") self.button_donate.setFont(QFont('Times', 12)) self.layout = QVBoxLayout() for k in [self.label, self.button_files_to_convert, self.button_created_files, self.button_donate]: self.layout.addWidget(k) self.setLayout(self.layout) self.button_created_files.clicked.connect(self.button_created_files_clicked) self.button_files_to_convert.clicked.connect(self.button_files_to_convert_clicked) def button_created_files_clicked(self): path_created_files = str(QFileDialog().getExistingDirectory(self, 'Select path for created files')) f = open("pcf.txt", "w") f.write(self.path_created_files) f.close() def button_files_to_convert_clicked(self): path_files_to_convert = str(QFileDialog().getExistingDirectory(self, 'Select path for files to convert')) f = open("pftc.txt", "w") f.write(self.path_files_to_convert) f.close() class MainWindow(QMainWindow): def __init__(self, parent=None): # No additional window yet self.w = None super(MainWindow, self).__init__(parent) self.profile_name = "" self.setWindowTitle("abc") self.resize(400, 600) self.central_widget = QWidget() self.setCentralWidget(self.central_widget) # center MainWindow to screen qr = self.frameGeometry() cp = self.screen().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) # --------------------- groupbox_have --------------------- self.groupbox_have = QGroupBox("what do you have?") self.groupbox_have.setFont(QFont('Times', 12)) self.groupbox_have.font().setBold(True) self.groupbox_have_layout = QVBoxLayout() self.listbox_medium = QListWidget() self.listbox_medium.setFont(QFont('Times', 12)) self.listbox_medium2 = QListWidget() self.listbox_medium2.setFont(QFont('Times', 12)) self.checkbox = QCheckBox("stack contains patchTpages") self.checkbox.setFont(QFont('Times', 12)) for x in [self.listbox_medium, self.listbox_medium2, self.checkbox]: self.groupbox_have_layout.addWidget(x) self.groupbox_have.setLayout(self.groupbox_have_layout) # --------------------- groupbox_receive --------------------- self.groupbox_receive = QGroupBox("what would you like to receive?") self.groupbox_receive.setFont(QFont('Times', 12)) self.groupbox_receive.font().setBold(True) self.groupbox_receive_layout = QVBoxLayout() self.listbox_target = QListWidget() self.listbox_target.setFont(QFont('Times', 12)) self.groupbox_move = QGroupBox("move file(s) to") self.groupbox_move.setFont(QFont('Times', 12)) self.groupbox_move.font().setBold(True) self.checkbox_move_to = QCheckBox("move file(s) to desired folder(s)") self.checkbox_move_to.setFont(QFont('Times', 12)) self.groupbox_move_layout = QVBoxLayout() self.groupbox_move_layout.addWidget(self.checkbox_move_to) self.groupbox_move.setLayout(self.groupbox_move_layout) self.groupbox_receive_layout = QVBoxLayout() for y in [self.listbox_target, self.groupbox_move]: self.groupbox_receive_layout.addWidget(y) self.groupbox_receive.setLayout(self.groupbox_receive_layout) # --------------------- groupbox_profile --------------------- self.groupbox_profile = QGroupBox("which profile should be used?") self.groupbox_profile.setFont(QFont('Times', 12)) self.groupbox_profile.font().setBold(True) self.listbox_profile = QListWidget() self.listbox_profile.setFont(QFont('Times', 12)) self.button_add_profile = QPushButton("add profile") self.button_add_profile.setFont(QFont('Times', 12)) self.button_clear_profile = QPushButton("clear profile") self.button_clear_profile.setFont(QFont('Times', 12)) self.groupbox_profile_intern_layout = QHBoxLayout() for x in [self.button_add_profile, self.button_clear_profile]: self.groupbox_profile_intern_layout.addWidget(x) self.groupbox_profile_layout = QVBoxLayout() self.groupbox_profile_layout.addWidget(self.listbox_profile) self.groupbox_profile_layout.addLayout(self.groupbox_profile_intern_layout) self.groupbox_profile.setLayout(self.groupbox_profile_layout) # -------------------------------------------------------------- self.button_apply_selection = QPushButton("apply selection") self.button_apply_selection.setFont(QFont('Times', 12)) self.button_adjustments = QPushButton("adjustments") self.button_adjustments.setFont(QFont('Times', 12)) self.label = QLabel("abc") self.label.setFont(QFont('Times', 12)) self.layout_base = QVBoxLayout() for c in [self.label, self.groupbox_have, self.groupbox_receive, self.groupbox_profile, self.button_apply_selection, self.button_adjustments]: self.layout_base.addWidget(c) self.central_widget.setLayout(self.layout_base) # clear listbox self.listbox_medium.clear() self.listbox_medium2.clear() self.listbox_target.clear() # fill listbox self.listbox_medium.insertItem(0, "paper") self.listbox_medium.insertItem(1, "file(s)") self.listbox_medium2.insertItem(0, "-") self.listbox_target.insertItem(0, "-") self.button_add_profile.clicked.connect(self.button_add_profile_clicked) self.button_clear_profile.clicked.connect(self.button_clear_profile_clicked) self.button_apply_selection.clicked.connect(self.button_apply_selection_clicked) self.button_adjustments.clicked.connect(self.button_adjustments_clicked) self.path_created_files = open("pcf.txt", "r").read() if self.path_created_files == "": QMessageBox.about(self, "Go to adjustments", "Please adjust created files path") self.path_files_to_convert = open("pftc.txt", "r").read() if self.path_files_to_convert == "": QMessageBox.about(self, "Go to adjustments", "Please adjust files to convert path") def button_add_profile_clicked(self): if self.w is None: self.w = LineEditWindow() self.w.show() def add_profile(self, profile_name): i = self.listbox_profile.count() self.listbox_profile.insertItem(i + 1, str(profile_name)) def button_clear_profile_clicked(self): f = open("profiles.txt", "w") f.write("") f.close() def button_adjustments_clicked(self): if self.w is None: self.w = AdjustmentsWindow() self.w.show() def button_apply_selection_clicked(self): current_index = self.listbox_medium.currentRow() if current_index == 0: print("paper") if current_index == 1: print("files") if __name__ == '__main__': app = QApplication(sys.argv) app.setStyleSheet(Path("stylesheet.qss").read_text()) win = MainWindow() win.show() app.exec()