options.py 1.54 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 18 18:34:40 2018

@author: Antoine Lima, Leo Reynaert, Domitille Jehenne
"""

import logging

11 12
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QTableWidgetItem, QComboBox, QApplication
13

14
from settings import Settings
15 16 17 18 19 20 21 22 23
from module import Module
import modules
from ui.options_ui import Ui_Form as OptionsWidget

class OptionsModule(Module):
	def __init__(self, parent):
		super().__init__(parent, OptionsWidget())

		# Button connections
24 25
		self.ui.btnSave.clicked.connect(self.handleSave)
		self.ui.btnBack.clicked.connect(self.handleBack)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

	def load(self):
		logging.debug('Loading OptionsModule')
		cbb = QComboBox()
		cbb.addItem('true')
		cbb.addItem('false')
		self.ui.options.insertRow(self.ui.options.rowCount())
		self.ui.options.setItem(self.ui.options.rowCount()-1, 0, QTableWidgetItem('FullScreen'))
		self.ui.options.setCellWidget(self.ui.options.rowCount()-1, 1, cbb)

	def unload(self):
		logging.debug('Unloading OptionsModule')
		# Delete the table's content
		self.ui.options.setRowCount(0)
	
	def other(self, **kwargs):
		logging.debug('Other OptionsModule')

44 45
	def keyPressEvent(self, e):
		if e.key() == Qt.Key_Escape:
46
			self.handleBack()
47
		elif e.key() == Qt.Key_Return:
48
			self.handleSave()
49

50
	def handleSave(self):
51 52
		Settings['ui.fullscreen'] = self.ui.options.cellWidget(0, 1).currentText().lower() == 'true'
		self.mainwin._refreshAfterSettings()
53 54
		self.switchModule(modules.MenuModule)

55
	def handleBack(self):
56 57
		# ToDo: Maybe add a warning
		self.switchModule(modules.MenuModule)