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

Commit a733e1e

Browse files
committed
Refactor talkeditor save prompts
1 parent ce6ebf0 commit a733e1e

2 files changed

Lines changed: 120 additions & 40 deletions

File tree

src/freeseer/frontend/talkeditor/SavePromptWidget.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,17 @@ def __init__(self, parent=None):
4242
self.bottomButtonLayout = QHBoxLayout()
4343

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

47-
#self.bottomButtonLayout.addWidget(self.testButton)
4849
self.layout.addWidget(self.label)
49-
self.layout.addWidget(self.testButton)
50+
51+
self.buttonLayout = QHBoxLayout()
52+
self.buttonLayout.addWidget(self.saveButton)
53+
self.buttonLayout.addWidget(self.discardButton)
54+
self.buttonLayout.addWidget(self.continueButton)
55+
56+
self.layout.addLayout(self.buttonLayout)
5057

5158
self.setWindowTitle("Unsaved Changes Exist")

src/freeseer/frontend/talkeditor/talkeditor.py

Lines changed: 110 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
from PyQt4.QtGui import QIcon
3939
from PyQt4.QtGui import QMessageBox
4040
from PyQt4.QtGui import QPixmap
41-
from PyQt4.QtGui import QPushButton
4241
from PyQt4.QtGui import QSortFilterProxyModel
4342
from PyQt4.QtGui import QTableView
4443
from PyQt4.QtGui import QVBoxLayout
@@ -95,29 +94,26 @@ def __init__(self, config, db):
9594
self.mainLayout.addWidget(self.importTalksWidget)
9695
# --- End Layout
9796

98-
# Keep track of index of the most recently selected talk
97+
# Keep track of current and most recently selected talk
9998
self.currentTalkIndex = QPersistentModelIndex()
100-
101-
# Prompt user to "Continue Editing", "Discard Changes" or "Save Changes"
102-
# Can't be a QMessageBox anymore. Must be a QDialog? Put in separate file
103-
self.savePromptBox = QMessageBox()
104-
self.savePromptBox.setWindowTitle("Unsaved Changes Exist")
105-
self.savePromptBox.setIcon(QMessageBox.Information)
106-
self.savePromptBox.setText("The talk you were editing has unsaved changes.")
107-
self.continueButton = QPushButton('Continue Editing')
108-
self.continueButton = self.savePromptBox.addButton("Continue Editing", QMessageBox.RejectRole)
109-
#self.discardButton = QPushButton('Discard Changes')
110-
self.discardButton = self.savePromptBox.addButton("Discard Changes", QMessageBox.DestructiveRole)
111-
#self.saveButton = QPushButton('Save Changes')
112-
self.saveButton = self.savePromptBox.addButton("Save Changes", QMessageBox.AcceptRole)
113-
#self.savePromptBox.addWidget(self.continueButton)
114-
#self.savePromptBox.addWidget(self.discardButton)
115-
#self.savePromptBox.addWidget(self.saveButton)
116-
self.savePromptBox.setDefaultButton(self.saveButton)
99+
self.newTalkIndex = QPersistentModelIndex()
117100

118101
# Setup SavePromptWidget
119-
self.savePromptWidget = SavePromptWidget()
120-
self.connect(self.savePromptWidget.testButton, SIGNAL('clicked()'), self.savePromptWidget.reject)
102+
self.savePromptWidgetTalk = SavePromptWidget()
103+
self.savePromptWidgetAdd = SavePromptWidget()
104+
self.savePromptWidgetExit = SavePromptWidget()
105+
# The actions of the save, discard and continue buttons vary depending on why they are pushed
106+
self.connect(self.savePromptWidgetTalk.saveButton, SIGNAL('clicked()'), self.save_button_talk)
107+
self.connect(self.savePromptWidgetTalk.discardButton, SIGNAL('clicked()'), self.discard_button_talk)
108+
self.connect(self.savePromptWidgetTalk.continueButton, SIGNAL('clicked()'), self.continue_button_talk)
109+
110+
self.connect(self.savePromptWidgetAdd.saveButton, SIGNAL('clicked()'), self.save_button_add)
111+
self.connect(self.savePromptWidgetAdd.discardButton, SIGNAL('clicked()'), self.discard_button_add)
112+
self.connect(self.savePromptWidgetAdd.continueButton, SIGNAL('clicked()'), self.continue_button_add)
113+
114+
self.connect(self.savePromptWidgetExit.saveButton, SIGNAL('clicked()'), self.save_button_exit)
115+
self.connect(self.savePromptWidgetExit.discardButton, SIGNAL('clicked()'), self.discard_button_exit)
116+
self.connect(self.savePromptWidgetExit.continueButton, SIGNAL('clicked()'), self.continue_button_exit)
121117

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

