class UserView(QMainWindow): userM = UserManager() def __init__(self, widget): super(UserView, self).__init__() loadUi("../designer/Users/UserView.ui", self) self.users = self.userM.list() self.widget = widget self.pop = '' self.load_data() self.setup() def setup(self): # Funzionalità dei Bottoni self.userButton.clicked.connect(self.__go_new_user) self.backButton.clicked.connect(self.close) self.schedaButton.clicked.connect(self.__go_user_card) self.disableButton.clicked.connect(self.enable_disable) self.enableButton.clicked.connect(self.enable_disable) self.deleteButton.clicked.connect(self.delete) self.disableButton.setVisible(True) self.enableButton.setVisible(False) #enableButton # Ricerca Dinamica self.nameField.textChanged.connect(lambda: self.search()) self.surnameField.textChanged.connect(lambda: self.search()) self.style() #checkbox self.checkBoxUserDisabled.stateChanged.connect(lambda: self.search()) def style(self): self.schedaButton.setStyleSheet(open("../designer/style/ButtonTheme.txt", "r").read()) """ Questo metodo setta lo stile della view :return: """ self.userButton.setStyleSheet(open("../designer/style/ButtonTheme.txt", "r").read()) self.backButton.setStyleSheet(open("../designer/style/ButtonTheme.txt", "r").read()) self.userTable.setStyleSheet(open("../designer/style/TableTheme.txt", "r").read()) self.nameField.setStyleSheet(open("../designer/style/TextBoxTheme.txt", "r").read()) self.surnameField.setStyleSheet(open("../designer/style/TextBoxTheme.txt", "r").read()) def load_table(self, users): """ Questo metodo permette di rimpire la QTableWidget presente nella view con una lista di utenti :param users: :return: None """ row = 0 self.userTable.setRowCount(len(users)) for user in self.users: self.userTable.setItem(row, 0, QtWidgets.QTableWidgetItem(user.name)) self.userTable.setItem(row, 1, QtWidgets.QTableWidgetItem(user.surname)) self.userTable.setItem(row, 2, QtWidgets.QTableWidgetItem(user.fiscal_code)) self.userTable.setItem(row, 3, QtWidgets.QTableWidgetItem(user.city)) row = row + 1 self.userTable.setEditTriggers(QTableWidget.NoEditTriggers) def load_data(self, users=None): if users is None: self.users = self.userM.list(self.checkBoxUserDisabled.isChecked()) self.load_table(self.users) else: self.load_table(users) # Region 'User Operation' def search(self): self.disableButton.setVisible(not self.checkBoxUserDisabled.isChecked()) self.enableButton.setVisible(self.checkBoxUserDisabled.isChecked()) if (self.nameField.text() == '') and (self.surnameField.text() == ''): self.load_data() # Search User by name elif (self.nameField.text() != '') and (self.surnameField.text() == ''): self.load_data_research(self.userM.findName(self.nameField.text(), self.checkBoxUserDisabled.isChecked())) # Search User by surname elif (self.nameField.text() == '') and (self.surnameField.text() != ''): self.load_data_research(self.userM.findSurname(self.surnameField.text(), self.checkBoxUserDisabled.isChecked())) # Search User by both elif (self.nameField.text() != '') and (self.surnameField.text() != ''): self.load_data_research(self.userM.findNameSurname(self.nameField.text(), self.surnameField.text(), self.checkBoxUserDisabled.isChecked())) def delete(self): rowtable = self.userTable.currentRow() if rowtable == -1: self.show_popup() else: self.pop = DeletePopup(self.delete_user) self.pop.show() def enable_disable(self): rowtable = self.userTable.currentRow() if rowtable == -1: self.show_popup() else: if self.checkBoxUserDisabled.isChecked(): text = "Sicuro di voler abilitare l' utente?" else: text = "Sicuro di voler disabilitare l' utente?" self.pop = EnableDisableUserPopup(self.enable_disable_user, text) self.pop.show() # endregion def load_data_research(self, users): """ Questo metodo riempe la tabella con quegli utenti che sono il risultato della ricerca :param users: :return: None """ self.users = users self.load_table(self.users) def delete_user(self): """ Questo metodo permette di rimuovere l'utente selezionato dal sistema :return: None """ row = self.userTable.currentRow() if self.userM.count_movement_with_the_same_user_id(self.users[row].id) == 0: self.userM.delete(self.users[row].id) self.users.remove(self.users[row]) self.userTable.removeRow(row) else: self.pop = Popup("Utente già presente in almeno 1 movimento.") self.pop.show() def enable_disable_user(self): """ Questo metodo permette di disabilitare l'utente selezionato dal sistema :return: None """ row = self.userTable.currentRow() #self.userM.delete(self.users[row].id) self.users[row].disabled = not self.checkBoxUserDisabled.isChecked() self.userM.set(self.users[row]) self.users.remove(self.users[row]) self.userTable.removeRow(row) def show_popup(self): self.pop = Popup("Selezionare un utente") self.pop.show() # Region 'View Links' def __go_new_user(self): """ Questo metodo consente di andare nella view che permette di creare un nuovo utente :return: None """ user = None self.view = UserCardView(self.widget, user, self.load_data) self.view.show() def __go_user_card(self): """ Questo metodo consente di andare nella view che permette di visualizzare le informazioni dell'utente selezionato a schermo :return: None """ rowtable = self.userTable.currentRow() if rowtable == -1: self.show_popup() else: user = self.users[rowtable] self.view = UserCardView(self.widget, user, self.load_data) self.view.show()
class MovementsView(QMainWindow): movementM = MovementManager() itemM = ItemManager() def __init__(self, widget): super(MovementsView, self).__init__() loadUi("../designer/Movements/MovementView.ui", self) self.widget = widget self.view = '' self.setup() def setup(self): self.style() self.loanButton.clicked.connect(lambda: self.new_loan()) self.consultationButton.clicked.connect( lambda: self.new_consultation()) self.infoButton.clicked.connect(lambda: self.movement_info()) self.backButton.clicked.connect(lambda: self.close()) self.givingbookButton.clicked.connect(lambda: self.giving()) self.deleteMovements.clicked.connect(lambda: self.delete()) self.loanRadio.setChecked(True) self.searchField.textChanged.connect(lambda: self.search()) self.loanRadio.toggled.connect(lambda: self.search()) self.consultationRadio.toggled.connect(lambda: self.search()) self.backRadio.toggled.connect(lambda: self.search()) self.load_data() def style(self): # Button Style self.loanButton.setStyleSheet( open("../designer/style/ButtonTheme.txt", "r").read()) self.consultationButton.setStyleSheet( open("../designer/style/ButtonTheme.txt", "r").read()) self.infoButton.setStyleSheet( open("../designer/style/ButtonTheme.txt", "r").read()) # Line Edit Style self.searchField.setStyleSheet( open("../designer/style/TextBoxTheme.txt", "r").read()) # Table Style self.movementTable.setStyleSheet( open("../designer/style/TableTheme.txt", "r").read()) def new_consultation(self): self.view = LoanView(self.widget, self.load_data, 0) self.view.show() def new_loan(self): self.view = LoanView(self.widget, self.load_data, 1) self.view.show() def movement_info(self): rowtable = self.movementTable.currentRow() if rowtable == -1: self.popUp = Popup("Selezionare prima un movimento!") self.popUp.show() else: movement = self.movements[rowtable] self.view = InfoView(self.widget, movement) #self.view = LoanView(self.widget, self.load_data, 1) self.view.show() def load_data(self): self.movements = self.movementM.find_all(self.radio_selection(), 5) self.load_table() def load_table(self): """ Questo metodo permette di rimpire la QTableWidget presente nella view con una lista di utenti :param users: :return: None """ row = 0 self.movementTable.setRowCount(len(self.movements)) for movement in self.movements: self.movementTable.setItem( row, 0, QtWidgets.QTableWidgetItem( movement.timestamp.strftime('%d/%m/%Y %H:%M:%S'))) self.movementTable.setItem( row, 1, QtWidgets.QTableWidgetItem(movement.item.isbn)) self.movementTable.setItem( row, 2, QtWidgets.QTableWidgetItem(movement.item.title)) self.movementTable.setItem( row, 3, QtWidgets.QTableWidgetItem(movement.user.fiscal_code)) self.movementTable.setItem( row, 4, QtWidgets.QTableWidgetItem(movement.user.name + " " + movement.user.surname)) self.movementTable.setItem( row, 5, QtWidgets.QTableWidgetItem(movement.user.first_cellphone)) row = row + 1 self.movementTable.setEditTriggers(QTableWidget.NoEditTriggers) def search(self): numSearchMode = 0 if self.searchField.text() != '': if self.searchMode.currentText() == 'In tutti i campi': numSearchMode = 0 elif self.searchMode.currentText() == 'Utente': numSearchMode = 1 elif self.searchMode.currentText() == 'Titolo': numSearchMode = 2 elif self.searchMode.currentText() == 'Data': numSearchMode = 3 elif self.searchMode.currentText() == 'ISBN': numSearchMode = 4 self.movements = self.movementM.find_all(self.radio_selection(), numSearchMode, self.searchField.text()) else: self.movements = self.movementM.find_all(self.radio_selection(), 5) self.load_table() def radio_selection(self): if self.consultationRadio.isChecked(): return 0 elif self.loanRadio.isChecked(): return 1 elif self.backRadio.isChecked(): return 2 def giving(self): rowtable = self.movementTable.currentRow() self.movements[ rowtable].item.availability = AvailabilityEnum.disponibile self.movements[rowtable].item.cataloging_level = CatalogingLevel.max self.movements[rowtable].item.publication_state = 0 self.movements[rowtable].mov_type = 2 self.movementM.set(self.movements[rowtable]) self.itemM.edit_item( self.movements[self.movementTable.currentRow()].item) self.load_data() #deleteMovements def delete(self): rowtable = self.movementTable.currentRow() if rowtable == -1: self.show_popup() else: text = "Sei sicuro di voler eliminare il movimento?" self.pop = DeletePopup(self.delete_movement, text) self.pop.show() def delete_movement(self): """ Questo metodo permette di rimuovere l'utente selezionato dal sistema :return: None """ row = self.movementTable.currentRow() self.movementM.delete(self.movements[row].id) self.movements.remove(self.movements[row]) self.movementTable.removeRow(row)
class MailView(QWidget): # Manager comunicationM = ComunicationManager() userM = UserManager() # Variabili per email sender_email = '' rec_email = '' password = '' server = '' msg = '' def __init__(self, widget): super(MailView, self).__init__() loadUi("../designer/Comunications/MailView.ui", self) # Variaibili self.widget = widget self.comunications = self.comunicationM.list() self.users = '' self.comunication = '' self.pop = '' self.com_sub_list = '' self.users_combo = [] self.com_rec_list = [] # Metodi Iniziali self.setup() # Region Set-Up def setup(self): self.setup_email() self.setup_component() def setup_component(self): # Function Button self.sendButton.clicked.connect(self.send) self.refreshtextButton.clicked.connect(self.refresh_text) self.backButton.clicked.connect(self.close) # Field Properties self.refreshtextButton.hide() self.mailField.setText(self.sender_email) self.mailField.setReadOnly(True) self.objectMail.setReadOnly(True) # ComboBox self.set_combo_box() # Progress bar self.progressBar.setVisible(False) #self.progressBar.setMaximum(100) #self.progressBar.setMinimum(0) def set_combo_box(self): # Lista dei Messaggi Predefiniti self.com_sub_list = [] self.com_sub_list.append('') for com in self.comunications: self.com_sub_list.append(com.subject) self.messageBox.addItems(self.com_sub_list) # Al cambiare del contenuto della comboBox cambia l'oggetto e il testo self.messageBox.currentTextChanged.connect(self.on_message_box_changed) # Lista Utenti che hanno registrato una mail self.users = self.userM.list() self.users_combo = [] self.com_rec_list = [] self.com_rec_list.append('') for user in self.users: if user.email != '': self.com_rec_list.append(user.name + " " + user.surname) self.users_combo.append(user) self.recipientBox.addItems(self.com_rec_list) # Al cambiare dell'utente selezionato cambia il destinatario self.recipientBox.currentTextChanged.connect( self.on_recipient_box_changed) self.allBox.stateChanged.connect(self.state_changed) def setup_email(self): # Credenziali per la mail self.sender_email = "*****@*****.**" # Enter your address self.password = "******" # endregion # Region Button Function def on_message_box_changed(self): # Eventi della Combo Box dei messaggi if self.messageBox.currentText() == '': self.objectMail.setPlainText('') self.textMail.setPlainText('') self.refreshtextButton.hide() self.objectMail.setReadOnly(False) else: self.objectMail.setPlainText( self.comunicationM.find( self.messageBox.currentIndex()).subject) self.textMail.setPlainText( self.comunicationM.find(self.messageBox.currentIndex()).text) self.refreshtextButton.show() self.objectMail.setReadOnly(True) def on_recipient_box_changed(self): self.rec_email = self.users_combo[self.recipientBox.currentIndex() - 1].email def send(self): progress = 100 / self.users_combo.__len__() self.progressBar.setVisible(True) sum = 0 if self.allBox.isChecked() == True: for i in range(0, self.users_combo.__len__()): sum = sum + progress self.progressBar.setValue(sum) self.sendEmail(i) #if i == (self.users_combo.__len__() - 1): #self.progressBar.setValue(100 - progress) self.progressBar.setVisible(False) str = "Email inviate con successo!" else: self.sendEmail(self.recipientBox.currentIndex() - 1) str = "Email inviata con successo!" self.pop = Popup(str) self.pop.show() print("Email has been sent to ", self.msg) def state_changed(self): if self.allBox.isChecked() == True: self.recipientBox.setEnabled(False) else: self.recipientBox.setEnabled(True) def sendEmail(self, i): # Destinatario self.rec_email = f"{self.users_combo[i].email}" # Contenuto del Messaggio self.msg = MIMEMultipart() self.msg['Subject'] = Header(self.objectMail.toPlainText()).encode() self.msg['To'] = self.rec_email self.txt = MIMEText('Gentile ' + self.users_combo[self.recipientBox.currentIndex() - 1].name + ',\n' + self.textMail.toPlainText()) self.msg.attach(self.txt) email_end = open('config/end_mail.html').read() end = MIMEText(email_end, 'html') self.msg.attach(end) # Connessione con il Server self.server = smtplib.SMTP('smtp.gmail.com', 587) self.server.starttls() self.server.login(self.sender_email, self.password) print("Login success") # Inoltro e-mail self.server.sendmail(self.sender_email, self.rec_email, self.msg.as_string()) def refresh_text(self): self.comunication.text = self.textMail.toPlainText() self.comunicationM.set(self.comunication) self.pop = Popup("Email predefinita aggiornata!") self.pop.show()
class LoanView(QDialog): userM = UserManager() itemM = ItemManager() movementM = MovementManager() def __init__(self, widget, callback, flag): super(LoanView, self).__init__() ''' 0:Consultazione 1:Prestito 2:Rientro ''' loadUi("../designer/Movements/LoanView.ui", self) self.widget = widget self.users = self.userM.list() self.items = self.movementM.get_items_available() self.user = '' self.movement = Movement() self.callback = callback self.flag = flag # self.setModal(True) # self.widget = QtWidgets.QStackedWidget() # self.widget.addWidget(self) # self.widget.show() self.setup() #self.movementM = MovementManager() #self.movementM.findAll("tu", 1) if self.flag == 0: self.loantypeBox.hide() self.expirationEdit.hide() self.label_9.hide() self.label_10.hide() #self.frame_13.setGeometry(931,210) def setup(self): self.selectuserButton.clicked.connect(lambda: self.select_user()) self.selectuserButton.setDisabled(False) self.selectdocButton.clicked.connect(lambda: self.select_item()) self.selectdocButton.setDisabled(False) self.newuserButton.clicked.connect(lambda: self.new_user()) self.confirmButton.clicked.connect( lambda: self.save()) #salvataggio del movimento self.returnButton.clicked.connect(lambda: self.close()) self.userField.setReadOnly(True) self.fiscalcodeField.setReadOnly(True) self.cellField.setReadOnly(True) self.style() self.load_user_table() self.load_item_table(self.items) def style(self): self.userTable.setStyleSheet( open("../designer/style/TableTheme.txt", "r").read()) self.itemTable.setStyleSheet( open("../designer/style/TableTheme.txt", "r").read()) self.nameField.textChanged.connect(lambda: self.search_user()) self.surnameField.textChanged.connect(lambda: self.search_user()) self.itemField.textChanged.connect(lambda: self.search_item()) def select_user(self): if self.userTable.currentRow() == -1: self.pop = Popup("Selezionare un utente") self.pop.show() else: row = self.userTable.currentRow() self.user = self.users[row] # assegno l'id dello user al movimento self.movement.user_id = self.user.id self.userField.setText(self.user.name + " " + self.user.surname) self.fiscalcodeField.setText(self.user.fiscal_code) self.cellField.setText(self.user.first_cellphone) def select_item(self): if self.itemTable.currentRow() == -1: self.pop = Popup("Selezionare un Documento") self.pop.show() else: row = self.itemTable.currentRow() item = self.items[row] #assegno l'id dell'item al movimento self.movement.item_id = item.id self.isbnField.setText(item.isbn) self.titleField.setText(item.title) def new_user(self): self.view = UserCardView(self.widget, None, self.load_user_table) self.view.show() # region Table def load_user_table(self, users=None): if users is None: self.users = self.userM.list() else: self.users = users if self.users is not None: row = 0 self.userTable.setRowCount(len(self.users)) for user in self.users: self.userTable.setItem(row, 0, QtWidgets.QTableWidgetItem(user.name)) self.userTable.setItem( row, 1, QtWidgets.QTableWidgetItem(user.surname)) self.userTable.setItem( row, 2, QtWidgets.QTableWidgetItem(user.fiscal_code)) row = row + 1 self.userTable.setEditTriggers(QTableWidget.NoEditTriggers) def load_item_table(self, items): self.items = items row = 0 self.itemTable.setRowCount(len(self.items)) for item in self.items: self.itemTable.setItem(row, 0, QtWidgets.QTableWidgetItem(item.title)) self.itemTable.setItem(row, 1, QtWidgets.QTableWidgetItem(item.author)) self.itemTable.setItem(row, 2, QtWidgets.QTableWidgetItem(item.isbn)) row = row + 1 self.itemTable.setEditTriggers(QTableWidget.NoEditTriggers) # endregion # region Search def search_user(self): try: if (self.nameField.text() == '') and (self.surnameField.text() == ''): self.load_user_table(self.userM.list()) elif (self.nameField.text() != '') and (self.surnameField.text() == ''): #print(self.userM.findName(self.nameField.text(), False)) self.load_user_table(self.userM.findName( self.nameField.text())) elif (self.nameField.text() == '') and (self.surnameField.text() != ''): self.load_user_table( self.userM.findSurname(self.surnameField.text())) elif (self.nameField.text() != '') and (self.surnameField.text() != ''): self.load_user_table( self.userM.findNameSurname(self.nameField.text(), self.surnameField.text())) except FileNotFoundError as err: src.Utils.UI.ErrorMessage(err).show() def search_item(self): self.load_item_table(self.itemM.get_items(self.itemField.text(), 1)) # endregion # region Save_and_back def save(self): row = self.itemTable.currentRow() if self.movement.user_id is None or self.movement.item_id is None: self.pop = Popup("Selezionare sia un Utente sia un Documento") self.pop.show() else: if self.flag == 1: self.movement.mov_type = 1 else: self.movement.mov_type = 0 self.movement.timestamp = date.today() self.movementM.add(self.movement) self.movement = self.movementM.find( self.movementM.get_last_movement_id()) newpath = os.path.expanduser("~/Desktop/Moduli Prestito") if not os.path.exists(newpath): os.makedirs(newpath) self.reportM = ReportManager(self.movement, newpath) self.reportM.set_report() self.back() self.items[row].availability = AvailabilityEnum.in_prestito self.itemM.edit_item(self.items[row]) def back(self): self.callback() self.close()