Skip to content

Commit

Permalink
Merge pull request #20 from zStupan/update-pyqt6
Browse files Browse the repository at this point in the history
Migrate to PyQt6
  • Loading branch information
firefly-cpp authored Nov 13, 2023
2 parents 4cdb307 + 5984fc5 commit 68b6fde
Show file tree
Hide file tree
Showing 17 changed files with 1,430 additions and 639 deletions.
10 changes: 2 additions & 8 deletions niaaml_gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,5 @@
from niaaml_gui.process_window_data import ProcessWindowData
from niaaml_gui.progress_bar import ProgressBar

__all__ = [
'widgets',
'windows',
'ProcessWindowData',
'ProgressBar',
'MainAppWindow'
]
__version__ = '0.1.13'
__all__ = ["widgets", "windows", "ProcessWindowData", "ProgressBar", "MainAppWindow"]
__version__ = "0.1.13"
42 changes: 19 additions & 23 deletions niaaml_gui/main.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import qApp, QMainWindow, QMessageBox, QAction
from PyQt5.QtCore import QSize
from PyQt6.QtWidgets import QMainWindow, QMessageBox, QApplication
from PyQt6.QtGui import QAction
from PyQt6.QtCore import QSize
from niaaml_gui.widgets import OptimizationWidget, UsePipelineWidget

class WriteStream(object):
def __init__(self,queue):
self.queue = queue

def write(self, text):
self.queue.append(text)

class MainAppWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setMinimumSize(QSize(1024, 768))
self.setWindowTitle('NiaAML - GUI')
self.setWindowTitle("NiaAML - GUI")

menuBar = self.menuBar()
menuBar.setNativeMenuBar(False)
fileMenu = menuBar.addMenu('&File')
exitAction = QAction(text='Exit', parent=self)
exitAction.triggered.connect(qApp.quit)
newPipelineAction = QAction(text='New Pipeline', parent=self)
fileMenu = menuBar.addMenu("&File")
exitAction = QAction(text="Exit", parent=self)
exitAction.triggered.connect(QApplication.quit)
newPipelineAction = QAction(text="New Pipeline", parent=self)
newPipelineAction.triggered.connect(self.__setOptimizationView)
newPipelineActionV1 = QAction(text='New Pipeline V1', parent=self)
newPipelineActionV1 = QAction(text="New Pipeline V1", parent=self)
newPipelineActionV1.triggered.connect(self.__setOptimizationV1View)
useExistingPipelineAction = QAction(text='Use Existing Pipeline', parent=self)
useExistingPipelineAction = QAction(text="Use Existing Pipeline", parent=self)
useExistingPipelineAction.triggered.connect(self.__setUsePipelineView)

fileMenu.addAction(newPipelineAction)
Expand All @@ -37,9 +31,9 @@ def __init__(self):
self.setCentralWidget(OptimizationWidget(self))

self.errorMessage = QMessageBox()
self.errorMessage.setIcon(QMessageBox.Critical)
self.errorMessage.setWindowTitle('Error')
self.errorMessage.setStandardButtons(QMessageBox.Ok)
self.errorMessage.setIcon(QMessageBox.Icon.Critical)
self.errorMessage.setWindowTitle("Error")
self.errorMessage.setStandardButtons(QMessageBox.StandardButton.Ok)

def __setOptimizationView(self):
self.setCentralWidget(OptimizationWidget(self))
Expand All @@ -50,12 +44,14 @@ def __setOptimizationV1View(self):
def __setUsePipelineView(self):
self.setCentralWidget(UsePipelineWidget(self))


def run():
app = QtWidgets.QApplication(sys.argv)
app.setStyle('Fusion')
app = QApplication(sys.argv)
app.setStyle("Fusion")
mainWin = MainAppWindow()
mainWin.show()
sys.exit(app.exec_())
sys.exit(app.exec())