312-
def show_save_prompt(self):
308+
def save_button_talk(self):
309+
log.info("NewTalkIndex row = %d.", self.newTalkIndex.row())
310+
log.info("Saving changes in row %d...", self.currentTalkIndex.row())
311+
self.tableView.selectRow(self.currentTalkIndex.row())
312+
newRow = self.newTalkIndex.row()
313+
self.update_talk()
314+
log.info("NewTalkIndex row = %d.", self.newTalkIndex.row())
315+
self.select_talk(self.tableView.currentIndex().sibling(newRow, 0))
316+
self.savePromptWidgetTalk.hide()
317+
318+
def discard_button_talk(self):
319+
log.info("Discarding changes in row %d...", self.currentTalkIndex.row())
320+
self.talk_selected(self.newTalkIndex)
321+
self.savePromptWidgetTalk.hide()
322+
323+
def continue_button_talk(self):
324+
log.info("Continue editing row %d", self.currentTalkIndex.row())
325+
self.tableView.selectRow(self.currentTalkIndex.row())
326+
self.savePromptWidgetTalk.hide()
327+
328+
def show_save_prompt_talk(self):
313329
"""Prompts the user to save or discard changes, or continue editing."""
314-
self.savePromptWidget.setModal(True)
315-
self.savePromptWidget.show()
316-
#self.savePromptBox.setDefaultButton(self.saveButton)
317-
#return self.savePromptBox.clickedButton()
330+
# Thought: Maybe there should be an argument to this function, depending on
331+
# why the method is called (e.g. selected new talk, adding new talk, etc.)
332+
self.savePromptWidgetTalk.setModal(True)
333+
self.savePromptWidgetTalk.show()
334+
self.savePromptWidgetTalk.saveButton.setDefault(True)
318335

319336
def click_talk(self, model):
320337
"""Warns user if there are unsaved changes, and selects talk clicked by the user."""
321338
log.info("Selecting row %d", model.row())
322-
modelRow = model.row()
339+
#modelRow = model.row()
340+
self.newTalkIndex = QPersistentModelIndex(model)
341+
log.info("newTalkIndex.row(): %d.", self.newTalkIndex.row())
323342
if self.unsaved_details_exist():
324343
log.info("Unsaved changes exist in row %d", self.currentTalkIndex.row())
325-
#confirm = self.show_save_prompt()
326-
self.show_save_prompt()
327-
confirm = self.discardButton
344+
# Define functions called by pressing buttons in save prompt
345+
self.show_save_prompt_talk()
346+
'''confirm = self.discardButton
328347
if confirm == self.saveButton:
329348
log.info("Saving changes in row %d...", self.currentTalkIndex.row())
330349
self.tableView.selectRow(self.currentTalkIndex.row())
@@ -336,17 +355,40 @@ def click_talk(self, model):
336355
self.talk_selected(model)
337356
else:
338357
log.info("Continue editing row %d", self.currentTalkIndex.row())
339-
self.tableView.selectRow(self.currentTalkIndex.row())
358+
self.tableView.selectRow(self.currentTalkIndex.row())'''
340359
else:
341360
self.talk_selected(model)
342361

