Beispiel #1
0
	def __init__(self, bData, parent=None, name=None):
		super(CWCommandBoxDialog, self).__init__(parent) #Formality
		self.ui = Ui_CommandBoxDialog()
		self.ui.setupUi(self)
		self.ui.CancelButton.clicked.connect(self.selfDestruct)
		if bData == None:
			self.ui.OkayButton.clicked.connect(self.saveSettings)
		else:
			self.ui.NameText.setReadOnly(True)
			self.data = bData
			self.ui.OkayButton.clicked.connect(self.updateSettings)
			self.ui.NameText.setText(bData.name)
			self.ui.CommandText.setText(bData.command)
			if bData.auto:
				self.ui.CBAutoUpdate.setChecked(True)
			if bData.interval == 1:
				self.ui.RB1s.toggle()
			elif bData.interval == 3:
				self.ui.RB3s.toggle()
			elif bData.interval == 5:
				self.ui.RB5s.toggle()
			else:
				self.ui.RB10s.toggle()
			if bData.location == 'l':
				self.ui.RBLeft.toggle()
			elif bData.location == 'r':
				self.ui.RBRight.toggle()
			else:
				self.ui.RBBottom.toggle()
Beispiel #2
0
class CWCommandBoxDialog(QDialog): # -----------------------------------------
	def __init__(self, bData, parent=None, name=None):
		super(CWCommandBoxDialog, self).__init__(parent) #Formality
		self.ui = Ui_CommandBoxDialog()
		self.ui.setupUi(self)
		self.ui.CancelButton.clicked.connect(self.selfDestruct)
		if bData == None:
			self.ui.OkayButton.clicked.connect(self.saveSettings)
		else:
			self.ui.NameText.setReadOnly(True)
			self.data = bData
			self.ui.OkayButton.clicked.connect(self.updateSettings)
			self.ui.NameText.setText(bData.name)
			self.ui.CommandText.setText(bData.command)
			if bData.auto:
				self.ui.CBAutoUpdate.setChecked(True)
			if bData.interval == 1:
				self.ui.RB1s.toggle()
			elif bData.interval == 3:
				self.ui.RB3s.toggle()
			elif bData.interval == 5:
				self.ui.RB5s.toggle()
			else:
				self.ui.RB10s.toggle()
			if bData.location == 'l':
				self.ui.RBLeft.toggle()
			elif bData.location == 'r':
				self.ui.RBRight.toggle()
			else:
				self.ui.RBBottom.toggle()
	
	def checkInput(self):
		if self.ui.CBAutoUpdate.isChecked() and self.ui.CommandText.text() == "":
			self.errorPopup = CWErrorDialog("Error: Cannot auto-run without a command.")
			self.errorPopup.show()
			return False
		elif self.ui.CBAutoUpdate.isChecked() and not self.ui.RB1s.isChecked() and not self.ui.RB3s.isChecked() and not self.ui.RB5s.isChecked() and not self.ui.RB10s.isChecked():
			self.errorPopup = CWErrorDialog("Error: All fields must have appropriate values.")
			self.errorPopup.show()
			return False
		if self.ui.NameText.text() == "":
		 	self.errorPopup = CWErrorDialog("Please enter a name.")
		 	self.errorPopup.show()
		 	return False
		return True

	def saveSettings(self):
		global boxList, boxDict
		if self.checkInput():
			bData = BoxData()
			if self.ui.CBAutoUpdate.isChecked():
				bData.auto = True
			if self.ui.RB1s.isChecked():
				bData.interval = 1
			elif self.ui.RB3s.isChecked():
				bData.interval = 3
			elif self.ui.RB5s.isChecked():
				bData.interval = 5
			else:
				bData.interval = 10
			bData.command = self.ui.CommandText.text()
			newCommandBox = CWCommandBox(bData)# QPlainTextEdit(window.ui.dockWidgetContents_6)
			newCommandBox.setReadOnly(True)
			newCommandBox.setObjectName(self.ui.NameText.text())
			bData.name = self.ui.NameText.text()
			if self.ui.RBLeft.isChecked():
				bData.location = "l"
				window.ui.verticalLayout_2.addWidget(newCommandBox)
			elif self.ui.RBBottom.isChecked():
				bData.location = "b"
				window.ui.horizontalLayout_3.addWidget(newCommandBox)
			else:
				bData.location = "r"
				window.ui.verticalLayout.addWidget(newCommandBox)
			bData.boxObj = newCommandBox
			boxDict[bData.name] = bData
			boxList.append(bData)
			self.close()
		

	def updateSettings(self):
		global boxList, boxDict
		if self.checkInput():
			if self.ui.CBAutoUpdate.isChecked():
				self.data.auto = True
			if self.ui.RB1s.isChecked():
				self.data.interval = 1
			elif self.ui.RB3s.isChecked():
				self.data.interval = 3
			elif self.ui.RB5s.isChecked():
				self.data.interval = 5
			else:
				self.data.interval = 10
			self.data.command = self.ui.CommandText.text()
			self.data.name = self.ui.NameText.text()
			if self.ui.RBLeft.isChecked():
				if self.data.location == "r":
					window.ui.verticalLayout.removeWidget(self.data.boxObj)
				elif self.data.location == "b":
					window.ui.horizontalLayout_3.removeWidget(self.data.boxObj)
				if self.data.location != "l":
					self.data.location = "l"
					window.ui.verticalLayout_2.addWidget(self.data.boxObj)
			elif self.ui.RBBottom.isChecked():
				if self.data.location == "r":
					window.ui.verticalLayout.removeWidget(self.data.boxObj)
				elif self.data.location == "l":
					window.ui.verticalLayout_2.removeWidget(self.data.boxObj)
				if self.data.location != "b":
					self.data.location = "b"
					window.ui.horizontalLayout_3.addWidget(self.data.boxObj)
			else:
				if self.data.location == "b":
					window.ui.horizontalLayout_3.removeWidget(self.data.boxObj)
				elif self.data.location == "l":
					window.ui.verticalLayout_2.removeWidget(self.data.boxObj)
				if self.data.location != "r":
					self.data.location = "r"
					window.ui.verticalLayout.addWidget(self.data.boxObj)
			self.close()

	def selfDestruct(self):
		self.close()