module.py 1.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
#!/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

from PyQt5 import QtWidgets
12 13
from PyQt5.QtCore import QTime, QTimer, Qt
from PyQt5.QtWidgets import QTableWidgetItem, QComboBox, QApplication
14 15 16 17

from modules import *

class Module(QtWidgets.QWidget):
Antoine Lima's avatar
Antoine Lima committed
18
	def __init__(self, parent, widget):
19 20
		# UI Setup
		QtWidgets.QWidget.__init__(self, parent)
Antoine Lima's avatar
Antoine Lima committed
21
		self.mainwin = parent
22 23
		self.ui = widget
		self.ui.setupUi(self)
Antoine Lima's avatar
Antoine Lima committed
24
	
25
	def switchModule(self, new_type):
Antoine Lima's avatar
Antoine Lima committed
26 27
		curmod_idx = self.mainwin.findMod(type(self))
		newmod_idx = self.mainwin.findMod(new_type)
28
		
Antoine Lima's avatar
Antoine Lima committed
29 30 31 32
		if curmod_idx<0:
			logging.error('Unknown panel {}'.format(type(self)))
		elif newmod_idx<0:
			logging.error('Unknown panel {}'.format(new_type))
33
		else:
Antoine Lima's avatar
Antoine Lima committed
34 35
			# Unfocus the current module
			self.mainwin.ui.panels.currentWidget().releaseKeyboard()
36 37 38
			if QApplication.focusWidget() != None:
				QApplication.focusWidget().clearFocus()
			
Antoine Lima's avatar
Antoine Lima committed
39 40 41 42
			# Swap modules by unloading, changing the ui then loading
			self.mainwin.modules[curmod_idx].unload()
			self.mainwin.ui.panels.setCurrentIndex(newmod_idx)
			self.mainwin.modules[newmod_idx].load()
43 44
			
			# Select first element of the Module
Antoine Lima's avatar
Antoine Lima committed
45 46 47
			self.mainwin.modules[newmod_idx].focusNextChild()
			self.mainwin.modules[newmod_idx].focusPreviousChild()
			self.mainwin.modules[newmod_idx].grabKeyboard()
48

Antoine Lima's avatar
Antoine Lima committed
49
	def send(self, to, **kwargs):
Antoine Lima's avatar
Antoine Lima committed
50
		mod_idx = self.mainwin.findMod(to)
Antoine Lima's avatar
Antoine Lima committed
51 52 53 54 55 56
		
		if mod_idx<0:
			logging.error('Unknown panel {}'.format(to))
		else:
			self.mainwin.modules[mod_idx].other(**kwargs)
	
57 58 59 60 61 62 63 64
	def load(self):
		logging.warning('Unimplemented method "load" for {}'.format(self.__class__))

	def unload(self):
		logging.warning('Unimplemented method "unload" for {}'.format(self.__class__))

	def other(self, **kwargs):
		logging.warning('Unimplemented method "other" for {}'.format(self.__class__))