Exemple #1
0
	def open_settings_window(self):
		"""
		Opens a window where we can review and change program settings
		"""
		self.settings_window = QtGui.QWidget()
		self.settings_form = Ui_setup_form()
		self.settings_form.setupUi(self.settings_window)
		self.settings_window.setStyleSheet(self.style)
		self.settings_window.show()

		# Sets the checkboxes
		if self.saveHistory: self.settings_form.cb_save_history.setChecked(True)
		else: self.settings_form.cb_save_history.setChecked(False)
		if self.readNetLogs: self.settings_form.cb_read_netlogs.setChecked(True)
		else:self.settings_form.cb_read_netlogs.setChecked(False)

		# Connects the NetLogs checkbox to function that enables/disables the file picker
		self.settings_form.cb_read_netlogs.stateChanged.connect(self._checkbox_response)

		# File picker label and button for NetLogs folder
		if self.NetLogFolder.startswith(os.path.expanduser('~')):
			self.settings_form.lbl_netlogs_path.setText('~' + self.NetLogFolder[len(os.path.expanduser('~')):])
		else:
			self.settings_form.lbl_netlogs_path.setText(self.NetLogFolder)

		self.settings_form.btn_netlogs_picker.clicked.connect(self._file_dialog_response)

		# Apply / Cancel buttons
		self.settings_form.btn_apply.clicked.connect(self._apply_settings)
		self.settings_form.btn_cancel.clicked.connect(self._cancel_settings)

		if self.readNetLogs:
			self.settings_form.lbl_netlogs_path.setEnabled(True)
			self.settings_form.btn_netlogs_picker.setEnabled(True)
		else:
			self.settings_form.lbl_netlogs_path.setEnabled(False)
			self.settings_form.btn_netlogs_picker.setEnabled(False)
