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')
class Settings(QWidget): def __init__(self): logging.debug('__init__() called SettingsWindow') super().__init__() self.delay = 500 def show(self): logging.debug('edit() called ExecReturn') self.settingsLayout = QVBoxLayout() self.delayRow = QWidget() self.delayRowLayout = QHBoxLayout() self.window = ElementEditor(self) self.window.setWindowTitle(QC.translate('', 'Settings')) self.top_text = QLabel() self.top_text.setText(QC.translate('', 'Debug delay:')) self.delay_text = QLabel() self.delay_text.setText(QC.translate('', 'Milliseconds')) self.delayInput = QLineEdit() self.delayInput.setValidator(QIntValidator(0, 9999)) self.delayInput.setText(str(self.delay)) self.delayRowLayout.addWidget(self.delayInput) self.delayRowLayout.addWidget(self.delay_text) self.delayRowLayout.addStretch(1) self.delayRow.setLayout(self.delayRowLayout) self.confirm_button = QPushButton(QC.translate('', 'Ok')) self.confirm_button.clicked.connect(self.window.closeEvent) self.window.window_closed.connect(self.edit_done) self.settingsLayout.addWidget(self.top_text) self.settingsLayout.addWidget(self.delayRow) self.settingsLayout.addStretch(1) self.settingsLayout.addWidget(self.confirm_button) self.window.setLayout(self.settingsLayout) self.window.show() def edit_done(self): logging.debug('edit_done() called : delay {} MS'.format( self.delayInput.text())) self.delay = int(self.delayInput.text())
class InfoWindow(QWidget): def __init__(self): logging.debug('__init__() called InfoWindow') super().__init__() def show(self): logging.debug('edit() called ExecReturn') self.infoLayout = QVBoxLayout() self.window = ElementEditor(self) self.window.setWindowTitle(QC.translate('', 'Info')) self.link_row = QWidget() self.link_row_layout = QHBoxLayout(self.link_row) self.link_row_layout.setAlignment(Qt.AlignLeft) self.link_line = QLabel() self.link_line.setText(QC.translate('', 'Pythonics by ')) self.link = QLabel() self.link.setText( '<a href="https://krypto-fuchs.de">https://krypto-fuchs.de</a>') self.link.setTextFormat(Qt.RichText) self.link.setTextInteractionFlags(Qt.TextBrowserInteraction) self.link.setOpenExternalLinks(True) self.link_row_layout.addWidget(self.link_line) self.link_row_layout.addWidget(self.link) self.logo = QWidget() self.logo_layout = QHBoxLayout(self.logo) self.logo_layout.setAlignment(Qt.AlignCenter) self.logo_label = QLabel() self.logo_label.setPixmap( QPixmap('images/logo_rechts.png').scaled(200, 200)) self.logo_layout.addWidget(self.logo_label) self.confirm_button = QPushButton(QC.translate('', 'Ok')) self.confirm_button.clicked.connect(self.window.closeEvent) self.infoLayout.addWidget(self.link_row) self.infoLayout.addWidget(self.logo) self.infoLayout.addStretch(1) self.infoLayout.addWidget(self.confirm_button) self.window.setLayout(self.infoLayout) self.window.show()
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, QPixmap(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, QPixmap(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)
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)
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, QPixmap(self.pixmap_path), True, self.config) super().edit_sig.connect(self.edit) logging.debug('BinanceOrder 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, QPixmap(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)
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, QPixmap(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, QPixmap(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') self.branchEditLayout = QVBoxLayout() self.branchEdit = ElementEditor(self) self.branchEdit.setWindowTitle(QC.translate('', 'Edit Branch')) self.branch_image = QLabel() self.branch_image.setPixmap(QPixmap(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 string 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')
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, QPixmap(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, QPixmap(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)
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, QPixmap(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, QPixmap(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)
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, QPixmap(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, QPixmap(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)
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, QPixmap(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, QPixmap(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)
class InfoWindow(QWidget): def __init__(self): logging.debug('__init__() called InfoWindow') super().__init__() def show(self): logging.debug('edit() called ExecReturn') self.infoLayout = QVBoxLayout() self.window = ElementEditor(self) self.window.setWindowTitle(QC.translate('', 'Info')) self.link_row = QWidget() self.link_row_layout = QHBoxLayout(self.link_row) self.link_row_layout.setAlignment(Qt.AlignLeft) self.license_txt_1 = QLabel() self.license_txt_1.setText(QC.translate('', 'Pythonic is published under the')) self.license_txt_2 = QLabel() self.license_txt_2.setText('<a href="https://raw.githubusercontent.com/hANSIc99/Pythonic/master/LICENSE">GNU General Public License v3.0') self.license_txt_2.setTextInteractionFlags(Qt.TextBrowserInteraction) self.license_txt_2.setOpenExternalLinks(True) self.license_txt_3 = QLabel() self.license_txt_3.setText(QC.translate('', 'Sources are available on')) self.license_txt_4 = QLabel() self.license_txt_4.setText('<a href="https://github.com/hANSIc99/Pythonic">GitHub') self.license_txt_4.setTextInteractionFlags(Qt.TextBrowserInteraction) self.license_txt_4.setOpenExternalLinks(True) self.license_line_1 = QWidget() self.license_line_layout_1 = QHBoxLayout(self.license_line_1) self.license_line_layout_1.addWidget(self.license_txt_1) self.license_line_layout_1.addWidget(self.license_txt_2) self.license_line_layout_1.addStretch(1) self.license_line_2 = QWidget() self.license_line_layout_2 = QHBoxLayout(self.license_line_2) self.license_line_layout_2.addWidget(self.license_txt_3) self.license_line_layout_2.addWidget(self.license_txt_4) self.license_line_layout_2.addStretch(1) self.link_line = QLabel() self.link_line.setText(QC.translate('', 'Pythonic by')) self.link = QLabel() self.link.setText('<a href="https://krypto-fuchs.de">https://krypto-fuchs.de</a>') self.link.setTextFormat(Qt.RichText) self.link.setTextInteractionFlags(Qt.TextBrowserInteraction) self.link.setOpenExternalLinks(True) self.link_row_layout.addWidget(self.link_line) self.link_row_layout.addWidget(self.link) self.logo = QWidget() self.logo_layout = QHBoxLayout(self.logo) self.logo_layout.setAlignment(Qt.AlignCenter) self.logo_label = QLabel() self.logo_label.setPixmap(QPixmap('images/vertical.png').scaledToHeight(200)) self.logo_layout.addWidget(self.logo_label) self.confirm_button = QPushButton(QC.translate('', 'Ok')) self.confirm_button.clicked.connect(self.window.closeEvent) self.infoLayout.addWidget(self.license_line_1) self.infoLayout.addWidget(self.license_line_2) self.infoLayout.addWidget(self.logo) #self.infoLayout.addWidget(self.link_row) self.infoLayout.addStretch(1) self.infoLayout.addWidget(self.confirm_button) self.window.setLayout(self.infoLayout) self.window.show()
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, QPixmap(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, QPixmap(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)