Esempio n. 1
0
class ExecProcess(ElementMaster):

    pixmap_path = 'images/ExecProcess.png'
    child_pos = (True, True)
    start_branch = pyqtSignal(int, int, name='start_branch')

    query_grid = pyqtSignal(name='query_grid')

    def __init__(self, row, column):
        self.row = row
        self.column = column
        super().__init__(self.row, self.column, QPixmap(self.pixmap_path),
                         True, None)
        super().edit_sig.connect(self.edit)
        logging.debug('ExecProcess called at row {}, column {}'.format(
            row, column))
        self.addFunction(ProcessFunction)

    def __setstate__(self, state):
        logging.debug('__setstate__() called ExecBranch')
        self.row, self.column = state
        super().__init__(self.row, self.column, QPixmap(self.pixmap_path),
                         True, None)
        super().edit_sig.connect(self.edit)
        self.addFunction(ProcessFunction)

    def __getstate__(self):
        logging.debug('__getstate__() called ExecBranch')
        return (self.row, self.column)

    def edit(self):
        logging.debug('edit() called ExecBranch')
        self.procEditLayout = QVBoxLayout()

        self.procEdit = ElementEditor(self)
        self.procEdit.setWindowTitle(QC.translate('', 'Edit Process Branch'))

        self.help_text = QLabel()
        self.help_text.setText(
            QC.translate('', 'Multiprocessing: Start a new execution path.'))

        self.procEditLayout.addWidget(self.help_text)
        self.procEditLayout.addStretch(1)
        self.procEdit.setLayout(self.procEditLayout)

        self.procEdit.show()

    def edit_done(self):
        logging.debug('edit_done() called ExecBranch')

    def windowClosed(self, event):
        logging.debug('windowClosed() called ExecBranch')
Esempio n. 2
0
class ExecStack(ElementMaster):

    pixmap_path = 'images/ExecStack.png'
    child_pos = (True, False)

    update_stack = pyqtSignal(str, name='update_stack')

    def __init__(self, row, column):
        self.row = row
        self.column = column

        self.show_window = False

        # filename, read_mode, write_mode, b_array_limits, n_array_limits, log_state
        filename = None
        read_mode = 0
        write_mode = 0
        delete_read = False
        b_array_limits = False
        n_array_limits = None
        log_state = False
        self.config = (filename, read_mode, write_mode, delete_read,
                       b_array_limits, n_array_limits, log_state)
        super().__init__(self.row, self.column, QPixmap(self.pixmap_path),
                         True, self.config)
        super().edit_sig.connect(self.edit)
        logging.debug('ExecStack called at row {}, column {}'.format(
            row, column))

        self.addFunction(StackFunction)

    def __setstate__(self, state):
        logging.debug('__setstate__() called ExecStack')
        self.row, self.column, self.config = state
        super().__init__(self.row, self.column, QPixmap(self.pixmap_path),
                         True, self.config)
        super().edit_sig.connect(self.edit)
        self.addFunction(StackFunction)

    def __getstate__(self):
        logging.debug('__getstate__() called ExecStack')
        return (self.row, self.column, self.config)

    def openEditor(self):
        logging.debug('openEditor() called ExecStack')

    def toggle_debug(self):
        logging.debug('ExecStack::toggle_debug() called OVERWRITTEN method')
        self.stackWindow = StackWindow(self)
        # diable debug button
        self.icon_bar.debug_button.debug_pressed.disconnect()
        self.icon_bar.debug_button.disableMouseEvent()
        # enable debug button when window is closed
        self.stackWindow.closed.connect(self.reconnect_debug_button)
        self.stackWindow.closed.connect(
            self.icon_bar.debug_button.enableMouseEvent)
        # connect the update signal
        self.update_stack.connect(self.stackWindow.updateStack)

        # pass filename to the window
        self.stackWindow.raiseWindow(self.config[0])

    def reconnect_debug_button(self):

        self.icon_bar.debug_button.debug_pressed.connect(
            self.icon_bar.click_debug_element)

    def highlightStop(self):

        logging.debug('ExecStack::highlightStop() called OVERWRITTEN method')
        # pass filename
        self.update_stack.emit(self.config[0])
        super().highlightStop()

    def edit(self):
        logging.debug('edit() called ExecStack')

        # filename, read_mode, write_mode, array_limits, log_state
        self.filename, self.read_mode, self.write_mode, self.delete_read, \
                self.b_array_limits, self.n_array_limits, log_state = self.config

        self.returnEditLayout = QVBoxLayout()

        self.returnEdit = ElementEditor(self)
        self.returnEdit.setWindowTitle(QC.translate('', 'Stack'))

        self.top_text = QLabel()
        self.top_text.setText(
            QC.translate('',
                         'Choose file on hard disc for storing stack data:'))

        self.filename_text = QLabel()
        if self.filename:
            self.filename_text.setText(self.filename)

        self.file_button = QPushButton(QC.translate('', 'Select file'))
        self.file_button.clicked.connect(self.ChooseFileDialog)

        self.writeInput()
        self.readOutput()
        self.loadLastConfig()

        self.mode_text = QLabel()
        self.mode_text.setText(QC.translate('', 'Configuration:'))

        self.help_text = QWidget()
        self.help_text_layout = QVBoxLayout(self.help_text)

        #self.help_text_1 = QLabel()
        # List
        #self.help_text_1.setText(QC.translate('', 'On input: Write / Read'))

        # Input: Liste
        #self.help_text_2 = QLabel()
        #self.help_text_2.setText(QC.translate('', 'Insert /Append'))

        # Option: Remove output
        # Output: Liste: First Out /  Last Out / all Out
        #self.help_text_3 = QLabel()
        #self.help_text_3.setText(QC.translate('', 'Help Text 3'))

        #self.help_text_layout.addWidget(self.help_text_1)
        #self.help_text_layout.addWidget(self.help_text_2)
        #self.help_text_layout.addWidget(self.help_text_3)

        self.confirm_button = QPushButton(QC.translate('', 'Ok'))

        # hier logging option einfügen
        self.log_line = QWidget()
        self.ask_for_logging = QLabel()
        self.ask_for_logging.setText(QC.translate('', 'Log output?'))
        self.log_checkbox = QCheckBox()
        self.log_line_layout = QHBoxLayout(self.log_line)
        self.log_line_layout.addWidget(self.ask_for_logging)
        self.log_line_layout.addWidget(self.log_checkbox)
        self.log_line_layout.addStretch(1)

        if log_state:
            self.log_checkbox.setChecked(True)

        self.confirm_button.clicked.connect(self.returnEdit.closeEvent)
        self.returnEdit.window_closed.connect(self.edit_done)
        self.returnEditLayout.addWidget(self.top_text)
        self.returnEditLayout.addWidget(self.filename_text)
        self.returnEditLayout.addWidget(self.file_button)
        self.returnEditLayout.addWidget(self.mode_text)
        self.returnEditLayout.addWidget(self.write_input)
        self.returnEditLayout.addWidget(self.read_input)
        self.returnEditLayout.addWidget(self.delete_read_widget)
        #self.returnEditLayout.addWidget(self.help_text)
        self.returnEditLayout.addStretch(1)
        self.returnEditLayout.addWidget(self.log_line)
        self.returnEditLayout.addWidget(self.confirm_button)
        self.returnEdit.setLayout(self.returnEditLayout)
        self.returnEdit.show()

    def loadLastConfig(self):

        self.select_read_mode.setCurrentIndex(self.read_mode)
        self.select_write_mode.setCurrentIndex(self.write_mode)

        if self.b_array_limits:
            self.enableArrLimits()
            self.array_limits_cbox.setChecked(True)
            if self.n_array_limits:
                self.max_array_elements.setText(str(self.n_array_limits))

        else:
            self.diableArrLimits()
            self.array_limits_cbox.setChecked(False)

        if self.delete_read:
            self.delete_read_checkbox.setChecked(True)
        else:
            self.delete_read_checkbox.setChecked(False)

    def ChooseFileDialog(self, event):
        options = QFileDialog.Options()
        options |= QFileDialog.DontUseNativeDialog
        fileName, _ = QFileDialog.getSaveFileName(self, \
                QC.translate('', 'Choose file'),"","All Files (*);;Text Files (*.txt)", \
                options=options)
        if fileName:
            logging.debug(
                'ChooseFileDialog() called with filename: {}'.format(fileName))
            self.filename = fileName
            self.filename_text.setText(self.filename)

    def writeInput(self):

        self.write_input = QWidget()
        self.write_layout = QVBoxLayout(self.write_input)

        self.write_input_line = QWidget()
        self.write_input_layout = QHBoxLayout(self.write_input_line)

        self.array_config = QWidget()
        self.array_config_layout = QHBoxLayout(self.array_config)

        self.outpub_behaviour = QWidget()
        self.output_behaviour_layout = QHBoxLayout()

        self.write_txt = QLabel()
        self.write_txt.setText(QC.translate('', 'Do this with input:'))

        self.select_write_mode = QComboBox()
        self.select_write_mode.addItem(QC.translate('', 'Nothing'),
                                       QVariant('none'))
        self.select_write_mode.addItem(QC.translate('', 'Insert'),
                                       QVariant('i'))
        self.select_write_mode.addItem(QC.translate('', 'Append'),
                                       QVariant('a'))

        # maximum array size
        self.array_limits_cbox = QCheckBox()
        self.array_limits_cbox.stateChanged.connect(self.toggleArrayLimits)

        self.array_limit_txt = QLabel()
        self.array_limit_txt.setText(QC.translate('', 'Max. array elements:'))

        self.max_array_elements = QLineEdit()
        self.max_array_elements.setValidator(QIntValidator(1, 999))
        self.max_array_elements.setPlaceholderText(
            QC.translate('', 'Default value: 20'))

        self.array_config_layout.addWidget(self.array_limits_cbox)
        self.array_config_layout.addWidget(self.array_limit_txt)
        self.array_config_layout.addWidget(self.max_array_elements)

        self.write_input_layout.addWidget(self.write_txt)
        self.write_input_layout.addWidget(self.select_write_mode)
        #self.write_layout.addWidget(self.array_limits)

        self.write_layout.addWidget(self.write_input_line)
        self.write_layout.addWidget(self.array_config)

        #self.variable_box.addWidget(self.write_input)

    def toggleArrayLimits(self, event):

        #einzeln aufrufen beim laden der config

        if self.array_limits_cbox.isChecked():
            self.enableArrLimits()
        else:
            self.diableArrLimits()

    def toggleReadBehaviour(self, event):

        if self.delete_read_checkbox.isChecked():
            self.delete_read_checkbox.setChecked(True)
        else:
            self.delete_read_checkbox.setChecked(False)

    def enableArrLimits(self):

        self.max_array_elements.setEnabled(True)
        self.max_array_elements.setPlaceholderText(
            QC.translate('', 'Default value: 20'))

    def diableArrLimits(self):

        self.max_array_elements.setEnabled(False)
        self.max_array_elements.setPlaceholderText(
            QC.translate('', 'Unlimited'))

    def readOutput(self):

        self.read_input = QWidget()
        self.read_layout = QHBoxLayout(self.read_input)

        self.delete_read_widget = QWidget()
        self.delete_read_layout = QHBoxLayout(self.delete_read_widget)

        self.read_txt = QLabel()
        self.read_txt.setText(QC.translate('', 'Do this when triggered:'))

        self.select_read_mode = QComboBox()
        self.select_read_mode.addItem(QC.translate('', 'Nothing'),
                                      QVariant('none'))
        self.select_read_mode.addItem(QC.translate('', 'Pass through'),
                                      QVariant('pass'))
        self.select_read_mode.addItem(QC.translate('', 'First out'),
                                      QVariant('fo'))
        self.select_read_mode.addItem(QC.translate('', 'Last out'),
                                      QVariant('lo'))
        self.select_read_mode.addItem(QC.translate('', 'All out'),
                                      QVariant('all'))

        # the delete_read widget is added in the edit() method
        self.delete_read_txt = QLabel()
        self.delete_read_txt.setText(
            QC.translate('', 'Delete object after read?'))

        self.delete_read_checkbox = QCheckBox()
        self.delete_read_checkbox.stateChanged.connect(
            self.toggleReadBehaviour)

        self.delete_read_layout.addWidget(self.delete_read_txt)
        self.delete_read_layout.addWidget(self.delete_read_checkbox)

        self.read_layout.addWidget(self.read_txt)
        self.read_layout.addWidget(self.select_read_mode)

    def edit_done(self):
        logging.debug('edit_done() called ExecStack')

        if self.max_array_elements.text() == '':
            n_array_limits = None
        else:
            n_array_limits = int(self.max_array_elements.text())

        log_state = self.log_checkbox.isChecked()
        write_mode = self.select_write_mode.currentIndex()
        read_mode = self.select_read_mode.currentIndex()
        b_array_limits = self.array_limits_cbox.isChecked()
        delete_read = self.delete_read_checkbox.isChecked()
        n_array_limits
        filename = self.filename
        # filename, read_mode, write_mode, b_array_limits, n_array_limits, log_state
        self.config = (filename, read_mode, write_mode, delete_read, b_array_limits, \
                n_array_limits, log_state)
        self.addFunction(StackFunction)
Esempio n. 3
0
class ExecOp(ElementMaster):

    pixmap_path = 'images/ExecOp.png'
    child_pos = (True, False)

    def __init__(self, row, column):
        self.row = row
        self.column = column
        self.config = (False, None)
        super().__init__(self.row, self.column, QPixmap(self.pixmap_path),
                         True, self.config)
        super().edit_sig.connect(self.edit)
        logging.debug('ExecOp called at row {}, column {}'.format(row, column))
        self.addFunction(OperationFunction)

    def __setstate__(self, state):
        logging.debug('__setstate__() called ExecOp')
        self.row, self.column, self.config = state
        super().__init__(self.row, self.column, QPixmap(self.pixmap_path),
                         True, self.config)
        self.addFunction(OperationFunction)
        super().edit_sig.connect(self.edit)

    def __getstate__(self):
        logging.debug('__getstate__() called ExecOp')
        return (self.row, self.column, self.config)

    def openEditor(self):
        logging.debug('openEditor() called ExecOp')

    def edit(self):
        logging.debug('edit() called ExecOp')

        self.opEditLayout = QVBoxLayout()

        self.op_edit = ElementEditor(self)
        self.op_edit.setWindowTitle(QC.translate('', 'Edit Basic Operation'))

        self.head_info = QLabel()
        self.head_info.setText(
            QC.translate('', 'Enter your Python 3 code below:'))

        self.help_text = QLabel()
        self.help_text.setText(
            QC.translate('', 'Process your own Python 3 code.'))

        self.op_image = QLabel()
        self.op_image.setPixmap(QPixmap(self.pixmap_path))

        self.code_input = QTextEdit()

        # hier logging option einfügen
        self.log_line = QWidget()
        self.ask_for_logging = QLabel()
        self.ask_for_logging.setText(QC.translate('', 'Log output?'))
        self.log_checkbox = QCheckBox()
        self.log_line_layout = QHBoxLayout(self.log_line)
        self.log_line_layout.addWidget(self.ask_for_logging)
        self.log_line_layout.addWidget(self.log_checkbox)
        self.log_line_layout.addStretch(1)

        if self.config[0]:
            self.log_checkbox.setChecked(True)

        if self.config[1]:
            self.code_input.setPlainText(self.config[1])
        else:
            self.placeholder_1 = QC.translate(
                '',
                '""" use the variable input to access data from previous elements """'
            )
            self.placeholder_2 = QC.translate(
                '',
                '""" set the output variable to pass data to following elements """'
            )
            self.placeholder_3 = QC.translate(
                '',
                '""" set the variable log_txt to adjust the logging text """')
            self.code_input.setPlaceholderText(self.placeholder_1 +
                                               '\r\n\r\n' +
                                               'print(input)\r\n\r\n' +
                                               self.placeholder_2 +
                                               '\r\n\r\n' +
                                               'output = 5\r\n\r\n' +
                                               self.placeholder_3 +
                                               '\r\n\r\n' +
                                               'log_txt = "debug text"')

        self.confirm_button = QPushButton(QC.translate('', 'Ok'))

        self.spacer = QSpacerItem(0, 30)
        self.picto_spacer = QSpacerItem(0, 40)

        self.picto_widget = QWidget()
        self.pictogram_layout = QGridLayout(self.picto_widget)
        self.pictogram_layout.addWidget(self.op_image, 0, 0)
        self.pictogram_layout.addItem(self.picto_spacer, 0, 1)
        self.pictogram_layout.addWidget(self.help_text, 0, 2)

        self.opEditLayout.addWidget(self.head_info)
        self.opEditLayout.addWidget(self.code_input)
        self.opEditLayout.addWidget(self.log_line)
        self.opEditLayout.addSpacerItem(self.spacer)
        self.opEditLayout.addWidget(self.picto_widget)
        self.opEditLayout.addWidget(self.confirm_button)
        self.op_edit.setLayout(self.opEditLayout)

        # signals and slots
        self.confirm_button.clicked.connect(self.op_edit.closeEvent)
        self.op_edit.window_closed.connect(self.edit_done)

        self.op_edit.show()

    def edit_done(self):
        logging.debug('edit_done() called ExecOp')

        if self.code_input.toPlainText() == '':
            code_input = None
        else:
            code_input = self.code_input.toPlainText()

        self.config = (self.log_checkbox.isChecked(), code_input)
        self.addFunction(OperationFunction)
        logging.debug('edit_done() 2 called ExecOp')