Exemple #2
0
class Settings:
	def __init__(self, style):
		"""
		Class to read, write and update the program's settings
		"""
		self.read_settings()
		self.style = style


	def read_settings(self):
		"""
		Uses QSettings, which will store the setting in different locations depending on OS
		For Linux normally in ~/.config/.config/OJ/EDreporter.conf
		For Windows in the registry at \HKEY_CURRENT_USER\Software\OJ\EDreporter
		"""
		config = QSettings('OJ', 'EDreporter')  # (organization, application name)
		if not config.contains('saveHistory'):  # If config are not defined, we're in the first run and save defaults
			print('no config - making one')
			config.setValue('saveHistory', True)  # Save data between runs to make statistics
			config.setValue('authenticated', False)  # Are we authenticated with the API yet?
			config.setValue('readNetLogs', True)  # Should we analyse the NetLog folder and all logs? (must be enabled in Elite's settings)
			config.setValue('systemsDataFile', '.\eddb_data\systems.json')  # JOSN data for systems (downloaded)
			config.setValue('stationsDataFile', '.\eddb_data\stations.json')  # JOSN data for stations (downloaded)
			config.setValue('systemsDataURL', 'https://eddb.io/archive/v4/systems.json')  # URL for systems JSON download
			config.setValue('stationsDataURL', 'https://eddb.io/archive/v4/stations.json')  # URL for stations JSON download
			config.setValue('NetLogFolder', os.path.expanduser("~") + '\AppData\Local\Frontier_Developments\Products\elite-dangerous-64\Logs')  # E:D Horizons default
			config.setValue('historyDatabase', '.\history.db')

		self.saveHistory  = config.value('saveHistory', type=bool)
		self.authenticated= config.value('authenticated', type=bool)
		self.readNetLogs  = config.value('readNetLogs', type=bool)
		self.NetLogFolder = config.value('NetLogFolder', type=str)
		self.historyDatabase = config.value('historyDatabase', type=str)
		self.stationsDataFile= config.value('stationsDataFile', type=str)
		self.systemsDataFile = config.value('systemsDataFile', type=str)
		self.stationsDataURL = config.value('stationsDataURL', type=str)
		self.systemsDataURL = config.value('systemsDataURL', type=str)

	def save_settings(self):
		config = QSettings('OJ', 'EDreporter')  # (organization, application name)
		config.setValue('saveHistory', self.saveHistory)  # Save data between runs to make statistics
		config.setValue('authenticated', self.authenticated)  # Are we authenticated with the API yet?
		config.setValue('readNetLogs', self.readNetLogs)  # Should we analyse the NetLog folder and all logs? (must be enabled in Elite's settings)
		config.setValue('systemsDataFile', self.systemsDataFile)  # JOSN data for systems (downloaded)
		config.setValue('stationsDataFile', self.stationsDataFile)  # JOSN data for stations (downloaded)
		config.setValue('systemsDataURL', self.systemsDataURL)  # URL for systems JSON download
		config.setValue('stationsDataURL', self.stationsDataURL)  # URL for stations JSON download
		config.setValue('NetLogFolder', self.NetLogFolder)  # E:D Horizons default
		config.setValue('historyDatabase', self.historyDatabase)

	def open_settings_window(self):
		"""
		Opens a window where we can review and change program settings
		"""
		self.settings_window = QtGui.QWidget()
		self.settings_form = Ui_setup_form()
		self.settings_form.setupUi(self.settings_window)
		self.settings_window.setStyleSheet(self.style)
		self.settings_window.show()

		# Sets the checkboxes
		if self.saveHistory: self.settings_form.cb_save_history.setChecked(True)
		else: self.settings_form.cb_save_history.setChecked(False)
		if self.readNetLogs: self.settings_form.cb_read_netlogs.setChecked(True)
		else:self.settings_form.cb_read_netlogs.setChecked(False)

		# Connects the NetLogs checkbox to function that enables/disables the file picker
		self.settings_form.cb_read_netlogs.stateChanged.connect(self._checkbox_response)

		# File picker label and button for NetLogs folder
		if self.NetLogFolder.startswith(os.path.expanduser('~')):
			self.settings_form.lbl_netlogs_path.setText('~' + self.NetLogFolder[len(os.path.expanduser('~')):])
		else:
			self.settings_form.lbl_netlogs_path.setText(self.NetLogFolder)

		self.settings_form.btn_netlogs_picker.clicked.connect(self._file_dialog_response)

		# Apply / Cancel buttons
		self.settings_form.btn_apply.clicked.connect(self._apply_settings)
		self.settings_form.btn_cancel.clicked.connect(self._cancel_settings)

		if self.readNetLogs:
			self.settings_form.lbl_netlogs_path.setEnabled(True)
			self.settings_form.btn_netlogs_picker.setEnabled(True)
		else:
			self.settings_form.lbl_netlogs_path.setEnabled(False)
			self.settings_form.btn_netlogs_picker.setEnabled(False)

	def _checkbox_response(self):
		if self.settings_form.cb_read_netlogs.isChecked():
			self.settings_form.btn_netlogs_picker.setEnabled(True)
			self.settings_form.lbl_netlogs_path.setEnabled(True)
		else:
			self.settings_form.btn_netlogs_picker.setEnabled(False)
			self.settings_form.lbl_netlogs_path.setEnabled(False)

	def _file_dialog_response(self):
		# Note that we only update the label, so if we want to save, we need to read the label
		self.chosen_folder = QtGui.QFileDialog.getExistingDirectory(self.settings_window, 'Please select folder where there NetLogs are saved', self.NetLogFolder)

		print(self.chosen_folder)
		if not self.chosen_folder == '':
			if self.chosen_folder.startswith(os.path.expanduser('~')):
				self.settings_form.lbl_netlogs_path.setText('~' + self.chosen_folder[len(os.path.expanduser('~')):])
			else:
				self.settings_form.lbl_netlogs_path.setText(self.chosen_folder)



	def _apply_settings(self):
		"""
		Reads the values from the form and saves into settings
		"""
		self.NetLogFolder = self.settings_form.lbl_netlogs_path.text()
		self.saveHistory = self.settings_form.cb_save_history.isChecked()
		self.readNetLogs = self.settings_form.cb_read_netlogs.isChecked()
		self.save_settings()  # We save all variables in the form
		self.settings_window.close()

	def _cancel_settings(self):
		"""
		Closes settings window discarding values (no changes)
		"""
		self.settings_window.close()