def save_callback(sender, app_data, user_data): print(dpg) print("Save Clicked") for i in dpg.get_all_items(): print(i) print(sender, app_data, user_data, dpg.get_value(2)) print(sender, app_data, user_data, dpg.get_value(3)) print(sender, app_data, user_data, dpg.get_value(4)) print(sender, app_data, user_data, dpg.get_value(21))
def _volume_plot_drop(sender, app_data, user_data): ta = prices[window_data.selected_ticker]['ta'] dates = (ta.data['date'].astype('int64') // 1e9).to_list() if app_data[0] == 'RSI': if window_data.volume_unit_yaxis == 0: window_data.volume_unit_yaxis = dpg.add_plot_axis(dpg.mvYAxis, label="RSI", parent=window_data.volume_plot) indicators.add_rsi_series(dpg.get_value(app_data[1]), dpg.get_value(app_data[2]), dates, ta, window_data.volume_unit_yaxis) dpg.set_axis_limits(window_data.volume_unit_yaxis, 0, 100)
def on_edit(self, item, data): item_label = dpg.get_item_label(item) row = int(item_label.split('_')[-2]) col = int(item_label.split('_')[-1]) id = dpg.get_value(self.rows_ids[f"##{self.name}_{row}_{1}"]) col_name = self.header[col] self.ssh_info[id][col_name] = dpg.get_value( self.rows_ids[f"##{self.name}_{row}_{col}"])
def update_verbosity(self, sender, data): self.com_verbosity = '' self.relic_verbosity = '' if importlib.util.find_spec('reliquery') is not None: self.relic_verbosity = dpg.get_value('relic#{}#{}'.format( self.operation.name, self.node_index)) self.com_verbosity = dpg.get_value('verb#{}#{}'.format( self.operation.name, self.node_index)) self.verbose = '{}||{}'.format(self.com_verbosity, self.relic_verbosity)
def call_send_button(self, sender: Any, app_data: Any, user_data: bool): message: str = dpg.get_value(MESSAGE_INPUT) receiver: str = dpg.get_value(CONTACT_LIST) send_to_all: bool = user_data self.typing_timestamps[receiver] = None dpg.set_value(MESSAGE_INPUT, "") if send_to_all is True: for receiver in self.data.contacts: self.send(receiver, message) else: self.send(receiver, message) self.changed = True
def cb_set_location(sender, data): record_id = get_value(ModifyID.ID_INPUT) if not validate_record_id(record_id): return record = query(Record).filter(Record.id == record_id).one_or_none() if record is None: set_error(f'could not find record by id: {record_id}') return record.location = get_value(ModifyID.LOCATION_INPUT).lower().strip() commit() set_error('')
def write_text(self): # Bruger encrypt funktionen til at kryptere brugerens indtastning with open( self.fileName, "w" ) as f: # Åbner eksisterende, eller opretter ny .txt fil under navnet fileName f.write(dpg.get_value(self.rwfield) ) # Skriver brugerens input i txt filen og gemmer den password = dpg.get_value(self.writePW) if self.encrypt(password): # Tjekker om der blev krypteret succesfult self.show_status("Text succesfult krypteret og gemt", True) # Fortæller brugeren om det var succesfult dpg.set_value(self.writePW, "") # Tømmer brugerens inputfelt og lukker skrivevinduet dpg.hide_item(self.writeWindow)
def __init__(self, parent=None): self.log_level = 0 self._auto_scroll = True self.filter_id = None if parent: self.window_id = parent else: self.window_id = dpg.add_window(label="mvLogger", pos=(10, 150), width=800, height=200) self.count = 0 self.flush_count = 1000 with dpg.group(horizontal=True, parent=self.window_id): dpg.add_checkbox(label="Auto-scroll", default_value=True, callback=lambda sender: self.auto_scroll( dpg.get_value(sender))) dpg.add_button(label="Clear", callback=lambda: dpg.delete_item( self.filter_id, children_only=True)) dpg.add_input_text(label="Filter", callback=lambda sender: dpg.set_value( self.filter_id, dpg.get_value(sender)), parent=self.window_id) self.child_id = dpg.add_child(parent=self.window_id, autosize_x=True, autosize_y=True) self.filter_id = dpg.add_filter_set(parent=self.child_id) with dpg.theme() as self.trace_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (0, 255, 0, 255)) with dpg.theme() as self.debug_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (64, 128, 255, 255)) with dpg.theme() as self.info_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 255, 255, 255)) with dpg.theme() as self.warning_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 255, 0, 255)) with dpg.theme() as self.error_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 0, 0, 255)) with dpg.theme() as self.critical_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 0, 0, 255))
def _candle_plot_drop(sender, app_data, user_data): global prices global window_data if window_data.selected_ticker == '': return ta = prices[window_data.selected_ticker]['ta'] dates = (ta.data['date'].astype('int64') // 1e9).to_list() # indicator comes in app_data logger.log('adding indicator ' + app_data[0]) if app_data[0] == 'RLINES': current_price = float(exchange.symbol_ticker(window_data.selected_ticker)[window_data.selected_ticker].current) threshold = dpg.get_value(app_data[1]) / 100 min_strength = dpg.get_value(app_data[2]) resistance_lines = ta.resistance_lines_for_price(current_price, min_strength, threshold) resistance_levels = [v[0] for v in resistance_lines] resistance_strengths = [v[1] for v in resistance_lines] resistance_lines = ta.support_lines_for_price(current_price, min_strength, threshold) resistance_levels += [v[0] for v in resistance_lines] resistance_strengths += [v[1] for v in resistance_lines] logger.log(str(resistance_levels)) hlid = dpg.add_hline_series(resistance_levels, label='RLINES', parent=window_data.candle_yaxis) def delete_hl_series(s, a, u): dpg.delete_item(u) for an in window_data.rlines_annotation_ids[u]: dpg.delete_item(an) window_data.rlines_annotation_ids[u] = [] dpg.add_button(label="Delete", user_data=dpg.last_item(), parent=dpg.last_item(), callback=delete_hl_series) window_data.rlines_annotation_ids[hlid] = [] # add annotations for ri in range(len(resistance_levels)): dpg.add_plot_annotation(label=str(resistance_strengths[ri]), default_value=(dates[-1], resistance_levels[ri]), offset=(10, 0), clamped=False, parent=window_data.candle_plot) window_data.rlines_annotation_ids[hlid].append(dpg.last_item()) elif app_data[0] == 'SMA': indicators.add_sma_series(app_data[1], dates, window_data.candle_yaxis, ta) elif app_data[0] == 'EMA': indicators.add_ema_series(app_data[1], dates, window_data.candle_yaxis, ta) elif app_data[0] == 'BOLLINGER_BANDS': indicators.add_bbands_series(app_data[1], app_data[2], dates, ta, window_data.candle_yaxis) dpg.add_button(label="Delete", user_data=dpg.last_item(), parent=dpg.last_item(), callback=lambda s, a, u: dpg.delete_item(u))
def execute(self): # get input attribute data value = round(self._input_attributes[0].get_data(), 5) min_value = dpg.get_value(self.min_id) max_value = dpg.get_value(self.max_id) expect_value = dpg.get_value(self.expected_id) if round(expect_value - min_value,5) <= value <= round(expect_value + max_value, 5): dpg.set_item_theme(self._static_attributes[0].status_id, self.success) else: dpg.set_item_theme(self._static_attributes[0].status_id, self.fail) self.finish()
def show_text_value(): global data global buffer global dpg_ids if len(data) == 1: data_to_show = data[0] data_to_show = str(data_to_show) splitter = '\n' else: data_to_show = pp.pformat(data) splitter = '||\n' previous_txt_data = dpg.get_value(dpg_ids['Text']) previous_list_data = previous_txt_data.split(splitter) if len(previous_list_data) == buffer: previous_list_data.pop(0) new_txt_data = '' for i in previous_list_data: if i != '__start__': new_txt_data = new_txt_data + i + splitter new_txt_data = new_txt_data + data_to_show dpg.set_value(dpg_ids['Text'], new_txt_data)
def sma(): with dpg.child(width=200, height=70): item = dpg.add_button(label='SMA') dpg.set_item_theme(dpg.last_item(), button_themes[5]) dpg.add_same_line() i = dpg.add_input_int(default_value=3, label='', width=70) dpg.add_button(label='SMA200') dpg.set_item_theme(dpg.last_item(), button_themes[4]) with dpg.tooltip(dpg.last_item()): dpg.add_text('Media Movel de 200 dias') with dpg.drag_payload(parent=dpg.last_item(), drag_data=('SMA', 200), payload_type='candle_plot'): dpg.add_text('SMA200') dpg.add_same_line() dpg.add_button(label='SMA50') dpg.set_item_theme(dpg.last_item(), button_themes[3]) with dpg.drag_payload(parent=dpg.last_item(), drag_data=('SMA', 50), payload_type='candle_plot'): dpg.add_text('SMA50') dpg.add_same_line() dpg.add_button(label='SMA7') dpg.set_item_theme(dpg.last_item(), button_themes[2]) with dpg.drag_payload(parent=dpg.last_item(), drag_data=('SMA', 7), payload_type='candle_plot'): dpg.add_text('SMA7') with dpg.drag_payload(parent=item, drag_data=('SMA', dpg.get_value(i)), payload_type='candle_plot'): dpg.add_text('SMA')
def execute(self): # get input attribute data value = dpg.get_value(self.value) self._output_attributes[0].execute(value) self.finish()
def bbands(): with dpg.child(width=200, height=95): item = dpg.add_button(label='BOLLINGER BANDS') dpg.set_item_theme(dpg.last_item(), button_themes[5]) i = dpg.add_slider_int(default_value=10, label='', min_value=3, max_value=200) j = dpg.add_slider_float(default_value=5, label='', min_value=1, max_value=5) with dpg.drag_payload(parent=item, drag_data=('BOLLINGER_BANDS', dpg.get_value(i), dpg.get_value(j)), payload_type='candle_plot'): dpg.add_text('BOLLINGER BANDS')
def delete_selected_rows(self): sel_rows = [] for row in range(self.num_of_rows): if dpg.get_value(self.rows_ids[f"##{self.name}_{row}_{0}"]): sel_rows.append(row) for row in sel_rows: id = dpg.get_value(self.rows_ids[f"##{self.name}_{row}_{1}"]) del self.ssh_info[id] for row in sel_rows: dpg.delete_item(self.rows_ids[f"##{self.name}_{row}_sep"]) for col in range(len(self.header)): dpg.delete_item(self.rows_ids[f"##{self.name}_{row}_{col}"]) self.save_to_json()
def cb_load_from_id(sender, data): id = get_value(ModifyID.ID_INPUT) if not validate_record_id(id): return record = query(Record).filter(Record.id == id).one_or_none() _update_record_fields(record)
def _load_record_from_id(record_id): record = query(Record).filter(Record.id == record_id).one_or_none() if record is None: _set_readonly_fields(get_value(FindID.RECORD_ID), '', '', '') return _set_readonly_fields(record.id, record.summary, ', '.join(load_tags_from_id_database(record.id)), record.location)
def cb_set_summary(sender, data): record_id = get_value(ModifyID.ID_INPUT) if not validate_record_id(record_id): return record = query(Record).filter(Record.id == record_id).one_or_none() if record is None: set_error(f'could not find record by id: {record_id}') return summary = get_value(ModifyID.SUMMARY_INPUT).strip() if not summary: set_error('summary must not be empty!') return record.summary = summary commit() set_error('')
def cb_set_tags(sender, data): record_id = get_value(ModifyID.ID_INPUT) if not validate_record_id(record_id): return query(Tag).filter(Tag.record_id == record_id).delete() for tag in load_tags_from_input(): Tag.new(tag, record_id) set_error('')
def init(self, parent): self.window_id = parent with dpg.group(horizontal=True, parent=self.window_id): dpg.add_checkbox(label="Auto-scroll", default_value=True, callback=lambda sender: self.auto_scroll( dpg.get_value(sender))) dpg.add_same_line() dpg.add_button(label="Clear", callback=lambda: dpg.delete_item( self.filter_id, children_only=True)) dpg.add_same_line() dpg.add_input_text(label="Filter", callback=lambda sender: dpg.set_value( self.filter_id, dpg.get_value(sender))) self.child_id = dpg.add_child(parent=self.window_id, autosize_x=True, autosize_y=True) self.filter_id = dpg.add_filter_set(parent=self.child_id)
def update_parameters(self): if self.socket_pub_parameters is None: self.initialise_parameters_socket() attribute_name = 'Parameters' + '##{}##{}'.format( self.operation.name, self.node_index) for i, parameter in enumerate(self.operation.parameters): self.node_parameters[i] = dpg.get_value( self.parameter_inputs_ids[parameter]) topic = self.operation.name + '##' + self.node_index topic = topic.replace(' ', '_') self.socket_pub_parameters.send_string(topic, flags=zmq.SNDMORE) self.socket_pub_parameters.send_pyobj(self.node_parameters)
def cb_find_by_summary(sender, data): clear_table(FindID.RESULT_TABLE) summary = get_value(FindID.SUMMARY).strip() if not summary: return records = query(Record).filter(Record.summary.contains(summary)).all() data = [[ record.id, ', '.join(load_tags_from_id_database(record.id)), record.location, record.summary ] for record in records] set_table_data(FindID.RESULT_TABLE, data)
def call_write(self, sender_widget, data): index = dpg.get_value(CONTACT_LIST) receiver = self.data.get_history_by_contact(index).contact now = time.time() if receiver in self.typing_timestamps: last_timestamp = self.typing_timestamps[receiver] if (last_timestamp is not None) and ( now - last_timestamp < self.typing_timeout_seconds ): return self.typing_timestamps[receiver] = now # call typing callback self.on_type(self.data.myself, receiver)
def read_text(self): # Bruger decrypt funktionen til at forsøge at dekryptere fileName.txt filen password = dpg.get_value(self.readPW) if self.decrypt(password): # Tjekker om dekryptering virkede with open(self.fileName, "r") as f: # Åbner dekryptet fil dpg.set_value(self.rwfield, f.read()) # Viser indholdet til brugeren self.delete_txt( ) # Sletter dekrypteret fil, så indholdet forbliver hemmeligt self.show_status("Fil dekrypteret succesfult!", True) dpg.set_value(self.readPW, "") # Tømmer inputfelt og lukker læsevinduets dpg.hide_item(self.readWindow)
def callback(sender): dpg.delete_item(editor_id, children_only=True) IncludeNode.count = 0 IncludeNode.level = 0 IncludeNode.levels = {0: 0} if sender is not None: selection = dpg.get_value(sender) file = selection else: file = IncludeNode.root inode = IncludeNode(file, 0) inode.start_tree()
def cb_add_record(sender, data): summary = get_value(ModifyID.SUMMARY_INPUT).strip() if not summary: set_error('no summary is set!') return if Record.exists_by_summary_exact(summary): set_error('duplicate record summary') return record = Record.new(summary, get_value(ModifyID.LOCATION_INPUT).lower().strip()) set_value(ModifyID.ID_INPUT, record.id) tags = load_tags_from_input() for tag in tags: Tag.new(tag, record.id) set_error('') set_value(ModifyID.ID_INPUT, 0) set_value(ModifyID.TAGS_INPUT, '') set_value(ModifyID.LOCATION_INPUT, '') set_value(ModifyID.SUMMARY_INPUT, '')
def update_table(self): contact = dpg.get_value(CONTACT_LIST) contact = get_team_prefix(contact) history = self.data.get_history_by_contact(contact) # history = dpg.get_value(CONTACT_LIST) if history is None: return for message_uuid in history.mark_as_read(): self.on_read(self.data.myself, history.contact, message_uuid) if history.is_typing(): dpg.set_value(STATUS_LABEL, "{} is typing...".format(history.contact)) history.set_typing(False) else: dpg.set_value(STATUS_LABEL, "") self.show_history_messages(history)
def execute(self): # get values from static attributes x_shift = dpg.get_value(self.x_shift) y_shift = dpg.get_value(self.y_shift) # get input attribute data x_orig_data = self._input_attributes[0].get_data() y_orig_data = self._input_attributes[1].get_data() # perform actual operations x_data = [] for i in range(0, len(x_orig_data)): x_data.append(x_orig_data[i] + x_shift) y_data = [] for i in range(0, len(y_orig_data)): y_data.append(y_orig_data[i] + y_shift) # execute output attributes self._output_attributes[0].execute(x_data) self._output_attributes[1].execute(y_data) self.finish()
def ignore(): file = dpg.get_value(files_id) if file is not None: items = dpg.get_item_configuration(files_id)["items"] ignore_files = dpg.get_item_configuration(ignore_id)["items"] ignore_files.append(file) dpg.configure_item(ignore_id, items=ignore_files) index = -1 found_index = 0 for item in items: index += 1 if item == file: found_index = index break del items[found_index] dpg.configure_item(files_id, items=items) callback(None)
def __read_csv_cars__(): if dpg.does_alias_exist(TABLE_TAG): dpg.delete_item(TABLE_TAG, children_only=False) if dpg.does_alias_exist(TABLE_TAG): dpg.remove_alias(TABLE_TAG) with dpg.table(header_row=True, resizable=True, tag=TABLE_TAG, parent=MAIN_WINDOW_TAG): with open(dpg.get_value(READ_FILENAME_FIELD)) as f: csv_reader = csv.reader(f, delimiter=',') # f'Table of {f.name}' for num, row in enumerate(csv_reader): if num == 0: for column in row: dpg.add_table_column(label=column, parent=TABLE_TAG) else: with dpg.table_row(parent=TABLE_TAG): for column in row: dpg.add_text(column) if num % 100 == 0: dpg.set_value(value=f'Loaded so far: {num:,}', item=LOADED_FIELD) dpg.set_value(value=f'Loaded ALL', item=LOADED_FIELD)