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

Commit

Permalink
Refactor talkeditor save prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
benbuckley committed Nov 15, 2014
1 parent ce6ebf0 commit a733e1e
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 40 deletions.
13 changes: 10 additions & 3 deletions src/freeseer/frontend/talkeditor/SavePromptWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ def __init__(self, parent=None):
self.bottomButtonLayout = QHBoxLayout()

self.label = QLabel("This is a test. Click the button below to continue.")
self.testButton = QPushButton('Test')
self.saveButton = QPushButton('Save Changes')
self.discardButton = QPushButton('Discard Changes')
self.continueButton = QPushButton('Continue Editing')

#self.bottomButtonLayout.addWidget(self.testButton)
self.layout.addWidget(self.label)
self.layout.addWidget(self.testButton)

self.buttonLayout = QHBoxLayout()
self.buttonLayout.addWidget(self.saveButton)
self.buttonLayout.addWidget(self.discardButton)
self.buttonLayout.addWidget(self.continueButton)

self.layout.addLayout(self.buttonLayout)

self.setWindowTitle("Unsaved Changes Exist")
147 changes: 110 additions & 37 deletions src/freeseer/frontend/talkeditor/talkeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
from PyQt4.QtGui import QIcon
from PyQt4.QtGui import QMessageBox
from PyQt4.QtGui import QPixmap
from PyQt4.QtGui import QPushButton
from PyQt4.QtGui import QSortFilterProxyModel
from PyQt4.QtGui import QTableView
from PyQt4.QtGui import QVBoxLayout
Expand Down Expand Up @@ -95,29 +94,26 @@ def __init__(self, config, db):
self.mainLayout.addWidget(self.importTalksWidget)
# --- End Layout

# Keep track of index of the most recently selected talk
# Keep track of current and most recently selected talk
self.currentTalkIndex = QPersistentModelIndex()

# Prompt user to "Continue Editing", "Discard Changes" or "Save Changes"
# 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.savePromptBox.setDefaultButton(self.saveButton)
self.newTalkIndex = QPersistentModelIndex()

# Setup SavePromptWidget
self.savePromptWidget = SavePromptWidget()
self.connect(self.savePromptWidget.testButton, SIGNAL('clicked()'), self.savePromptWidget.reject)
self.savePromptWidgetTalk = SavePromptWidget()
self.savePromptWidgetAdd = SavePromptWidget()
self.savePromptWidgetExit = SavePromptWidget()
# The actions of the save, discard and continue buttons vary depending on why they are pushed
self.connect(self.savePromptWidgetTalk.saveButton, SIGNAL('clicked()'), self.save_button_talk)
self.connect(self.savePromptWidgetTalk.discardButton, SIGNAL('clicked()'), self.discard_button_talk)
self.connect(self.savePromptWidgetTalk.continueButton, SIGNAL('clicked()'), self.continue_button_talk)

self.connect(self.savePromptWidgetAdd.saveButton, SIGNAL('clicked()'), self.save_button_add)
self.connect(self.savePromptWidgetAdd.discardButton, SIGNAL('clicked()'), self.discard_button_add)
self.connect(self.savePromptWidgetAdd.continueButton, SIGNAL('clicked()'), self.continue_button_add)

self.connect(self.savePromptWidgetExit.saveButton, SIGNAL('clicked()'), self.save_button_exit)
self.connect(self.savePromptWidgetExit.discardButton, SIGNAL('clicked()'), self.discard_button_exit)
self.connect(self.savePromptWidgetExit.continueButton, SIGNAL('clicked()'), self.continue_button_exit)

# Initialize geometry, to be used for restoring window positioning.
self.geometry = None
Expand Down Expand Up @@ -309,22 +305,45 @@ def search_talks(self):
self.proxy.setFilterKeyColumn(-1)
self.proxy.setFilterFixedString(self.commandButtons.searchLineEdit.text())

def show_save_prompt(self):
def save_button_talk(self):
log.info("NewTalkIndex row = %d.", self.newTalkIndex.row())
log.info("Saving changes in row %d...", self.currentTalkIndex.row())
self.tableView.selectRow(self.currentTalkIndex.row())
newRow = self.newTalkIndex.row()
self.update_talk()
log.info("NewTalkIndex row = %d.", self.newTalkIndex.row())
self.select_talk(self.tableView.currentIndex().sibling(newRow, 0))
self.savePromptWidgetTalk.hide()

def discard_button_talk(self):
log.info("Discarding changes in row %d...", self.currentTalkIndex.row())
self.talk_selected(self.newTalkIndex)
self.savePromptWidgetTalk.hide()

def continue_button_talk(self):
log.info("Continue editing row %d", self.currentTalkIndex.row())
self.tableView.selectRow(self.currentTalkIndex.row())
self.savePromptWidgetTalk.hide()

