← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~googol-hush/openlp/custom into lp:openlp

 

Andreas Preikschat has proposed merging lp:~googol-hush/openlp/custom into lp:openlp.

Requested reviews:
  Jonathan Corwin (j-corwin)

For more details, see:
https://code.launchpad.net/~googol-hush/openlp/custom/+merge/48653

Hello!

- Buttons which require a slide to act on are disabled if there is none to act on
- some other changes
-- 
https://code.launchpad.net/~googol-hush/openlp/custom/+merge/48653
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/custom/forms/editcustomdialog.py'
--- openlp/plugins/custom/forms/editcustomdialog.py	2011-02-03 18:19:56 +0000
+++ openlp/plugins/custom/forms/editcustomdialog.py	2011-02-04 19:36:56 +0000
@@ -60,16 +60,20 @@
         self.addButton.setObjectName(u'addButton')
         self.buttonLayout.addWidget(self.addButton)
         self.editButton = QtGui.QPushButton(customEditDialog)
+        self.editButton.setEnabled(False)
         self.editButton.setObjectName(u'editButton')
         self.buttonLayout.addWidget(self.editButton)
         self.editAllButton = QtGui.QPushButton(customEditDialog)
         self.editAllButton.setObjectName(u'editAllButton')
         self.buttonLayout.addWidget(self.editAllButton)
         self.deleteButton = delete_push_button(customEditDialog)
+        self.deleteButton.setEnabled(False)
         self.buttonLayout.addWidget(self.deleteButton)
         self.buttonLayout.addStretch()
         self.upButton, self.downButton = up_down_push_button_set(
             customEditDialog)
+        self.upButton.setEnabled(False)
+        self.downButton.setEnabled(False)
         self.buttonLayout.addWidget(self.upButton)
         self.buttonLayout.addWidget(self.downButton)
         self.centralLayout.addLayout(self.buttonLayout)
@@ -91,6 +95,9 @@
         self.bottomFormLayout.addRow(self.creditLabel, self.creditEdit)
         self.dialogLayout.addLayout(self.bottomFormLayout)
         self.buttonBox = save_cancel_button_box(customEditDialog)
+        self.previewButton = QtGui.QPushButton()
+        self.buttonBox.addButton(
+            self.previewButton, QtGui.QDialogButtonBox.ActionRole)
         self.dialogLayout.addWidget(self.buttonBox)
         self.retranslateUi(customEditDialog)
         QtCore.QMetaObject.connectSlotsByName(customEditDialog)
@@ -119,3 +126,5 @@
             translate('CustomPlugin.EditCustomForm', 'The&me:'))
         self.creditLabel.setText(
             translate('CustomPlugin.EditCustomForm', '&Credits:'))
+        self.previewButton.setText(
+            translate('CustomPlugin.EditCustomForm', 'Save && Preview'))

=== modified file 'openlp/plugins/custom/forms/editcustomform.py'
--- openlp/plugins/custom/forms/editcustomform.py	2011-02-03 18:19:56 +0000
+++ openlp/plugins/custom/forms/editcustomform.py	2011-02-04 19:36:56 +0000
@@ -48,46 +48,22 @@
         """
         QtGui.QDialog.__init__(self, parent)
         self.setupUi(self)
+        # Create other objects and forms.
+        self.manager = manager
+        self.editSlideForm = EditCustomSlideForm(self)
         # Connecting signals and slots
-        self.previewButton = QtGui.QPushButton()
-        self.previewButton.setText(
-            translate('CustomPlugin.EditCustomForm', 'Save && Preview'))
-        self.buttonBox.addButton(
-            self.previewButton, QtGui.QDialogButtonBox.ActionRole)
-        QtCore.QObject.connect(self.buttonBox,
-            QtCore.SIGNAL(u'clicked(QAbstractButton*)'), self.onPreview)
+        QtCore.QObject.connect(self.previewButton,
+            QtCore.SIGNAL(u'pressed()'), self.onPreviewButtonPressed)
         QtCore.QObject.connect(self.addButton,
             QtCore.SIGNAL(u'pressed()'), self.onAddButtonPressed)
         QtCore.QObject.connect(self.editButton,
             QtCore.SIGNAL(u'pressed()'), self.onEditButtonPressed)
         QtCore.QObject.connect(self.editAllButton,
             QtCore.SIGNAL(u'pressed()'), self.onEditAllButtonPressed)
-        QtCore.QObject.connect(self.slideListView,
-            QtCore.SIGNAL(u'itemClicked(QListWidgetItem*)'),
-            self.onSlideListViewPressed)
         QtCore.QObject.connect(Receiver.get_receiver(),
             QtCore.SIGNAL(u'theme_update_list'), self.loadThemes)
-        # Create other objects and forms.
-        self.manager = manager
-        self.editSlideForm = EditCustomSlideForm(self)
-        self.initialise()
-
-    def onPreview(self, button):
-        log.debug(u'onPreview')
-        if button.text() == unicode(translate('CustomPlugin.EditCustomForm',
-            'Save && Preview')) and self.saveCustom():
-            Receiver.send_message(u'custom_preview')
-
-    def initialise(self):
-        self.addButton.setEnabled(True)
-        self.deleteButton.setEnabled(False)
-        self.editButton.setEnabled(False)
-        self.editAllButton.setEnabled(True)
-        self.titleEdit.setText(u'')
-        self.creditEdit.setText(u'')
-        self.slideListView.clear()
-        # Make sure we have a new item.
-        self.customSlide = CustomSlide()
+        QtCore.QObject.connect(self.slideListView,
+            QtCore.SIGNAL(u'currentRowChanged(int)'), self.onCurrentRowChanged)
 
     def loadThemes(self, themelist):
         self.themeComboBox.clear()
@@ -106,9 +82,13 @@
             States whether the custom is edited while being previewed in the
             preview panel.
         """