if __name__ == '__main__':
if __name__ == "__main__":
run()
35 changes: 18 additions & 17 deletions niaaml_gui/process_window_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ class ProcessWindowData:
def __init__(
self,
isOptimization,
csvSrc = None,
csvHasHeader = None,
encoder = None,
imputer = None,
optAlgName = None,
optAlgInnerName = None,
popSize = None,
popSizeInner = None,
numEvals = None,
numEvalsInner = None,
fsas = None,
ftas = None,
classifiers = None,
fitnessFunctionName = None,
outputFolder = None,
pipelineSrc = None):
csvSrc=None,
csvHasHeader=None,
encoder=None,
imputer=None,
optAlgName=None,
optAlgInnerName=None,
popSize=None,
popSizeInner=None,
numEvals=None,
numEvalsInner=None,
fsas=None,
ftas=None,
classifiers=None,
fitnessFunctionName=None,
outputFolder=None,
pipelineSrc=None,
):
self.isOptimization = isOptimization
self.csvSrc = csvSrc
self.csvHasHeader = csvHasHeader
Expand All @@ -34,4 +35,4 @@ def __init__(
self.classifiers = classifiers
self.fitnessFunctionName = fitnessFunctionName
self.outputFolder = outputFolder
self.pipelineSrc = pipelineSrc
self.pipelineSrc = pipelineSrc
7 changes: 4 additions & 3 deletions niaaml_gui/progress_bar.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from PyQt5 import QtCore
from PyQt5.QtWidgets import QProgressBar
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QProgressBar


class ProgressBar(QProgressBar):
def __init__(self):
super(ProgressBar, self).__init__()
self.setTextVisible(True)
self.setMaximum(100)
self.setAlignment(QtCore.Qt.AlignCenter)
self.setAlignment(Qt.AlignmentFlag.AlignCenter)
6 changes: 1 addition & 5 deletions niaaml_gui/widgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@
from niaaml_gui.widgets.optimization_widget import OptimizationWidget
from niaaml_gui.widgets.use_pipeline_widget import UsePipelineWidget

__all__ = [
'ListWidgetCustom',
'OptimizationWidget',
'UsePipelineWidget'
]
__all__ = ["ListWidgetCustom", "OptimizationWidget", "UsePipelineWidget"]
23 changes: 13 additions & 10 deletions niaaml_gui/widgets/base_main_widget.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from PyQt5.QtWidgets import QWidget, QPushButton, QLineEdit, QFileDialog
from PyQt6.QtWidgets import QWidget, QPushButton, QLineEdit, QFileDialog
from niaaml_gui.windows import CSVEditorWindow
from PyQt5 import QtCore
from PyQt6.QtCore import QSize


class BaseMainWidget(QWidget):
def __init__(self, parent, *args, **kwargs):
Expand All @@ -9,7 +10,7 @@ def __init__(self, parent, *args, **kwargs):
self._processWindow = None
self.__csvEditWindow = None

def _createButton(self, text, callback = None, objectName = None, icon = None):
def _createButton(self, text, callback=None, objectName=None, icon=None):
btn = QPushButton(self._parent)
btn.setText(text)
font = btn.font()
Expand All @@ -18,13 +19,13 @@ def _createButton(self, text, callback = None, objectName = None, icon = None):

if callback is not None:
btn.clicked.connect(callback)

if objectName is not None:
btn.setObjectName(objectName)

if icon is not None:
btn.setIcon(icon)
btn.setIconSize(QtCore.QSize(21, 21))
btn.setIconSize(QSize(21, 21))

return btn

Expand All @@ -33,11 +34,13 @@ def _isNoneOrWhiteSpace(self, text):
return True

def _openCSVFile(self):
fname = QFileDialog.getOpenFileName(parent=self._parent, caption='Select CSV File', filter='CSV files (*.csv)')
self.findChild(QLineEdit, 'csvFile').setText(fname[0])
self.findChild(QPushButton, 'editCSVButton').setEnabled(True)
fname = QFileDialog.getOpenFileName(
parent=self._parent, caption="Select CSV File", filter="CSV files (*.csv)"
)
self.findChild(QLineEdit, "csvFile").setText(fname[0])
self.findChild(QPushButton, "editCSVButton").setEnabled(True)

def _editCSVFile(self):
src = self.findChild(QLineEdit, 'csvFile').text()
src = self.findChild(QLineEdit, "csvFile").text()
self.__csvEditWindow = CSVEditorWindow(src)
self.__csvEditWindow.show()
self.__csvEditWindow.show()
11 changes: 6 additions & 5 deletions niaaml_gui/widgets/list_widget_custom.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from PyQt5 import QtCore
from PyQt5.QtWidgets import QListWidget
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QListWidget


class ListWidgetCustom(QListWidget):
def __init__(self, items, target, name, *args, **kwargs):
Expand All @@ -10,15 +11,15 @@ def __init__(self, items, target, name, *args, **kwargs):
for k in self.__items:
self.addItem(k)

self.sortItems(QtCore.Qt.AscendingOrder)
self.sortItems(Qt.SortOrder.AscendingOrder)
self.itemClicked.connect(self.__clicked)
self.setObjectName(name)

def setTarget(self, value):
self.__target = value

def __clicked(self,item):
def __clicked(self, item):
if self.__target is not None:
self.__target.addItem(item.text())
self.takeItem(self.row(item))
self.__target.sortItems(QtCore.Qt.AscendingOrder)
self.__target.sortItems(Qt.SortOrder.AscendingOrder)
Loading

0 comments on commit 68b6fde

Please sign in to comment.