Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

Commit

Permalink
Add test SavePromptWidget to talk editor
Browse files Browse the repository at this point in the history
  • Loading branch information
benbuckley committed Nov 5, 2014
1 parent 39943b0 commit f889ac0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 41 deletions.
35 changes: 10 additions & 25 deletions src/freeseer/frontend/talkeditor/SavePromptWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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")
43 changes: 27 additions & 16 deletions src/freeseer/frontend/talkeditor/talkeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -307,18 +312,20 @@ 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."""
log.info("Selecting row %d", model.row())
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())
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit f889ac0

Please sign in to comment.