コード例 #1
0
	def addEntry(self):
		dialog = DomEditEntryDialog(self, None)
		value = dialog.exec_()
		
		# Only if the user really pushed the 'OK' or 'Enter' button/key
		if value == QtGui.QDialog.Accepted:
			name = dialog.getSiteName()
			value = dialog.getSiteURL()
			user = dialog.getUser()
			pw   = dialog.getPassword()
			# Makes sure it doesn't duplicate the name of another site
			duplicate = False
			for element in self.configObject:
				if element['name'] == name: duplicate = True
			# Only proceed if we are in a valid place
			if not duplicate:
				self.configObject.append({'name' : str(name), 'destination' : str(value), 'user' : str(user), 'pw' : str(pw)})
				# Displays in the dialog
				QtGui.QListWidgetItem(name + '\t' + value, self.siteList)
				# Flag the current entry as changed
				self.changes = True
				# Sorting is fun!
				self.siteList.sortItems()
			else:
				print 'Duplicate detected'
				QtGui.QMessageBox.warning(self, 'Duplicate Detected', 'That entry already exists, ignoring.')
		else:
			print 'Rejecting'
コード例 #2
0
	def editEntry(self):
		# Find out which one we're on
		item = self.siteList.currentItem()
		name, trash, url = str(item.text()).partition('\t')
		entry = None
		for obj in self.configObject:
			if obj['name'] == name: entry = obj
		# Create & show the dialog
		dialog = DomEditEntryDialog(self, entry)
		value = dialog.exec_()
		
		# Process answers
		if value == QtGui.QDialog.Accepted:
			# Iterate over the configs
			for obj in self.configObject:
				if obj['name'] == name:
					idx = self.configObject.index(obj)
					self.configObject[idx]['name'] = str(dialog.getSiteName())
					self.configObject[idx]['destination'] = str(dialog.getSiteURL())
					self.configObject[idx]['user'] = str(dialog.getUser())
					self.configObject[idx]['pw'] = str(dialog.getPassword())
					item.setText(self.configObject[idx]['name'] + '\t' + self.configObject[idx]['destination'])
					break