Rework prepareView.

+ introduce View() as a way of organzing.
+ resolve most of the IDE warnings.
master
Ivan Olexyn 6 years ago
parent 6b2780c2d6
commit dfa396ca50

@ -1,188 +1,167 @@
from PyQt5.QtWidgets import QWidget, QGridLayout, QLabel, QPushButton
from tools import Tools, Table, Text, View
from PyQt5.QtWidgets import QPlainTextEdit, QVBoxLayout, QHBoxLayout, QWidget, QGridLayout, QLabel, QPushButton, QTableWidget, QTableWidgetItem
from PyQt5.QtGui import QPixmap
from tools import Tools, Table, Text
class PrepareView(QWidget):
def __init__(self):
''' Widget containing the entire Zebra Mode view. '''
""" Widget mainontaining the entire Zebra Mode view. """
super().__init__()
self.grid = QGridLayout()
self.setLayout(self.grid)
# Tools.View()s group Widgets for ease of use.
self.base = View()
self.nuc = View()
self.mag = View()
# Define Files so IDE does not issue warnings.
self.crystalFile = None
self.instrumentFile = None
# Define widgets.
self.define_widgets()
self.showView('none')
self.set_widget_actions()
# Start by showing the base view.
self.show_view()
def define_widgets(self):
''' Define widgets such as buttons. This must be done before setting widget actions.
Otherwise a widget action might try to modify a widget that is not defined yet.'''
# add empty label as spacer after buttons
# this has some side effects (i suspect) :
# + when adding the Buttons20, we really mean for it to span from grid position (3,1) to (3,2)
# but to create the correct visual effect it must span also over the invisible spacder column,
# Thus from (3,1) to (3,3).
self.grid.addWidget(QLabel(), 10,10)
"""
Define widgets, such as buttons. This must be done before setting widget actions.
Otherwise a widget action might try to modify a widget that is not defined yet.
"""
# Common items
# Add empty label as spacer after buttons.I suspect this has a side effect.
# When adding Buttons20, we mean for them to span from grid position (3,1) to (3,2).
# However to mainreate the mainorrect visual effect they must also mainover the invisible spacer mainolumn.
# Thus we set them to span from grid position (3,1) to (3,3).
self.grid.addWidget(QLabel(), 10, 10)
self.baseTable = Table()
self.grid.addWidget(self.baseTable,0,1)
self.buttons00 = Buttons00(self)
self.grid.addWidget(self.buttons00,0,0)
# Base Items (Left mainolumn, always shown)
self.base.table = Table()
self.grid.addWidget(self.base.table, 0, 1)
self.base.buttons00 = BaseButtons00(self)
self.grid.addWidget(self.base.buttons00, 0, 0)
# Zebra Nuc View
self.nucTable = Table()
self.grid.addWidget(self.nucTable,0,1)
self.nucButtons11 = NucButtons11(self)
self.grid.addWidget(self.nucButtons11, 1,1)
self.nuc.table = Table()
self.grid.addWidget(self.nuc.table, 0, 1)
self.nuc.buttons11 = NucButtons11(self)
self.grid.addWidget(self.nuc.buttons11, 1, 1)
# Zebra Mag View
self.magTable = Table()
self.grid.addWidget(self.magTable,0,1)
self.magButtons11 = MagButtons11(self)
self.grid.addWidget(self.magButtons11,1,1)
self.magVisual = Text("List of Files:\n+ File 1\n+ File 2")
self.grid.addWidget(self.magVisual, 0,2)
self.magButtons12 = MagButtons12(self)
self.grid.addWidget(self.magButtons12,1,2)
self.mag.table = Table()
self.grid.addWidget(self.mag.table, 0, 1)
self.mag.buttons11 = MagButtons11(self)
self.grid.addWidget(self.mag.buttons11, 1, 1)
self.mag.visual = Text("List of Files:\n+ File 1\n+ File 2")
self.grid.addWidget(self.mag.visual, 0, 2)
self.mag.buttons12 = MagButtons12(self)
self.grid.addWidget(self.mag.buttons12, 1, 2)
def set_widget_actions(self):
self.crystalFile = self.loadCrystalFileButton.clicked.connect(lambda: Tools().open_file(self))
self.instrumentFile = self.loadInstrumentFileButton.clicked.connect(lambda: Tools().open_file(self))
self.sectorNucButton.clicked.connect(lambda: self.showView('nuc'))
self.sectorMagButton.clicked.connect(lambda: self.showView('mag'))
pass
self.sectorNucButton.clicked.connect(lambda: self.show_view('nuc'))
self.sectorMagButton.clicked.connect(lambda: self.show_view('mag'))
def showView(self,view):
''' Will hide everything if called with anything besides nuc or mag.'''
self.nucTable.setHidden(True)
self.nucButtons11.setHidden(True)
self.magTable.setHidden(True)
self.magButtons11.setHidden(True)
self.magVisual.setHidden(True)
self.magButtons12.setHidden(True)
def show_view(self, view = None):
""" Will hide everything if mainalled with anything besides nuc or mag."""
self.nuc.hide()
self.mag.hide()
if view == 'nuc':
self.baseTable.setHidden(True)
self.nucTable.setHidden(False)
self.nucButtons11.setHidden(False)
elif view == 'mag':
self.baseTable.setHidden(True)
self.magTable.setHidden(False)
self.magButtons11.setHidden(False)
self.magVisual.setHidden(False)
self.magButtons12.setHidden(False)
else:
pass
self.base.table.setHidden(True)
# above line mainan be written as below (to avoid the IDE warning)
# vars(self.base)['table'].setHidden(True)
self.nuc.show()
elif view == 'mag':
self.base.table.setHidden(True)
self.mag.show()
class Buttons00(QWidget):
class BaseButtons00(QWidget):
def __init__(self, c):
''' Here c stands for container, thus the main window.'''
def __init__(self, main):
""" Here main is the main window."""
super().__init__()
grid = QGridLayout()
self.setLayout(grid)
c.loadCrystalFileButton = QPushButton("Load Crystal File")
grid.addWidget(c.loadCrystalFileButton, 0, 0)
main.loadCrystalFileButton = QPushButton("Load Crystal File")
grid.addWidget(main.loadCrystalFileButton, 0, 0)
c.loadInstrumentFileButton = QPushButton('Load Instrument File')
grid.addWidget(c.loadInstrumentFileButton,1,0)
main.loadInstrumentFileButton = QPushButton('Load Instrument File')
grid.addWidget(main.loadInstrumentFileButton, 1, 0)
c.sectorNucButton = QPushButton('Prepare Sector Nuc')
grid.addWidget(c.sectorNucButton,2,0)
main.sectorNucButton = QPushButton('Prepare Sector Nuc')
grid.addWidget(main.sectorNucButton, 2, 0)
c.sectorMagButton = QPushButton('Prepare Sector Mag')
grid.addWidget(c.sectorMagButton,3,0)
main.sectorMagButton = QPushButton('Prepare Sector Mag')
grid.addWidget(main.sectorMagButton, 3, 0)
c.readInfoButton = QPushButton('Place holder for read Info')
grid.addWidget(c.readInfoButton, 4,0)
main.readInfoButton = QPushButton('Place holder for read Info')
grid.addWidget(main.readInfoButton, 4, 0)
class NucButtons11(QWidget):
def __init__(self,c):
''' Here c stands for container, thus the main window.\n
The purpose of this notation is to enable access to each button via self in the main window.'''
def __init__(self, main):
""" Here main is the main window.\n
The purpose of this notation is to enable access to each button via self in the main window."""
super().__init__()
grid = QGridLayout()
self.setLayout(grid)
c.sortNucButton = QPushButton("Sort")
grid.addWidget(c.sortNucButton,0,0)
main.nuc.sortButton = QPushButton("Sort")
grid.addWidget(main.nuc.sortButton, 0, 0)
main.nuc.optimizeButton = QPushButton("Optimize")
grid.addWidget(main.nuc.optimizeButton, 0, 1)
c.optimizeNucButton = QPushButton("Optimize")
grid.addWidget(c.optimizeNucButton,0,1)
main.nuc.saveButton = QPushButton("Save")
grid.addWidget(main.nuc.saveButton, 0, 2)
c.saveNucButton = QPushButton("Save")
grid.addWidget(c.saveNucButton,0,2)
class MagButtons11(QWidget):
def __init__(self,c):
def __init__(self, main):
super().__init__()
grid = QGridLayout()
self.setLayout(grid)
c.runMagButton = QPushButton('Run')
grid.addWidget(c.runMagButton,0,0)
main.mag.runButton = QPushButton('Run')
grid.addWidget(main.mag.runButton, 0, 0)
class MagButtons12(QWidget):
def __init__(self,c):
def __init__(self, main):
super().__init__()
grid = QGridLayout()
self.setLayout(grid)
c.sortMagButton = QPushButton('Sort')
grid.addWidget(c.sortMagButton,0,0)
main.mag.sortButton = QPushButton('Sort')
grid.addWidget(main.mag.sortButton, 0, 0)
c.optimizeMagButton = QPushButton('Optimize')
grid.addWidget(c.optimizeMagButton,0,1)
main.mag.optimizeButton = QPushButton('Optimize')
grid.addWidget(main.mag.optimizeButton, 0, 1)
c.saveMagButton = QPushButton('Save')
grid.addWidget(c.saveMagButton,0,2)
main.mag.saveButton = QPushButton('Save')
grid.addWidget(main.mag.saveButton, 0, 2)

@ -1,7 +1,7 @@
import sys
from PyQt5.QtWidgets import QFileDialog, QTableWidget, QPlainTextEdit
from PyQt5.QtWidgets import QFileDialog, QTableWidget, QPlainTextEdit,QWidget
@ -24,6 +24,7 @@ class Tools():
pass
class Table(QTableWidget):
def __init__(self):
super().__init__()
@ -39,8 +40,33 @@ class Table(QTableWidget):
class Text(QPlainTextEdit,):
class Text(QPlainTextEdit):
def __init__(self, text):
super().__init__()
self.setMinimumSize(200,200)
self.setPlainText(text)
class View():
def __init__(self):
pass
def show(self):
''' Show widgets. '''
#TODO filter this, so that it applies to QWidgets only.
for widget in vars(self):
vars(self)[widget].setHidden(False)
def hide(self):
''' Hide widgets. '''
for widget in vars(self):
vars(self)[widget].setHidden(True)

Loading…
Cancel
Save