From f889ac024f506abae7c89b96d69b354187b670f2 Mon Sep 17 00:00:00 2001 From: Ben Buckley Date: Tue, 4 Nov 2014 21:49:12 -0800 Subject: [PATCH] Add test SavePromptWidget to talk editor --- .../frontend/talkeditor/SavePromptWidget.py | 35 +++++---------- .../frontend/talkeditor/talkeditor.py | 43 ++++++++++++------- 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/freeseer/frontend/talkeditor/SavePromptWidget.py b/src/freeseer/frontend/talkeditor/SavePromptWidget.py index ad98a6db..b2b456b8 100644 --- a/src/freeseer/frontend/talkeditor/SavePromptWidget.py +++ b/src/freeseer/frontend/talkeditor/SavePromptWidget.py @@ -24,17 +24,15 @@ from PyQt4.QtGui import QDialog from PyQt4.QtGui import QHBoxLayout -from PyQt4.QtGui import QIcon +from PyQt4.QtGui import QLabel from PyQt4.QtGui import QPushButton from PyQt4.QtGui import QVBoxLayout -from freeseer.frontend.talkeditor.TalkDetailsWidget import TalkDetailsWidget - -class NewTalkWidget(QDialog): - """Dialog for adding new talk to database""" +class SavePromptWidget(QDialog): + """Dialog warning the user if there are unsaved changes to the current talk""" def __init__(self, parent=None): - super(NewTalkWidget, self).__init__(parent) + super(SavePromptWidget, self).__init__(parent) self.resize(600, 200) @@ -43,24 +41,11 @@ def __init__(self, parent=None): self.bottomButtonLayout = QHBoxLayout() - self.talkDetailsWidget = TalkDetailsWidget() - self.layout.addWidget(self.talkDetailsWidget) - - self.talkDetailsWidget.saveButton.hide() - addIcon = QIcon.fromTheme("list-add") - cancelIcon = QIcon.fromTheme("edit-clear") - - self.addButton = QPushButton('Add') - self.addButton.setIcon(addIcon) - self.cancelButton = QPushButton('Cancel') - self.cancelButton.setIcon(cancelIcon) - - self.talkDetailsWidget.layout.addLayout(self.bottomButtonLayout, 6, 1, 1, 1) - - self.bottomButtonLayout.addWidget(self.addButton) - self.bottomButtonLayout.addWidget(self.cancelButton) + self.label = QLabel("This is a test. Click the button below to continue.") + self.testButton = QPushButton('Test') - self.setWindowTitle("New Talk") + #self.bottomButtonLayout.addWidget(self.testButton) + self.layout.addWidget(self.label) + self.layout.addWidget(self.testButton) - self.talkDetailsWidget.enable_input_fields() - self.talkDetailsWidget.dateEdit.setDisplayFormat('dd MMMM, yyyy') + self.setWindowTitle("Unsaved Changes Exist") diff --git a/src/freeseer/frontend/talkeditor/talkeditor.py b/src/freeseer/frontend/talkeditor/talkeditor.py index 2aacd20a..34e428a6 100644 --- a/src/freeseer/frontend/talkeditor/talkeditor.py +++ b/src/freeseer/frontend/talkeditor/talkeditor.py @@ -53,6 +53,7 @@ from freeseer.frontend.talkeditor.TalkDetailsWidget import TalkDetailsWidget from freeseer.frontend.talkeditor.NewTalkWidget import NewTalkWidget from freeseer.frontend.talkeditor.ImportTalksWidget import ImportTalksWidget +from freeseer.frontend.talkeditor.SavePromptWidget import SavePromptWidget log = logging.getLogger(__name__) @@ -99,22 +100,26 @@ def __init__(self, config, db): self.currentTalkIndex = QPersistentModelIndex() # Prompt user to "Continue Editing", "Discard Changes" or "Save Changes" - # Can't be a QMessageBox anymore. Must be a QWidget? + # Can't be a QMessageBox anymore. Must be a QDialog? Put in separate file self.savePromptBox = QMessageBox() self.savePromptBox.setWindowTitle("Unsaved Changes Exist") self.savePromptBox.setIcon(QMessageBox.Information) self.savePromptBox.setText("The talk you were editing has unsaved changes.") self.continueButton = QPushButton('Continue Editing') - #self.continueButton = self.savePromptBox.addButton("Continue Editing", QMessageBox.RejectRole) - self.discardButton = QPushButton('Discard Changes') - #self.discardButton = self.savePromptBox.addButton("Discard Changes", QMessageBox.DestructiveRole) - self.saveButton = QPushButton('Save Changes') - #self.saveButton = self.savePromptBox.addButton("Save Changes", QMessageBox.AcceptRole) - self.savePromptBox.addWidget(self.continueButton) - self.savePromptBox.addWidget(self.discardButton) - self.savePromptBox.addWidget(self.saveButton) + self.continueButton = self.savePromptBox.addButton("Continue Editing", QMessageBox.RejectRole) + #self.discardButton = QPushButton('Discard Changes') + self.discardButton = self.savePromptBox.addButton("Discard Changes", QMessageBox.DestructiveRole) + #self.saveButton = QPushButton('Save Changes') + self.saveButton = self.savePromptBox.addButton("Save Changes", QMessageBox.AcceptRole) + #self.savePromptBox.addWidget(self.continueButton) + #self.savePromptBox.addWidget(self.discardButton) + #self.savePromptBox.addWidget(self.saveButton) self.savePromptBox.setDefaultButton(self.saveButton) + # Setup SavePromptWidget + self.savePromptWidget = SavePromptWidget() + self.connect(self.savePromptWidget.testButton, SIGNAL('clicked()'), self.savePromptWidget.reject) + # Initialize geometry, to be used for restoring window positioning. self.geometry = None @@ -307,10 +312,10 @@ def search_talks(self): def show_save_prompt(self): """Prompts the user to save or discard changes, or continue editing.""" - self.savePromptBox.setModal(True) - self.savePromptBox.show() - self.savePromptBox.setDefaultButton(self.saveButton) - return self.savePromptBox.clickedButton() + self.savePromptWidget.setModal(True) + self.savePromptWidget.show() + #self.savePromptBox.setDefaultButton(self.saveButton) + #return self.savePromptBox.clickedButton() def click_talk(self, model): """Warns user if there are unsaved changes, and selects talk clicked by the user.""" @@ -318,7 +323,9 @@ def click_talk(self, model): modelRow = model.row() if self.unsaved_details_exist(): log.info("Unsaved changes exist in row %d", self.currentTalkIndex.row()) - confirm = self.show_save_prompt() + #confirm = self.show_save_prompt() + self.show_save_prompt() + confirm = self.discardButton if confirm == self.saveButton: log.info("Saving changes in row %d...", self.currentTalkIndex.row()) self.tableView.selectRow(self.currentTalkIndex.row()) @@ -338,7 +345,9 @@ def click_add_button(self): """Warns user if there are unsaved changes, and shows the New Talk window.""" if self.unsaved_details_exist(): log.info("Unsaved changes exist in row %d", self.currentTalkIndex.row()) - confirm = self.show_save_prompt() + #confirm = self.show_save_prompt() + self.show_save_prompt() + confirm = self.discardButton if confirm == self.saveButton: log.info("Saving changes in row %d...", self.currentTalkIndex.row()) self.update_talk() @@ -512,7 +521,9 @@ def add_talks_from_rss(self): def closeEvent(self, event): if self.unsaved_details_exist(): log.info("Unsaved changes exist in row %d", self.currentTalkIndex.row()) - confirm = self.show_save_prompt() + #confirm = self.show_save_prompt() + self.show_save_prompt() + confirm = self.discardButton if confirm == self.saveButton: log.info("Saving changes in row %d...", self.currentTalkIndex.row()) self.update_talk()