Esempio n. 4
0
class ExecBranch(ElementMaster):

    pixmap_path = 'images/ExecBranch.png'
    child_pos = (True, True)

    def __init__(self, row, column):
        self.row = row
        self.column = column

        compare_with = None
        negate = False
        operation = '>'
        log_state = False
        op_index = 0
        # compare_with,  operation, op_index, negate, log_state
        self.config = (compare_with, operation, op_index, negate, log_state)

        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config)
        super().edit_sig.connect(self.edit)
        self.initUI()
        logging.debug('ExecBranch called at row {}, column {}'.format(
            row, column))

    def initUI(self):

        self.selectCondition = QComboBox()
        self.selectCondition.addItem(QC.translate('', 'Greater than (>) ...'),
                                     QVariant('>'))
        self.selectCondition.addItem(
            QC.translate('', 'Greater or equal than (>=) ...'), QVariant('>='))
        self.selectCondition.addItem(QC.translate('', 'Less than (<) ...'),
                                     QVariant('<'))
        self.selectCondition.addItem(
            QC.translate('', 'Less or equal than (<=) ...'), QVariant('<='))
        self.selectCondition.addItem(QC.translate('', 'Equal to (==) ...'),
                                     QVariant('=='))
        self.selectCondition.addItem(QC.translate('', 'NOT equal to (!=) ...'),
                                     QVariant('!='))
        self.selectCondition.setCurrentIndex(0)

        #self.addFunction(BranchFunction)

    def __setstate__(self, state):
        # BAUSTELLE
        logging.debug('__setstate__() called ExecBranch')
        self.row, self.column, self.config = state
        self.initUI()
        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config)
        super().edit_sig.connect(self.edit)
        self.addFunction(BranchFunction)

    def __getstate__(self):
        logging.debug('__getstate__() called ExecBranch')
        return (self.row, self.column, self.config)

    def edit(self):

        logging.debug('edit() called ExecBranch')
        mod_path = os.path.dirname(Pythonic.__file__)

        self.branchEditLayout = QVBoxLayout()

        self.branchEdit = ElementEditor(self)
        self.branchEdit.setWindowTitle(QC.translate('', 'Edit Branch'))

        self.branch_image = QLabel()
        self.branch_image.setPixmap(
            QPixmap(os.path.join(mod_path, self.pixmap_path)))

        self.branch_yes = QLabel()
        self.branch_yes.setText(QC.translate('', 'Yes'))
        self.branch_yes.setAlignment(Qt.AlignCenter)

        self.branch_no = QLabel()
        self.branch_no.setText(QC.translate('', 'No'))

        self.help_text = QWidget()
        self.help_text_layout = QVBoxLayout(self.help_text)

        self.help_text_1 = QLabel()
        self.help_text_1.setText(QC.translate('', 'Leads the execution path'))

        self.help_text_2 = QLabel()
        self.help_text_2.setText(
            QC.translate('', 'according to the defined condition.'))

        self.help_text_3 = QLabel()
        self.help_text_3.setText(
            QC.translate('', 'Put strings in quotation marks:'))

        self.help_text_4 = QLabel()
        self.help_text_4.setText(QC.translate('', 'e.g. "state_x"'))

        self.help_text_layout.addWidget(self.help_text_1)
        self.help_text_layout.addWidget(self.help_text_2)
        self.help_text_layout.addWidget(self.help_text_3)
        self.help_text_layout.addWidget(self.help_text_4)

        self.spacer = QSpacerItem(0, 30)
        self.picto_spacer = QSpacerItem(40, 0)

        self.confirm_button = QPushButton(QC.translate('', 'Ok'))

        self.picto_widget = QWidget()
        self.pictogram_layout = QGridLayout(self.picto_widget)
        self.pictogram_layout.addWidget(self.branch_image, 0, 0)
        self.pictogram_layout.addWidget(self.branch_yes, 1, 0)
        self.pictogram_layout.addWidget(self.branch_no, 0, 1)
        self.pictogram_layout.addItem(self.picto_spacer, 0, 2)
        self.pictogram_layout.addWidget(self.help_text, 0, 3)
        self.pictogram_layout.setColumnStretch(4, 1)

        self.checkNegate = QCheckBox(
            QC.translate('', 'Negate query (if NOT ... )'))
        # try to load status
        try:
            compare_with, operation, op_index, negate, log_state = self.config
        except TypeError as e:
            pass

        self.selectCondition.setCurrentIndex(op_index)

        if negate:
            self.checkNegate.setChecked(True)

        self.if_text_1 = QLabel()
        self.if_text_1.setText(QC.translate('', 'if INPUT is ...'))

        self.user_input = QLineEdit()
        if compare_with:
            self.user_input.setText(compare_with)

        # hier logging option einfügen
        self.log_line = QWidget()
        self.ask_for_logging = QLabel()
        self.ask_for_logging.setText(QC.translate('', 'Log output?'))
        self.log_checkbox = QCheckBox()
        self.log_line_layout = QHBoxLayout(self.log_line)
        self.log_line_layout.addWidget(self.ask_for_logging)
        self.log_line_layout.addWidget(self.log_checkbox)
        self.log_line_layout.addStretch(1)

        if log_state:
            self.log_checkbox.setChecked(True)

        self.branchEditLayout.addWidget(self.checkNegate)
        self.branchEditLayout.addWidget(self.if_text_1)
        self.branchEditLayout.addWidget(self.selectCondition)
        self.branchEditLayout.addWidget(self.user_input)
        self.branchEditLayout.addWidget(self.log_line)
        self.branchEditLayout.addSpacerItem(self.spacer)
        self.branchEditLayout.addWidget(self.picto_widget)
        self.branchEditLayout.addStretch(1)
        self.branchEditLayout.addWidget(self.confirm_button)
        self.branchEdit.setLayout(self.branchEditLayout)

        # signals and slots
        self.confirm_button.clicked.connect(self.branchEdit.closeEvent)
        self.branchEdit.window_closed.connect(self.edit_done)

        self.branchEdit.show()

    def edit_done(self):
        logging.debug('edit_done() called ExecBranch')
        text_input = self.user_input.text()

        if text_input == '':
            compare_with = None
        else:
            compare_with = self.user_input.text()

        operation = self.selectCondition.currentData()
        op_index = self.selectCondition.currentIndex()
        negate = self.checkNegate.isChecked()
        log_state = self.log_checkbox.isChecked()

        # compare_with,  operation, op_index, negate, log_state
        self.config = (compare_with, operation, op_index, negate, log_state)

        self.addFunction(BranchFunction)

    def windowClosed(self, event):
        logging.debug('windowClosed() called ExecBranch')
Esempio n. 5
0
class ExecReturn(ElementMaster):

    pixmap_path = 'images/ExecReturn.png'
    child_pos = (False, False)

    def __init__(self, row, column):
        self.row = row
        self.column = column

        # currentdata, currentindex, ischecked
        self.config = (None, None, False)
        super().__init__(self.row, self.column, QPixmap(self.pixmap_path), True, self.config)
        super().edit_sig.connect(self.edit)
        logging.debug('ExecReturn called at row {}, column {}'.format(row, column))

        self.addFunction(ReturnFunction)

    def __setstate__(self, state):
        logging.debug('__setstate__() called ExecReturn')
        self.row, self.column, self.config = state
        super().__init__(self.row, self.column, QPixmap(self.pixmap_path), True, self.config)
        super().edit_sig.connect(self.edit)
        self.addFunction(ReturnFunction)

    def __getstate__(self):
        logging.debug('__getstate__() called ExecReturn')
        return (self.row, self.column, self.config)

    def openEditor(self):
        logging.debug('openEditor() called ExecReturn')

    def edit(self):
        logging.debug('edit() called ExecReturn')
        self.returnEditLayout = QVBoxLayout()

        self.returnEdit = ElementEditor(self)
        self.returnEdit.setWindowTitle(QC.translate('', 'Edit Return'))

        self.top_text = QLabel()
        self.top_text.setText(QC.translate('', 'Go to element:'))

        self.help_text = QWidget()
        self.help_text_layout = QVBoxLayout(self.help_text)

        self.help_text_1 = QLabel()
        self.help_text_1.setText(QC.translate('', 'Choose an element from the list')) 

        self.help_text_2 = QLabel()
        self.help_text_2.setText(QC.translate('', 'to which you want to return with the'))

        self.help_text_3 = QLabel()
        self.help_text_3.setText(QC.translate('', 'current input'))

        self.help_text_layout.addWidget(self.help_text_1)
        self.help_text_layout.addWidget(self.help_text_2)
        self.help_text_layout.addWidget(self.help_text_3)


        self.confirm_button = QPushButton(QC.translate('', 'Ok'))

        # hier logging option einfügen
        self.log_line = QWidget()
        self.ask_for_logging = QLabel()
        self.ask_for_logging.setText(QC.translate('', 'Log output?'))
        self.log_checkbox = QCheckBox()
        self.log_line_layout = QHBoxLayout(self.log_line)
        self.log_line_layout.addWidget(self.ask_for_logging)
        self.log_line_layout.addWidget(self.log_checkbox)
        self.log_line_layout.addStretch(1)


        self.element_selector = QComboBox()
        self.populateSelector()

        if self.config[1]:
            self.element_selector.setCurrentIndex(self.config[1])
        if self.config[2]:
            self.log_checkbox.setChecked(True)

        self.confirm_button.clicked.connect(self.returnEdit.closeEvent)
        self.returnEdit.window_closed.connect(self.edit_done)
        self.returnEditLayout.addWidget(self.top_text)
        self.returnEditLayout.addWidget(self.element_selector)
        self.returnEditLayout.addWidget(self.log_line)
        self.returnEditLayout.addWidget(self.help_text)
        self.returnEditLayout.addStretch(1)
        self.returnEditLayout.addWidget(self.confirm_button)
        self.returnEdit.setLayout(self.returnEditLayout)
        self.returnEdit.show()

    def populateSelector(self):

        index = self.parent().returnCurrentElements()

        for pos in index:
            if self.getPos() != pos:
                self.element_selector.addItem('{} {}'.format(pos[0], alphabet[pos[1]]), QVariant(pos))

    def edit_done(self):
        logging.debug('edit_done() called ExecReturn' )
        self.config = (self.element_selector.currentData(), self.element_selector.currentIndex(), self.log_checkbox.isChecked())
        self.addFunction(ReturnFunction)
Esempio n. 6
0
class ExecTA(ElementMaster):

    pixmap_path = 'images/ExecTA.png'
    child_pos = (True, False)

    def __init__(self, row, column):

        self.row = row
        self.column = column

        ta_str = 'MA'
        ta_index = 0
        ta_config = (3, )
        log_state = False

        self.config = (ta_str, ta_index, ta_config, log_state)

        super().__init__(self.row, self.column, self.pixmap_path, True, self.config)
        super().edit_sig.connect(self.edit)
        logging.debug('ExecTA called at row {}, column {}'.format(row, column))
        self.addFunction(TAFunction)

    def __setstate__(self, state):
        logging.debug('__setstate__() called ExecTA')
        self.row, self.column, self.config = state
        super().__init__(self.row, self.column, self.pixmap_path, True, self.config)
        super().edit_sig.connect(self.edit)
        self.addFunction(TAFunction)

    def __getstate__(self):
        logging.debug('__getstate__() called ExecTA')
        return (self.row, self.column, self.config)

    def openEditor(self):
        logging.debug('openEditor() called ExecTA')

    def edit(self):

        logging.debug('edit() called ExecTA')

        ta_str, ta_index, ta_config, log_state = self.config

        self.basic_ta_layout = QVBoxLayout()
        self.confirm_button = QPushButton(QC.translate('', 'Ok'))

        self.interval_txt = QLabel()
        self.interval_txt.setText(QC.translate('', 'Choose technical analysis function'))

        # https://github.com/sammchardy/python-binance/blob/master/binance/client.py
        self.selectTA = QComboBox()
        self.selectTA.addItem(QC.translate('', 'Moving Average'), QVariant('MA'))
        self.selectTA.addItem(QC.translate('', 'Exponential Moving Average'), QVariant('EMA'))
        self.selectTA.addItem(QC.translate('', 'Stochastic Oscillator %K'), QVariant('STOK'))
        self.selectTA.addItem(QC.translate('', 'Stochastic Oscillator %D'), QVariant('STO'))
        self.selectTA.addItem(QC.translate('', 'Relative Strenght Index'), QVariant('RSI'))
        """
        self.selectTA.addItem(QC.translate('', 'Momentum'), QVariant('MOM'))
        self.selectTA.addItem(QC.translate('', 'Rate of Change'), QVariant('ROC'))
        self.selectTA.addItem(QC.translate('', 'Average True Range'), QVariant('ATR'))
        self.selectTA.addItem(QC.translate('', 'Bollinger Bands'), QVariant('BBANDS'))
        self.selectTA.addItem(QC.translate('', 'Pivot Points, Support and Resitances'), QVariant('PPSR'))
        self.selectTA.addItem(QC.translate('', 'Trix'), QVariant('TRIX'))
        self.selectTA.addItem(QC.translate('', 'Average Directional Movement Index'), QVariant('ADX'))
        self.selectTA.addItem(QC.translate('', 'MACD, MACD Signal and MACD diffrence'), QVariant('MACD'))
        self.selectTA.addItem(QC.translate('', 'Mass Index'), QVariant('MI'))
        self.selectTA.addItem(QC.translate('', 'Vortex Indikator'), QVariant('VORTEX'))
        self.selectTA.addItem(QC.translate('', 'KST Oscillator'), QVariant('KST'))
        self.selectTA.addItem(QC.translate('', 'True Strenght Index'), QVariant('TSI'))
        self.selectTA.addItem(QC.translate('', 'Accumulation/Distribution'), QVariant('ACCDIST'))
        self.selectTA.addItem(QC.translate('', 'Chaikin Oscillator'), QVariant('CHAI'))
        self.selectTA.addItem(QC.translate('', 'Money Flow Index and Ratio'), QVariant('MFI'))
        self.selectTA.addItem(QC.translate('', 'On Balance Volume'), QVariant('OBV'))
        self.selectTA.addItem(QC.translate('', 'Force Index'), QVariant('FI'))
        self.selectTA.addItem(QC.translate('', 'Ease of Movement'), QVariant('EOM'))
        self.selectTA.addItem(QC.translate('', 'Commodity Channel Index'), QVariant('CCI'))
        """
        self.selectTA.setCurrentIndex(ta_index)


        self.variable_box = QStackedWidget()
        self.maInput()
        self.emaInput()
        self.stokInput()
        self.stoInput()
        self.rsiInput()
        self.loadLastConfig()

        logging.debug('edit() - {} elements in QStackedWidget'.format(self.variable_box.count()))

        self.link_line = QWidget()
        self.link_line_layout = QHBoxLayout(self.link_line)

        self.link_txt = QLabel()
        self.link_txt.setText(QC.translate('', 'Find information about technical analysis on'))

        self.link = QLabel()
        self.link.setText('<a href="https://www.investopedia.com/walkthrough/forex/">Investopedia</a>')
        self.link.setTextFormat(Qt.RichText)
        self.link.setTextInteractionFlags(Qt.TextBrowserInteraction)
        self.link.setOpenExternalLinks(True)

        self.link_line_layout.addWidget(self.link_txt)
        self.link_line_layout.addWidget(self.link)
        self.link_line_layout.addStretch(1)

        # hier logging option einfügen
        self.log_line = QWidget()
        self.ask_for_logging = QLabel()
        self.ask_for_logging.setText(QC.translate('', 'Log output?'))
        self.log_checkbox = QCheckBox()
        self.log_line_layout = QHBoxLayout(self.log_line)
        self.log_line_layout.addWidget(self.ask_for_logging)
        self.log_line_layout.addWidget(self.log_checkbox)
        self.log_line_layout.addStretch(1)

        if log_state:
            self.log_checkbox.setChecked(True)


        self.basic_ta_edit = ElementEditor(self)
        self.basic_ta_edit.setWindowTitle(QC.translate('', 'Edit TA function'))

        # signals and slots
        self.confirm_button.clicked.connect(self.basic_ta_edit.closeEvent)
        self.basic_ta_edit.window_closed.connect(self.edit_done)
        self.selectTA.currentIndexChanged.connect(self.indexChanged)

        self.basic_ta_layout.addWidget(self.interval_txt)
        self.basic_ta_layout.addWidget(self.selectTA)
        self.basic_ta_layout.addWidget(self.variable_box)
        self.basic_ta_layout.addStretch(1)
        self.basic_ta_layout.addWidget(self.log_line)
        self.basic_ta_layout.addWidget(self.link_line)
        self.basic_ta_layout.addWidget(self.confirm_button)
        self.basic_ta_edit.setLayout(self.basic_ta_layout)
        self.basic_ta_edit.show()
        
    def loadLastConfig(self):

        ta_str, ta_index, ta_config, log_state = self.config

        logging.debug('loadLastConfig() called with ta_str = {}'.format(ta_str))

        self.variable_box.setCurrentIndex(ta_index)

        if ta_str == 'MA':
            self.ma_range_input.setText(str(ta_config[0]))
        elif ta_str == 'EMA':
            self.ema_range_input.setText(str(ta_config[0]))
        elif ta_str == 'STO':
            self.sto_range_input.setText(str(ta_config[0]))
        elif ta_str == 'RSI':
            self.rsi_range_input.setText(str(ta_config[0]))

    def maInput(self):

        self.ma_input = QWidget()
        self.ma_layout = QHBoxLayout(self.ma_input)

        self.ma_range_txt = QLabel()
        self.ma_range_txt.setText(QC.translate('', 'Enter time range MA'))

        self.ma_range_input = QLineEdit()
        self.ma_range_input.setValidator(QIntValidator(1, 999))
        self.ma_range_input.setPlaceholderText(QC.translate('', 'Default value: 3'))

        self.ma_layout.addWidget(self.ma_range_txt)
        self.ma_layout.addWidget(self.ma_range_input)


        self.variable_box.addWidget(self.ma_input)

    def emaInput(self):

        self.ema_input = QWidget()
        self.ema_layout = QHBoxLayout(self.ema_input)

        self.ema_range_txt = QLabel()
        self.ema_range_txt.setText(QC.translate('', 'Enter time range EMA'))

        self.ema_range_input = QLineEdit()
        self.ema_range_input.setValidator(QIntValidator(1, 999))
        self.ema_range_input.setPlaceholderText(QC.translate('', 'Default value: 3'))

        self.ema_layout.addWidget(self.ema_range_txt)
        self.ema_layout.addWidget(self.ema_range_input)

        self.variable_box.addWidget(self.ema_input)

    def stokInput(self):

        self.stok_input = QWidget()
        self.stok_layout = QHBoxLayout(self.stok_input)

        self.variable_box.addWidget(self.stok_input)

    def stoInput(self):

        self.sto_input = QWidget()
        self.sto_layout = QHBoxLayout(self.sto_input)

        self.sto_range_txt = QLabel()
        self.sto_range_txt.setText(QC.translate('', 'Enter MA period'))

        self.sto_range_input = QLineEdit()
        self.sto_range_input.setValidator(QIntValidator(1, 999))
        self.sto_range_input.setPlaceholderText(QC.translate('', 'Default value: 3'))

        self.sto_layout.addWidget(self.sto_range_txt)
        self.sto_layout.addWidget(self.sto_range_input)

        self.variable_box.addWidget(self.sto_input)

    def rsiInput(self):

        self.rsi_input = QWidget()
        self.rsi_layout = QHBoxLayout(self.rsi_input)

        self.rsi_range_txt = QLabel()
        self.rsi_range_txt.setText(QC.translate('', 'Enter periods'))

        self.rsi_range_input = QLineEdit()
        self.rsi_range_input.setValidator(QIntValidator(1, 999))
        self.rsi_range_input.setPlaceholderText(QC.translate('', 'Default value: 3'))

        self.rsi_layout.addWidget(self.rsi_range_txt)
        self.rsi_layout.addWidget(self.rsi_range_input)

        self.variable_box.addWidget(self.rsi_input)

    def indexChanged(self, event):

        current_index = event
        logging.debug('indexChanged() called {}'.format(current_index))
        self.variable_box.setCurrentIndex(current_index)

        if current_index == 0:

            logging.debug('Moving Average selected - {}'.format(self.selectTA.currentData()))

        elif current_index == 1:

            logging.debug('Exponential Moving Average selected')

    def edit_done(self):

        logging.debug('edit_done() called ExecTA')
        if self.selectTA.currentData() == 'MA':

            period = self.ma_range_input.text()

            if period == '':
                ta_config = (3, )
            else:
                ta_config = (int(period), )

            logging.debug('edit_done() - Moving Average selected - {}'.format(ta_config))

        elif self.selectTA.currentData() == 'EMA':

            period = self.ema_range_input.text()

            if period == '':
                ta_config = (3, )
            else:
                ta_config = (int(period), )

            logging.debug('edit_done() - Exponential Moving Average selected - {}'.format(ta_config))

        elif self.selectTA.currentData() == 'STO':

            period = self.sto_range_input.text()

            if period == '':
                ta_config = (3, )
            else:
                ta_config = (int(period), )

            logging.debug('edit_done() - Stochastic Oscillator %D or EMA or RSI selected - {}'.format(ta_config))

        elif self.selectTA.currentData() == 'RSI':

            period = self.rsi_range_input.text()

            if period == '':
                ta_config = (3, )
            else:
                ta_config = (int(period), )

            logging.debug('edit_done() - Relative Strenght Index selected - {}'.format(ta_config))


        else:
            ta_config = None


        ta_str    = self.selectTA.currentData()
        ta_index  = self.selectTA.currentIndex()
        log_state = self.log_checkbox.isChecked()

        self.config = (ta_str, ta_index, ta_config, log_state)
        self.addFunction(TAFunction)
