← Back to team overview

openlp-core team mailing list archive

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

 

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

Requested reviews:
  OpenLP Core (openlp-core)

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

The buttons are disabled, when there is nothing to act on. (E. g. when the first/last item is selected, the up/down button is disabled). Just test it out.

When you run the Reorder dialog the first time, the first item will be kind of selected, but not really (I don't know why). But I don't know what to do about this. (However, would you have noticed it, when I hadn't said it?)

Cheers :-)
-- 
https://code.launchpad.net/~googol-hush/openlp/tweaks/+merge/46523
Your team OpenLP Core is requested to review the proposed merge of lp:~googol-hush/openlp/tweaks into lp:openlp.
=== modified file 'openlp/core/ui/serviceitemeditform.py'
--- openlp/core/ui/serviceitemeditform.py	2010-12-26 11:04:47 +0000
+++ openlp/core/ui/serviceitemeditform.py	2011-01-17 19:49:18 +0000
@@ -25,6 +25,7 @@
 ###############################################################################
 
 from PyQt4 import QtCore, QtGui
+
 from serviceitemeditdialog import Ui_ServiceItemEditDialog
 
 class ServiceItemEditForm(QtGui.QDialog, Ui_ServiceItemEditDialog):
@@ -39,16 +40,18 @@
         self.setupUi(self)
         self.itemList = []
         # enable drop
-        QtCore.QObject.connect(self.upButton, QtCore.SIGNAL(u'clicked()'),
-            self.onItemUp)
-        QtCore.QObject.connect(self.downButton, QtCore.SIGNAL(u'clicked()'),
-            self.onItemDown)
-        QtCore.QObject.connect(self.deleteButton, QtCore.SIGNAL(u'clicked()'),
-            self.onItemDelete)
-        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'accepted()'),
-            self.accept)
-        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'rejected()'),
-            self.reject)
+        QtCore.QObject.connect(self.upButton,
+            QtCore.SIGNAL(u'clicked()'), self.onItemUp)
+        QtCore.QObject.connect(self.downButton,
+            QtCore.SIGNAL(u'clicked()'), self.onItemDown)
+        QtCore.QObject.connect(self.deleteButton,
+            QtCore.SIGNAL(u'clicked()'), self.onItemDelete)
+        QtCore.QObject.connect(self.buttonBox,
+            QtCore.SIGNAL(u'accepted()'), self.accept)
+        QtCore.QObject.connect(self.buttonBox,
+            QtCore.SIGNAL(u'rejected()'), self.reject)
+        QtCore.QObject.connect(self.listWidget,
+            QtCore.SIGNAL(u'currentRowChanged(int)'), self.onCurrentRowChanged)
 
     def setServiceItem(self, item):
         self.item = item
@@ -58,6 +61,7 @@
             for frame in self.item._raw_frames:
                 self.itemList.append(frame)
         self.loadData()
+        self.listWidget.setCurrentItem(self.listWidget.currentItem())
 
     def getServiceItem(self):
         if self.data:
@@ -69,57 +73,78 @@
         return self.item
 
     def loadData(self):
+        """
+        Loads the image list.
+        """
         self.listWidget.clear()
         for frame in self.itemList:
             item_name = QtGui.QListWidgetItem(frame[u'title'])
             self.listWidget.addItem(item_name)
-        if self.listWidget.count() == 1:
+
+    def onItemDelete(self):
+        """
+        Delete the current row.
+        """
+        item = self.listWidget.currentItem()
+        if not item:
+            return
+        row = self.listWidget.row(item)
+        self.itemList.remove(self.itemList[row])
+        self.loadData()
+        if row == self.listWidget.count():
+            self.listWidget.setCurrentRow(row - 1)
+        else:
+            self.listWidget.setCurrentRow(row)
+
+    def onItemUp(self):
+        """
+        Move the current row up in the list.
+        """
+        item = self.listWidget.currentItem()
+        if not item:
+            return
+        row = self.listWidget.row(item)
+        temp = self.itemList[row]
+        self.itemList.remove(self.itemList[row])
+        self.itemList.insert(row - 1, temp)
+        self.loadData()
+        self.listWidget.setCurrentRow(row - 1)
+
+    def onItemDown(self):
+        """
+        Move the current row down in the list
+        """
+        item = self.listWidget.currentItem()
+        if not item:
+            return
+        row = self.listWidget.row(item)
+        temp = self.itemList[row]
+        self.itemList.remove(self.itemList[row])
+        self.itemList.insert(row + 1, temp)
+        self.loadData()
+        self.listWidget.setCurrentRow(row + 1)
+
+    def onCurrentRowChanged(self, row):
+        """
+        Called when the currentRow has changed.
+
+        ``row``
+            The row number (int).
+        """
+        # Disable all buttons, as no row is selected or only one image is left.
+        if row == -1 or self.listWidget.count() == 1:
             self.downButton.setEnabled(False)
             self.upButton.setEnabled(False)
             self.deleteButton.setEnabled(False)
         else:
-            self.downButton.setEnabled(True)
-            self.upButton.setEnabled(True)
+            # Check if we are at the end of the list.
+            if self.listWidget.count() == row + 1:
+                self.downButton.setEnabled(False)
+            else:
+                self.downButton.setEnabled(True)
+            # Check if we are at the beginning of the list.
+            if row == 0:
+                self.upButton.setEnabled(False)
+            else:
+                self.upButton.setEnabled(True)
             self.deleteButton.setEnabled(True)
-
-    def onItemDelete(self):
-        """
-        Delete the selected row
-        """
-        items = self.listWidget.selectedItems()
-        for item in items:
-            row = self.listWidget.row(item)
-            self.itemList.remove(self.itemList[row])
-            self.loadData()
-            if row == self.listWidget.count():
-                self.listWidget.setCurrentRow(row - 1)
-            else:
-                self.listWidget.setCurrentRow(row)
-
-    def onItemUp(self):
-        """
-        Move the selected row up in the list
-        """
-        items = self.listWidget.selectedItems()
-        for item in items:
-            row = self.listWidget.row(item)
-            if row > 0:
-                temp = self.itemList[row]
-                self.itemList.remove(self.itemList[row])
-                self.itemList.insert(row - 1, temp)
-                self.loadData()
-                self.listWidget.setCurrentRow(row - 1)
-
-    def onItemDown(self):
-        """
-        Move the selected row down in the list
-        """
-        items = self.listWidget.selectedItems()
-        for item in items:
-            row = self.listWidget.row(item)
-            if row < len(self.itemList) and row is not -1:
-                temp = self.itemList[row]
-                self.itemList.remove(self.itemList[row])
-                self.itemList.insert(row + 1, temp)
-                self.loadData()
-                self.listWidget.setCurrentRow(row + 1)
\ No newline at end of file


Follow ups