+ introduce View() as a way of organzing. + resolve most of the IDE warnings. + replace def define_widgets() with comment banners, so that grid does not need to be self.grid. + move inactive code to code samples.master
parent
dfa396ca50
commit
6bfd63d66e
@ -1,7 +1,7 @@
|
||||
import sys
|
||||
|
||||
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMainWindow, QGridLayout, QLabel, QSpacerItem, QSizePolicy, QComboBox, QFileDialog
|
||||
from plot_canvas import PlotCanvas
|
||||
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMainWindow, QGridLayout, QLabel, QComboBox, QFileDialog
|
||||
from code_samples.plot_canvas import PlotCanvas
|
||||
|
||||
class Window(QMainWindow):
|
||||
'''
|
@ -1,2 +0,0 @@
|
||||
''''''
|
||||
from PyQt5.QtWidgets import QWidget
|
@ -1,147 +0,0 @@
|
||||
from PyQt5.QtWidgets import QPlainTextEdit, QHBoxLayout, QWidget, QGridLayout, QLabel, QPushButton, QTableWidget, QTableWidgetItem
|
||||
from tools import Tools
|
||||
|
||||
class OneDimView(QWidget):
|
||||
|
||||
|
||||
def __init__(self):
|
||||
''' Widget containing the entire 2D Mode view. '''
|
||||
super().__init__()
|
||||
|
||||
self.grid = QGridLayout()
|
||||
|
||||
self.setLayout(self.grid)
|
||||
|
||||
|
||||
self.define_widgets()
|
||||
self.set_widget_actions()
|
||||
|
||||
|
||||
|
||||
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)
|
||||
self.loadDataButton = QPushButton()
|
||||
self.loadDataButton.setText("Load Data File")
|
||||
self.loadDataButton.setMaximumWidth(200)
|
||||
self.grid.addWidget(self.loadDataButton, 0, 0)
|
||||
|
||||
|
||||
self.one_d_text = OneDText()
|
||||
self.grid.addWidget(self.one_d_text, 1,0)
|
||||
|
||||
|
||||
self.one_d_table = OneDTable()
|
||||
self.grid.addWidget(self.one_d_table,0,1, 4,1)
|
||||
|
||||
|
||||
self.one_d_visualize = OneDVisualize()
|
||||
self.grid.addWidget(self.one_d_visualize,0,2,2,2)
|
||||
|
||||
self.buttons20 = Buttons20()
|
||||
self.grid.addWidget(self.buttons20, 2,0)
|
||||
|
||||
self.buttons30 = Buttons30()
|
||||
self.grid.addWidget(self.buttons30, 3,0)
|
||||
|
||||
self.buttons32 = Buttons32()
|
||||
self.grid.addWidget(self.buttons32,3,2)
|
||||
|
||||
def set_widget_actions(self):
|
||||
|
||||
self.dataFile = self.loadDataButton.clicked.connect(lambda: Tools().open_file(self))
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
class OneDText(QPlainTextEdit):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setMinimumSize(200,200)
|
||||
self.setPlainText("List of Files:\n+ File 1\n+ File 2")
|
||||
|
||||
|
||||
|
||||
class OneDTable(QTableWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.setSortingEnabled(True)
|
||||
|
||||
self.setRowCount(4)
|
||||
self.setColumnCount(4)
|
||||
|
||||
self.setMinimumSize(300,200)
|
||||
|
||||
self.setHorizontalHeaderLabels({'h', 'k', 'l'})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Buttons20(QWidget):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.hbox = QHBoxLayout()
|
||||
self.setLayout(self.hbox)
|
||||
self.searchButton = QPushButton('Search')
|
||||
self.addButton = QPushButton('Add')
|
||||
self.substractButton = QPushButton('Substract')
|
||||
self.hbox.addWidget(self.searchButton)
|
||||
self.hbox.addWidget(self.addButton)
|
||||
self.hbox.addWidget(self.substractButton)
|
||||
|
||||
|
||||
|
||||
|
||||
class Buttons30(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.hbox = QHBoxLayout()
|
||||
self.setLayout(self.hbox)
|
||||
|
||||
|
||||
self.integrateButton = QPushButton('Integrate')
|
||||
self.lorentzButton = QPushButton('Lorentz')
|
||||
self.absorptionButton = QPushButton('Absorption')
|
||||
|
||||
self.hbox.addWidget(self.integrateButton)
|
||||
self.hbox.addWidget(self.lorentzButton)
|
||||
self.hbox.addWidget(self.absorptionButton)
|
||||
|
||||
|
||||
|
||||
class Buttons32(QWidget):
|
||||
def __init__(self):
|
||||
''' Named after its position in the containing grid: row 3, column 2.'''
|
||||
super().__init__()
|
||||
self.grid= QGridLayout()
|
||||
self.setLayout(self.grid)
|
||||
self.saveButton = QPushButton('Save')
|
||||
self.grid.addWidget(self.saveButton,0,0)
|
||||
self.visualizeButton = QPushButton('Visualize in 2D')
|
||||
self.grid.addWidget(self.visualizeButton, 0,1)
|
||||
|
||||
|
||||
|
||||
class OneDVisualize(QPlainTextEdit):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setMinimumSize(200,200)
|
||||
self.setPlainText('Placeholder\nfor OneDVisualize().')
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,126 @@
|
||||
from PyQt5.QtWidgets import QPlainTextEdit, QHBoxLayout, QWidget, QGridLayout, QLabel, QPushButton
|
||||
|
||||
from tools import Tools, View, Text, Table
|
||||
|
||||
|
||||
class OneDimView(QWidget):
|
||||
|
||||
|
||||
def __init__(self):
|
||||
""" Widget containing the entire 2D Mode view. """
|
||||
super().__init__()
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# PREPARE
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
self.grid = QGridLayout()
|
||||
self.setLayout(self.grid)
|
||||
|
||||
# Tools.View() groups Widgets for ease of use.
|
||||
self.one = View()
|
||||
|
||||
# Define Files so IDE does not issue warnings (self. variables should be defined in __init__).
|
||||
self.dataFile = None
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# DEFINE WIDGETS
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
# 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.one.loadDataButton = QPushButton("Load Data File")
|
||||
self.one.loadDataButton.setMaximumWidth(200)
|
||||
self.grid.addWidget(self.one.loadDataButton, 0, 0)
|
||||
|
||||
self.one.text = Text("List of Files:\n+ File 1\n+ File 2")
|
||||
self.grid.addWidget(self.one.text, 1, 0)
|
||||
|
||||
self.one.table = Table()
|
||||
self.grid.addWidget(self.one.table, 0, 1, 4, 1)
|
||||
|
||||
self.one.visualize = OneVisualize()
|
||||
self.grid.addWidget(self.one.visualize, 0, 2, 2, 2)
|
||||
|
||||
self.one.buttons20 = Buttons20(self)
|
||||
self.grid.addWidget(self.one.buttons20, 2, 0)
|
||||
|
||||
self.one.buttons30 = Buttons30(self)
|
||||
self.grid.addWidget(self.one.buttons30, 3, 0)
|
||||
|
||||
self.one.buttons32 = Buttons32(self)
|
||||
self.grid.addWidget(self.one.buttons32, 3, 2)
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# SET WIDGET ACTIONS
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
self.dataFile = self.one.loadDataButton.clicked.connect(lambda: Tools().open_file(self))
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# FINISH
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class Buttons20(QWidget):
|
||||
|
||||
def __init__(self, main):
|
||||
super().__init__()
|
||||
hbox = QHBoxLayout()
|
||||
self.setLayout(hbox)
|
||||
|
||||
main.one.searchButton = QPushButton('Search')
|
||||
hbox.addWidget(main.one.searchButton)
|
||||
|
||||
main.one.addButton = QPushButton('Add')
|
||||
hbox.addWidget(main.one.addButton)
|
||||
|
||||
main.one.substractButton = QPushButton('Substract')
|
||||
hbox.addWidget(main.one.substractButton)
|
||||
|
||||
|
||||
class Buttons30(QWidget):
|
||||
|
||||
def __init__(self, main):
|
||||
super().__init__()
|
||||
hbox = QHBoxLayout()
|
||||
self.setLayout(hbox)
|
||||
|
||||
main.one.integrateButton = QPushButton('Integrate')
|
||||
hbox.addWidget(main.one.integrateButton)
|
||||
|
||||
main.one.lorentzButton = QPushButton('Lorentz')
|
||||
hbox.addWidget(main.one.lorentzButton)
|
||||
|
||||
main.one.absorptionButton = QPushButton('Absorption')
|
||||
hbox.addWidget(main.one.absorptionButton)
|
||||
|
||||
|
||||
class Buttons32(QWidget):
|
||||
""" Named after its position in the containing grid: row 3, column 2."""
|
||||
|
||||
def __init__(self, main):
|
||||
super().__init__()
|
||||
grid = QGridLayout()
|
||||
self.setLayout(grid)
|
||||
|
||||
main.one.saveButton = QPushButton('Save')
|
||||
grid.addWidget(main.one.saveButton, 0, 0)
|
||||
|
||||
main.one.visualizeButton = QPushButton('Visualize in 2D')
|
||||
grid.addWidget(main.one.visualizeButton, 0, 1)
|
||||
|
||||
|
||||
class OneVisualize(QPlainTextEdit):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setMinimumSize(200, 200)
|
||||
self.setPlainText('Placeholder\nfor the 1D Visualization.')
|
@ -1,156 +0,0 @@
|
||||
|
||||
from PyQt5.QtWidgets import QWidget, QGridLayout, QComboBox, QLabel, QPushButton, QAction, QHBoxLayout, QTabWidget, QTableWidget, QPlainTextEdit
|
||||
from tools import Tools
|
||||
|
||||
class TwoDimView(QWidget):
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def __init__(self):
|
||||
''' Widget containing the entire Zebra Mode view. '''
|
||||
super().__init__()
|
||||
|
||||
self.grid = QGridLayout()
|
||||
|
||||
self.setLayout(self.grid)
|
||||
|
||||
|
||||
self.define_widgets()
|
||||
self.set_widget_actions()
|
||||
|
||||
|
||||
|
||||
|
||||
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 Buttons12, 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)
|
||||
self.loadDataButton = QPushButton()
|
||||
self.loadDataButton.setText("Load Data File")
|
||||
self.loadDataButton.setMaximumWidth(200)
|
||||
self.grid.addWidget(self.loadDataButton, 1, 0)
|
||||
|
||||
|
||||
self.one_d_text = OneDText()
|
||||
self.grid.addWidget(self.one_d_text, 0,0)
|
||||
|
||||
|
||||
self.one_d_table = OneDTable()
|
||||
self.grid.addWidget(self.one_d_table,0,1)
|
||||
|
||||
self.one_d_visualize = OneDVisualize()
|
||||
self.grid.addWidget(self.one_d_visualize,0,2)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
self.buttons11 = Buttons11()
|
||||
self.grid.addWidget(self.buttons11, 1,1)
|
||||
|
||||
self.buttons12 = Buttons12()
|
||||
self.grid.addWidget(self.buttons12, 1,2)
|
||||
|
||||
|
||||
def set_widget_actions(self):
|
||||
|
||||
self.dataFile = self.loadDataButton.clicked.connect(lambda: Tools().open_file(self))
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
class OneDText(QPlainTextEdit):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setMinimumSize(200,200)
|
||||
self.setPlainText("List of Files:\n+ File 1\n+ File 2")
|
||||
|
||||
|
||||
|
||||
class OneDTable(QTableWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.setSortingEnabled(True)
|
||||
|
||||
self.setRowCount(4)
|
||||
self.setColumnCount(4)
|
||||
|
||||
self.setMinimumSize(300,200)
|
||||
|
||||
self.setHorizontalHeaderLabels({'h', 'k', 'l'})
|
||||
|
||||
|
||||
|
||||
class OneDVisualize(QPlainTextEdit):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setMinimumSize(200,200)
|
||||
self.setPlainText('Placeholder\nfor Visualization.')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Buttons11(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.grid = QGridLayout()
|
||||
self.setLayout(self.grid)
|
||||
|
||||
self.searchButton = QPushButton('Search')
|
||||
self.grid.addWidget(self.searchButton, 0,0)
|
||||
|
||||
self.addButton = QPushButton('Add')
|
||||
self.grid.addWidget(self.addButton,0,1)
|
||||
|
||||
self.substractButton = QPushButton('Substract')
|
||||
self.grid.addWidget(self.substractButton, 0,2)
|
||||
|
||||
|
||||
self.integrateComboBox = QComboBox()
|
||||
self.integrateComboBox.addItems(['Integrate','-> Gaussian', '-> Pseudo-Voidg', '-> Lorenzian', '-> Several Peaks'])
|
||||
self.grid.addWidget(self.integrateComboBox,1,0)
|
||||
|
||||
|
||||
|
||||
|
||||
self.lorentzButton = QPushButton('Lorentz')
|
||||
self.grid.addWidget(self.lorentzButton,1,1)
|
||||
|
||||
self.absorptionButton = QPushButton('Absorption')
|
||||
self.grid.addWidget(self.absorptionButton,1,2)
|
||||
|
||||
self.saveWorksheetButton = QPushButton('Save')
|
||||
self.grid.addWidget(self.saveWorksheetButton,0,3,2,3)
|
||||
|
||||
|
||||
class Buttons12(QWidget):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.grid = QGridLayout()
|
||||
self.setLayout(self.grid)
|
||||
self.qmapsButton = QPushButton('Q-Maps')
|
||||
self.grid.addWidget(self.qmapsButton,0,0)
|
||||
|
||||
self.plotdatavsButton = QPushButton('Plot Data VS')
|
||||
self.grid.addWidget(self.plotdatavsButton,1,0)
|
||||
|
||||
self.saveVisualizationButton = QPushButton('Save')
|
||||
self.grid.addWidget(self.saveVisualizationButton,0,1,2,1)
|
@ -0,0 +1,124 @@
|
||||
from PyQt5.QtWidgets import QWidget, QGridLayout, QComboBox, QLabel, QPushButton, QPlainTextEdit
|
||||
|
||||
from tools import Tools, View, Text, Table
|
||||
|
||||
|
||||
class TwoDimView(QWidget):
|
||||
|
||||
|
||||
def __init__(self):
|
||||
""" Widget containing the entire Zebra Mode view. """
|
||||
super().__init__()
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# PREPARE
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
grid = QGridLayout()
|
||||
self.setLayout(grid)
|
||||
|
||||
# Tools.View() groups Widgets for ease of use.
|
||||
self.two = View()
|
||||
|
||||
# Define Files so IDE does not issue warnings.
|
||||
self.dataFile = None
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# DEFINE WIDGETS
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
# 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).
|
||||
grid.addWidget(QLabel(), 10, 10)
|
||||
|
||||
self.two.loadDataButton = QPushButton("Load Data File")
|
||||
self.two.loadDataButton.setMaximumWidth(200)
|
||||
grid.addWidget(self.two.loadDataButton, 1, 0)
|
||||
|
||||
self.two.text = Text("List of Files:\n+ File 1\n+ File 2")
|
||||
grid.addWidget(self.two.text, 0, 0)
|
||||
|
||||
self.two.table = Table()
|
||||
grid.addWidget(self.two.table, 0, 1)
|
||||
|
||||
self.two.visualize = Visualize()
|
||||
grid.addWidget(self.two.visualize, 0, 2)
|
||||
|
||||
self.two.buttons11 = Buttons11(self)
|
||||
grid.addWidget(self.two.buttons11, 1, 1)
|
||||
|
||||
self.two.buttons12 = Buttons12(self)
|
||||
grid.addWidget(self.two.buttons12, 1, 2)
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# SET WIDGET ACTIONS
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
self.dataFile = self.two.loadDataButton.clicked.connect(lambda: Tools().open_file(self))
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# FINISH
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class Visualize(QPlainTextEdit):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setMinimumSize(200, 200)
|
||||
self.setPlainText('Placeholder\nfor Visualization.')
|
||||
|
||||
|
||||
class Buttons11(QWidget):
|
||||
|
||||
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)
|
||||
|
||||
main.two.searchButton = QPushButton('Search')
|
||||
grid.addWidget(main.two.searchButton, 0, 0)
|
||||
|
||||
main.two.addButton = QPushButton('Add')
|
||||
grid.addWidget(main.two.addButton, 0, 1)
|
||||
|
||||
main.two.substractButton = QPushButton('Substract')
|
||||
grid.addWidget(main.two.substractButton, 0, 2)
|
||||
|
||||
main.two.integrateComboBox = QComboBox()
|
||||
main.two.integrateComboBox.addItems(['Integrate', '-> Gaussian', '-> Pseudo-Voidg', '-> Lorenzian', '-> Several Peaks'])
|
||||
grid.addWidget(main.two.integrateComboBox, 1, 0)
|
||||
|
||||
main.two.lorentzButton = QPushButton('Lorentz')
|
||||
grid.addWidget(main.two.lorentzButton, 1, 1)
|
||||
|
||||
main.two.absorptionButton = QPushButton('Absorption')
|
||||
grid.addWidget(main.two.absorptionButton, 1, 2)
|
||||
|
||||
main.two.saveWorksheetButton = QPushButton('Save')
|
||||
grid.addWidget(main.two.saveWorksheetButton, 0, 3, 2, 3)
|
||||
|
||||
|
||||
class Buttons12(QWidget):
|
||||
|
||||
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)
|
||||
|
||||
main.two.qmapsButton = QPushButton('Q-Maps')
|
||||
grid.addWidget(main.two.qmapsButton, 0, 0)
|
||||
|
||||
main.two.plotdatavsButton = QPushButton('Plot Data VS')
|
||||
grid.addWidget(main.two.plotdatavsButton, 1, 0)
|
||||
|
||||
main.two.saveVisualizationButton = QPushButton('Save')
|
||||
grid.addWidget(main.two.saveVisualizationButton, 0, 1, 2, 1)
|
Loading…
Reference in new issue