Esempio n. 7
0
class MLSVM(ElementMaster):

    pixmap_path = 'images/MLSVM.png'
    child_pos = (True, False)

    def __init__(self, row, column):
        self.row = row
        self.column = column

        # scale_option, scale_mean, scale_std train_eval, decision_function, gamma_mode,
        #    gamma_value, filename, log_state

        scale_option = 0
        scale_mean = True
        scale_std = True
        train_eval = 2
        decision_function = 0
        gamma_mode = 0
        gamma_value = '1.0'
        filename = None
        log_state = False
        rel_path = False

        self.config = scale_option, scale_mean, scale_std, train_eval, decision_function, \
                gamma_mode, gamma_value, filename, rel_path, log_state

        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config)
        super().edit_sig.connect(self.edit)
        logging.debug('MLSVM::__init__() called at row {}, column {}'.format(
            row, column))
        self.addFunction(MLSVMFunction)

    def __setstate__(self, state):
        logging.debug('MLSVM::__setstate__() called')
        self.row, self.column, self.config = state
        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config)
        super().edit_sig.connect(self.edit)
        self.addFunction(MLSVMFunction)

    def __getstate__(self):
        logging.debug('MLSVM::__getstate__() called')
        return (self.row, self.column, self.config)

    def openEditor(self):
        logging.debug('MLSVM::openEditor() called')

    def edit(self):

        logging.debug('MLSVM::edit()')
        """
        gamma: auto oder float eingabe
        decision function shape: ovr oder ovo

        data split train / eval
        """
        self.scale_option, self.scale_mean, self.scale_std, self.train_eval, self.decision_function, \
                self.gamma_mode, self.gamma_value, self.filename, self.rel_path, self.log_state = self.config

        self.scale_label = QLabel()
        self.scale_label.setText(QC.translate('', 'Scale n_samples ?'))
        self.scale_list = QComboBox()
        self.scale_list.addItem(QC.translate('', 'No'), QVariant(False))
        self.scale_list.addItem(QC.translate('', 'Yes'), QVariant(True))

        self.scale_center_input_line = QWidget()
        self.scale_center_input_line_layout = QHBoxLayout(
            self.scale_center_input_line)
        self.scale_center_label = QLabel()
        self.scale_center_label.setText(
            QC.translate('', 'Center data before scaling?'))
        self.scale_center_checkbox = QCheckBox()
        self.scale_center_input_line_layout.addWidget(self.scale_center_label)
        self.scale_center_input_line_layout.addWidget(
            self.scale_center_checkbox)

        self.scale_std_input_line = QWidget()
        self.scale_std_input_line_layout = QHBoxLayout(
            self.scale_std_input_line)
        self.scale_std_label = QLabel()
        self.scale_std_label.setText(
            QC.translate('', 'Scale data until variance?'))
        self.scale_std_checkbox = QCheckBox()
        self.scale_std_input_line_layout.addWidget(self.scale_std_label)
        self.scale_std_input_line_layout.addWidget(self.scale_std_checkbox)

        self.scale_input_area = QWidget()
        self.scale_input_area_layout = QVBoxLayout(self.scale_input_area)
        self.scale_input_area_layout.addWidget(self.scale_center_input_line)
        self.scale_input_area_layout.addWidget(self.scale_std_input_line)

        self.train_test_label = QLabel()
        self.train_test_label.setText(
            QC.translate('', 'Choose train / evalutaion ratio:'))

        self.train_test_list = QComboBox()
        self.train_test_list.addItem('90/10', QVariant(90))
        self.train_test_list.addItem('80/20', QVariant(80))
        self.train_test_list.addItem('70/30', QVariant(70))
        self.train_test_list.addItem('60/40', QVariant(60))
        self.train_test_list.addItem('50/50', QVariant(50))

        self.decision_function_label = QLabel()
        self.decision_function_label.setText(
            QC.translate('', 'Choose decision function shape:'))

        self.decision_function_list = QComboBox()
        self.decision_function_list.addItem('ovo', QVariant('ovo'))
        self.decision_function_list.addItem('ovr', QVariant('ovr'))

        self.gamma_label = QLabel()
        self.gamma_label.setText(QC.translate('', 'Gamma:'))

        self.gamma_list = QComboBox()
        self.gamma_list.addItem(QC.translate('', 'Auto'), QVariant('auto'))
        self.gamma_list.addItem(QC.translate('', 'Scaled'), QVariant('scaled'))
        self.gamma_list.addItem(QC.translate('', 'Manual'), QVariant('manual'))

        self.gamma_input_line = QWidget()
        self.gamma_input_line_layout = QHBoxLayout(self.gamma_input_line)
        self.gamma_input_txt = QLabel()
        self.gamma_input_txt.setText(QC.translate('', 'Gamma:'))
        self.gamma_input = QLineEdit()
        self.gamma_input.setPlaceholderText('1.0')
        self.gamma_input.setValidator(QDoubleValidator(0, 999, 3))
        self.gamma_input_line_layout.addWidget(self.gamma_input_txt)
        self.gamma_input_line_layout.addWidget(self.gamma_input)

        self.conn_rest_layout = QVBoxLayout()
        self.confirm_button = QPushButton(QC.translate('', 'Ok'))

        self.filename_text = QLabel()
        self.filename_text.setWordWrap(True)

        self.file_button = QPushButton(
            QC.translate('', 'Select model output file'))
        self.file_button.clicked.connect(self.ChooseFileDialog)

        self.relative_file_check = QWidget()
        self.relative_file_check_layout = QHBoxLayout(self.relative_file_check)

        self.relative_file_label = QLabel()
        self.relative_file_label.setText(
            QC.translate('', 'Filename relative to $HOME.'))
        self.relative_file_checkbox = QCheckBox()
        self.relative_file_check_layout.addWidget(self.relative_file_checkbox)
        self.relative_file_check_layout.addWidget(self.relative_file_label)
        self.relative_file_check_layout.addStretch(1)

        self.relative_filepath_input = QLineEdit()
        self.relative_filepath_input.setPlaceholderText('my_folder/my_file')

        self.file_input = QWidget()
        self.file_input_layout = QVBoxLayout(self.file_input)
        self.file_input_layout.addWidget(self.filename_text)
        self.file_input_layout.addWidget(self.file_button)
        self.file_input_layout.addWidget(self.relative_file_check)
        self.file_input_layout.addWidget(self.relative_filepath_input)
        """
        output: prediction quality
        """
        self.help_text_1 = QLabel()
        self.help_text_1.setText(
            QC.translate('',
                         'Expects a tuple (n_samples, n_features) as input.'))

        self.help_text_2 = QLabel()
        self.help_text_2.setText(
            QC.translate('', 'Outputs a contigency table in the format:'))
        self.help_text_3 = QLabel()
        self.help_text_3.setText(
            QC.translate('',
                         '{\'TP\': 23, \'FP\': 13, \'FN\':12, \'TN\': 33}'))

        # hier logging option einfügen
        self.log_line = QWidget()
        self.ask_for_logging = QLabel()
        self.ask_for_logging.setText(QC.translate('', 'Log output?'))
        self.log_checkbox = QCheckBox()
        self.log_line_layout = QHBoxLayout(self.log_line)
        self.log_line_layout.addWidget(self.ask_for_logging)
        self.log_line_layout.addWidget(self.log_checkbox)
        self.log_line_layout.addStretch(1)

        self.ml_svm_edit = ElementEditor(self)
        self.ml_svm_edit.setWindowTitle(
            QC.translate('', 'Support Vector Machine'))
        self.ml_svm_edit.setMinimumHeight(600)

        # signals and slots
        self.relative_file_checkbox.stateChanged.connect(self.toggleFileInput)
        self.gamma_list.currentIndexChanged.connect(self.gammaIndexChanged)
        self.scale_list.currentIndexChanged.connect(self.scaledIndexChanged)
        self.confirm_button.clicked.connect(self.ml_svm_edit.closeEvent)
        self.ml_svm_edit.window_closed.connect(self.edit_done)

        # load config
        self.loadLastConfig()

        self.conn_rest_layout.addWidget(self.help_text_1)
        self.conn_rest_layout.addWidget(
            self.scale_label)  # scale: copy = false
        self.conn_rest_layout.addWidget(self.scale_list)
        self.conn_rest_layout.addWidget(self.scale_input_area)
        self.conn_rest_layout.addWidget(self.train_test_label)
        self.conn_rest_layout.addWidget(self.train_test_list)
        self.conn_rest_layout.addWidget(self.decision_function_label)
        self.conn_rest_layout.addWidget(self.decision_function_list)
        self.conn_rest_layout.addWidget(self.gamma_label)
        self.conn_rest_layout.addWidget(self.gamma_list)
        self.conn_rest_layout.addWidget(self.gamma_input_line)
        self.conn_rest_layout.addWidget(self.file_input)
        self.conn_rest_layout.addStretch(1)
        self.conn_rest_layout.addWidget(self.help_text_2)
        self.conn_rest_layout.addWidget(self.help_text_3)
        self.conn_rest_layout.addWidget(self.log_line)
        self.conn_rest_layout.addWidget(self.confirm_button)
        self.ml_svm_edit.setLayout(self.conn_rest_layout)
        self.ml_svm_edit.show()

    def toggleFileInput(self, event):
        logging.debug('MLSVM::toggleFileInput() called: {}'.format(event))
        # 0 = FALSE, 2 = TRUE
        if event:  # TRUE
            self.file_button.setDisabled(True)
            self.relative_filepath_input.setDisabled(False)
            self.filename_text.setText('')
        else:
            self.file_button.setDisabled(False)
            self.relative_filepath_input.clear()
            self.relative_filepath_input.setDisabled(True)
            self.relative_filepath_input.setPlaceholderText(
                'my_folder/my_file')

    def loadLastConfig(self):

        logging.debug('MLSVM::loadLastConfig() called')

        self.train_test_list.setCurrentIndex(self.train_eval)
        self.decision_function_list.setCurrentIndex(self.decision_function)
        self.gamma_list.setCurrentIndex(self.gamma_mode)
        self.gamma_input.setText('{}'.format(self.gamma_value))
        self.gammaIndexChanged(self.gamma_mode)
        self.scale_list.setCurrentIndex(self.scale_option)
        self.scaledIndexChanged(self.scale_option)
        self.scale_center_checkbox.setChecked(self.scale_mean)
        self.scale_std_checkbox.setChecked(self.scale_std)
        self.log_checkbox.setChecked(self.log_state)
        self.relative_file_checkbox.setChecked(self.rel_path)

        if self.rel_path:
            self.toggleFileInput(2)
            if self.filename:
                self.relative_filepath_input.setText(self.filename)
        else:
            self.toggleFileInput(0)
            if self.filename:
                self.filename_text.setText(self.filename)

    def scaledIndexChanged(self, event):

        current_index = event
        logging.debug('MLSVM::scaledIndexChanged() called: {}'.format(event))
        if event == 1:
            self.scale_input_area.setVisible(True)
        else:
            self.scale_input_area.setVisible(False)

    def gammaIndexChanged(self, event):

        current_index = event
        logging.debug('MLSVM::gammaIndexChanged() called: {}'.format(event))
        if event == 2:
            self.gamma_input_line.setVisible(True)
        else:
            self.gamma_input_line.setVisible(False)

    def ChooseFileDialog(self, event):
        options = QFileDialog.Options()
        options |= QFileDialog.DontUseNativeDialog
        fileName, _ = QFileDialog.getSaveFileName(self, \
                QC.translate('', 'Choose file'),"","All Files (*);;Text Files (*.txt)", \
                options=options)
        if fileName:
            logging.debug(
                'ChooseFileDialog() called with filename: {}'.format(fileName))
            self.filename = fileName
            self.filename_text.setText(self.filename)

    def edit_done(self):

        logging.debug('MLSVM::edit_done() called')
        # scale_option, scale_mean, scale_std train_eval, decision_function, gamma_mode,
        #    gamma_value, filename, log_state

        scale_option = self.scale_list.currentIndex()
        scale_mean = self.scale_center_checkbox.isChecked()
        scale_std = self.scale_std_checkbox.isChecked()
        train_eval = self.train_test_list.currentIndex()
        decision_function = self.decision_function_list.currentIndex()
        gamma_mode = self.gamma_list.currentIndex()
        gamma_value = float(self.gamma_input.text())
        filename = self.filename
        log_state = self.log_checkbox.isChecked()
        rel_path = self.relative_file_checkbox.isChecked()
        if rel_path:
            filename = self.relative_filepath_input.text()
        else:
            filename = self.filename

        if filename == '':
            filename = None

        self.config = scale_option, scale_mean, scale_std, train_eval, decision_function, gamma_mode, \
                gamma_value, filename, rel_path, log_state

        self.addFunction(MLSVMFunction)
