+ introduce View() as a way of organzing. + resolve most of the IDE warnings.master
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):
|
class PrepareView(QWidget):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
''' Widget containing the entire Zebra Mode view. '''
|
""" Widget mainontaining the entire Zebra Mode view. """
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.grid = QGridLayout()
|
self.grid = QGridLayout()
|
||||||
|
|
||||||
self.setLayout(self.grid)
|
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.define_widgets()
|
||||||
self.showView('none')
|
|
||||||
self.set_widget_actions()
|
self.set_widget_actions()
|
||||||
|
|
||||||
|
# Start by showing the base view.
|
||||||
|
self.show_view()
|
||||||
|
|
||||||
|
|
||||||
def define_widgets(self):
|
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.'''
|
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)
|
|
||||||
|
|
||||||
|
|
||||||
# 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()
|
# Base Items (Left mainolumn, always shown)
|
||||||
self.grid.addWidget(self.baseTable,0,1)
|
|
||||||
|
|
||||||
self.buttons00 = Buttons00(self)
|
|
||||||
self.grid.addWidget(self.buttons00,0,0)
|
|
||||||
|
|
||||||
|
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
|
# Zebra Nuc View
|
||||||
|
|
||||||
self.nucTable = Table()
|
self.nuc.table = Table()
|
||||||
self.grid.addWidget(self.nucTable,0,1)
|
self.grid.addWidget(self.nuc.table, 0, 1)
|
||||||
|
|
||||||
self.nucButtons11 = NucButtons11(self)
|
|
||||||
self.grid.addWidget(self.nucButtons11, 1,1)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
self.nuc.buttons11 = NucButtons11(self)
|
||||||
|
self.grid.addWidget(self.nuc.buttons11, 1, 1)
|
||||||
|
|
||||||
# Zebra Mag View
|
# Zebra Mag View
|
||||||
|
|
||||||
self.magTable = Table()
|
self.mag.table = Table()
|
||||||
self.grid.addWidget(self.magTable,0,1)
|
self.grid.addWidget(self.mag.table, 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.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):
|
def set_widget_actions(self):
|
||||||
self.crystalFile = self.loadCrystalFileButton.clicked.connect(lambda: Tools().open_file(self))
|
self.crystalFile = self.loadCrystalFileButton.clicked.connect(lambda: Tools().open_file(self))
|
||||||
self.instrumentFile = self.loadInstrumentFileButton.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.sectorNucButton.clicked.connect(lambda: self.show_view('nuc'))
|
||||||
self.sectorMagButton.clicked.connect(lambda: self.showView('mag'))
|
self.sectorMagButton.clicked.connect(lambda: self.show_view('mag'))
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def showView(self,view):
|
def show_view(self, view = None):
|
||||||
''' Will hide everything if called with anything besides nuc or mag.'''
|
""" Will hide everything if mainalled with anything besides nuc or mag."""
|
||||||
self.nucTable.setHidden(True)
|
self.nuc.hide()
|
||||||
self.nucButtons11.setHidden(True)
|
self.mag.hide()
|
||||||
self.magTable.setHidden(True)
|
|
||||||
self.magButtons11.setHidden(True)
|
|
||||||
self.magVisual.setHidden(True)
|
|
||||||
self.magButtons12.setHidden(True)
|
|
||||||
|
|
||||||
if view == 'nuc':
|
if view == 'nuc':
|
||||||
self.baseTable.setHidden(True)
|
self.base.table.setHidden(True)
|
||||||
self.nucTable.setHidden(False)
|
# above line mainan be written as below (to avoid the IDE warning)
|
||||||
self.nucButtons11.setHidden(False)
|
# vars(self.base)['table'].setHidden(True)
|
||||||
elif view == 'mag':
|
self.nuc.show()
|
||||||
self.baseTable.setHidden(True)
|
|
||||||
self.magTable.setHidden(False)
|
|
||||||
self.magButtons11.setHidden(False)
|
|
||||||
self.magVisual.setHidden(False)
|
|
||||||
self.magButtons12.setHidden(False)
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
elif view == 'mag':
|
||||||
|
self.base.table.setHidden(True)
|
||||||
|
self.mag.show()
|
||||||
|
|
||||||
|
|
||||||
class Buttons00(QWidget):
|
class BaseButtons00(QWidget):
|
||||||
|
|
||||||
def __init__(self, c):
|
def __init__(self, main):
|
||||||
''' Here c stands for container, thus the main window.'''
|
""" Here main is the main window."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
grid = QGridLayout()
|
grid = QGridLayout()
|
||||||
self.setLayout(grid)
|
self.setLayout(grid)
|
||||||
|
|
||||||
c.loadCrystalFileButton = QPushButton("Load Crystal File")
|
main.loadCrystalFileButton = QPushButton("Load Crystal File")
|
||||||
grid.addWidget(c.loadCrystalFileButton, 0, 0)
|
grid.addWidget(main.loadCrystalFileButton, 0, 0)
|
||||||
|
|
||||||
c.loadInstrumentFileButton = QPushButton('Load Instrument File')
|
main.loadInstrumentFileButton = QPushButton('Load Instrument File')
|
||||||
grid.addWidget(c.loadInstrumentFileButton,1,0)
|
grid.addWidget(main.loadInstrumentFileButton, 1, 0)
|
||||||
|
|
||||||
c.sectorNucButton = QPushButton('Prepare Sector Nuc')
|
main.sectorNucButton = QPushButton('Prepare Sector Nuc')
|
||||||
grid.addWidget(c.sectorNucButton,2,0)
|
grid.addWidget(main.sectorNucButton, 2, 0)
|
||||||
|
|
||||||
c.sectorMagButton = QPushButton('Prepare Sector Mag')
|
main.sectorMagButton = QPushButton('Prepare Sector Mag')
|
||||||
grid.addWidget(c.sectorMagButton,3,0)
|
grid.addWidget(main.sectorMagButton, 3, 0)
|
||||||
|
|
||||||
c.readInfoButton = QPushButton('Place holder for read Info')
|
main.readInfoButton = QPushButton('Place holder for read Info')
|
||||||
grid.addWidget(c.readInfoButton, 4,0)
|
grid.addWidget(main.readInfoButton, 4, 0)
|
||||||
|
|
||||||
|
|
||||||
class NucButtons11(QWidget):
|
class NucButtons11(QWidget):
|
||||||
|
|
||||||
def __init__(self,c):
|
def __init__(self, main):
|
||||||
''' Here c stands for container, thus the main window.\n
|
""" 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.'''
|
The purpose of this notation is to enable access to each button via self in the main window."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
grid = QGridLayout()
|
grid = QGridLayout()
|
||||||
self.setLayout(grid)
|
self.setLayout(grid)
|
||||||
|
|
||||||
c.sortNucButton = QPushButton("Sort")
|
main.nuc.sortButton = QPushButton("Sort")
|
||||||
grid.addWidget(c.sortNucButton,0,0)
|
grid.addWidget(main.nuc.sortButton, 0, 0)
|
||||||
|
|
||||||
|
main.nuc.optimizeButton = QPushButton("Optimize")
|
||||||
|
grid.addWidget(main.nuc.optimizeButton, 0, 1)
|
||||||
|
|
||||||
c.optimizeNucButton = QPushButton("Optimize")
|
main.nuc.saveButton = QPushButton("Save")
|
||||||
grid.addWidget(c.optimizeNucButton,0,1)
|
grid.addWidget(main.nuc.saveButton, 0, 2)
|
||||||
|
|
||||||
c.saveNucButton = QPushButton("Save")
|
|
||||||
grid.addWidget(c.saveNucButton,0,2)
|
|
||||||
|
|
||||||
class MagButtons11(QWidget):
|
class MagButtons11(QWidget):
|
||||||
|
|
||||||
def __init__(self,c):
|
def __init__(self, main):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
grid = QGridLayout()
|
grid = QGridLayout()
|
||||||
self.setLayout(grid)
|
self.setLayout(grid)
|
||||||
|
|
||||||
c.runMagButton = QPushButton('Run')
|
main.mag.runButton = QPushButton('Run')
|
||||||
grid.addWidget(c.runMagButton,0,0)
|
grid.addWidget(main.mag.runButton, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
class MagButtons12(QWidget):
|
class MagButtons12(QWidget):
|
||||||
|
|
||||||
def __init__(self,c):
|
def __init__(self, main):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
grid = QGridLayout()
|
grid = QGridLayout()
|
||||||
self.setLayout(grid)
|
self.setLayout(grid)
|
||||||
|
|
||||||
c.sortMagButton = QPushButton('Sort')
|
main.mag.sortButton = QPushButton('Sort')
|
||||||
grid.addWidget(c.sortMagButton,0,0)
|
grid.addWidget(main.mag.sortButton, 0, 0)
|
||||||
|
|
||||||
c.optimizeMagButton = QPushButton('Optimize')
|
main.mag.optimizeButton = QPushButton('Optimize')
|
||||||
grid.addWidget(c.optimizeMagButton,0,1)
|
grid.addWidget(main.mag.optimizeButton, 0, 1)
|
||||||
|
|
||||||
c.saveMagButton = QPushButton('Save')
|
main.mag.saveButton = QPushButton('Save')
|
||||||
grid.addWidget(c.saveMagButton,0,2)
|
grid.addWidget(main.mag.saveButton, 0, 2)
|
||||||
|
Loading…
Reference in new issue