362+
def save_button_add(self):
363+
log.info("Saving changes in row %d...", self.currentTalkIndex.row())
364+
self.update_talk()
365+
self.savePromptWidgetAdd.hide()
366+
self.show_new_talk_popup()
367+
368+
def discard_button_add(self):
369+
log.info("Discarding changes in row %d...", self.currentTalkIndex.row())
370+
self.savePromptWidgetAdd.hide()
371+
self.show_new_talk_popup()
372+
373+
def continue_button_add(self):
374+
log.info("Continue editing row %d", self.currentTalkIndex.row())
375+
self.savePromptWidgetAdd.hide()
376+
377+
def show_save_prompt_add(self):
378+
"""Prompts the user to save or discard changes, or continue editing."""
379+
# Thought: Maybe there should be an argument to this function, depending on
380+
# why the method is called (e.g. selected new talk, adding new talk, etc.)
381+
self.savePromptWidgetAdd.setModal(True)
382+
self.savePromptWidgetAdd.show()
383+
self.savePromptWidgetAdd.saveButton.setDefault(True)
384+
343385
def click_add_button(self):
344386
"""Warns user if there are unsaved changes, and shows the New Talk window."""
345387
if self.unsaved_details_exist():
346388
log.info("Unsaved changes exist in row %d", self.currentTalkIndex.row())
347389
#confirm = self.show_save_prompt()
348-
self.show_save_prompt()
349-
confirm = self.discardButton
390+
self.show_save_prompt_add()
391+
'''confirm = self.discardButton
350392
if confirm == self.saveButton:
351393
log.info("Saving changes in row %d...", self.currentTalkIndex.row())
352394
self.update_talk()
@@ -357,7 +399,7 @@ def click_add_button(self):
357399
self.talk_selected(self.currentTalkIndex)
358400
self.show_new_talk_popup()
359401
else:
360-
log.info("Continue editing row %d", self.currentTalkIndex.row())
402+
log.info("Continue editing row %d", self.currentTalkIndex.row())'''
361403
else:
362404
self.show_new_talk_popup()
363405

@@ -406,7 +448,9 @@ def update_talk(self):
406448

407449
if presentation:
408450
self.db.update_presentation(talk_id, presentation)
451+
log.info("(In UpdateTalk) NewTalkIndex row = %d.", self.newTalkIndex.row())
409452
self.apply_changes(selected_talk)
453+
log.info("(In UpdateTalk) NewTalkIndex row = %d.", self.newTalkIndex.row())
410454
self.talkDetailsWidget.saveButton.setEnabled(False)
411455

412456
def create_presentation(self, talkDetailsWidget):
@@ -517,12 +561,41 @@ def add_talks_from_rss(self):
517561
error.setText("Please enter a RSS URL")
518562
error.exec_()
519563

564+
def save_button_exit(self):
565+
log.info("Saving changes in row %d...", self.currentTalkIndex.row())
566+
self.update_talk()
567+
log.info('Exiting talk database editor...')
568+
self.geometry = self.saveGeometry()
569+
self.savePromptWidgetExit.hide()
570+
self.close()
571+
572+
def discard_button_exit(self):
573+
log.info("Discarding changes in row %d...", self.currentTalkIndex.row())
574+
self.talk_selected(self.newTalkIndex)
575+
log.info('Exiting talk database editor...')
576+
self.geometry = self.saveGeometry()
577+
self.savePromptWidgetExit.hide()
578+
self.close()
579+
580+
def continue_button_exit(self):
581+
log.info("Continue editing row %d", self.currentTalkIndex.row())
582+
self.savePromptWidgetExit.hide()
583+
584+
def show_save_prompt_exit(self):
585+
"""Prompts the user to save or discard changes, or continue editing."""
586+
# Thought: Maybe there should be an argument to this function, depending on
587+
# why the method is called (e.g. selected new talk, adding new talk, etc.)
588+
self.savePromptWidgetExit.setModal(True)
589+
self.savePromptWidgetExit.show()
590+
self.savePromptWidgetExit.saveButton.setDefault(True)
591+
520592
def closeEvent(self, event):
521593
if self.unsaved_details_exist():
522594
log.info("Unsaved changes exist in row %d", self.currentTalkIndex.row())
523595
#confirm = self.show_save_prompt()
524-
self.show_save_prompt()
525-
confirm = self.discardButton
596+
event.ignore()
597+
self.show_save_prompt_exit()
598+
'''confirm = self.discardButton
526599
if confirm == self.saveButton:
527600
log.info("Saving changes in row %d...", self.currentTalkIndex.row())
528601
self.update_talk()
@@ -538,7 +611,7 @@ def closeEvent(self, event):
538611
event.accept()
539612
else:
540613
log.info("Continue editing row %d", self.currentTalkIndex.row())
541-
event.ignore()
614+
event.ignore()'''
542615
else:
543616
log.info('Exiting talk database editor...')
544617
self.geometry = self.saveGeometry()

0 commit comments

Comments
 (0)