Esempio n. 8
0
class CCXT(ElementMaster):

    pixmap_path = 'images/CCXT.png'
    child_pos = (True, False)

    def __init__(self, row, column):
        self.row = row
        self.column = column

        self.current_exchangeObj = None
        self.current_exchange = 'kraken'
        api_key = ''
        sec_key = ''
        #current_method      = 'fetchOHLCV'
        self.current_method = 'create_limit_order'
        self.current_params = {}  # actual parameter values, saved to config
        self.positional_params = [
        ]  # list of object references of parameter input
        log_state = False

        # exchange, api_key, sec_key, method, params, log_state
        self.config = (self.current_exchange, api_key, sec_key,
                       self.current_method, self.current_params, log_state)
        #new
        # exchange_index,

        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config)
        super().edit_sig.connect(self.edit)
        logging.debug('CCXT called at row {}, column {}'.format(row, column))
        self.addFunction(CCXTFunction)

    def __setstate__(self, state):
        logging.debug('__setstate__() called CCXT')
        self.row, self.column, self.config = state
        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config)
        super().edit_sig.connect(self.edit)
        self.addFunction(CCXTFunction)

    def __getstate__(self):
        logging.debug('__getstate__() called CCXT')
        return (self.row, self.column, self.config)

    def openEditor(self):
        logging.debug('openEditor() called CCXT')

    def edit(self):

        logging.debug('edit() called CCXT')

        # exchange, api_key, sec_key, method, params, log_state
        self.current_exchange, api_key, sec_key, \
             self.current_method, self.current_params, log_state = self.config

        self.ccxt_layout = QVBoxLayout()
        self.confirm_button = QPushButton(QC.translate('', 'Ok'))

        self.exchange_txt = QLabel()
        self.exchange_txt.setText(QC.translate('', 'Choose Exchange'))

        # create list of exchanges
        self.selectExchange = QComboBox()

        for exchange_id in ccxt.exchanges:
            try:
                exchange = getattr(ccxt, exchange_id)()
                self.selectExchange.addItem(exchange.name,
                                            QVariant(exchange_id))
            except Exception as e:
                print(e)

        # load current exchange object
        self.current_exchangeObj = getattr(ccxt,
                                           self.selectExchange.currentData())()

        # select saved exchange from config

        index = ccxt.exchanges.index(self.current_exchange)
        self.selectExchange.setCurrentIndex(index)

        self.pub_key_txt = QLabel()
        self.pub_key_txt.setText(QC.translate('', 'Enter API key:'))
        self.pub_key_input = QLineEdit()
        self.pub_key_input.setText(api_key)

        self.prv_key_txt = QLabel()
        self.prv_key_txt.setText(QC.translate('', 'Enter secret key:'))
        self.prv_key_input = QLineEdit()
        self.prv_key_input.setText(sec_key)

        # List all available methods

        self.method_txt = QLabel()
        self.method_txt.setText(QC.translate('', 'Select method'))

        self.selectMethod = QComboBox()
        self.updateMethods()

        # List method parameters

        self.method_params = QWidget()
        self.method_params_layout = QVBoxLayout(self.method_params)

        self.updateParams()  # brauche ich das noch?

        # hier logging option einfügen
        #??????
        self.log_line = QWidget()
        self.ask_for_logging = QLabel()
        self.ask_for_logging.setText(QC.translate('', 'Log output?'))
        self.log_checkbox = QCheckBox()
        self.log_line_layout = QHBoxLayout(self.log_line)
        self.log_line_layout.addWidget(self.ask_for_logging)
        self.log_line_layout.addWidget(self.log_checkbox)
        self.log_line_layout.addStretch(1)

        if log_state:
            self.log_checkbox.setChecked(True)

        self.ccxt_edit = ElementEditor(self)
        self.ccxt_edit.setWindowTitle(QC.translate('', 'CCXT'))

        # signals and slots
        self.confirm_button.clicked.connect(self.ccxt_edit.closeEvent)
        self.ccxt_edit.window_closed.connect(self.edit_done)
        self.selectExchange.currentIndexChanged.connect(self.exchangeChanged)
        self.selectMethod.currentIndexChanged.connect(self.methodChanged)

        self.ccxt_layout.addWidget(self.exchange_txt)
        self.ccxt_layout.addWidget(self.selectExchange)
        self.ccxt_layout.addWidget(self.pub_key_txt)
        self.ccxt_layout.addWidget(self.pub_key_input)
        self.ccxt_layout.addWidget(self.prv_key_txt)
        self.ccxt_layout.addWidget(self.prv_key_input)
        self.ccxt_layout.addWidget(self.selectMethod)
        self.ccxt_layout.addWidget(self.method_params)
        self.ccxt_layout.addWidget(self.log_line)
        self.ccxt_layout.addStretch(1)

        self.ccxt_layout.addWidget(self.confirm_button)
        self.ccxt_edit.setLayout(self.ccxt_layout)

        # select saved method from config

        methodsList = [
            m[0] for m in inspect.getmembers(self.current_exchangeObj,
                                             predicate=inspect.ismethod)
            if m[0][:2] != '__'
        ]

        index = methodsList.index(self.current_method)
        self.selectMethod.setCurrentIndex(index)

        # load saved parameter values

        self.loadSavedParams()

        # display element editor

        self.ccxt_edit.show()

    def exchangeChanged(self, event):

        logging.debug('CCXT::exchangeChanged() called {}'.format(event))

        self.current_exchange = self.selectExchange.currentData()
        self.current_exchangeObj = getattr(ccxt, self.current_exchange)()
        self.updateMethods()

    def methodChanged(self, event):

        logging.debug('updateSignature() called CCXT')
        method_name = self.selectMethod.currentData()
        if method_name:
            self.current_method = method_name
            self.updateParams()

    def updateMethods(self):

        logging.debug('CCXT::updateMethods() called')
        self.selectMethod.clear()

        for method in inspect.getmembers(self.current_exchangeObj,
                                         predicate=inspect.ismethod):
            if method[0][:2] != '__':
                # mit getattr lässt sich die methode dann wieder aufrufen

                self.selectMethod.addItem(method[0], QVariant(method[0]))

    def updateParams(self):

        logging.debug('CCXT::updateParams() called')

        method = getattr(self.current_exchangeObj, self.current_method)
        signature = inspect.signature(method)

        # remove widgets from layout

        for i in reversed(range(self.method_params_layout.count())):
            self.method_params_layout.itemAt(i).widget().setParent(None)

        # remove params from list

        self.positional_params.clear()

        for param in signature.parameters.values():
            if param.kind == param.POSITIONAL_OR_KEYWORD:
                paramLabel = QLabel('{}:'.format(param.name.capitalize()))
                self.method_params_layout.addWidget(paramLabel)

                paramInput = QLineEdit()
                paramInput.setObjectName(param.name)
                self.positional_params.append(paramInput)
                self.method_params_layout.addWidget(paramInput)

            if param.kind == param.VAR_POSITIONAL:
                # e.g. createLimitOrder
                varArgs = VarPositionalParser()
                self.positional_params.append(varArgs)
                self.method_params_layout.addWidget(varArgs)

    def loadSavedParams(self):

        for param in self.positional_params:
            if (isinstance(param, VarPositionalParser)
                    and 'args' in self.current_params):

                for argName, argVal in self.current_params['args'].items():
                    param.addArgument(argName, argVal)
            else:
                key = param.objectName()
                if key in self.current_params:
                    param.setText(self.current_params[key])

    def edit_done(self):

        logging.debug('edit_done() called CCXT')

        varArgs = {}  # only used in case of variable length argument list

        self.current_params.clear()

        for param in self.positional_params:
            if isinstance(param, VarPositionalParser):
                for arg in param.arg_list:

                    varArgs[arg.s_arg_name] = arg.s_arg_val

                self.current_params['args'] = varArgs

            else:
                name = param.objectName()
                self.current_params[name] = param.text()

        log_state = self.log_checkbox.isChecked()
        api_key = self.pub_key_input.text()
        sec_key = self.prv_key_input.text()

        # exchange, api_key, sec_key, method, params, log_state

        self.config = (self.current_exchange, api_key, sec_key,
                       self.current_method, self.current_params, log_state)

        self.addFunction(CCXTFunction)
Esempio n. 9
0
class ExecOp(ElementMaster):

    pixmap_path = 'images/ExecOp.png'
    child_pos = (True, False)

    def __init__(self, row, column):
        self.row = row
        self.column = column
        # log_state, code_input, custom_edit_state, cmd
        self.config = (False, None, False, None)
        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config)
        super().edit_sig.connect(self.edit)
        logging.debug('ExecOp called at row {}, column {}'.format(row, column))
        self.addFunction(OperationFunction)

    def __setstate__(self, state):
        logging.debug('__setstate__() called ExecOp')
        self.row, self.column, self.config = state
        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config)
        self.addFunction(OperationFunction)
        super().edit_sig.connect(self.edit)

    def __getstate__(self):
        logging.debug('__getstate__() called ExecOp')
        return (self.row, self.column, self.config)

    def openEditor(self):
        logging.debug('openEditor() called ExecOp')

    def edit(self):

        logging.debug('edit() called ExecOp')
        mod_path = os.path.dirname(Pythonic.__file__)

        self.opEditLayout = QVBoxLayout()

        self.op_edit = ElementEditor(self)
        self.op_edit.setWindowTitle(QC.translate('', 'Edit Basic Operation'))

        self.head_info = QLabel()
        self.head_info.setText(
            QC.translate('', 'Enter your Python 3 code below:'))

        self.help_text = QLabel()
        self.help_text.setText(
            QC.translate('', 'Process your own Python 3 code.'))

        self.cmd_line_txt_1 = QLabel()
        self.cmd_line_txt_1.setText(QC.translate('', 'Use custom editor?'))
        self.cmd_line_txt_2 = QLabel()
        self.cmd_line_txt_2.setText(
            QC.translate('',
                         'Use keyword $FILENAME to specify the code file.'))
        self.cmd_line_txt_3 = QLabel()
        self.cmd_line_txt_3.setText(
            QC.translate('', 'Re-open to activate settings.'))

        self.custom_editor_checkbox = QCheckBox()
        self.custom_editor_cmd = QLineEdit()
        self.custom_editor_line = QWidget()
        self.custom_editor_line_layout = QHBoxLayout(self.custom_editor_line)
        self.custom_editor_line_layout.addWidget(self.cmd_line_txt_1)
        self.custom_editor_line_layout.addWidget(self.custom_editor_checkbox)

        self.op_image = QLabel()
        self.op_image.setPixmap(
            QPixmap(os.path.join(mod_path, self.pixmap_path)))

        self.code_input = QTextEdit()
        self.code_input.setMinimumHeight(250)

        # hier logging option einfügen
        self.log_line = QWidget()
        self.ask_for_logging = QLabel()
        self.ask_for_logging.setText(QC.translate('', 'Log output?'))
        self.log_checkbox = QCheckBox()
        self.log_line_layout = QHBoxLayout(self.log_line)
        self.log_line_layout.addWidget(self.ask_for_logging)
        self.log_line_layout.addWidget(self.log_checkbox)
        self.log_line_layout.addStretch(1)

        self.loadLastConfig()

        self.confirm_button = QPushButton(QC.translate('', 'Ok'))

        self.spacer = QSpacerItem(0, 30)
        self.picto_spacer = QSpacerItem(0, 40)

        self.picto_widget = QWidget()
        self.pictogram_layout = QGridLayout(self.picto_widget)
        self.pictogram_layout.addWidget(self.op_image, 0, 0)
        self.pictogram_layout.addItem(self.picto_spacer, 0, 1)
        self.pictogram_layout.addWidget(self.help_text, 0, 2)

        self.opEditLayout.addWidget(self.head_info)
        self.opEditLayout.addWidget(self.code_input)
        self.opEditLayout.addWidget(self.custom_editor_line)
        self.opEditLayout.addWidget(self.custom_editor_cmd)
        self.opEditLayout.addWidget(self.cmd_line_txt_2)
        self.opEditLayout.addWidget(self.cmd_line_txt_3)
        self.opEditLayout.addWidget(self.log_line)
        self.opEditLayout.addSpacerItem(self.spacer)
        self.opEditLayout.addWidget(self.picto_widget)
        self.opEditLayout.addWidget(self.confirm_button)
        self.op_edit.setLayout(self.opEditLayout)

        # signals and slots
        self.custom_editor_checkbox.stateChanged.connect(
            self.toggle_custom_editor)
        self.confirm_button.clicked.connect(self.op_edit.closeEvent)
        self.op_edit.window_closed.connect(self.edit_done)

        self.op_edit.setMinimumHeight(650)
        self.op_edit.show()

    def toggle_custom_editor(self, event):
        logging.debug('ExecOp::toggle_custom_editor() called {}'.format(event))
        if event == 2:  #custom editor enabled
            self.code_input.setEnabled(False)
            self.custom_editor_cmd.setEnabled(True)
        else:
            self.code_input.setEnabled(True)
            self.custom_editor_cmd.setEnabled(False)

    def loadLastConfig(self):
        logging.debug('ExecOp::loadLastConfig() called')
        log_state, code_input, custom_edit_state, cmd = self.config

        self.log_checkbox.setChecked(log_state)
        self.custom_editor_checkbox.setChecked(custom_edit_state)

        if code_input:
            self.code_input.setPlainText(code_input)
        else:
            self.placeholder_1 = QC.translate(
                '',
                '""" use the variable input to access data from previous elements """'
            )
            self.placeholder_2 = QC.translate(
                '',
                '""" set the output variable to pass data to following elements """'
            )
            self.placeholder_3 = QC.translate(
                '',
                '""" set the variable log_txt to adjust the logging text """')
            self.code_input.setPlaceholderText(self.placeholder_1 +
                                               '\r\n\r\n' +
                                               'print(input)\r\n\r\n' +
                                               self.placeholder_2 +
                                               '\r\n\r\n' +
                                               'output = 5\r\n\r\n' +
                                               self.placeholder_3 +
                                               '\r\n\r\n' +
                                               'log_txt = "debug text"')

        if cmd:
            self.custom_editor_cmd.setText(cmd)
        else:
            if os.name == 'nt':
                self.custom_editor_cmd.setPlaceholderText(
                    r'C:\"Program Files (x86)"\Notepad++\notepad++.exe $FILENAME'
                )
            else:
                self.custom_editor_cmd.setPlaceholderText(
                    'gnome-terminal --wait -e "vim $FILENAME"')

        if custom_edit_state:
            self.code_input.setEnabled(False)
            self.custom_editor_cmd.setEnabled(True)
            self.openCustomEditor(cmd, code_input)
        else:
            self.code_input.setEnabled(True)
            self.custom_editor_cmd.setEnabled(False)

    def openCustomEditor(self, cmd, code_input):
        logging.debug('ExecOp::openCustomEditor() called')
        filename = '{}_{}_{}.py'.format(self.row, alphabet[self.column],
                                        int(random.random() * 1e7))
        filename = os.path.join(tempfile.gettempdir(), filename)
        logging.debug(
            'ExecOp::openCustomEditor() filename: {}'.format(filename))

        if cmd:
            try:
                # create new file
                with open(filename, 'w') as f:
                    if code_input:
                        f.write(code_input)
            except Exception as e:
                # not writeable?
                return e

            cmd = cmd.replace('$FILENAME', filename)
        else:
            logging.debug(
                'ExecOp::openCustomEditor() no command specified - returning')
            return

        logging.debug('ExecOp::openCustomEditor() cmd: {}'.format(cmd))
        logging.debug('ExecOp::openCustomEditor() subprocess called')
        edit_proc = QProcess()
        edit_proc.start(cmd)
        edit_proc.waitForFinished(-1)

        logging.debug('ExecOp::openCustomEditor() subprocess ended')

        try:
            # create new file
            with open(filename, 'r') as f:
                code_input = f.read()
        except Exception as e:
            # not writeable?
            return e

        self.code_input.setPlainText(code_input)
        logging.debug('ExecOp::openCustomEditor() removing temporary file')
        os.remove(filename)

    def edit_done(self):
        logging.debug('edit_done() called ExecOp')

        if self.code_input.toPlainText() == '':
            code_input = None
        else:
            code_input = self.code_input.toPlainText()

        if self.custom_editor_cmd.text() == '':
            cmd = None
        else:
            cmd = self.custom_editor_cmd.text()

        custom_edit_state = self.custom_editor_checkbox.isChecked()

        self.config = (self.log_checkbox.isChecked(), code_input,
                       custom_edit_state, cmd)
        self.addFunction(OperationFunction)
        logging.debug('edit_done() 2 called ExecOp')
Esempio n. 10
0
class ConnREST(ElementMaster):

    pixmap_path = 'images/ConnREST.png'
    child_pos = (True, False)

    def __init__(self, row, column):
        self.row = row
        self.column = column

        # pass_input, url, log_state

        pass_input = False
        url = None
        log_state = False

        self.config = pass_input, url, log_state

        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config)
        super().edit_sig.connect(self.edit)
        logging.debug(
            'ConnREST::__init__() called at row {}, column {}'.format(
                row, column))
        self.addFunction(ConnRESTFunction)

    def __setstate__(self, state):
        logging.debug('ConnREST::__setstate__() called')
        self.row, self.column, self.config = state
        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config)
        super().edit_sig.connect(self.edit)
        self.addFunction(ConnRESTFunction)

    def __getstate__(self):
        logging.debug('ConnREST::__getstate__() called')
        return (self.row, self.column, self.config)

    def openEditor(self):
        logging.debug('ConnREST::openEditor() called')

    def edit(self):

        logging.debug('ConnREST::edit()')

        self.conn_rest_layout = QVBoxLayout()
        self.confirm_button = QPushButton(QC.translate('', 'Ok'))

        self.pass_input_line = QWidget()
        self.pass_input_txt = QLabel()
        self.pass_input_txt.setText(
            QC.translate('', 'Use input string as URL?'))
        self.pass_input_check = QCheckBox()
        self.pass_input_line_layout = QHBoxLayout(self.pass_input_line)
        self.pass_input_line_layout.addWidget(self.pass_input_txt)
        self.pass_input_line_layout.addWidget(self.pass_input_check)
        self.pass_input_line_layout.addStretch(1)

        self.url_address_txt = QLabel()
        self.url_address_txt.setText(QC.translate('', 'URL:'))
        self.url_address_input = QLineEdit()
        self.url_address_input.setPlaceholderText(
            QC.translate('', 'https://www.bitstamp.net/api/ticker/'))

        self.help_text_1 = QLabel()
        self.help_text_1.setText(
            QC.translate('',
                         'GET answer is transformed to Python list object'))

        # hier logging option einfügen
        self.log_line = QWidget()
        self.ask_for_logging = QLabel()
        self.ask_for_logging.setText(QC.translate('', 'Log output?'))
        self.log_checkbox = QCheckBox()
        self.log_line_layout = QHBoxLayout(self.log_line)
        self.log_line_layout.addWidget(self.ask_for_logging)
        self.log_line_layout.addWidget(self.log_checkbox)
        self.log_line_layout.addStretch(1)

        self.conn_mail_edit = ElementEditor(self)
        self.conn_mail_edit.setWindowTitle(QC.translate('', 'REST (GET)'))

        # signals and slots
        self.confirm_button.clicked.connect(self.conn_mail_edit.closeEvent)
        self.conn_mail_edit.window_closed.connect(self.edit_done)
        self.pass_input_check.stateChanged.connect(self.toggle_url_input)

        # load config
        self.loadLastConfig()

        self.conn_rest_layout.addWidget(self.pass_input_line)
        self.conn_rest_layout.addWidget(self.url_address_txt)
        self.conn_rest_layout.addWidget(self.url_address_input)
        self.conn_rest_layout.addWidget(self.help_text_1)
        self.conn_rest_layout.addWidget(self.log_line)
        self.conn_rest_layout.addWidget(self.confirm_button)
        self.conn_mail_edit.setLayout(self.conn_rest_layout)
        self.conn_mail_edit.show()

    def loadLastConfig(self):

        logging.debug('ConnREST::loadLastConfig() called')
        # pass_input, url, log_state
        pass_input, url, log_state = self.config

        self.pass_input_check.setChecked(pass_input)
        self.log_checkbox.setChecked(log_state)

        if url:
            self.url_address_input.setText(url)

    def toggle_url_input(self, event):

        logging.debug('ConnREST::toggle_url_input() called')
        if event == 0:
            self.url_address_input.setDisabled(False)
        else:
            self.url_address_input.setDisabled(True)

    def edit_done(self):

        logging.debug('ConnREST::edit_done() called')

        # pass_input, url, log_state

        pass_input = self.pass_input_check.isChecked()
        url = self.url_address_input.text()
        log_state = self.log_checkbox.isChecked()

        self.config = pass_input, url, log_state
        logging.debug('########CONFIG: {}'.format(self.config))

        self.addFunction(ConnRESTFunction)
