Skip to content

Commit

Permalink
Updated main.py, refactor and structuring
Browse files Browse the repository at this point in the history
  • Loading branch information
alexemanuelol committed Oct 9, 2019
1 parent e7a3b9e commit 6103373
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions rustdavinci/ui/views/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from PyQt5 import QtCore, QtGui
from PyQt5 import QtCore
from PyQt5 import QtGui
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QLabel, QAction, QPushButton, QVBoxLayout, QGroupBox, QMenu
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtCore import QSize, QRect
from PyQt5.QtWidgets import QMenu

from ui.settings.settings import Settings
from lib.rustDaVinci import rustDaVinci
Expand All @@ -17,31 +16,40 @@ class MainWindow(QtWidgets.QMainWindow):
closeEventSignal = QtCore.pyqtSignal(QtGui.QCloseEvent)

def __init__(self, parent=None):
""" Main window init """
super(MainWindow, self).__init__(parent)

# Setup UI
self.ui = Ui_MainUI()
self.ui.setupUi(self)

# Setup settings object
self.settings = QtCore.QSettings()

# Setup rustDaVinci object
self.rustDaVinci = rustDaVinci(self)

# Menu actions
# Clear Image action
self.action_clearImage = None


# Connect UI modules
self.connectAll()
self.rustDaVinci.update_status()

# Update the rustDaVinci module
self.rustDaVinci.update_status()


def connectAll(self):
""" Connect all the buttons """
# Add actions to the loadImagePushButton
loadMenu = QtWidgets.QMenu()
loadMenu.addAction("From File...", self.loadImageFile_clicked)
loadMenu.addAction("From URL...", self.loadImageURL_clicked)
self.action_clearImage = loadMenu.addAction("Clear image", self.clearCurrentImage_clicked)
self.action_clearImage.setEnabled(False)
self.ui.loadImagePushButton.setMenu(loadMenu)

# Add actions to the identifyAreasPushButton
identifyMenu = QtWidgets.QMenu()
identifyMenu.addAction("Manually", self.locateControlAreaManually_clicked)
identifyMenu.addAction("Automatically", self.locateControlAreaAutomatically_clicked)
Expand All @@ -50,45 +58,59 @@ def connectAll(self):
self.ui.paintImagePushButton.clicked.connect(self.paintImage_clicked)
self.ui.settingsPushButton.clicked.connect(self.settings_clicked)

def initial_setup(self):
None


def loadImageFile_clicked(self):
""" Load image from file """
self.rustDaVinci.load_image_from_file()
if self.rustDaVinci.image_path != None:
self.action_clearImage.setEnabled(True)


def loadImageURL_clicked(self):
""" Load image from URL """
self.rustDaVinci.load_image_from_url()
if self.rustDaVinci.image_path != None:
self.action_clearImage.setEnabled(True)


def clearCurrentImage_clicked(self):
""" Clear the current image """
self.rustDaVinci.clear_image()
self.action_clearImage.setEnabled(False)


def locateControlAreaManually_clicked(self):
""" Locate the control area coordinates manually """
self.rustDaVinci.locate_control_area_manually()


def locateControlAreaAutomatically_clicked(self):
""" Locate the control area coordinates automatically """
self.rustDaVinci.locate_control_area_automatically()


def paintImage_clicked(self):
""" Start the painting process """
self.rustDaVinci.start_painting()


def settings_clicked(self):
""" Create an instance of a settings window """
settings = Settings(self)
settings.setModal(True)
settings.show()


def show(self):
""" Show the main window """
super(MainWindow, self).show()


def hide(self):
""" Hide the main window """
super(MainWindow, self).hide()


def closeEvent(self, closeEvent):
""" Close the main window """
super(MainWindow, self).closeEvent(closeEvent)
self.closeEventSignal.emit(closeEvent)

0 comments on commit 6103373

Please sign in to comment.