-        self.customSlide = CustomSlide()
-        self.initialise()
-        if id != 0:
+        self.slideListView.clear()
+        if id == 0:
+            self.customSlide = CustomSlide()
+            self.titleEdit.setText(u'')
+            self.creditEdit.setText(u'')
+            self.themeComboBox.setCurrentIndex(0)
+        else:
             self.customSlide = self.manager.get_object(CustomSlide, id)
             self.titleEdit.setText(self.customSlide.title)
             self.creditEdit.setText(self.customSlide.credits)
@@ -122,9 +102,6 @@
             if id == -1:
                 id = 0
             self.themeComboBox.setCurrentIndex(id)
-        else:
-            self.themeComboBox.setCurrentIndex(0)
-            self.editAllButton.setEnabled(False)
         # If not preview hide the preview button.
         self.previewButton.setVisible(False)
         if preview:
@@ -144,9 +121,7 @@
         """
         Saves the custom.
         """
-        valid, message = self._validate()
-        if not valid:
-            critical_error_message_box(message=message)
+        if not self._validate():
             return False
         sxml = CustomXMLBuilder()
         sxml.new_document()
@@ -177,16 +152,11 @@
             self.slideListView.insertItem(selectedRow + 1, qw)
             self.slideListView.setCurrentRow(selectedRow + 1)
 
-    def onSlideListViewPressed(self, item):
-        self.deleteButton.setEnabled(True)
-        self.editButton.setEnabled(True)
-
     def onAddButtonPressed(self):
         self.editSlideForm.setText(u'')
         if self.editSlideForm.exec_():
             for slide in self.editSlideForm.getText():
                 self.slideListView.addItem(slide)
-            self.editAllButton.setEnabled(True)
 
     def onEditButtonPressed(self):
         self.editSlideForm.setText(self.slideListView.currentItem().text())
@@ -197,16 +167,23 @@
         """
         Edits all slides.
         """
-        if self.slideListView.count() > 0:
-            slide_list = u''
-            for row in range(0, self.slideListView.count()):
-                item = self.slideListView.item(row)
-                slide_list += item.text()
-                if row != self.slideListView.count() - 1:
-                    slide_list += u'\n[---]\n'
-            self.editSlideForm.setText(slide_list)
-            if self.editSlideForm.exec_():
-                self.updateSlideList(self.editSlideForm.getText(), True)
+        slide_list = u''
+        for row in range(0, self.slideListView.count()):
+            item = self.slideListView.item(row)
+            slide_list += item.text()
+            if row != self.slideListView.count() - 1:
+                slide_list += u'\n[---]\n'
+        self.editSlideForm.setText(slide_list)
+        if self.editSlideForm.exec_():
+            self.updateSlideList(self.editSlideForm.getText(), True)
+
+    def onPreviewButtonPressed(self):
+        """
+        Save the custom item and preview it.
+        """
+        log.debug(u'onPreview')
+        if self.saveCustom():
+            Receiver.send_message(u'custom_preview')
 
     def updateSlideList(self, slides, edit_all=False):
         """
@@ -238,13 +215,40 @@
         self.slideListView.repaint()
 
     def onDeleteButtonClicked(self):
+        """
+        Removes the current row from the list.
+        """
         self.slideListView.takeItem(self.slideListView.currentRow())
-        self.editButton.setEnabled(True)
-        self.editAllButton.setEnabled(True)
-        if self.slideListView.count() == 0:
+        if self.slideListView.currentRow() == 0:
+            self.upButton.setEnabled(False)
+        if self.slideListView.currentRow() == self.slideListView.count():
+            self.downButton.setEnabled(False)
+
+    def onCurrentRowChanged(self, row):
+        """
+        Called when the *slideListView*'s current row has been changed. This
+        enables or disables buttons which require an slide to act on.
+
+        ``row``
+            The row (int). If there is no current row, the value is -1.
+        """
+        if row == -1:
             self.deleteButton.setEnabled(False)
             self.editButton.setEnabled(False)
-            self.editAllButton.setEnabled(False)
+            self.upButton.setEnabled(False)
+            self.downButton.setEnabled(False)
+        else:
+            self.deleteButton.setEnabled(True)
+            self.editButton.setEnabled(True)
+            # Decide if the up/down buttons should be enabled or not.
+            if self.slideListView.count() - 1 == row:
+                self.downButton.setEnabled(False)
+            else:
+                self.downButton.setEnabled(True)
+            if row == 0:
+                self.upButton.setEnabled(False)
+            else:
+                self.upButton.setEnabled(True)
 
     def _validate(self):
         """
@@ -253,10 +257,14 @@
         # We must have a title.
         if len(self.titleEdit.displayText()) == 0:
             self.titleEdit.setFocus()
-            return False, translate('CustomPlugin.EditCustomForm',
-                'You need to type in a title.')
+            critical_error_message_box(
+                message=translate('CustomPlugin.EditCustomForm',
+                'You need to type in a title.'))
+            return False
         # We must have at least one slide.
         if self.slideListView.count() == 0:
-            return False, translate('CustomPlugin.EditCustomForm',
-                'You need to add at least one slide')
-        return True, u''
+            critical_error_message_box(
+                message=translate('CustomPlugin.EditCustomForm',
+                'You need to add at least one slide'))
+            return False
+        return True


Follow ups