Esempio n. 1
0
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(421, 340)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayoutWidget_3 = QtWidgets.QWidget(self.centralwidget)
        self.gridLayoutWidget_3.setGeometry(QtCore.QRect(20, 10, 381, 311))
        self.gridLayoutWidget_3.setObjectName("gridLayoutWidget_3")
        self.gridLayout_3 = QtWidgets.QGridLayout(self.gridLayoutWidget_3)
        self.gridLayout_3.setContentsMargins(0, 0, 0, 0)
        self.gridLayout_3.setObjectName("gridLayout_3")
        self.gridLayout = QtWidgets.QGridLayout()
        self.gridLayout.setSizeConstraint(QtWidgets.QLayout.SetNoConstraint)
        self.gridLayout.setObjectName("gridLayout")
        self.SearchData = QtWidgets.QLineEdit(self.gridLayoutWidget_3)
        font = QtGui.QFont()
        font.setPointSize(14)
        self.SearchData.setFont(font)
        self.SearchData.setObjectName("SearchData")
        self.gridLayout.addWidget(self.SearchData, 1, 0, 1, 1)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setSizeConstraint(
            QtWidgets.QLayout.SetMaximumSize)
        self.horizontalLayout.setSpacing(4)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.SearchDataButton = QtWidgets.QPushButton(self.gridLayoutWidget_3)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.SearchDataButton.sizePolicy().hasHeightForWidth())
        self.SearchDataButton.setSizePolicy(sizePolicy)
        self.SearchDataButton.setMinimumSize(QtCore.QSize(0, 40))
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.SearchDataButton.setFont(font)
        self.SearchDataButton.setObjectName("SearchDataButton")
        self.horizontalLayout.addWidget(self.SearchDataButton)
        self.ClipboardButton = QtWidgets.QPushButton(self.gridLayoutWidget_3)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.ClipboardButton.sizePolicy().hasHeightForWidth())
        self.ClipboardButton.setSizePolicy(sizePolicy)
        self.ClipboardButton.setMinimumSize(QtCore.QSize(0, 40))
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.ClipboardButton.setFont(font)
        self.ClipboardButton.setObjectName("ClipboardButton")
        self.horizontalLayout.addWidget(self.ClipboardButton)
        self.gridLayout.addLayout(self.horizontalLayout, 5, 0, 1, 1)
        self.SearchButton = QtWidgets.QPushButton(self.gridLayoutWidget_3)
        font = QtGui.QFont()
        font.setPointSize(14)
        self.SearchButton.setFont(font)
        self.SearchButton.setObjectName("SearchButton")
        self.gridLayout.addWidget(self.SearchButton, 2, 0, 1, 1)
        self.line = QtWidgets.QFrame(self.gridLayoutWidget_3)
        self.line.setFrameShape(QtWidgets.QFrame.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")
        self.gridLayout.addWidget(self.line, 4, 0, 1, 1)
        self.ResultsBox = QtWidgets.QComboBox(self.gridLayoutWidget_3)
        font = QtGui.QFont()
        font.setPointSize(14)
        self.ResultsBox.setFont(font)
        self.ResultsBox.setObjectName("ResultsBox")
        self.gridLayout.addWidget(self.ResultsBox, 3, 0, 1, 1)
        self.SearchLabel = QtWidgets.QLabel(self.gridLayoutWidget_3)
        self.SearchLabel.setEnabled(True)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                           QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.SearchLabel.sizePolicy().hasHeightForWidth())
        self.SearchLabel.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setPointSize(16)
        font.setBold(True)
        font.setWeight(75)
        self.SearchLabel.setFont(font)
        self.SearchLabel.setObjectName("SearchLabel")
        self.gridLayout.addWidget(self.SearchLabel, 0, 0, 1, 1)
        self.gridLayout_3.addLayout(self.gridLayout, 0, 0, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.SearchButton.clicked.connect(self.getSearchResults)
        self.ClipboardButton.clicked.connect(self.copyToClipboard)
        self.SearchDataButton.clicked.connect(self.createDataFrameWindow)

        self.retValSearch = -2
        self.searchObj = Search()
        logger.info("Search object added")
        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        logger.info("SearchGUI window initialized!")

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Search GUI"))
        self.SearchDataButton.setText(
            _translate("MainWindow", "SEARCH DATA TABLE"))
        self.ClipboardButton.setText(
            _translate("MainWindow", "COPY SELECTED TO CLIPBOARD"))
        self.SearchButton.setText(_translate("MainWindow", "Search!"))
        self.SearchLabel.setText(
            _translate("MainWindow", "Search Your Stock by Name"))

    def getSearchResults(self):
        data = self.SearchData.text()
        self.searchObj.setName(data.strip())
        self.retValSearch = self.searchObj.topResults()
        if self.retValSearch == -1:
            self.dialog = StandardErrorDialog(
                parent=None, text=f"Nothing returned for this name: {data}!")
            self.dialog.ui.pushButton.clicked.connect(self.dialog.close)
            self.dialog.exec()
            logger.error(f"Nothing returned for this name: {data}!")
            return
        self.ResultsBox.clear()
        self.ResultsBox.addItems(self.searchObj.results)
        logger.info(
            f"Items{len(self.searchObj.results)} added from search results!")

    def copyToClipboard(self):
        if self.retValSearch == -2 or self.retValSearch == -1:
            self.dialog = StandardErrorDialog(
                parent=None,
                text=
                "Nothing to copy, please enter valid company name and click on 'Search!' Button"
            )
            self.dialog.ui.pushButton.clicked.connect(self.dialog.close)
            self.dialog.exec()
            logger.error("Nothing to copy!")
            return

        data = (self.ResultsBox.currentText().split('-')[1]).strip()
        pyperclip.copy(data)
        logger.info(f"This stock:{data} has been copied successfully!")

    def createDataFrameWindow(self):
        if self.retValSearch == -1:
            self.dialog = StandardErrorDialog(
                parent=None, text="No results available for this stock name!")
            self.dialog.ui.pushButton.clicked.connect(self.dialog.close)
            self.dialog.exec()
            logger.error("No results available for this stock name!")
            return
        if self.retValSearch == -2:
            self.dialog = StandardErrorDialog(
                parent=None, text="You haven't searched for anything!")
            self.dialog.ui.pushButton.clicked.connect(self.dialog.close)
            self.dialog.exec()
            logger.error("No search has been done!")
            return
        self.dataWindow = DataFrameView()
        self.dataWindow.setData(self.searchObj.resultsDataFrame)
        self.dataWindow.show()
        logger.info("DataFrameView created!")
Esempio n. 2
0
class Ui_TriggerWindow(object):
    def setupUi(self, TriggerWindow):
        TriggerWindow.setObjectName("TriggerWindow")
        TriggerWindow.resize(355, 257)
        self.centralwidget = QtWidgets.QWidget(TriggerWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 10, 331, 221))
        self.gridLayoutWidget.setObjectName("gridLayoutWidget")
        self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
        self.gridLayout.setContentsMargins(0, 0, 0, 0)
        self.gridLayout.setObjectName("gridLayout")
        self.RelationLayout = QtWidgets.QHBoxLayout()
        self.RelationLayout.setObjectName("RelationLayout")
        self.RelationLabel = QtWidgets.QLabel(self.gridLayoutWidget)
        font = QtGui.QFont()
        font.setPointSize(16)
        self.RelationLabel.setFont(font)
        self.RelationLabel.setAlignment(QtCore.Qt.AlignCenter)
        self.RelationLabel.setObjectName("RelationLabel")
        self.RelationLayout.addWidget(self.RelationLabel)
        self.RelationComboBox = QtWidgets.QComboBox(self.gridLayoutWidget)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.RelationComboBox.setFont(font)
        self.RelationComboBox.setObjectName("RelationComboBox")
        self.RelationComboBox.addItem("")
        self.RelationComboBox.addItem("")
        self.RelationComboBox.addItem("")
        self.RelationComboBox.addItem("")
        self.RelationComboBox.addItem("")
        self.RelationLayout.addWidget(self.RelationComboBox)
        self.gridLayout.addLayout(self.RelationLayout, 1, 0, 1, 1)
        self.NameLayout = QtWidgets.QHBoxLayout()
        self.NameLayout.setObjectName("NameLayout")
        self.NameLabel = QtWidgets.QLabel(self.gridLayoutWidget)
        font = QtGui.QFont()
        font.setPointSize(16)
        self.NameLabel.setFont(font)
        self.NameLabel.setAlignment(QtCore.Qt.AlignCenter)
        self.NameLabel.setObjectName("NameLabel")
        self.NameLayout.addWidget(self.NameLabel)
        self.NameText = QtWidgets.QLineEdit(self.gridLayoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.NameText.sizePolicy().hasHeightForWidth())
        self.NameText.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.NameText.setFont(font)
        self.NameText.setObjectName("NameText")
        self.NameLayout.addWidget(self.NameText)
        self.gridLayout.addLayout(self.NameLayout, 3, 0, 1, 1)
        self.DeactivateLayout = QtWidgets.QHBoxLayout()
        self.DeactivateLayout.setObjectName("DeactivateLayout")
        self.DeactivateLable = QtWidgets.QLabel(self.gridLayoutWidget)
        font = QtGui.QFont()
        font.setPointSize(16)
        self.DeactivateLable.setFont(font)
        self.DeactivateLable.setAlignment(QtCore.Qt.AlignCenter)
        self.DeactivateLable.setObjectName("DeactivateLable")
        self.DeactivateLayout.addWidget(self.DeactivateLable)
        self.DeactivateComboBox = QtWidgets.QComboBox(self.gridLayoutWidget)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.DeactivateComboBox.setFont(font)
        self.DeactivateComboBox.setMaxVisibleItems(10)
        self.DeactivateComboBox.setObjectName("DeactivateComboBox")
        self.DeactivateComboBox.addItem("")
        self.DeactivateComboBox.addItem("")
        self.DeactivateLayout.addWidget(self.DeactivateComboBox)
        self.gridLayout.addLayout(self.DeactivateLayout, 4, 0, 1, 1)
        self.ValueLayout = QtWidgets.QHBoxLayout()
        self.ValueLayout.setObjectName("ValueLayout")
        self.ValueLabel = QtWidgets.QLabel(self.gridLayoutWidget)
        font = QtGui.QFont()
        font.setPointSize(18)
        self.ValueLabel.setFont(font)
        self.ValueLabel.setAlignment(QtCore.Qt.AlignCenter)
        self.ValueLabel.setObjectName("ValueLabel")
        self.ValueLayout.addWidget(self.ValueLabel)
        self.ValueText = QtWidgets.QLineEdit(self.gridLayoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Ignored,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.ValueText.sizePolicy().hasHeightForWidth())
        self.ValueText.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.ValueText.setFont(font)
        self.ValueText.setObjectName("ValueText")
        self.ValueLayout.addWidget(self.ValueText)
        self.gridLayout.addLayout(self.ValueLayout, 2, 0, 1, 1)
        self.SymbolLayout = QtWidgets.QHBoxLayout()
        self.SymbolLayout.setObjectName("SymbolLayout")
        self.SymbolLabel = QtWidgets.QLabel(self.gridLayoutWidget)
        font = QtGui.QFont()
        font.setPointSize(16)
        self.SymbolLabel.setFont(font)
        self.SymbolLabel.setAlignment(QtCore.Qt.AlignCenter)
        self.SymbolLabel.setObjectName("SymbolLabel")
        self.SymbolLayout.addWidget(self.SymbolLabel)
        self.SymbolText = QtWidgets.QLineEdit(self.gridLayoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum,
                                           QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.SymbolText.sizePolicy().hasHeightForWidth())
        self.SymbolText.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.SymbolText.setFont(font)
        self.SymbolText.setText("")
        self.SymbolText.setObjectName("SymbolText")
        self.SymbolLayout.addWidget(self.SymbolText)
        self.gridLayout.addLayout(self.SymbolLayout, 0, 0, 1, 1)
        self.ButtonLayout = QtWidgets.QHBoxLayout()
        self.ButtonLayout.setObjectName("ButtonLayout")
        self.AddButton = QtWidgets.QPushButton(self.gridLayoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum,
                                           QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.AddButton.sizePolicy().hasHeightForWidth())
        self.AddButton.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.AddButton.setFont(font)
        self.AddButton.setObjectName("AddButton")
        self.ButtonLayout.addWidget(self.AddButton)
        self.DeleteButton = QtWidgets.QPushButton(self.gridLayoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum,
                                           QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.DeleteButton.sizePolicy().hasHeightForWidth())
        self.DeleteButton.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.DeleteButton.setFont(font)
        self.DeleteButton.setObjectName("DeleteButton")
        self.ButtonLayout.addWidget(self.DeleteButton)
        self.ListButton = QtWidgets.QPushButton(self.gridLayoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum,
                                           QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.ListButton.sizePolicy().hasHeightForWidth())
        self.ListButton.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.ListButton.setFont(font)
        self.ListButton.setObjectName("ListButton")
        self.ButtonLayout.addWidget(self.ListButton)
        self.gridLayout.addLayout(self.ButtonLayout, 5, 0, 1, 1)
        TriggerWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(TriggerWindow)
        self.statusbar.setObjectName("statusbar")
        TriggerWindow.setStatusBar(self.statusbar)

        self.AddButton.clicked.connect(self.addTrigger)
        self.DeleteButton.clicked.connect(self.deleteTrigger)
        self.ListButton.clicked.connect(self.listTriggers)

        self.TrigHand = TriggerHandler.fromJson(
        )  # * For now the default file is set to dataFile.json
        logger.info("TriggerGUI obtained the data from jsonFile")

        self.retranslateUi(TriggerWindow)
        QtCore.QMetaObject.connectSlotsByName(TriggerWindow)
        logger.debug("TriggerGUI window initiliazed!")

    def retranslateUi(self, TriggerWindow):
        _translate = QtCore.QCoreApplication.translate
        TriggerWindow.setWindowTitle(_translate("TriggerWindow",
                                                "Trigger GUI"))
        self.RelationLabel.setText(_translate("TriggerWindow", "Relation"))
        self.RelationComboBox.setItemText(0, _translate("TriggerWindow", "<="))
        self.RelationComboBox.setItemText(1, _translate("TriggerWindow", "<"))
        self.RelationComboBox.setItemText(2, _translate("TriggerWindow", ">="))
        self.RelationComboBox.setItemText(3, _translate("TriggerWindow", ">"))
        self.RelationComboBox.setItemText(4, _translate("TriggerWindow", "="))
        self.NameLabel.setText(_translate("TriggerWindow", "Trigger Name"))
        self.DeactivateLable.setText(
            _translate("TriggerWindow", "Deactivate on Trigger?"))
        self.DeactivateComboBox.setItemText(0,
                                            _translate("TriggerWindow", "Yes"))
        self.DeactivateComboBox.setItemText(1,
                                            _translate("TriggerWindow", "No"))
        self.ValueLabel.setText(_translate("TriggerWindow", "Value"))
        self.SymbolLabel.setText(_translate("TriggerWindow", "Symbol"))
        self.AddButton.setText(_translate("TriggerWindow", "Add Trigger"))
        self.DeleteButton.setText(_translate("TriggerWindow",
                                             "Delete Trigger"))
        self.ListButton.setText(
            _translate("TriggerWindow", "List all Triggers"))

    def addTrigger(self):
        relationOpStr = {
            "<=": "LE",
            "<": "LT",
            ">=": "GE",
            ">": "GT",
            "=": "EQ"
        }
        deactivateStrBool = {"Yes": True, "No": False}
        try:
            name = self.NameText.text()
            value = float(self.ValueText.text())
            symbol = self.SymbolText.text()
            relation = relationOpStr[self.RelationComboBox.currentText()]
            deactivate = deactivateStrBool[
                self.DeactivateComboBox.currentText()]
        except:  # noqa: E722
            self.dialog = StandardErrorDialog(
                parent=None,
                text="Something is empty or wrong, name, value or symbol")
            self.dialog.ui.pushButton.clicked.connect(self.dialog.close)
            self.dialog.exec()
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            logger.error("ERROR! Type: {}, File: {}, Line: {}".format(
                exc_type, fname, exc_tb.tb_lineno))
            return

        if len(name) == 0 or value <= 0 or len(symbol) == 0:
            self.dialog = StandardErrorDialog(
                parent=None,
                text=f"Something is empty or wrong, {name} {value} {symbol}")
            self.dialog.ui.pushButton.clicked.connect(self.dialog.close)
            self.dialog.exec()
            logger.error(
                "Either name is empty, value is less than 0 or symbol name is empty"
            )
            return

        trigger = Trigger(symbol, value, relation, name, deactivate)
        logger.debug(f"Trigger object created with name={name}")
        retVal = self.TrigHand.addTrigger(trigger)

        if retVal == -1:
            self.dialog = StandardErrorDialog(
                parent=None,
                text=
                f"Name already exists, can't add this trigger with this name: {name}"
            )
            self.dialog.ui.pushButton.clicked.connect(self.dialog.close)
            self.dialog.exec()
            logger.error(
                f"Name already exists, can't add this trigger with this name: {name}"
            )
            return

        logger.info(f"Trigger({name}) added successfully")

        self.TrigHand.toJsonFile()
        logger.info(f"Written back succesfully with new trigger name: {name}")

    def deleteTrigger(self):
        name = self.NameText.text()

        if len(name) == 0:
            self.dialog = StandardErrorDialog(
                parent=None, text="Name is empty, please add a valid name!")
            self.dialog.ui.pushButton.clicked.connect(self.dialog.close)
            self.dialog.exec()
            logger.error("Name is empty, please add a valid name!")
            return

        retVal = self.TrigHand.deleteTrigger(name)

        if retVal == 1:
            self.dialog = StandardErrorDialog(
                parent=None, text=f"No trigger exists with this name: {name}")
            self.dialog.ui.pushButton.clicked.connect(self.dialog.close)
            self.dialog.exec()
            logger.error("No trigger exists with this name")

        self.TrigHand.toJsonFile()
        logger.info(f"Written back succesfully with trigger removed: {name}")

    def listTriggers(self):
        df = self.TrigHand.listAllTriggers()
        logger.info("Listing all triggers")
        self.dataWindow = DataFrameView()
        self.dataWindow.setData(df)
        self.dataWindow.show()