- Name changes/clean ups.

- I improved the selection behaviour. For example when a child item is supposed to be selected I used "child", otherwise -1 (e. g. when deleting an item).

bzr-revno: 1245
This commit is contained in:
Andreas Preikschat 2011-01-24 17:07:31 +00:00 committed by Tim Bentley
commit d49f062c6a

View File

@ -603,7 +603,7 @@ class ServiceManager(QtGui.QWidget):
if self.serviceNoteForm.exec_(): if self.serviceNoteForm.exec_():
self.serviceItems[item][u'service_item'].notes = \ self.serviceItems[item][u'service_item'].notes = \
self.serviceNoteForm.textEdit.toPlainText() self.serviceNoteForm.textEdit.toPlainText()
self.repaintServiceList(item, 0) self.repaintServiceList(item, -1)
def onServiceItemEditForm(self): def onServiceItemEditForm(self):
item = self.findServiceItem()[0] item = self.findServiceItem()[0]
@ -615,8 +615,7 @@ class ServiceManager(QtGui.QWidget):
def nextItem(self): def nextItem(self):
""" """
Called by the SlideController to select the Called by the SlideController to select the next service item.
next service item
""" """
if len(self.serviceManagerList.selectedItems()) == 0: if len(self.serviceManagerList.selectedItems()) == 0:
return return
@ -634,8 +633,7 @@ class ServiceManager(QtGui.QWidget):
def previousItem(self): def previousItem(self):
""" """
Called by the SlideController to select the Called by the SlideController to select the previous service item.
previous service item
""" """
if len(self.serviceManagerList.selectedItems()) == 0: if len(self.serviceManagerList.selectedItems()) == 0:
return return
@ -654,13 +652,13 @@ class ServiceManager(QtGui.QWidget):
def onSetItem(self, message): def onSetItem(self, message):
""" """
Called by a signal to select a specific item Called by a signal to select a specific item.
""" """
self.setItem(int(message[0])) self.setItem(int(message[0]))
def setItem(self, index): def setItem(self, index):
""" """
Makes a specific item in the service live Makes a specific item in the service live.
""" """
if index >= 0 and index < self.serviceManagerList.topLevelItemCount: if index >= 0 and index < self.serviceManagerList.topLevelItemCount:
item = self.serviceManagerList.topLevelItem(index) item = self.serviceManagerList.topLevelItem(index)
@ -669,8 +667,7 @@ class ServiceManager(QtGui.QWidget):
def onMoveSelectionUp(self): def onMoveSelectionUp(self):
""" """
Moves the selection up the window Moves the selection up the window. Called by the up arrow.
Called by the up arrow
""" """
serviceIterator = QtGui.QTreeWidgetItemIterator(self.serviceManagerList) serviceIterator = QtGui.QTreeWidgetItemIterator(self.serviceManagerList)
tempItem = None tempItem = None
@ -695,8 +692,7 @@ class ServiceManager(QtGui.QWidget):
def onMoveSelectionDown(self): def onMoveSelectionDown(self):
""" """
Moves the selection down the window Moves the selection down the window. Called by the down arrow.
Called by the down arrow
""" """
serviceIterator = QtGui.QTreeWidgetItemIterator(self.serviceManagerList) serviceIterator = QtGui.QTreeWidgetItemIterator(self.serviceManagerList)
firstItem = None firstItem = None
@ -718,7 +714,7 @@ class ServiceManager(QtGui.QWidget):
def onCollapseAll(self): def onCollapseAll(self):
""" """
Collapse all the service items Collapse all the service items.
""" """
for item in self.serviceItems: for item in self.serviceItems:
item[u'expanded'] = False item[u'expanded'] = False
@ -726,15 +722,15 @@ class ServiceManager(QtGui.QWidget):
def collapsed(self, item): def collapsed(self, item):
""" """
Record if an item is collapsed Record if an item is collapsed. Used when repainting the list to get the
Used when repainting the list to get the correct state correct state.
""" """
pos = item.data(0, QtCore.Qt.UserRole).toInt()[0] pos = item.data(0, QtCore.Qt.UserRole).toInt()[0]
self.serviceItems[pos -1 ][u'expanded'] = False self.serviceItems[pos -1 ][u'expanded'] = False
def onExpandAll(self): def onExpandAll(self):
""" """
Collapse all the service items Collapse all the service items.
""" """
for item in self.serviceItems: for item in self.serviceItems:
item[u'expanded'] = True item[u'expanded'] = True
@ -742,70 +738,68 @@ class ServiceManager(QtGui.QWidget):
def expanded(self, item): def expanded(self, item):
""" """
Record if an item is collapsed Record if an item is collapsed. Used when repainting the list to get the
Used when repainting the list to get the correct state correct state.
""" """
pos = item.data(0, QtCore.Qt.UserRole).toInt()[0] pos = item.data(0, QtCore.Qt.UserRole).toInt()[0]
self.serviceItems[pos -1 ][u'expanded'] = True self.serviceItems[pos -1 ][u'expanded'] = True
def onServiceTop(self): def onServiceTop(self):
""" """
Move the current ServiceItem to the top of the list Move the current ServiceItem to the top of the list.
""" """
item, count = self.findServiceItem() item, child = self.findServiceItem()
if item < len(self.serviceItems) and item is not -1: if item < len(self.serviceItems) and item is not -1:
temp = self.serviceItems[item] temp = self.serviceItems[item]
self.serviceItems.remove(self.serviceItems[item]) self.serviceItems.remove(self.serviceItems[item])
self.serviceItems.insert(0, temp) self.serviceItems.insert(0, temp)
self.repaintServiceList(0, count) self.repaintServiceList(0, child)
self.setModified(True) self.setModified(True)
def onServiceUp(self): def onServiceUp(self):
""" """
Move the current ServiceItem up in the list Move the current ServiceItem one position up in the list.
Note move up means move to top of area ie 0.
""" """
item, count = self.findServiceItem() item, child = self.findServiceItem()
if item > 0: if item > 0:
temp = self.serviceItems[item] temp = self.serviceItems[item]
self.serviceItems.remove(self.serviceItems[item]) self.serviceItems.remove(self.serviceItems[item])
self.serviceItems.insert(item - 1, temp) self.serviceItems.insert(item - 1, temp)
self.repaintServiceList(item - 1, count) self.repaintServiceList(item - 1, child)
self.setModified(True) self.setModified(True)
def onServiceDown(self): def onServiceDown(self):
""" """
Move the current ServiceItem down in the list Move the current ServiceItem one position down in the list.
Note move down means move to bottom of area i.e len().
""" """
item, count = self.findServiceItem() item, child = self.findServiceItem()
if item < len(self.serviceItems) and item is not -1: if item < len(self.serviceItems) and item is not -1:
temp = self.serviceItems[item] temp = self.serviceItems[item]
self.serviceItems.remove(self.serviceItems[item]) self.serviceItems.remove(self.serviceItems[item])
self.serviceItems.insert(item + 1, temp) self.serviceItems.insert(item + 1, temp)
self.repaintServiceList(item + 1, count) self.repaintServiceList(item + 1, child)
self.setModified(True) self.setModified(True)
def onServiceEnd(self): def onServiceEnd(self):
""" """
Move the current ServiceItem to the bottom of the list Move the current ServiceItem to the bottom of the list.
""" """
item, count = self.findServiceItem() item, child = self.findServiceItem()
if item < len(self.serviceItems) and item is not -1: if item < len(self.serviceItems) and item is not -1:
temp = self.serviceItems[item] temp = self.serviceItems[item]
self.serviceItems.remove(self.serviceItems[item]) self.serviceItems.remove(self.serviceItems[item])
self.serviceItems.insert(len(self.serviceItems), temp) self.serviceItems.insert(len(self.serviceItems), temp)
self.repaintServiceList(len(self.serviceItems) - 1, count) self.repaintServiceList(len(self.serviceItems) - 1, child)
self.setModified(True) self.setModified(True)
def onDeleteFromService(self): def onDeleteFromService(self):
""" """
Remove the current ServiceItem from the list Remove the current ServiceItem from the list.
""" """
item = self.findServiceItem()[0] item = self.findServiceItem()[0]
if item is not -1: if item != -1:
self.serviceItems.remove(self.serviceItems[item]) self.serviceItems.remove(self.serviceItems[item])
self.repaintServiceList(0, 0) self.repaintServiceList(item - 1, -1)
self.setModified(True) self.setModified(True)
def repaintServiceList(self, serviceItem, serviceItemChild): def repaintServiceList(self, serviceItem, serviceItemChild):
@ -867,7 +861,7 @@ class ServiceManager(QtGui.QWidget):
def validateItem(self, serviceItem): def validateItem(self, serviceItem):
""" """
Validates the service item and if the suffix matches an accepted Validates the service item and if the suffix matches an accepted
one it allows the item to be displayed one it allows the item to be displayed.
""" """
if serviceItem.is_command(): if serviceItem.is_command():
type = serviceItem._raw_frames[0][u'title'].split(u'.')[1] type = serviceItem._raw_frames[0][u'title'].split(u'.')[1]
@ -876,7 +870,7 @@ class ServiceManager(QtGui.QWidget):
def cleanUp(self): def cleanUp(self):
""" """
Empties the servicePath of temporary files Empties the servicePath of temporary files.
""" """
for file in os.listdir(self.servicePath): for file in os.listdir(self.servicePath):
file_path = os.path.join(self.servicePath, file) file_path = os.path.join(self.servicePath, file)
@ -884,7 +878,7 @@ class ServiceManager(QtGui.QWidget):
def onThemeComboBoxSelected(self, currentIndex): def onThemeComboBoxSelected(self, currentIndex):
""" """
Set the theme for the current service Set the theme for the current service.
""" """
log.debug(u'onThemeComboBoxSelected') log.debug(u'onThemeComboBoxSelected')
self.service_theme = unicode(self.themeComboBox.currentText()) self.service_theme = unicode(self.themeComboBox.currentText())
@ -967,12 +961,12 @@ class ServiceManager(QtGui.QWidget):
# if not passed set to config value # if not passed set to config value
if expand is None: if expand is None:
expand = self.expandTabs expand = self.expandTabs
sitem = self.findServiceItem()[0]
item.render() item.render()
if replace: if replace:
sitem, child = self.findServiceItem()
item.merge(self.serviceItems[sitem][u'service_item']) item.merge(self.serviceItems[sitem][u'service_item'])
self.serviceItems[sitem][u'service_item'] = item self.serviceItems[sitem][u'service_item'] = item
self.repaintServiceList(sitem, 0) self.repaintServiceList(sitem, child)
self.mainwindow.liveController.replaceServiceManagerItem(item) self.mainwindow.liveController.replaceServiceManagerItem(item)
else: else:
# nothing selected for dnd # nothing selected for dnd
@ -981,17 +975,17 @@ class ServiceManager(QtGui.QWidget):
for inditem in item: for inditem in item:
self.serviceItems.append({u'service_item': inditem, self.serviceItems.append({u'service_item': inditem,
u'order': len(self.serviceItems) + 1, u'order': len(self.serviceItems) + 1,
u'expanded':expand}) u'expanded': expand})
else: else:
self.serviceItems.append({u'service_item': item, self.serviceItems.append({u'service_item': item,
u'order': len(self.serviceItems) + 1, u'order': len(self.serviceItems) + 1,
u'expanded':expand}) u'expanded': expand})
self.repaintServiceList(len(self.serviceItems) + 1, 0) self.repaintServiceList(len(self.serviceItems) - 1, -1)
else: else:
self.serviceItems.insert(self.dropPosition, self.serviceItems.insert(self.dropPosition,
{u'service_item': item, u'order': self.dropPosition, {u'service_item': item, u'order': self.dropPosition,
u'expanded':expand}) u'expanded': expand})
self.repaintServiceList(self.dropPosition, 0) self.repaintServiceList(self.dropPosition, -1)
# if rebuilding list make sure live is fixed. # if rebuilding list make sure live is fixed.
if rebuild: if rebuild:
self.mainwindow.liveController.replaceServiceManagerItem(item) self.mainwindow.liveController.replaceServiceManagerItem(item)
@ -1002,15 +996,15 @@ class ServiceManager(QtGui.QWidget):
""" """
Send the current item to the Preview slide controller Send the current item to the Preview slide controller
""" """
item, count = self.findServiceItem() item, child = self.findServiceItem()
if self.serviceItems[item][u'service_item'].is_valid: if self.serviceItems[item][u'service_item'].is_valid:
self.mainwindow.previewController.addServiceManagerItem( self.mainwindow.previewController.addServiceManagerItem(
self.serviceItems[item][u'service_item'], count) self.serviceItems[item][u'service_item'], child)
else: else:
criticalErrorMessageBox( criticalErrorMessageBox(
translate('OpenLP.ServiceManager', 'Missing Display Handler'), translate('OpenLP.ServiceManager', 'Missing Display Handler'),
translate('OpenLP.ServiceManager', 'Your item cannot be ' translate('OpenLP.ServiceManager', 'Your item cannot be '
'displayed as there is no handler to display it')) 'displayed as there is no handler to display it'))
def getServiceItem(self): def getServiceItem(self):
""" """
@ -1026,10 +1020,10 @@ class ServiceManager(QtGui.QWidget):
""" """
Send the current item to the Live slide controller Send the current item to the Live slide controller
""" """
item, count = self.findServiceItem() item, child = self.findServiceItem()
if self.serviceItems[item][u'service_item'].is_valid: if self.serviceItems[item][u'service_item'].is_valid:
self.mainwindow.liveController.addServiceManagerItem( self.mainwindow.liveController.addServiceManagerItem(
self.serviceItems[item][u'service_item'], count) self.serviceItems[item][u'service_item'], child)
if QtCore.QSettings().value( if QtCore.QSettings().value(
self.mainwindow.generalSettingsSection + u'/auto preview', self.mainwindow.generalSettingsSection + u'/auto preview',
QtCore.QVariant(False)).toBool(): QtCore.QVariant(False)).toBool():
@ -1060,26 +1054,26 @@ class ServiceManager(QtGui.QWidget):
def findServiceItem(self): def findServiceItem(self):
""" """
Finds a ServiceItem in the list and returns the position of the Finds the selected ServiceItem in the list and returns the position of
serviceitem and its selected child item. For example, if the third child the serviceitem and its selected child item. For example, if the third
item (in the Slidecontroller known as slide) in the second service item child item (in the Slidecontroller known as slide) in the second service
is selected this will return:: item is selected this will return::
(1, 2) (1, 2)
""" """
items = self.serviceManagerList.selectedItems() items = self.serviceManagerList.selectedItems()
pos = 0 serviceItem = 0
count = -1 serviceItemChild = -1
for item in items: for item in items:
parentitem = item.parent() parentitem = item.parent()
if parentitem is None: if parentitem is None:
pos = item.data(0, QtCore.Qt.UserRole).toInt()[0] serviceItem = item.data(0, QtCore.Qt.UserRole).toInt()[0]
else: else:
pos = parentitem.data(0, QtCore.Qt.UserRole).toInt()[0] serviceItem = parentitem.data(0, QtCore.Qt.UserRole).toInt()[0]
count = item.data(0, QtCore.Qt.UserRole).toInt()[0] serviceItemChild = item.data(0, QtCore.Qt.UserRole).toInt()[0]
# adjust for zero based arrays # Adjust for zero based arrays.
pos = pos - 1 serviceItem -= 1
return pos, count return serviceItem, serviceItemChild
def dragEnterEvent(self, event): def dragEnterEvent(self, event):
""" """
@ -1105,7 +1099,7 @@ class ServiceManager(QtGui.QWidget):
item = self.serviceManagerList.itemAt(event.pos()) item = self.serviceManagerList.itemAt(event.pos())
# ServiceManager started the drag and drop # ServiceManager started the drag and drop
if plugin == u'ServiceManager': if plugin == u'ServiceManager':
startpos, startCount = self.findServiceItem() startpos, child = self.findServiceItem()
# If no items selected # If no items selected
if startpos == -1: if startpos == -1:
return return
@ -1116,7 +1110,7 @@ class ServiceManager(QtGui.QWidget):
serviceItem = self.serviceItems[startpos] serviceItem = self.serviceItems[startpos]
self.serviceItems.remove(serviceItem) self.serviceItems.remove(serviceItem)
self.serviceItems.insert(endpos, serviceItem) self.serviceItems.insert(endpos, serviceItem)
self.repaintServiceList(endpos, startCount) self.repaintServiceList(endpos, child)
else: else:
# we are not over anything so drop # we are not over anything so drop
replace = False replace = False
@ -1182,9 +1176,9 @@ class ServiceManager(QtGui.QWidget):
def listRequest(self, message=None): def listRequest(self, message=None):
data = [] data = []
curindex = self.findServiceItem()[0] item = self.findServiceItem()[0]
if curindex >= 0 and curindex < len(self.serviceItems): if item >= 0 and item < len(self.serviceItems):
curitem = self.serviceItems[curindex] curitem = self.serviceItems[item]
else: else:
curitem = None curitem = None
for item in self.serviceItems: for item in self.serviceItems: