module.py 1.93 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
			# Unfocus the current module
35 36 37
			if QApplication.focusWidget() != None:
				QApplication.focusWidget().clearFocus()
			
Antoine Lima's avatar
Antoine Lima committed
38 39 40
			# Swap modules by unloading, changing the ui then loading
			self.mainwin.modules[curmod_idx].unload()
			self.mainwin.ui.panels.setCurrentIndex(newmod_idx)
Antoine Lima's avatar
Antoine Lima committed
41 42
			self.mainwin.ui.panels.setFocusProxy(self.mainwin.modules[newmod_idx])
			self.mainwin.modules[newmod_idx].setFocus()
Antoine Lima's avatar
Antoine Lima committed
43
			self.mainwin.modules[newmod_idx].load()
44 45
			
			# Select first element of the Module
Antoine Lima's avatar
Antoine Lima committed
46 47
			self.mainwin.modules[newmod_idx].focusNextChild()
			self.mainwin.modules[newmod_idx].focusPreviousChild()
Antoine Lima's avatar
Antoine Lima committed
48
			self.mainwin.modules[newmod_idx].focusPreviousChild()
49

Antoine Lima's avatar
Antoine Lima committed
50
	def send(self, to, **kwargs):
Antoine Lima's avatar
Antoine Lima committed
51
		mod_idx = self.mainwin.findMod(to)
Antoine Lima's avatar
Antoine Lima committed
52 53 54 55 56 57
		
		if mod_idx<0:
			logging.error('Unknown panel {}'.format(to))
		else:
			self.mainwin.modules[mod_idx].other(**kwargs)
	
58 59 60 61 62 63 64 65
	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__))