Skip to content

Commit

Permalink
update simsef main file
Browse files Browse the repository at this point in the history
- command line start
- fix log window not updating during run (threading)
  • Loading branch information
SteffenHeu authored Jul 10, 2023
1 parent 51841e1 commit c5d7aaf
Showing 1 changed file with 85 additions and 37 deletions.
122 changes: 85 additions & 37 deletions src/simsef_pewpew.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import shutil
from datetime import datetime
import sys
from threading import Thread

from PyQt5.QtWidgets import QApplication, QWidget, QTextEdit, QPushButton, QVBoxLayout, QHBoxLayout, QFileDialog
from PyQt5.QtGui import QPalette, QColor
from PyQt5.QtCore import Qt
Expand All @@ -14,36 +16,57 @@
from src.AcquisitionControl import AcquisitionControl
from src.AcquisitionParameters import AcquisitionParameters

def log(msg: str):
if(stopThread == True):
return

print(msg)
if text_area:
text_area.append(msg)


def main():
app = QApplication(sys.argv)
global stopThread
stopThread = False

parser = argparse.ArgumentParser()
parser.add_argument('--commandfile', help='the path to command file', type=str, required=False)
argtable = parser.parse_args()

# Create a QWidget object (a window)
global window
window = QWidget()
window.setGeometry(100, 100, 300, 200) # Set the position and size of the window
window.setWindowTitle('SIMSEF pewpew') # Set the window title

# Create a QTextEdit object (a text area)
global text_area
global commandFilePath
commandFilePath = None
text_area = QTextEdit()
text_area.setPlaceholderText('Please select a file')

if (argtable.commandfile):
commandFilePath = argtable.commandfile
log("Command file path already set via arg: " + commandFilePath)

if (commandFilePath):
log(commandFilePath)

# Create two QPushButton objects (buttons)
button1 = QPushButton('Select command file')
button2 = QPushButton('Run acquisition')

# Define a function to handle the button1 click event
def open_file_dialog():
file_dialog = QFileDialog()
file_dialog.setNameFilter("Text file (*.txt)")
file_path = file_dialog.getOpenFileName(window, 'Select command file')[0]
if file_path:
text_area.setText(file_path)

# Connect the button1 click event to the open_file_dialog function
button1.clicked.connect(open_file_dialog)

# Connect the button2 click event to the run_function function
button2.clicked.connect(run_function)
button2.clicked.connect(startRunThread)

if (commandFilePath != None):
log("Starting auto execute.")
startRunThread()

# Create a QVBoxLayout object to arrange the widgets vertically
layout = QVBoxLayout()
Expand All @@ -57,22 +80,19 @@ def open_file_dialog():
layout.addLayout(button_layout)

# Set the dark mode stylesheet
dark_palette = QPalette()
dark_palette.setColor(QPalette.Window, QColor(53, 53, 53))
dark_palette.setColor(QPalette.WindowText, Qt.white)
dark_palette.setColor(QPalette.Base, QColor(25, 25, 25))
dark_palette.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
dark_palette.setColor(QPalette.ToolTipBase, Qt.white)
dark_palette.setColor(QPalette.ToolTipText, Qt.white)
dark_palette.setColor(QPalette.Text, Qt.white)
dark_palette.setColor(QPalette.Button, QColor(53, 53, 53))
dark_palette.setColor(QPalette.ButtonText, Qt.white)
dark_palette.setColor(QPalette.BrightText, Qt.red)
dark_palette.setColor(QPalette.Link, QColor(42, 130, 218))
dark_palette.setColor(QPalette.Highlight, QColor(42, 130, 218))
dark_palette.setColor(QPalette.HighlightedText, Qt.black)
dark_palette = getDarkPalette()
app.setPalette(dark_palette)

style_sheet = getStyleSheet()
window.setStyleSheet(style_sheet)
window.setLayout(layout)
window.show() # Show the window

sys.exit(app.exec_())
stopThread = True


def getStyleSheet():
# Apply the stylesheet to the widgets
style_sheet = """
QTextEdit {
Expand All @@ -91,25 +111,50 @@ def open_file_dialog():
background-color: #444444;
}
"""
window.setStyleSheet(style_sheet)
return style_sheet

window.setLayout(layout)

window.show() # Show the window
def getDarkPalette():
dark_palette = QPalette()
dark_palette.setColor(QPalette.Window, QColor(53, 53, 53))
dark_palette.setColor(QPalette.WindowText, Qt.white)
dark_palette.setColor(QPalette.Base, QColor(25, 25, 25))
dark_palette.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
dark_palette.setColor(QPalette.ToolTipBase, Qt.white)
dark_palette.setColor(QPalette.ToolTipText, Qt.white)
dark_palette.setColor(QPalette.Text, Qt.white)
dark_palette.setColor(QPalette.Button, QColor(53, 53, 53))
dark_palette.setColor(QPalette.ButtonText, Qt.white)
dark_palette.setColor(QPalette.BrightText, Qt.red)
dark_palette.setColor(QPalette.Link, QColor(42, 130, 218))
dark_palette.setColor(QPalette.Highlight, QColor(42, 130, 218))
dark_palette.setColor(QPalette.HighlightedText, Qt.black)
return dark_palette

sys.exit(app.exec_())

def run_function():
def startRunThread():
log("Creating run thread...")
global thread
thread = Thread(target=run_function)
thread.start()


# Your code here
# text_area.append('Button 2 was clicked!')
# create Parameters
# Define a function to handle the button1 click event
def open_file_dialog():
file_dialog = QFileDialog()
file_dialog.setNameFilter("Text file (*.txt)")
file_path = file_dialog.getOpenFileName(window, 'Select command file')[0]
if file_path:
globals()["commandFilePath"] = file_path
log("Command file selected:")
log(commandFilePath)

def run_function():
control = AcquisitionControl()

# parser = argparse.ArgumentParser()
# parser.add_argument('--commandfile', help='the path to command file', type=str, required=True)
# argtable = parser.parse_args()
commandFilePath = text_area.toPlainText()
if commandFilePath is None:
log("Cannot start acquisition, command file path not set.")
return

with open(commandFilePath) as f:
lines = f.readlines()
Expand All @@ -124,12 +169,15 @@ def run_function():

control.controller.waitUntilAcqFinished()

if stopThread == True:
return

measured = measured + 1
elapsedTime = datetime.now() - starttime
text_area.append('Acquired MS/MS in spot ' + parameters.spot + ' ' + str(measured) + '/' + str(len(lines)))
log('Acquired MS/MS in spot ' + parameters.spot + ' ' + str(measured) + '/' + str(len(lines)))

remaining = (elapsedTime / measured) * (len(lines) - measured)
text_area.append('Time elapsed: ' + str(elapsedTime) + ' Remaining: ' + str(remaining))
log('Time elapsed: ' + str(elapsedTime) + ' Remaining: ' + str(remaining))


if __name__ == "__main__":
Expand Down

0 comments on commit c5d7aaf

Please sign in to comment.