def show_save_prompt_talk(self):
"""Prompts the user to save or discard changes, or continue editing."""
self.savePromptWidget.setModal(True)
self.savePromptWidget.show()
#self.savePromptBox.setDefaultButton(self.saveButton)
#return self.savePromptBox.clickedButton()
# Thought: Maybe there should be an argument to this function, depending on
# why the method is called (e.g. selected new talk, adding new talk, etc.)
self.savePromptWidgetTalk.setModal(True)
self.savePromptWidgetTalk.show()
self.savePromptWidgetTalk.saveButton.setDefault(True)

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()
#modelRow = model.row()
self.newTalkIndex = QPersistentModelIndex(model)
log.info("newTalkIndex.row(): %d.", self.newTalkIndex.row())
if self.unsaved_details_exist():
log.info("Unsaved changes exist in row %d", self.currentTalkIndex.row())
#confirm = self.show_save_prompt()
self.show_save_prompt()
confirm = self.discardButton
# Define functions called by pressing buttons in save prompt
self.show_save_prompt_talk()
'''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 @@ -336,17 +355,40 @@ def click_talk(self, model):
self.talk_selected(model)
else:
log.info("Continue editing row %d", self.currentTalkIndex.row())
self.tableView.selectRow(self.currentTalkIndex.row())
self.tableView.selectRow(self.currentTalkIndex.row())'''
else:
self.talk_selected(model)

def save_button_add(self):
log.info("Saving changes in row %d...", self.currentTalkIndex.row())
self.update_talk()
self.savePromptWidgetAdd.hide()
self.show_new_talk_popup()

def discard_button_add(self):
log.info("Discarding changes in row %d...", self.currentTalkIndex.row())
self.savePromptWidgetAdd.hide()
self.show_new_talk_popup()

def continue_button_add(self):
log.info("Continue editing row %d", self.currentTalkIndex.row())
self.savePromptWidgetAdd.hide()

def show_save_prompt_add(self):
"""Prompts the user to save or discard changes, or continue editing."""
# Thought: Maybe there should be an argument to this function, depending on
# why the method is called (e.g. selected new talk, adding new talk, etc.)
self.savePromptWidgetAdd.setModal(True)
self.savePromptWidgetAdd.show()
self.savePromptWidgetAdd.saveButton.setDefault(True)

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()
self.show_save_prompt()
confirm = self.discardButton
self.show_save_prompt_add()
'''confirm = self.discardButton
if confirm == self.saveButton:
log.info("Saving changes in row %d...", self.currentTalkIndex.row())
self.update_talk()
Expand All @@ -357,7 +399,7 @@ def click_add_button(self):
self.talk_selected(self.currentTalkIndex)
self.show_new_talk_popup()
else:
log.info("Continue editing row %d", self.currentTalkIndex.row())
log.info("Continue editing row %d", self.currentTalkIndex.row())'''
else:
self.show_new_talk_popup()

Expand Down Expand Up @@ -406,7 +448,9 @@ def update_talk(self):

if presentation:
self.db.update_presentation(talk_id, presentation)
log.info("(In UpdateTalk) NewTalkIndex row = %d.", self.newTalkIndex.row())
self.apply_changes(selected_talk)
log.info("(In UpdateTalk) NewTalkIndex row = %d.", self.newTalkIndex.row())
self.talkDetailsWidget.saveButton.setEnabled(False)

def create_presentation(self, talkDetailsWidget):
Expand Down Expand Up @@ -517,12 +561,41 @@ def add_talks_from_rss(self):
error.setText("Please enter a RSS URL")
error.exec_()

def save_button_exit(self):
log.info("Saving changes in row %d...", self.currentTalkIndex.row())
self.update_talk()
log.info('Exiting talk database editor...')
self.geometry = self.saveGeometry()
self.savePromptWidgetExit.hide()
self.close()

def discard_button_exit(self):
log.info("Discarding changes in row %d...", self.currentTalkIndex.row())
self.talk_selected(self.newTalkIndex)
log.info('Exiting talk database editor...')
self.geometry = self.saveGeometry()
self.savePromptWidgetExit.hide()
self.close()

def continue_button_exit(self):
log.info("Continue editing row %d", self.currentTalkIndex.row())
self.savePromptWidgetExit.hide()

def show_save_prompt_exit(self):
"""Prompts the user to save or discard changes, or continue editing."""
# Thought: Maybe there should be an argument to this function, depending on
# why the method is called (e.g. selected new talk, adding new talk, etc.)
self.savePromptWidgetExit.setModal(True)
self.savePromptWidgetExit.show()
self.savePromptWidgetExit.saveButton.setDefault(True)

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()
self.show_save_prompt()
confirm = self.discardButton
event.ignore()
self.show_save_prompt_exit()
'''confirm = self.discardButton
if confirm == self.saveButton:
log.info("Saving changes in row %d...", self.currentTalkIndex.row())
self.update_talk()
Expand All @@ -538,7 +611,7 @@ def closeEvent(self, event):
event.accept()
else:
log.info("Continue editing row %d", self.currentTalkIndex.row())
event.ignore()
event.ignore()'''
else:
log.info('Exiting talk database editor...')
self.geometry = self.saveGeometry()
Expand Down

0 comments on commit a733e1e

Please sign in to comment.