Esempio n. 11
0
class BinanceSched(ElementMaster):

    pixmap_path = 'images/BinanceSched.png'
    child_pos = (True, False)

    def __init__(self, row, column):
        self.row = row
        self.column = column

        interval_str = '1m'
        interval_index = 0
        offset = 0
        log_state = False

        # interval-str, inteval-index, offset, log-state
        self.config = (interval_str, interval_index, offset, log_state)

        # self_sync = True (last True)
        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config, True)
        super().edit_sig.connect(self.edit)
        logging.debug('BinanceSched called at row {}, column {}'.format(
            row, column))
        self.addFunction(BinanceScheduler)

    def __setstate__(self, state):
        logging.debug('__setstate__() called BinanceSched')
        self.row, self.column, self.config = state
        # interval-str, inteval-index, offset, log-state
        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config, True)
        super().edit_sig.connect(self.edit)
        self.addFunction(BinanceScheduler)

    def __getstate__(self):
        logging.debug('__getstate__() called BinanceSched')
        return (self.row, self.column, self.config)

    def openEditor(self):
        logging.debug('openEditor() called BinanceSched')

    def edit(self):

        logging.debug('edit() called BinanceSched')

        interval_str, interval_index, offset, log_state = self.config

        self.binance_sched_layout = QVBoxLayout()
        self.confirm_button = QPushButton(QC.translate('', 'Ok'))

        self.interval_txt = QLabel()
        self.interval_txt.setText(
            QC.translate('', 'Choose the scheduler interval'))

        # https://github.com/sammchardy/python-binance/blob/master/binance/client.py
        self.selectInterval = QComboBox()
        self.selectInterval.addItem(QC.translate('', '1 Minute'),
                                    QVariant('1m'))
        self.selectInterval.addItem(QC.translate('', '3 Minutes'),
                                    QVariant('3m'))
        self.selectInterval.addItem(QC.translate('', '5 Minutes'),
                                    QVariant('5m'))
        self.selectInterval.addItem(QC.translate('', '15 Minutes'),
                                    QVariant('15m'))
        self.selectInterval.addItem(QC.translate('', '30 Minutes'),
                                    QVariant('30m'))
        self.selectInterval.addItem(QC.translate('', '1 Hour'), QVariant('1h'))
        self.selectInterval.addItem(QC.translate('', '2 Hours'),
                                    QVariant('2h'))
        self.selectInterval.addItem(QC.translate('', '4 Hours'),
                                    QVariant('4h'))
        self.selectInterval.addItem(QC.translate('', '6 Hours'),
                                    QVariant('6h'))
        self.selectInterval.addItem(QC.translate('', '8 Hours'),
                                    QVariant('8h'))
        self.selectInterval.addItem(QC.translate('', '12 Hours'),
                                    QVariant('12h'))
        self.selectInterval.addItem(QC.translate('', '1 Day'), QVariant('1d'))
        self.selectInterval.setCurrentIndex(interval_index)

        self.offset_txt = QLabel()
        self.offset_txt.setText(
            QC.translate(
                '',
                'Enter time offset [s] (default: 0; range: -999s to + 999s)'))

        self.offset_input = QLineEdit()
        self.offset_input.setValidator(QIntValidator(-999, 999))
        self.offset_input.setText(str(offset))

        self.help_text = QWidget()
        self.help_text_layout = QVBoxLayout(self.help_text)

        self.help_text_1 = QLabel()
        self.help_text_1.setText(
            QC.translate(
                '', 'Synchronize with Binance and execute subsequent modules'))

        self.help_text_2 = QLabel()
        self.help_text_2.setText(
            QC.translate('', 'after expiration of the selected interval.'))

        self.help_text_layout.addWidget(self.help_text_1)
        self.help_text_layout.addWidget(self.help_text_2)

        self.log_line = QWidget()
        self.ask_for_logging = QLabel()
        self.ask_for_logging.setText(QC.translate('', 'Log output?'))
        self.log_checkbox = QCheckBox()
        self.log_line_layout = QHBoxLayout(self.log_line)
        self.log_line_layout.addWidget(self.ask_for_logging)
        self.log_line_layout.addWidget(self.log_checkbox)
        self.log_line_layout.addStretch(1)

        if log_state:
            self.log_checkbox.setChecked(True)

        self.binance_sched_edit = ElementEditor(self)
        self.binance_sched_edit.setWindowTitle(
            QC.translate('', 'Edit Binance Scheduler'))

        # signals and slots
        self.confirm_button.clicked.connect(self.binance_sched_edit.closeEvent)
        self.binance_sched_edit.window_closed.connect(self.edit_done)

        self.binance_sched_layout.addWidget(self.interval_txt)
        self.binance_sched_layout.addWidget(self.selectInterval)
        self.binance_sched_layout.addWidget(self.offset_txt)
        self.binance_sched_layout.addWidget(self.offset_input)
        self.binance_sched_layout.addWidget(self.log_line)
        self.binance_sched_layout.addWidget(self.help_text)
        self.binance_sched_layout.addStretch(1)
        self.binance_sched_layout.addWidget(self.confirm_button)
        self.binance_sched_edit.setLayout(self.binance_sched_layout)
        self.binance_sched_edit.show()

    def edit_done(self):

        logging.debug('edit_done() called BinanceSched')

        interval_str = self.selectInterval.currentData()
        interval_index = self.selectInterval.currentIndex()
        log_state = self.log_checkbox.isChecked()
        try:
            offset = int(self.offset_input.text())
        except Exception as e:
            offset = 0

        # interval-str, inteval-index, offset, log-state
        self.config = (interval_str, interval_index, offset, log_state)

        self.addFunction(BinanceScheduler)
Esempio n. 12
0
class ExecSched(ElementMaster):

    pixmap_path = 'images/ExecSched.png'
    child_pos = (True, False)

    def __init__(self, row, column):
        self.row = row
        self.column = column

        mode_index = 0
        mode_data = None
        log_state = False

        # interval-str, inteval-index, offset, log-state
        self.config = (mode_index, mode_data, log_state)

        # self_sync = True
        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config, True)
        super().edit_sig.connect(self.edit)
        logging.debug(
            'ExecSched::__init__() called at row {}, column {}'.format(
                row, column))
        self.addFunction(BasicScheduler)

    def __setstate__(self, state):
        logging.debug('ExecSched::__setstate__() called')
        self.row, self.column, self.config = state
        # self-self_sync = True
        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config, True)
        super().edit_sig.connect(self.edit)
        self.addFunction(BasicScheduler)

    def __getstate__(self):
        logging.debug('ExecSched::__getstate__() called')
        return (self.row, self.column, self.config)

    def openEditor(self):
        logging.debug('ExecSched::openEditor() called')

    def edit(self):

        logging.debug('ExecSched::edit() called')

        self.basic_sched_layout = QVBoxLayout()
        self.confirm_button = QPushButton(QC.translate('', 'Ok'))

        self.sched_txt = QLabel()
        self.sched_txt.setText(QC.translate('', 'Choose the scheduler mode'))

        self.selectMode = QComboBox()
        self.selectMode.addItem(QC.translate('', 'None'), QVariant('none'))
        self.selectMode.addItem(QC.translate('', 'Interval'),
                                QVariant('interval'))
        self.selectMode.addItem(QC.translate('', 'Interval between times'),
                                QVariant('time_between'))
        self.selectMode.addItem(QC.translate('', 'At specific time'),
                                QVariant('time'))
        self.selectMode.addItem(QC.translate('', 'On every full interval'),
                                QVariant('time'))
        self.selectMode.addItem(
            QC.translate('', 'Full interval between times'), QVariant('time'))

        self.options_box = QWidget()
        self.options_box_layout = QVBoxLayout(self.options_box)
        self.interval()
        self.at_time()
        self.time_between()
        self.on_weekdays()
        self.full_interval()

        self.help_text_1 = QLabel()
        self.help_text_1.setText(
            QC.translate('',
                         'Start subsequent actions after your requirements.'))

        self.log_line = QWidget()
        self.ask_for_logging = QLabel()
        self.ask_for_logging.setText(QC.translate('', 'Log output?'))
        self.log_checkbox = QCheckBox()
        self.log_line_layout = QHBoxLayout(self.log_line)
        self.log_line_layout.addWidget(self.ask_for_logging)
        self.log_line_layout.addWidget(self.log_checkbox)
        self.log_line_layout.addStretch(1)

        # load config
        self.loadLastConfig(self.config)

        #self.selectMode.setCurrentIndex(mode_index)
        #self.selectMode.setCurrentIndex(1) #anpassen

        self.basic_sched_edit = ElementEditor(self)
        self.basic_sched_edit.setWindowTitle(
            QC.translate('', 'Edit Basic Scheduler'))
        self.basic_sched_edit.setMinimumHeight(580)

        # signals and slots
        self.confirm_button.clicked.connect(self.basic_sched_edit.closeEvent)
        self.basic_sched_edit.window_closed.connect(self.edit_done)
        self.selectMode.currentIndexChanged.connect(self.indexChanged)

        self.basic_sched_layout.addWidget(self.sched_txt)
        self.basic_sched_layout.addWidget(self.selectMode)
        self.basic_sched_layout.addWidget(self.options_box)

        self.basic_sched_layout.addWidget(self.log_line)
        self.basic_sched_layout.addStretch(1)
        self.basic_sched_layout.addWidget(self.help_text_1)
        self.basic_sched_layout.addWidget(self.confirm_button)
        self.basic_sched_edit.setLayout(self.basic_sched_layout)
        self.basic_sched_edit.show()

    def at_time(self):

        logging.debug('at_time() called')

        self.at_time_input = QWidget()
        self.at_time_layout = QVBoxLayout(self.at_time_input)

        self.time_text = QLabel()
        self.time_text.setText(QC.translate('', 'At:'))

        self.time_input = QLineEdit()
        regexp_validator = QRegExp('^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$')
        self.time_validator = QRegExpValidator(regexp_validator)
        self.time_input.setValidator(self.time_validator)
        self.time_input.setPlaceholderText(QC.translate('', 'hh:mm'))

        self.at_time_layout.addWidget(self.time_text)
        self.at_time_layout.addWidget(self.time_input)

        self.at_time_input.hide()
        self.options_box_layout.addWidget(self.at_time_input)

    def on_weekdays(self):

        logging.debug('on_weekdays() called')

        self.on_weekdays_input = QWidget()
        self.on_weekdays_layout = QVBoxLayout(self.on_weekdays_input)

        self.weekday_txt = QLabel()
        self.weekday_txt.setText(QC.translate('', 'On:'))

        self.check_monday = QCheckBox()
        self.check_tuesday = QCheckBox()
        self.check_wednesday = QCheckBox()
        self.check_thursday = QCheckBox()
        self.check_friday = QCheckBox()
        self.check_saturday = QCheckBox()
        self.check_sunday = QCheckBox()

        self.txt_monday = QLabel()
        self.txt_tuesday = QLabel()
        self.txt_wednesday = QLabel()
        self.txt_thursday = QLabel()
        self.txt_friday = QLabel()
        self.txt_saturday = QLabel()
        self.txt_sunday = QLabel()

        self.txt_monday.setText(QC.translate('', 'Monday'))
        self.txt_tuesday.setText(QC.translate('', 'Tuesday'))
        self.txt_wednesday.setText(QC.translate('', 'Wednesday'))
        self.txt_thursday.setText(QC.translate('', 'Thursday'))
        self.txt_friday.setText(QC.translate('', 'Friday'))
        self.txt_saturday.setText(QC.translate('', 'Saturday'))
        self.txt_sunday.setText(QC.translate('', 'Sunday'))

        self.mon_tue_wed = QWidget()
        self.mon_tue_wed_layout = QHBoxLayout(self.mon_tue_wed)
        self.mon_tue_wed_layout.addWidget(self.txt_monday)
        self.mon_tue_wed_layout.addWidget(self.check_monday)
        self.mon_tue_wed_layout.addWidget(self.txt_tuesday)
        self.mon_tue_wed_layout.addWidget(self.check_tuesday)
        self.mon_tue_wed_layout.addWidget(self.txt_wednesday)
        self.mon_tue_wed_layout.addWidget(self.check_wednesday)
        self.mon_tue_wed_layout.addStretch(1)

        self.thu_fri_sat = QWidget()
        self.thu_fri_sat_layout = QHBoxLayout(self.thu_fri_sat)
        self.thu_fri_sat_layout.addWidget(self.txt_thursday)
        self.thu_fri_sat_layout.addWidget(self.check_thursday)
        self.thu_fri_sat_layout.addWidget(self.txt_friday)
        self.thu_fri_sat_layout.addWidget(self.check_friday)
        self.thu_fri_sat_layout.addWidget(self.txt_saturday)
        self.thu_fri_sat_layout.addWidget(self.check_saturday)
        self.thu_fri_sat_layout.addStretch(1)

        self.sun = QWidget()
        self.sun_layout = QHBoxLayout(self.sun)
        self.sun_layout.addWidget(self.txt_sunday)
        self.sun_layout.addWidget(self.check_sunday)
        self.sun_layout.addStretch(1)

        self.on_weekdays_layout.addWidget(self.weekday_txt)
        self.on_weekdays_layout.addWidget(self.mon_tue_wed)
        self.on_weekdays_layout.addWidget(self.thu_fri_sat)
        self.on_weekdays_layout.addWidget(self.sun)

        self.on_weekdays_input.hide()

        self.options_box_layout.addWidget(self.on_weekdays_input)

    def interval(self):

        logging.debug('interval() called')

        self.interval_input = QWidget()
        self.interval_layout = QVBoxLayout(self.interval_input)

        self.time_base_input_line = QWidget()
        self.time_base_input_layout = QHBoxLayout(self.time_base_input_line)

        self.interval_txt = QLabel()
        self.interval_txt.setText(QC.translate('', 'Every'))

        self.repeat_val_input = QLineEdit()
        self.repeat_val_input.setValidator(QIntValidator(1, 9999))
        self.repeat_val_input.setText('1')

        self.time_base_input = QComboBox()
        self.time_base_input.addItem(QC.translate('', 'Seconds'),
                                     QVariant('sec'))
        self.time_base_input.addItem(QC.translate('', 'Minutes'),
                                     QVariant('min'))
        self.time_base_input.addItem(QC.translate('', 'Hours'),
                                     QVariant('hour'))

        self.time_base_input_layout.addWidget(self.repeat_val_input)
        self.time_base_input_layout.addWidget(self.time_base_input)

        self.interval_layout.addWidget(self.interval_txt)
        self.interval_layout.addWidget(self.time_base_input_line)

        self.interval_input.hide()

        self.options_box_layout.addWidget(self.interval_input)

    def full_interval(self):

        logging.debug('full_interval() called')

        self.full_interval_input = QWidget()
        self.full_interval_layout = QVBoxLayout(self.full_interval_input)

        self.description_1 = QLabel()
        self.description_1.setText(
            QC.translate(
                '', 'For instance a 15 minute interval executes every full'))

        self.description_2 = QLabel()
        self.description_2.setText(
            QC.translate('', '15 minutes: 10:00, 10:15, 10:30, 10:45, ...'))

        self.full_interval_layout.addWidget(self.description_1)
        self.full_interval_layout.addWidget(self.description_2)

        self.full_interval_input.hide()

        self.options_box_layout.addWidget(self.full_interval_input)

    def time_between(self):

        logging.debug('time_between() called')
        self.time_between_input = QWidget()
        self.time_between_layout = QVBoxLayout(self.time_between_input)

        self.time_between_txt = QLabel()
        self.time_between_txt.setText(QC.translate('', 'Between'))

        regexp_validator = QRegExp('^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$')
        self.time_validator = QRegExpValidator(regexp_validator)

        self.time_row = QWidget()
        self.time_row_layout = QHBoxLayout(self.time_row)

        self.start_time_input = QLineEdit()
        self.start_time_input.setValidator(self.time_validator)
        self.start_time_input.setPlaceholderText(
            QC.translate('', 'hh:mm (default 00:00)'))

        self.and_text = QLabel()
        self.and_text.setText(QC.translate('', 'and'))

        self.stop_time_input = QLineEdit()
        self.stop_time_input.setValidator(self.time_validator)
        self.stop_time_input.setPlaceholderText(
            QC.translate('', 'hh:mm (default 00:00)'))

        self.time_row_layout.addWidget(self.start_time_input)
        self.time_row_layout.addWidget(self.and_text)
        self.time_row_layout.addWidget(self.stop_time_input)

        self.time_between_layout.addWidget(self.time_between_txt)
        self.time_between_layout.addWidget(self.time_row)

        self.time_between_input.hide()

        self.options_box_layout.addWidget(self.time_between_input)

    def indexChanged(self, event):

        current_index = event
        logging.debug('indexChanged() called {}'.format(current_index))

        if current_index == 0:  # None
            self.interval_input.hide()
            self.at_time_input.hide()
            self.time_between_input.hide()
            self.on_weekdays_input.hide()
            self.full_interval_input.hide()
        if current_index == 1:  # Interval
            self.interval_input.show()
            self.at_time_input.hide()
            self.time_between_input.hide()
            self.on_weekdays_input.hide()
            self.full_interval_input.hide()
        elif current_index == 2:  # Interval between times
            self.interval_input.show()
            self.time_between_input.show()
            self.on_weekdays_input.show()
            self.at_time_input.hide()
            self.full_interval_input.hide()
        elif current_index == 3:  # At specific time
            self.time_between_input.hide()
            self.at_time_input.show()
            self.on_weekdays_input.show()
            self.interval_input.hide()
            self.full_interval_input.hide()
        elif current_index == 4:  # full interval
            self.time_between_input.hide()
            self.at_time_input.hide()
            self.on_weekdays_input.hide()
            self.interval_input.show()
            self.full_interval_input.show()
        elif current_index == 5:  # full interval between times
            self.interval_input.show()
            self.time_between_input.show()
            self.on_weekdays_input.show()
            self.at_time_input.hide()
            self.full_interval_input.show()

    def loadLastConfig(self, config):

        mode_index, mode_data, log_state = self.config
        logging.debug(
            'loadLastConfig() called with mode_index = {}'.format(mode_index))

        if log_state:
            self.log_checkbox.setChecked(True)

        self.indexChanged(mode_index)
        self.selectMode.setCurrentIndex(mode_index)

        if not mode_data == None:

            if mode_index == 1 or mode_index == 4:  # Interval or full interval
                repeat_val, time_base = mode_data

                self.repeat_val_input.setText(repeat_val)
                self.time_base_input.setCurrentIndex(time_base)

            # Interval between times or full interval between times
            elif mode_index == 2 or mode_index == 5:

                repeat_val, time_base, start_time, stop_time, active_days = mode_data

                self.repeat_val_input.setText(repeat_val)
                self.time_base_input.setCurrentIndex(time_base)

                self.start_time_input.setText('{:02d}:{:02d}'.format(
                    start_time[0], start_time[1]))
                self.stop_time_input.setText('{:02d}:{:02d}'.format(
                    stop_time[0], stop_time[1]))

                self.set_days(active_days)

            elif mode_index == 3:  # At specific time

                time_input, active_days = mode_data

                self.time_input.setText('{:02d}:{:02d}'.format(
                    time_input[0], time_input[1]))

                self.set_days(active_days)

    def parse_time(self, time_input):

        if not time_input == '':
            try:
                hour, minute = time_input.split(':')
                hour = int(hour)
                minute = int(minute)
            except Exception as e:
                hour = int(time_input)
                minute = 0
        else:
            hour = 0
            minute = 0

        return (hour, minute)

    def get_days(self):

        logging.debug('get_days() called')

        check_monday = self.check_monday.isChecked()
        check_tuesday = self.check_tuesday.isChecked()
        check_wednesday = self.check_wednesday.isChecked()
        check_thursday = self.check_thursday.isChecked()
        check_friday = self.check_friday.isChecked()
        check_saturday = self.check_saturday.isChecked()
        check_sunday = self.check_sunday.isChecked()

        logging.debug(
            'Mon {}, Tue {}, Wed {}, Thu {}, Fri {}, Sat {}, Sun {}'.format(
                check_monday, check_tuesday, check_wednesday, check_thursday,
                check_friday, check_saturday, check_sunday))

        return (check_monday, check_tuesday, check_wednesday, check_thursday,
                check_friday, check_saturday, check_sunday)

    def set_days(self, active_days):

        self.check_monday.setChecked(active_days[0])
        self.check_tuesday.setChecked(active_days[1])
        self.check_wednesday.setChecked(active_days[2])
        self.check_thursday.setChecked(active_days[3])
        self.check_friday.setChecked(active_days[4])
        self.check_saturday.setChecked(active_days[5])
        self.check_sunday.setChecked(active_days[6])

    def edit_done(self):

        mode_index = self.selectMode.currentIndex()
        log_state = self.log_checkbox.isChecked()
        logging.debug('edit_done() called BinanceSched, mode-index {}'.format(
            mode_index))
        # mode-index, mode-data, log_state

        if mode_index == 0:  # None

            mode_data = None

        elif mode_index == 1 or mode_index == 4:  #Interval or full interval

            logging.debug('mode_index = 1 or 4')
            repeat_val = self.repeat_val_input.text()
            time_base = self.time_base_input.currentIndex()
            # 0 = Seconds
            # 1 = Minutes
            # 2 = Hours

            mode_data = (repeat_val, time_base)

        elif mode_index == 2 or mode_index == 5:  # Interval between times or full interval between times

            logging.debug('mode_index = 2')

            repeat_val = self.repeat_val_input.text()
            time_base = self.time_base_input.currentIndex()
            # 0 = Seconds
            # 1 = Minutes
            # 2 = Hours
            start_time_input = self.start_time_input.text()
            start_time = self.parse_time(start_time_input)

            logging.debug('Start hour {} - Start minute {}'.format(
                start_time[0], start_time[1]))

            stop_time_input = self.stop_time_input.text()
            stop_time = self.parse_time(stop_time_input)

            logging.debug('Stop hour {} - Stop minute {}'.format(
                stop_time[0], stop_time[1]))

            active_days = self.get_days()

            mode_data = (repeat_val, time_base, start_time, stop_time,
                         active_days)

        elif mode_index == 3:  # At specific time
            logging.debug('mode_index = 3')

            time_input = self.time_input.text()
            time_input = self.parse_time(time_input)

            logging.debug('Hour {} - Minute {}'.format(time_input[0],
                                                       time_input[1]))
            active_days = self.get_days()

            mode_data = (time_input, active_days)

        self.config = (mode_index, mode_data, log_state)

        self.addFunction(BasicScheduler)
Esempio n. 13
0
class ConnMail(ElementMaster):

    pixmap_path = 'images/ConnMail.png'
    child_pos = (True, False)

    def __init__(self, row, column):
        self.row = row
        self.column = column

        recipient = None
        sender = None
        password = None
        server_url = None
        server_port = '465'
        subject = None
        input_opt_index = 0
        input_opt_data = None
        filename = None
        pass_input = False
        message_state = False
        message_txt = None
        log_state = False

        # recipient, sender, password, server_url, server_port, subject
        # input_opt_index, input_opt_data, filename, pass_input, message_state, message_txt, log_state
        self.config = (recipient, sender, password, server_url, server_port,
                       subject, input_opt_index, input_opt_data, filename,
                       pass_input, message_state, message_txt, log_state)

        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config)
        super().edit_sig.connect(self.edit)
        logging.debug(
            'ConnMail::__init__() called at row {}, column {}'.format(
                row, column))
        self.addFunction(ConnMailFunction)

    def __setstate__(self, state):
        logging.debug('ConnMail::__setstate__() called')
        self.row, self.column, self.config = state
        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config)
        super().edit_sig.connect(self.edit)
        self.addFunction(ConnMailFunction)

    def __getstate__(self):
        logging.debug('ConnMail__getstate__() called')
        return (self.row, self.column, self.config)

    def openEditor(self):
        logging.debug('ConnMail::openEditor() called')

    def edit(self):

        logging.debug('ConnMail::edit()')

        self.conn_mail_layout = QVBoxLayout()
        self.confirm_button = QPushButton(QC.translate('', 'Ok'))

        self.recipient_address_txt = QLabel()
        self.recipient_address_txt.setText(
            QC.translate('', 'Recipient address:'))
        self.recipient_address_input = QLineEdit()
        self.recipient_address_input.setPlaceholderText(
            QC.translate('', 'Separate addresses with spaces'))

        self.sender_address_txt = QLabel()
        self.sender_address_txt.setText(
            QC.translate('', 'Enter sender address:'))
        self.sender_address_input = QLineEdit()
        self.sender_address_input.setPlaceholderText(
            QC.translate('', '*****@*****.**'))

        self.password_txt = QLabel()
        self.password_txt.setText(QC.translate('', 'Enter password:'******'', 'Enter subject:'))
        self.subject_input = QLineEdit()

        self.server_txt = QLabel()
        self.server_txt.setText(
            QC.translate('', 'Enter server URL and port number:'))

        self.server_input_line = QWidget()
        self.server_input_line_layout = QHBoxLayout(self.server_input_line)
        self.server_url_input = QLineEdit()
        self.server_url_input.setPlaceholderText(
            QC.translate('', 'e.g. smtp.gmail.com'))
        self.server_port_input = QLineEdit()
        self.server_port_input.setMaximumWidth(50)
        self.server_port_input.setValidator(QIntValidator(0, 9999))
        self.server_port_input.setText('465')
        self.server_input_line_layout.addWidget(self.server_url_input)
        self.server_input_line_layout.addWidget(self.server_port_input)

        self.message_box_line = QWidget()
        self.message_box_txt = QLabel()
        self.message_box_txt.setText(
            QC.translate('', 'Activate user defined message text?'))
        self.message_box_checkbox = QCheckBox()
        self.message_box_line_layout = QHBoxLayout(self.message_box_line)
        self.message_box_line_layout.addWidget(self.message_box_txt)
        self.message_box_line_layout.addWidget(self.message_box_checkbox)
        self.message_box_line_layout = QHBoxLayout(self.message_box_line)

        self.message_txt_input = QTextEdit()

        self.input_option_line = QWidget()
        self.input_option_txt = QLabel()
        self.input_option_txt.setText(QC.translate('', 'Use input as:'))
        self.input_options = QComboBox()
        self.input_options.addItem(QC.translate('', 'None'))
        self.input_options.addItem(QC.translate('', 'Message text'))
        self.input_options.addItem(QC.translate('', 'Attachment (String)'))
        self.input_options.addItem(QC.translate('', 'Attachment (Pickle)'))
        self.input_option_line_layout = QHBoxLayout(self.input_option_line)
        self.input_option_line_layout.addWidget(self.input_option_txt)
        self.input_option_line_layout.addWidget(self.input_options)

        self.filename_input_line = QWidget()
        self.filename_input_line_layout = QHBoxLayout(self.filename_input_line)
        self.filename_input_txt = QLabel()
        self.filename_input_txt.setText(QC.translate('', 'Filename:'))
        self.filename_input = QLineEdit()
        self.filename_input.setPlaceholderText(QC.translate(
            '', 'filename.txt'))
        self.filename_input_line_layout.addWidget(self.filename_input_txt)
        self.filename_input_line_layout.addWidget(self.filename_input)

        self.input_params_1 = QLabel()
        self.input_params_1.setText(
            QC.translate('', 'Note: Input configuration dict has priority'))
        self.input_params_2 = QLabel()
        self.input_params_2.setText(
            '{\'subject\' : \'Hello\', \'message\' : \'World!\'}')

        self.pass_input_line = QWidget()
        self.pass_input_txt = QLabel()
        self.pass_input_txt.setText(QC.translate('', 'Pass input forward?'))
        self.pass_input_check = QCheckBox()
        self.pass_input_line_layout = QHBoxLayout(self.pass_input_line)
        self.pass_input_line_layout.addWidget(self.pass_input_txt)
        self.pass_input_line_layout.addWidget(self.pass_input_check)

        self.help_txt = QLabel()
        self.help_txt.setText(
            QC.translate('', 'Only encrypted connections are allowed'))

        # hier logging option einfügen
        self.log_line = QWidget()
        self.ask_for_logging = QLabel()
        self.ask_for_logging.setText(QC.translate('', 'Log output?'))
        self.log_checkbox = QCheckBox()
        self.log_line_layout = QHBoxLayout(self.log_line)
        self.log_line_layout.addWidget(self.ask_for_logging)
        self.log_line_layout.addWidget(self.log_checkbox)
        self.log_line_layout.addStretch(1)

        self.conn_mail_edit = ElementEditor(self)
        self.conn_mail_edit.setWindowTitle(QC.translate('', 'Send E-Mail'))
        #self.conn_mail_edit.setMinimumSize(240, 330)

        # signals and slots
        self.confirm_button.clicked.connect(self.conn_mail_edit.closeEvent)
        self.conn_mail_edit.window_closed.connect(self.edit_done)
        self.message_box_checkbox.stateChanged.connect(self.toggle_message_box)
        self.input_options.currentIndexChanged.connect(self.indexChanged)
        # load existing config
        self.loadLastConfig()

        self.conn_mail_layout.addWidget(self.recipient_address_txt)
        self.conn_mail_layout.addWidget(self.recipient_address_input)
        self.conn_mail_layout.addWidget(self.sender_address_txt)
        self.conn_mail_layout.addWidget(self.sender_address_input)
        self.conn_mail_layout.addWidget(self.password_txt)
        self.conn_mail_layout.addWidget(self.password_input)
        self.conn_mail_layout.addWidget(self.server_txt)
        self.conn_mail_layout.addWidget(self.server_input_line)
        self.conn_mail_layout.addWidget(self.subject_txt)
        self.conn_mail_layout.addWidget(self.subject_input)
        self.conn_mail_layout.addWidget(self.message_box_line)
        self.conn_mail_layout.addWidget(self.message_txt_input)
        self.conn_mail_layout.addWidget(self.input_option_line)
        self.conn_mail_layout.addWidget(self.filename_input_line)
        self.conn_mail_layout.addWidget(self.input_params_1)
        self.conn_mail_layout.addWidget(self.input_params_2)
        self.conn_mail_layout.addWidget(self.pass_input_line)

        self.conn_mail_layout.addWidget(self.help_txt)
        self.conn_mail_layout.addWidget(self.log_line)
        self.conn_mail_layout.addWidget(self.confirm_button)
        self.conn_mail_edit.setLayout(self.conn_mail_layout)
        self.conn_mail_edit.show()

    def toggle_message_box(self, event):

        logging.debug('ConnMail::toggle_message_box() called')
        if event == 0:
            self.message_txt_input.setDisabled(True)
        else:
            self.message_txt_input.setDisabled(False)

    def indexChanged(self, event):

        current_index = event
        logging.debug('ConnMail::indexChanged() called: {}'.format(event))
        if event == 2 or event == 3:
            self.filename_input_line.setVisible(True)
        else:
            self.filename_input_line.setVisible(False)

    def loadLastConfig(self):

        # recipient, sender, password, server_url, server_port, subject
        # input_opt_index, input_opt_data, filename, pass_input, message_state, log_state

        recipient, sender, password, server_url, server_port, subject, \
                input_opt_index, input_opt_data, filename, pass_input, message_state, \
                message_txt, log_state = self.config

        if message_state:
            self.toggle_message_box(2)
            self.message_box_checkbox.setChecked(True)
        else:
            self.toggle_message_box(0)
            self.message_box_checkbox.setChecked(False)

        if pass_input:
            self.pass_input_check.setChecked(True)
        else:
            self.pass_input_check.setChecked(False)

        if recipient:
            self.recipient_address_input.setText(recipient)

        if sender:
            self.sender_address_input.setText(sender)

        if password:
            self.password_input.setText(password)

        if server_url:
            self.server_url_input.setText(server_url)

        if server_port:
            self.server_port_input.setText(server_port)

        if subject:
            self.subject_input.setText(subject)

        if message_txt:
            self.message_txt_input.setPlainText(message_txt)

        if filename:
            self.filename_input.setText(filename)

        if log_state:
            self.log_checkbox.setChecked(True)
        else:
            self.log_checkbox.setChecked(False)

        self.input_options.setCurrentIndex(input_opt_index)
        self.indexChanged(input_opt_index)

    def edit_done(self):

        logging.debug('ConnMail::edit_done() called')

        recipient = self.recipient_address_input.text()
        sender = self.sender_address_input.text()
        password = self.password_input.text()
        server_url = self.server_url_input.text()
        server_port = self.server_port_input.text()
        subject = self.subject_input.text()
        input_opt_index = self.input_options.currentIndex()
        input_opt_data = self.input_options.currentData()
        filename = self.filename_input.text()

        pass_input = self.pass_input_check.isChecked()
        message_state = self.message_box_checkbox.isChecked()
        log_state = self.log_checkbox.isChecked()

        if self.message_txt_input.toPlainText() == '':
            message_txt = None
        else:
            message_txt = self.message_txt_input.toPlainText()
        # recipient, sender, password, server_url, server_port, subject
        # input_opt_index, input_opt_data, filename, pass_input, message_state, message_txt, log_state
        self.config = (recipient, sender, password, server_url, server_port,
                       subject, input_opt_index, input_opt_data, filename,
                       pass_input, message_state, message_txt, log_state)

        self.addFunction(ConnMailFunction)
Esempio n. 14
0
class ExecReturn(ElementMaster):

    pixmap_path = 'images/ExecReturn.png'
    child_pos = (False, False)

    query_grid_config = pyqtSignal(name='query_grid_config')

    def __init__(self, row, column):
        self.row = row
        self.column = column

        # grid, wrk_selecctor_index, wrk_pos, ischecked
        self.config = (0, 0, (0,0), False)
        super().__init__(self.row, self.column, QPixmap(self.pixmap_path), True, self.config)
        super().edit_sig.connect(self.edit)
        logging.debug('ExecReturn called at row {}, column {}'.format(row, column))

        self.addFunction(ReturnFunction)

    def __setstate__(self, state):
        logging.debug('__setstate__() called ExecReturn')
        self.row, self.column, self.config = state
        super().__init__(self.row, self.column, QPixmap(self.pixmap_path), True, self.config)
        super().edit_sig.connect(self.edit)
        self.addFunction(ReturnFunction)

    def __getstate__(self):
        logging.debug('__getstate__() called ExecReturn')
        return (self.row, self.column, self.config)

    def openEditor(self):
        logging.debug('openEditor() called ExecReturn')


    def edit(self):
        logging.debug('edit() called ExecReturn')
        self.returnEditLayout = QVBoxLayout()

        self.returnEdit = ElementEditor(self)
        self.returnEdit.setWindowTitle(QC.translate('', 'Edit Return'))

        self.grid_text = QLabel()
        self.grid_text.setText(QC.translate('', 'Go to grid:'))

        self.element_text = QLabel()
        self.element_text.setText(QC.translate('', 'Go to element:'))

        self.help_text = QWidget()
        self.help_text_layout = QVBoxLayout(self.help_text)

        self.help_text_1 = QLabel()
        self.help_text_1.setText(QC.translate('', 'Choose an element from the list')) 

        self.help_text_2 = QLabel()
        self.help_text_2.setText(QC.translate('', 'to which you want to return with the'))

        self.help_text_3 = QLabel()
        self.help_text_3.setText(QC.translate('', 'current input'))

        self.help_text_layout.addWidget(self.help_text_1)
        self.help_text_layout.addWidget(self.help_text_2)
        self.help_text_layout.addWidget(self.help_text_3)


        self.confirm_button = QPushButton(QC.translate('', 'Ok'))

        # hier logging option einfügen
        self.log_line = QWidget()
        self.ask_for_logging = QLabel()
        self.ask_for_logging.setText(QC.translate('', 'Log output?'))
        self.log_checkbox = QCheckBox()
        self.log_line_layout = QHBoxLayout(self.log_line)
        self.log_line_layout.addWidget(self.ask_for_logging)
        self.log_line_layout.addWidget(self.log_checkbox)
        self.log_line_layout.addStretch(1)


        self.element_selector = QStackedWidget()

        self.grid_selector = QComboBox()

        # emmiting signal
        self.query_grid_config.emit()
        self.grid_selector.currentIndexChanged.connect(self.gridIndexChanged)

        self.loadLastConfig()

        self.confirm_button.clicked.connect(self.returnEdit.closeEvent)
        self.returnEdit.window_closed.connect(self.edit_done)
        self.returnEditLayout.addWidget(self.grid_text)
        self.returnEditLayout.addWidget(self.grid_selector)
        self.returnEditLayout.addWidget(self.element_text)
        self.returnEditLayout.addWidget(self.element_selector)
        self.returnEditLayout.addWidget(self.log_line)
        self.returnEditLayout.addWidget(self.help_text)
        self.returnEditLayout.addStretch(1)
        self.returnEditLayout.addWidget(self.confirm_button)
        self.returnEdit.setLayout(self.returnEditLayout)
        self.returnEdit.show()

    def baustelle(self, config):

        self.wrk_selectors_arr = []

        logging.debug('ExecReturn::baustelle config: {}'.format(config))
        for index, wrk_area in enumerate(config):
            self.grid_selector.addItem('Grid {}'.format(index + 1))

            self.wrk_selectors_arr.append(QComboBox())
            self.element_selector.addWidget(self.wrk_selectors_arr[index])
            for pos in wrk_area:
                self.wrk_selectors_arr[index].addItem('{} {}'.format(pos[0], alphabet[pos[1]]), QVariant(pos))

    def gridIndexChanged(self, index):

        logging.debug('ExecReturn::gridIndexChanged() called: {}'.format(index))
        self.element_selector.setCurrentIndex(index)


    def loadLastConfig(self):

        grid, wrk_selecctor_index, wrk_pos, log_state = self.config

        self.grid_selector.setCurrentIndex(grid)
        self.element_selector.setCurrentIndex(grid)
        self.wrk_selectors_arr[grid].setCurrentIndex(wrk_selecctor_index)
        self.log_checkbox.setChecked(log_state)

    def edit_done(self):
        logging.debug('edit_done() called ExecReturn' )
        grid = self.grid_selector.currentIndex()
        wrk_selecctor_index = self.wrk_selectors_arr[grid].currentIndex()
        wrk_pos = self.wrk_selectors_arr[grid].currentData()

        self.config = (grid, wrk_selecctor_index, wrk_pos, self.log_checkbox.isChecked())
        self.addFunction(ReturnFunction)
Esempio n. 15
0
class BinanceOrder(ElementMaster):

    pixmap_path = 'images/BinanceOrder.png'
    child_pos = (True, False)

    def __init__(self, row, column):
        self.row = row
        self.column = column

        pub_key = None
        prv_key = None
        side_index = 0
        side_txt = 'BUY'
        symbol_txt = None
        quantity = 0.0
        order_index = 0
        order_string = 'MARKET'
        order_config = (0, )
        log_state = False

        self.config = (pub_key, prv_key, side_index, side_txt, symbol_txt, \
                quantity, order_index, order_string, order_config, log_state)

        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config)
        super().edit_sig.connect(self.edit)
        logging.debug(
            'BinanceOrder::__init__() called at row {}, column {}'.format(
                row, column))
        self.addFunction(BinanceOrderFunction)

    def __setstate__(self, state):
        logging.debug('__setstate__() called BinanceOrder')
        self.row, self.column, self.config = state
        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config)
        super().edit_sig.connect(self.edit)
        self.addFunction(BinanceOrderFunction)

    def __getstate__(self):
        logging.debug('BinanceOrder::__getstate__() called')
        return (self.row, self.column, self.config)

    def openEditor(self):
        logging.debug('BinanceOrder::openEditor() called')

    def edit(self):

        logging.debug('BinanceOrder::edit() called')

        pub_key, prv_key, side_index, side_txt, symbol_txt, quantity, \
                order_index, order_string, order_config, log_state = self.config

        self.binance_order_layout = QVBoxLayout()
        self.confirm_button = QPushButton(QC.translate('', 'Ok'))

        self.pub_key_txt = QLabel()
        self.pub_key_txt.setText(QC.translate('', 'Enter API key:'))
        self.pub_key_input = QLineEdit()

        self.prv_key_txt = QLabel()
        self.prv_key_txt.setText(QC.translate('', 'Enter secret key:'))
        self.prv_key_input = QLineEdit()

        self.symbol_txt = QLabel()
        self.symbol_txt.setText(QC.translate('', 'Enter currency pair'))

        self.order_data_line = QWidget()
        self.order_data_layout = QHBoxLayout(self.order_data_line)

        self.order_side = QComboBox()
        self.order_side.addItem(QC.translate('', 'Buy'), QVariant('BUY'))
        self.order_side.addItem(QC.translate('', 'Sell'), QVariant('SELL'))

        self.symbol_input = QLineEdit()
        self.symbol_input.setPlaceholderText(QC.translate('', 'e.g. "XMRBTC"'))

        self.order_data_layout.addWidget(self.order_side)
        self.order_data_layout.addWidget(self.symbol_input)

        self.quantity_txt = QLabel()
        self.quantity_txt.setText(QC.translate('', 'Enter quantity:'))

        if symbol_txt:
            self.symbol_input.setText(symbol_txt)

        self.quantity_input = QLineEdit()
        self.quantity_input.setValidator(QDoubleValidator(999999, -999999, 8))

        self.selectOrder = QComboBox()
        self.selectOrder.addItem(QC.translate('', 'Limit Order'),
                                 QVariant('LIMIT'))
        self.selectOrder.addItem(QC.translate('', 'Market Order'),
                                 QVariant('MARKET'))
        self.selectOrder.addItem(QC.translate('', 'Stop Loss'),
                                 QVariant('STOP_LOSS'))
        self.selectOrder.addItem(QC.translate('', 'Stop Loss Limit'),
                                 QVariant('STOP_LOSS_LIMIT'))
        self.selectOrder.addItem(QC.translate('', 'Take Profit'),
                                 QVariant('TAKE_PROFIT'))
        self.selectOrder.addItem(QC.translate('', 'Take Profit Limit'),
                                 QVariant('TAKE_PROFIT_LIMIT'))
        self.selectOrder.addItem(QC.translate('', 'Limit Maker'),
                                 QVariant('LIMIT_MAKER'))

        self.order_box = QStackedWidget()
        self.limitOrder()
        self.marketOrder()
        self.stopLoss()
        self.stopLossLimit()
        self.takeProfit()
        self.takeProfitLimit()
        self.limitMaker()
        self.loadLastConfig()

        self.help_txt = QLabel()
        self.help_txt.setText(
            QC.translate('',
                         'Attention: Use a dot (".") as decimal seperator!'))

        # hier logging option einfügen
        self.log_line = QWidget()
        self.ask_for_logging = QLabel()
        self.ask_for_logging.setText(QC.translate('', 'Log output?'))
        self.log_checkbox = QCheckBox()
        self.log_line_layout = QHBoxLayout(self.log_line)
        self.log_line_layout.addWidget(self.ask_for_logging)
        self.log_line_layout.addWidget(self.log_checkbox)
        self.log_line_layout.addStretch(1)

        if log_state:
            self.log_checkbox.setChecked(True)

        self.binance_order_edit = ElementEditor(self)
        self.binance_order_edit.setWindowTitle(
            QC.translate('', 'Place a Order'))
        #self.binance_order_edit.setMinimumSize(240, 330)

        # signals and slots
        self.confirm_button.clicked.connect(self.binance_order_edit.closeEvent)
        self.binance_order_edit.window_closed.connect(self.edit_done)
        self.selectOrder.currentIndexChanged.connect(self.indexChanged)

        self.binance_order_layout.addWidget(self.pub_key_txt)
        self.binance_order_layout.addWidget(self.pub_key_input)
        self.binance_order_layout.addWidget(self.prv_key_txt)
        self.binance_order_layout.addWidget(self.prv_key_input)
        self.binance_order_layout.addWidget(self.symbol_txt)
        self.binance_order_layout.addWidget(self.order_data_line)
        self.binance_order_layout.addWidget(self.quantity_txt)
        self.binance_order_layout.addWidget(self.quantity_input)
        self.binance_order_layout.addWidget(self.selectOrder)
        self.binance_order_layout.addStretch(1)
        self.binance_order_layout.addWidget(self.order_box)
        self.binance_order_layout.addWidget(self.help_txt)
        self.binance_order_layout.addWidget(self.log_line)
        self.binance_order_layout.addWidget(self.confirm_button)
        self.binance_order_edit.setLayout(self.binance_order_layout)
        self.binance_order_edit.show()

    def limitOrder(self):

        logging.debug('BinanceOrder::limitOrder() called')

        self.limit_input = QWidget()
        self.limit_layout = QVBoxLayout(self.limit_input)

        self.limit_time_in_force_txt = QLabel()
        self.limit_time_in_force_txt.setText(QC.translate(
            '', 'Time in force:'))

        self.limit_time_in_force_input = QComboBox()
        self.limit_time_in_force_input.addItem(
            QC.translate('', 'Good til canceled'), QVariant('GTC'))
        self.limit_time_in_force_input.addItem(
            QC.translate('', 'Immediate or Cancel'), QVariant('IOC'))
        self.limit_time_in_force_input.addItem(
            QC.translate('', 'Fill or Kill'), QVariant('FOK'))

        self.limit_price_txt = QLabel()
        self.limit_price_txt.setText(QC.translate('', 'Limit price:'))

        self.limit_price_input = QLineEdit()
        self.limit_price_input.setValidator(
            QDoubleValidator(999999, -999999, 8))

        self.limit_input_params = QLabel()
        self.limit_input_params.setText(
            '{\'price\' : 12.345, \'quantity\' : 0.005, \'type\' : \'GTC\'/\'IOC\'/\'FOK\'}'
        )

        self.limit_layout.addWidget(self.limit_time_in_force_txt)
        self.limit_layout.addWidget(self.limit_time_in_force_input)
        self.limit_layout.addWidget(self.limit_price_txt)
        self.limit_layout.addWidget(self.limit_price_input)
        self.limit_layout.addWidget(self.limit_input_params)

        self.order_box.addWidget(self.limit_input)

    def stopLoss(self):

        logging.debug('BinanceOrder::stopLoss() called')

        self.stop_loss_input = QWidget()
        self.stop_loss_layout = QVBoxLayout(self.stop_loss_input)

        self.stop_loss_price_txt = QLabel()
        self.stop_loss_price_txt.setText(QC.translate('', 'Stop price:'))

        self.stop_loss_price_input = QLineEdit()
        self.stop_loss_price_input.setValidator(
            QDoubleValidator(999999, -999999, 8))

        self.stop_loss_params = QLabel()
        self.stop_loss_params.setText(
            '{\'stopPrice\' : 12.345, \'quantity\' : 0.005}')

        self.stop_loss_layout.addWidget(self.stop_loss_price_txt)
        self.stop_loss_layout.addWidget(self.stop_loss_price_input)
        self.stop_loss_layout.addWidget(self.stop_loss_params)
        self.stop_loss_layout.addStretch(1)

        self.order_box.addWidget(self.stop_loss_input)

    def stopLossLimit(self):

        logging.debug('BinanceOrder::stopLossLimit() called')

        self.stop_loss_limit_input = QWidget()
        self.stop_loss_limit_layout = QVBoxLayout(self.stop_loss_limit_input)

        self.stop_loss_limit_time_in_force_txt = QLabel()
        self.stop_loss_limit_time_in_force_txt.setText(
            QC.translate('', 'Time in force:'))

        self.stop_loss_limit_time_in_force_input = QComboBox()
        self.stop_loss_limit_time_in_force_input.addItem(
            QC.translate('', 'Good til canceled'), QVariant('GTC'))
        self.stop_loss_limit_time_in_force_input.addItem(
            QC.translate('', 'Immediate or Cancel'), QVariant('IOC'))
        self.stop_loss_limit_time_in_force_input.addItem(
            QC.translate('', 'Fill or Kill'), QVariant('FOK'))

        self.stop_loss_limit_price_txt = QLabel()
        self.stop_loss_limit_price_txt.setText(QC.translate('', 'Price:'))

        self.stop_loss_limit_price_input = QLineEdit()
        self.stop_loss_limit_price_input.setValidator(
            QDoubleValidator(999999, -999999, 8))

        self.stop_loss_limit_stop_price_txt = QLabel()
        self.stop_loss_limit_stop_price_txt.setText(
            QC.translate('', 'Stop price:'))

        self.stop_loss_limit_stop_price_input = QLineEdit()
        self.stop_loss_limit_stop_price_input.setValidator(
            QDoubleValidator(999999, -999999, 8))

        self.stop_loss_limit_params = QLabel()
        self.stop_loss_limit_params.setText(
            '{\'price\' : 12.345, \'stopPrice\': 12.345, \'quantity\' : 0.005, \'type\' : \'GTC\'/\'IOC\'/\'FOK\'}'
        )

        self.stop_loss_limit_layout.addWidget(
            self.stop_loss_limit_time_in_force_txt)
        self.stop_loss_limit_layout.addWidget(
            self.stop_loss_limit_time_in_force_input)
        self.stop_loss_limit_layout.addWidget(self.stop_loss_limit_price_txt)
        self.stop_loss_limit_layout.addWidget(self.stop_loss_limit_price_input)
        self.stop_loss_limit_layout.addWidget(
            self.stop_loss_limit_stop_price_txt)
        self.stop_loss_limit_layout.addWidget(
            self.stop_loss_limit_stop_price_input)
        self.stop_loss_limit_layout.addWidget(self.stop_loss_limit_params)

        self.order_box.addWidget(self.stop_loss_limit_input)

    def takeProfit(self):

        logging.debug('BinanceOrder::takeProfit() called')

        self.take_profit_input = QWidget()
        self.take_profit_layout = QVBoxLayout(self.take_profit_input)

        self.take_profit_stop_price = QLabel()
        self.take_profit_stop_price.setText(QC.translate('', 'Stop price:'))

        self.take_profit_stop_price_input = QLineEdit()
        self.take_profit_stop_price_input.setValidator(
            QDoubleValidator(999999, -999999, 8))

        self.take_profit_params = QLabel()
        self.take_profit_params.setText(
            '{\'stopPrice\': 12.345, \'quantity\' : 0.005}')

        self.take_profit_layout.addWidget(self.take_profit_stop_price)
        self.take_profit_layout.addWidget(self.take_profit_stop_price_input)
        self.take_profit_layout.addWidget(self.take_profit_params)
        self.take_profit_layout.addStretch(1)

        self.order_box.addWidget(self.take_profit_input)

    def takeProfitLimit(self):

        logging.debug('BinanceOrder::takeProfitLimit() called')

        self.take_profit_limit_input = QWidget()
        self.take_profit_limit_layout = QVBoxLayout(
            self.take_profit_limit_input)

        self.take_profit_limit_time_in_force_txt = QLabel()
        self.take_profit_limit_time_in_force_txt.setText(
            QC.translate('', 'Time in force:'))

        self.take_profit_limit_time_in_force_input = QComboBox()
        self.take_profit_limit_time_in_force_input.addItem(
            QC.translate('', 'Good til canceled'), QVariant('GTC'))
        self.take_profit_limit_time_in_force_input.addItem(
            QC.translate('', 'Immediate or Cancel'), QVariant('IOC'))
        self.take_profit_limit_time_in_force_input.addItem(
            QC.translate('', 'Fill or Kill'), QVariant('FOK'))

        self.take_profit_limit_price = QLabel()
        self.take_profit_limit_price.setText(QC.translate('', 'Price:'))

        self.take_profit_limit_price_input = QLineEdit()
        self.take_profit_limit_price_input.setValidator(
            QDoubleValidator(999999, -999999, 8))

        self.take_profit_limit_stop_price = QLabel()
        self.take_profit_limit_stop_price.setText(
            QC.translate('', 'Stop price:'))

        self.take_profit_limit_stop_price_input = QLineEdit()
        self.take_profit_limit_stop_price_input.setValidator(
            QDoubleValidator(999999, -999999, 8))

        self.take_profit_limit_params = QLabel()
        self.take_profit_limit_params.setText(
            '{\'price\' : 12.345, \'stopPrice\': 12.345, \'quantity\' : 0.005, \'type\' : \'GTC\'/\'IOC\'/\'FOK\'}'
        )

        self.take_profit_limit_layout.addWidget(
            self.take_profit_limit_time_in_force_txt)
        self.take_profit_limit_layout.addWidget(
            self.take_profit_limit_time_in_force_input)
        self.take_profit_limit_layout.addWidget(self.take_profit_limit_price)
        self.take_profit_limit_layout.addWidget(
            self.take_profit_limit_price_input)
        self.take_profit_limit_layout.addWidget(
            self.take_profit_limit_stop_price)
        self.take_profit_limit_layout.addWidget(
            self.take_profit_limit_stop_price_input)
        self.take_profit_limit_layout.addWidget(self.take_profit_limit_params)

        self.order_box.addWidget(self.take_profit_limit_input)

    def marketOrder(self):

        logging.debug('BinanceOrder::marketOrder() called')

        self.market_params = QLabel()
        self.market_params.setText('{\'quantity\' : 0.005}')

        self.market_input = QWidget()
        self.market_layout = QVBoxLayout(self.market_input)
        self.market_layout.addWidget(self.market_params)
        self.market_layout.addStretch(1)

        self.order_box.addWidget(self.market_input)

    def limitMaker(self):

        logging.debug('BinanceOrder::limitMaker() called')

        self.limit_maker_params = QLabel()
        self.limit_maker_params.setText('{\'quantity\' : 0.005}')

        self.limit_maker_input = QWidget()
        self.limit_maker_layout = QVBoxLayout(self.limit_maker_input)
        self.limit_maker_layout.addWidget(self.limit_maker_params)
        self.limit_maker_layout.addStretch(1)

        self.order_box.addWidget(self.limit_maker_input)

    def indexChanged(self, event):

        current_index = event
        logging.debug(
            'BinanceOrder::indexChanged() called {}'.format(current_index))
        self.order_box.setCurrentIndex(current_index)

    def loadLastConfig(self):

        pub_key, prv_key, side_index, side_txt, symbol_txt, quantity, \
                order_index, order_string, order_config, log_state = self.config

        if pub_key != '':

            self.pub_key_input.setText(pub_key)

        if prv_key != '':

            self.prv_key_input.setText(prv_key)

        self.quantity_input.setText('{:.8f}'.format(quantity))

        logging.debug(
            'BinanceOrder::loadLastConfig() called with order_string = {}'.
            format(order_string))

        self.selectOrder.setCurrentIndex(order_index)
        self.order_box.setCurrentIndex(order_index)
        self.order_side.setCurrentIndex(side_index)

        if order_string == 'LIMIT':
            self.limit_time_in_force_input.setCurrentIndex(order_config[1])
            self.limit_price_input.setText('{:.8f}'.format(order_config[2]))
        elif order_string == 'STOP_LOSS':
            self.stop_loss_price_input.setText('{:.8f}'.format(
                order_config[0]))
        elif order_string == 'STOP_LOSS_LIMIT':
            self.stop_loss_limit_time_in_force_input.setCurrentIndex(
                order_config[1])
            self.stop_loss_limit_price_input.setText('{:.8f}'.format(
                order_config[2]))
            self.stop_loss_limit_stop_price_input.setText('{:.8f}'.format(
                order_config[3]))
        elif order_string == 'TAKE_PROFIT':
            self.take_profit_stop_price_input.setText('{:.8f}'.format(
                order_config[0]))
        elif order_string == 'TAKE_PROFIT_LIMIT':
            self.take_profit_limit_time_in_force_input.setCurrentIndex(
                order_config[1])
            self.take_profit_limit_price_input.setText('{:.8f}'.format(
                order_config[2]))
            self.take_profit_limit_stop_price_input.setText('{:.8f}'.format(
                order_config[3]))

    def edit_done(self):

        logging.debug('BinanceOrder::edit_done() called')

        # Init order_config with None for LIMIT_MAKER and MARKET order
        # which habe no order_config
        order_config = None

        if self.selectOrder.currentData() == 'LIMIT':

            tif_string = self.limit_time_in_force_input.currentData()
            tif_index = self.limit_time_in_force_input.currentIndex()

            if self.limit_price_input.text() == '':

                limit_price_value = 0.0

            else:

                limit_price_value = float(self.limit_price_input.text())

            order_config = (tif_string, tif_index, limit_price_value)

        elif self.selectOrder.currentData() == 'STOP_LOSS':

            if self.stop_loss_price_input.text() == '':

                stop_price_value = 0.0

            else:

                stop_price_value = float(self.stop_loss_price_input.text())

            order_config = (stop_price_value, )

        elif self.selectOrder.currentData() == 'STOP_LOSS_LIMIT':

            tif_string = self.stop_loss_limit_time_in_force_input.currentData()
            tif_index = self.stop_loss_limit_time_in_force_input.currentIndex()

            if self.stop_loss_limit_price_input.text() == '':

                limit_price_value = 0.0

            else:

                limit_price_value = float(
                    self.stop_loss_limit_price_input.text())

            if self.stop_loss_limit_stop_price_input.text() == '':

                stop_price_value = 0.0

            else:

                stop_price_value = float(
                    self.stop_loss_limit_stop_price_input.text())

            order_config = (tif_string, tif_index, limit_price_value,
                            stop_price_value)

        elif self.selectOrder.currentData() == 'TAKE_PROFIT':

            if self.take_profit_stop_price_input.text() == '':

                stop_price_value = 0.0

            else:

                stop_price_value = float(
                    self.take_profit_stop_price_input.text())

            order_config = (stop_price_value, )

        elif self.selectOrder.currentData() == 'TAKE_PROFIT_LIMIT':

            tif_string = self.take_profit_limit_time_in_force_input.currentData(
            )
            tif_index = self.take_profit_limit_time_in_force_input.currentIndex(
            )

            if self.take_profit_limit_price_input.text() == '':

                limit_price_value = 0.0

            else:

                limit_price_value = float(
                    self.take_profit_limit_price_input.text())

            if self.take_profit_limit_stop_price_input.text() == '':

                stop_price_value = 0.0

            else:

                stop_price_value = float(
                    self.take_profit_limit_stop_price_input.text())

            order_config = (tif_string, tif_index, limit_price_value,
                            stop_price_value)

        #elif self.selectOrder.currentData() == 'LIMIT_MAKER':
        # No order config necessary

        #elif self.selectOrder.currentData() == 'MARKET':
        # No order config necessary

        pub_key = self.pub_key_input.text()
        prv_key = self.prv_key_input.text()
        side_index = self.order_side.currentIndex()
        side_txt = self.order_side.currentData()
        symbol_txt = self.symbol_input.text()

        if self.quantity_input.text() == '':
            quantity = 0.0
        else:
            quantity = float(self.quantity_input.text())

        order_index = self.selectOrder.currentIndex()
        order_string = self.selectOrder.currentData()
        log_state = self.log_checkbox.isChecked()

        self.config = (pub_key, prv_key, side_index, side_txt, symbol_txt,
                       quantity, order_index, order_string, order_config,
                       log_state)

        self.addFunction(BinanceOrderFunction)
Esempio n. 16
0
class BinanceOHLC(ElementMaster):

    pixmap_path = 'images/BinanceOHLC.png'
    child_pos = (True, False)

    def __init__(self, row, column):
        self.row = row
        self.column = column

        interval_str = '1m'
        interval_index = 0
        log_state = False
        symbol_txt = None

        # interval-str, inteval-index, symbol_txt, log-state
        self.config = (interval_str, interval_index, symbol_txt, log_state)

        super().__init__(self.row, self.column, self.pixmap_path, True, self.config)
        super().edit_sig.connect(self.edit)
        logging.debug('BinanceOHLC called at row {}, column {}'.format(row, column))
        self.addFunction(BinanceOHLCFUnction)

    def __setstate__(self, state):
        logging.debug('__setstate__() called BinanceOHLC')
        self.row, self.column, self.config = state
        super().__init__(self.row, self.column, self.pixmap_path, True, self.config)
        super().edit_sig.connect(self.edit)
        self.addFunction(BinanceOHLCFUnction)

    def __getstate__(self):
        logging.debug('__getstate__() called BinanceOHLC')
        return (self.row, self.column, self.config)

    def openEditor(self):
        logging.debug('openEditor() called BinanceOHLC')

    def edit(self):

        logging.debug('edit() called BinanceOHLC')

        # interval-str, inteval-index, symbol_txt, log-state
        interval_str, interval_index, symbol_txt, log_state = self.config

        self.binance_ohlc_layout = QVBoxLayout()
        self.confirm_button = QPushButton(QC.translate('', 'Ok'))

        self.interval_txt = QLabel()
        self.interval_txt.setText(QC.translate('', 'Choose the OHLC interval'))

        # https://github.com/sammchardy/python-binance/blob/master/binance/client.py
        self.selectInterval = QComboBox()
        self.selectInterval.addItem(QC.translate('', '1 Minute'), QVariant('1m'))
        self.selectInterval.addItem(QC.translate('', '3 Minutes'), QVariant('3m'))
        self.selectInterval.addItem(QC.translate('', '5 Minutes'), QVariant('5m'))
        self.selectInterval.addItem(QC.translate('', '15 Minutes'), QVariant('15m'))
        self.selectInterval.addItem(QC.translate('', '30 Minutes'), QVariant('30m'))
        self.selectInterval.addItem(QC.translate('', '1 Hour'), QVariant('1h'))
        self.selectInterval.addItem(QC.translate('', '2 Hours'), QVariant('2h'))
        self.selectInterval.addItem(QC.translate('', '4 Hours'), QVariant('4h'))
        self.selectInterval.addItem(QC.translate('', '6 Hours'), QVariant('6h'))
        self.selectInterval.addItem(QC.translate('', '8 Hours'), QVariant('8h'))
        self.selectInterval.addItem(QC.translate('', '12 Hours'), QVariant('12h'))
        self.selectInterval.addItem(QC.translate('', '1 Day'), QVariant('1d'))
        self.selectInterval.setCurrentIndex(interval_index)


        self.symbol_txt = QLabel()
        self.symbol_txt.setText(QC.translate('', 'Enter currency pair'))

        self.symbol_input = QLineEdit()
        self.symbol_input.setPlaceholderText(QC.translate('', 'e.g. "XMRBTC"'))

        if symbol_txt:
            self.symbol_input.setText(symbol_txt)

        self.help_txt = QWidget()
        self.help_txt_layout = QVBoxLayout(self.help_txt)

        self.help_txt_1 = QLabel()
        self.help_txt_1.setText(QC.translate('', 'Outputs a Pandas dataframe in the following format:')) 

        self.help_txt_2 = QLabel()
        self.help_txt_2.setText('\r\n')

        self.help_txt_3 = QLabel()
        self.help_txt_3.setText(QC.translate('','open_time [Unix, 10 digits], open, high, low, close,\r\nvolume, close_time [Unix, 10 digits], quote_assetv,\r\n' \
            'trades, taker_b_asset_v, taker_b_asset_v, datetime'))

        self.help_txt_layout.addWidget(self.help_txt_1)
        self.help_txt_layout.addWidget(self.help_txt_2)
        self.help_txt_layout.addWidget(self.help_txt_3)


        # hier logging option einfügen
        self.log_line = QWidget()
        self.ask_for_logging = QLabel()
        self.ask_for_logging.setText(QC.translate('', 'Log output?'))
        self.log_checkbox = QCheckBox()
        self.log_line_layout = QHBoxLayout(self.log_line)
        self.log_line_layout.addWidget(self.ask_for_logging)
        self.log_line_layout.addWidget(self.log_checkbox)
        self.log_line_layout.addStretch(1)

        if log_state:
            self.log_checkbox.setChecked(True)


        self.binance_ohlc_edit = ElementEditor(self)
        self.binance_ohlc_edit.setWindowTitle(QC.translate('', 'Edit OHLC Query'))

        # signals and slots
        self.confirm_button.clicked.connect(self.binance_ohlc_edit.closeEvent)
        self.binance_ohlc_edit.window_closed.connect(self.edit_done)

        self.binance_ohlc_layout.addWidget(self.interval_txt)
        self.binance_ohlc_layout.addWidget(self.selectInterval)
        self.binance_ohlc_layout.addWidget(self.symbol_txt)
        self.binance_ohlc_layout.addWidget(self.symbol_input)
        self.binance_ohlc_layout.addWidget(self.log_line)
        self.binance_ohlc_layout.addStretch(1)
        self.binance_ohlc_layout.addWidget(self.help_txt)
        self.binance_ohlc_layout.addWidget(self.confirm_button)
        self.binance_ohlc_edit.setLayout(self.binance_ohlc_layout)
        self.binance_ohlc_edit.show()

    def edit_done(self):

        logging.debug('edit_done() called BinanceOHLC')

        if self.symbol_input.text() == '':
            symbol_txt = None
        else:
            symbol_txt = self.symbol_input.text()
       
        interval_str    = self.selectInterval.currentData()
        interval_index  = self.selectInterval.currentIndex()
        log_state       = self.log_checkbox.isChecked()

        # interval-str, inteval-index, symbol_txt, log-state
        self.config = (interval_str, interval_index, symbol_txt, log_state)

        self.addFunction(BinanceOHLCFUnction)
Esempio n. 17
0
class MLSVM_Predict(ElementMaster):

    pixmap_path = 'images/MLSVM_Predict.png'
    child_pos = (True, False)

    def __init__(self, row, column):
        self.row = row
        self.column = column

        # scale_option, scale_mean, scale_std, predict_val, filename, log_state

        scale_option = 0
        scale_mean = True
        scale_std = True
        predict_val = False
        filename = None
        rel_path = False
        log_state = False

        self.config = scale_option, scale_mean, scale_std, predict_val, filename, rel_path, log_state

        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config)
        super().edit_sig.connect(self.edit)
        logging.debug(
            'MLSVM_Predict::__init__() called at row {}, column {}'.format(
                row, column))
        self.addFunction(MLSVM_PredictFunction)

    def __setstate__(self, state):
        logging.debug('MLSVM_Predict::__setstate__() called')
        self.row, self.column, self.config = state
        super().__init__(self.row, self.column, self.pixmap_path, True,
                         self.config)
        super().edit_sig.connect(self.edit)
        self.addFunction(MLSVM_PredictFunction)

    def __getstate__(self):
        logging.debug('MLSVM_Predict::__getstate__() called')
        return (self.row, self.column, self.config)

    def openEditor(self):
        logging.debug('MLSVM_Predict::openEditor() called')

    def edit(self):

        logging.debug('MLSVM_Predict::edit()')

        # scale_option, scale_mean, scale_std, predict_val, filename, log_state
        self.scale_option, self.scale_mean, self.scale_std, self.predict_val, \
                self.filename, self.rel_path, self.log_state = self.config

        self.home_dict = str(Path.home())

        self.scale_label = QLabel()
        self.scale_label.setText(QC.translate('', 'Scale n_samples ?'))
        self.scale_list = QComboBox()
        self.scale_list.addItem(QC.translate('', 'No'), QVariant(False))
        self.scale_list.addItem(QC.translate('', 'Yes'), QVariant(True))

        self.scale_center_input_line = QWidget()
        self.scale_center_input_line_layout = QHBoxLayout(
            self.scale_center_input_line)
        self.scale_center_label = QLabel()
        self.scale_center_label.setText(
            QC.translate('', 'Center data before scaling?'))
        self.scale_center_checkbox = QCheckBox()
        self.scale_center_input_line_layout.addWidget(self.scale_center_label)
        self.scale_center_input_line_layout.addWidget(
            self.scale_center_checkbox)

        self.scale_std_input_line = QWidget()
        self.scale_std_input_line_layout = QHBoxLayout(
            self.scale_std_input_line)
        self.scale_std_label = QLabel()
        self.scale_std_label.setText(
            QC.translate('', 'Scale data until variance?'))
        self.scale_std_checkbox = QCheckBox()
        self.scale_std_input_line_layout.addWidget(self.scale_std_label)
        self.scale_std_input_line_layout.addWidget(self.scale_std_checkbox)

        self.scale_input_area = QWidget()
        self.scale_input_area_layout = QVBoxLayout(self.scale_input_area)
        self.scale_input_area_layout.addWidget(self.scale_center_input_line)
        self.scale_input_area_layout.addWidget(self.scale_std_input_line)

        self.last_value_line = QWidget()
        self.last_value_line_layout = QHBoxLayout(self.last_value_line)
        self.last_value_label = QLabel()
        self.last_value_label.setText(
            QC.translate('', 'Predict only last value [-1]?'))
        self.last_value_checkbox = QCheckBox()

        self.last_value_line_layout.addWidget(self.last_value_label)
        self.last_value_line_layout.addWidget(self.last_value_checkbox)

        self.conn_rest_layout = QVBoxLayout()
        self.confirm_button = QPushButton(QC.translate('', 'Ok'))
        """
        self.filename_text = QLabel()
        self.filename_text.setWordWrap(True)
        
        self.file_button = QPushButton(QC.translate('', 'Select model file'))
        self.file_button.clicked.connect(self.openFileNameDialog)
        """

        self.filename_text = QLabel()
        self.filename_text.setWordWrap(True)

        self.file_button = QPushButton(
            QC.translate('', 'Select model output file'))
        self.file_button.clicked.connect(self.openFileNameDialog)

        self.relative_file_check = QWidget()
        self.relative_file_check_layout = QHBoxLayout(self.relative_file_check)

        self.relative_file_label = QLabel()
        self.relative_file_label.setText(
            QC.translate('', 'Filename relative to $HOME.'))
        self.relative_file_checkbox = QCheckBox()
        self.relative_file_check_layout.addWidget(self.relative_file_checkbox)
        self.relative_file_check_layout.addWidget(self.relative_file_label)
        self.relative_file_check_layout.addStretch(1)

        self.relative_filepath_input = QLineEdit()
        self.relative_filepath_input.setPlaceholderText('my_folder/my_file')

        self.file_input = QWidget()
        self.file_input_layout = QVBoxLayout(self.file_input)
        self.file_input_layout.addWidget(self.filename_text)
        self.file_input_layout.addWidget(self.file_button)
        self.file_input_layout.addWidget(self.relative_file_check)
        self.file_input_layout.addWidget(self.relative_filepath_input)
        """
        output: prediction quality
        """
        self.help_text_1 = QLabel()
        self.help_text_1.setText(
            QC.translate('', 'Expects an array of samples as input.'))

        self.help_text_2 = QLabel()
        self.help_text_2.setText(
            QC.translate('', 'Outputs a single value or an array.'))

        # hier logging option einfügen
        self.log_line = QWidget()
        self.ask_for_logging = QLabel()
        self.ask_for_logging.setText(QC.translate('', 'Log output?'))
        self.log_checkbox = QCheckBox()
        self.log_line_layout = QHBoxLayout(self.log_line)
        self.log_line_layout.addWidget(self.ask_for_logging)
        self.log_line_layout.addWidget(self.log_checkbox)
        self.log_line_layout.addStretch(1)

        self.ml_svm_predict_edit = ElementEditor(self)
        self.ml_svm_predict_edit.setWindowTitle(
            QC.translate('', 'Support Vector Machine Prediction'))
        self.ml_svm_predict_edit.setMinimumHeight(450)

        # signals and slots
        self.relative_file_checkbox.stateChanged.connect(self.toggleFileInput)
        self.scale_list.currentIndexChanged.connect(self.scaledIndexChanged)
        self.confirm_button.clicked.connect(
            self.ml_svm_predict_edit.closeEvent)
        self.ml_svm_predict_edit.window_closed.connect(self.edit_done)

        # load config
        self.loadLastConfig()

        self.conn_rest_layout.addWidget(self.help_text_1)
        self.conn_rest_layout.addWidget(
            self.scale_label)  # scale: copy = false
        self.conn_rest_layout.addWidget(self.scale_list)
        self.conn_rest_layout.addWidget(self.scale_input_area)
        self.conn_rest_layout.addWidget(self.last_value_line)
        self.conn_rest_layout.addWidget(self.file_input)
        self.conn_rest_layout.addStretch(1)
        self.conn_rest_layout.addWidget(self.help_text_2)
        self.conn_rest_layout.addWidget(self.log_line)
        self.conn_rest_layout.addWidget(self.confirm_button)
        self.ml_svm_predict_edit.setLayout(self.conn_rest_layout)
        self.ml_svm_predict_edit.show()

    def loadLastConfig(self):

        logging.debug('MLSVM_Predict::loadLastConfig() called')

        self.scale_list.setCurrentIndex(self.scale_option)
        self.scaledIndexChanged(self.scale_option)
        self.scale_center_checkbox.setChecked(self.scale_mean)
        self.scale_std_checkbox.setChecked(self.scale_std)
        self.last_value_checkbox.setChecked(self.predict_val)
        self.log_checkbox.setChecked(self.log_state)
        self.relative_file_checkbox.setChecked(self.rel_path)

        if self.rel_path:
            self.toggleFileInput(2)
            if self.filename:
                self.relative_filepath_input.setText(self.filename)
        else:
            self.toggleFileInput(0)
            if self.filename:
                self.filename_text.setText(self.filename)

    def toggleFileInput(self, event):
        logging.debug('MLSVM::toggleFileInput() called: {}'.format(event))
        # 0 = FALSE, 2 = TRUE
        if event:  # TRUE
            self.file_button.setDisabled(True)
            self.relative_filepath_input.setDisabled(False)
            self.filename_text.setText('')
        else:
            self.file_button.setDisabled(False)
            self.relative_filepath_input.clear()
            self.relative_filepath_input.setDisabled(True)
            self.relative_filepath_input.setPlaceholderText(
                'my_folder/my_file')

    def scaledIndexChanged(self, event):

        current_index = event
        logging.debug(
            'MLSVM_Predict::scaledIndexChanged() called: {}'.format(event))
        if event == 1:
            self.scale_input_area.setVisible(True)
        else:
            self.scale_input_area.setVisible(False)

    def openFileNameDialog(self, event):
        options = QFileDialog.Options()
        #options |= QFileDialog.DontUseNativeDialog

        fileName, _ = QFileDialog.getOpenFileName(
            self,
            QC.translate('', 'Open SVM model file'),
            self.home_dict,
            "All Files (*);;Pythonic Files (*.pyc)",
            options=options)
        if fileName:
            logging.debug(
                'MLSVM_Predict::openFileNameDialog() called with filename: {}'.
                format(fileName))
            self.filename = fileName
            self.filename_text.setText(self.filename)

    def edit_done(self):

        logging.debug('MLSVM_Predict::edit_done() called')
        # scale_option, scale_mean, scale_std, predict_val, filename, log_state

        scale_option = self.scale_list.currentIndex()
        scale_mean = self.scale_center_checkbox.isChecked()
        scale_std = self.scale_std_checkbox.isChecked()
        predict_val = self.last_value_checkbox.isChecked()
        log_state = self.log_checkbox.isChecked()
        rel_path = self.relative_file_checkbox.isChecked()
        if rel_path:
            filename = self.relative_filepath_input.text()
        else:
            filename = self.filename

        if filename == '':
            filename = None

        self.config = scale_option, scale_mean, scale_std, predict_val, filename, rel_path, log_state

        self.addFunction(MLSVM_PredictFunction)