def test_dialog(): global test_data Screen.attr_color(C_WHITE, C_BLUE) Screen.cls() Screen.attr_reset() test_data.dialog_w = DialogNew(1, 1, 70, 20, title="RR-DUINO TEST SETUP") test_data.dialog_w.add( 1, 1, WFrame(58, 3, "Device setup address " + str(address))) test_data.dialog_w.add(2, 2, "Status:") test_data.device_status = WLabel("Unknown state", 22) test_data.dialog_w.add(10, 2, test_data.device_status) test_data.dialog_w.add(1, 4, WFrame(25, 9, "Test setup")) test_data.dialog_w.add(2, 5, "Subaddress:") test_data.subadd_entry = WTextEntry(5, "0") test_data.dialog_w.add(14, 5, test_data.subadd_entry) test_data.io = WRadioButton(["sensor", "turnout"]) test_data.dialog_w.add(2, 7, test_data.io) test_data.value = WRadioButton(["OFF", "ON"]) test_data.dialog_w.add(2, 9, test_data.value) test_read_button = WButton(10, "Read") test_read_button.on("click", test_read_clicked) test_data.dialog_w.add(2, 11, test_read_button) test_write_button = WButton(10, "Write") test_write_button.on("click", test_write_clicked) test_data.dialog_w.add(13, 11, test_write_button) test_data.dialog_w.loop() next_dialog = None
def loading_project(): with Context(): rows, columns = os.popen('stty size', 'r').read().split() Screen.attr_color(C_WHITE, C_RED) Screen.cls() Screen.attr_reset() d = Dialog(0, 0, int(columns), int(rows)) d.add(1, 1, "Loading Project") choice = WListBox(16, int(rows) - 5, ["choice%d" % i for i in range(100)]) d.add(1, 3, choice) b = WButton(8, "Choose") d.add(1, int(rows) - 2, b) b.finish_dialog = ACTION_OK res = d.loop()
def sensor_dialog(): global sensor_data Screen.attr_color(C_WHITE, C_BLUE) Screen.cls() Screen.attr_reset() sensor_data.dialog_w = DialogNew(1, 1, 70, 20, title="RR-DUINO SENSOR SETUP") sensor_data.dialog_w.add( 1, 1, WFrame(58, 3, "Device setup address " + str(address))) sensor_data.dialog_w.add(2, 2, "Status:") sensor_data.device_status = WLabel("Unknown state", 22) sensor_data.dialog_w.add(10, 2, sensor_data.device_status) sensor_data.eeprom_status = WLabel("Not loaded / Not storing", 25) set_eeprom_status(sensor_data.eeprom_status) sensor_data.dialog_w.add(32, 2, sensor_data.eeprom_status) sensor_data.dialog_w.add(1, 4, WFrame(25, 8, "New sensor")) sensor_data.dialog_w.add(2, 5, "Subaddress:") sensor_data.subadd_entry = WTextEntry(5, "0") sensor_data.dialog_w.add(14, 5, sensor_data.subadd_entry) sensor_data.dialog_w.add(2, 6, "Pin:") sensor_data.pin_entry = WTextEntry(5, "0") sensor_data.dialog_w.add(14, 6, sensor_data.pin_entry) sensor_data.io = WRadioButton(["input", "input with pull-up", "output"]) sensor_data.dialog_w.add(2, 7, sensor_data.io) sensor_commit_button = WButton(15, "Commit sensor") sensor_commit_button.on("click", sensor_commit_clicked) sensor_data.dialog_w.add(5, 10, sensor_commit_button) sensor_data.device_status.t, sensor_data.sensors_list = load_sensors() sensor_data.list_wg = WListBox(28, 6, sensor_data.sensors_list) sensor_data.dialog_w.add(26, 4, WFrame(30, 8, "Sensors")) sensor_data.dialog_w.add(27, 5, sensor_data.list_wg) button = WButton(28, "Delete sensor") button.on("click", sensor_delete_clicked) sensor_data.dialog_w.add(27, 12, button) sensor_data.dialog_w.loop() next_dialog = None
def restore_dialog(): global restore_data Screen.attr_color(C_WHITE, C_BLUE) Screen.cls() Screen.attr_reset() restore_data.dialog_w = DialogNew(1, 1, 70, 20, title="RR-DUINO NODE RESTORE") restore_data.dialog_w.add( 1, 1, WFrame(58, 4, "Device setup address " + str(address))) restore_data.dialog_w.add(2, 2, "Status:") if main_data.status is None: s = "Unknown state" else: s = main_data.status restore_data.device_status = WLabel(s, 22) restore_data.dialog_w.add(10, 2, restore_data.device_status) restore_data.dialog_w.add(2, 3, "EEPROM Status:") restore_data.eeprom_status = WLabel(eeprom_status_str(), 22) restore_data.dialog_w.add(16, 3, restore_data.eeprom_status) restore_data.dialog_w.add(1, 5, WFrame(68, 16, "Restore")) restore_data.dialog_w.add(2, 6, "Restore file:") restore_data.file_entry = WTextEntry(53, "") restore_data.dialog_w.add(15, 6, restore_data.file_entry) restore_load_button = WButton(66, "Load restore file") restore_load_button.on("click", restore_load_clicked) restore_data.dialog_w.add(2, 8, restore_load_button) restore_node_button = WButton(66, "Restore selected node") restore_node_button.on("click", restore_node_clicked) restore_data.dialog_w.add(2, 19, restore_node_button) restore_data.warning = WLabel( "File name not set ") restore_data.dialog_w.add(2, 7, restore_data.warning) restore_data.list_wg = WListBox(64, 7, []) restore_data.dialog_w.add(2, 10, WFrame(66, 9, "Nodes")) restore_data.dialog_w.add(3, 11, restore_data.list_wg) restore_data.dialog_w.loop() next_dialog = None
def backup_dialog(): global backup_data Screen.attr_color(C_WHITE, C_BLUE) Screen.cls() Screen.attr_reset() backup_data.dialog_w = DialogNew(1, 1, 70, 20, title="RR-DUINO NODE BACKUP") backup_data.dialog_w.add( 1, 1, WFrame(58, 4, "Device setup address " + str(address))) backup_data.dialog_w.add(2, 2, "Status:") if main_data.status is None: s = "Unknown state" else: s = main_data.status backup_data.device_status = WLabel(s, 22) backup_data.dialog_w.add(10, 2, backup_data.device_status) backup_data.dialog_w.add(2, 3, "EEPROM Status:") backup_data.eeprom_status = WLabel(eeprom_status_str(), 22) backup_data.dialog_w.add(16, 3, backup_data.eeprom_status) backup_data.dialog_w.add(1, 5, WFrame(68, 7, "Backup")) backup_data.dialog_w.add(2, 6, "Backup file:") backup_data.file_entry = WTextEntry(54, "") backup_data.dialog_w.add(14, 6, backup_data.file_entry) backup_data.dialog_w.add(2, 7, "Node name:") backup_data.name_entry = WTextEntry(54, "") backup_data.dialog_w.add(14, 7, backup_data.name_entry) backup_write_button = WButton(66, "Write to file") backup_write_button.on("click", backup_write_clicked) backup_data.dialog_w.add(2, 9, backup_write_button) backup_data.warning = WLabel( "File name not set ") backup_data.dialog_w.add(2, 10, backup_data.warning) backup_data.dialog_w.loop() next_dialog = None
from picotui.context import Context from picotui.screen import Screen from picotui.widgets import * from picotui.defs import * with Context(): Screen.attr_color(C_WHITE, C_BLUE) Screen.cls() Screen.attr_reset() d = Dialog(5, 5, 50, 12) # Can add a raw string to dialog, will be converted to WLabel d.add(1, 1, "Label:") d.add(11, 1, WLabel("it's me!")) d.add(1, 2, "Entry:") d.add(11, 2, WTextEntry(4, "foo")) d.add(1, 3, "Dropdown:") d.add(11, 3, WDropDown(10, ["Red", "Green", "Yellow"])) d.add(1, 4, "Combo:") d.add(11, 4, WComboBox(8, "fo", ["foo", "foobar", "bar", "long string"])) d.add(1, 5, "Auto complete:") d.add(15, 5, WAutoComplete(8, "fo", ["foo", "foobar", "bar", "car", "dar"])) d.add(1, 6, "Password:"******""))
from picotui.screen import Screen from picotui.widgets import * from picotui.defs import * if __name__ == "__main__": s = Screen() # Set the list of all available DropDown choices choices = ["Green1", "Green2", "Green3", "Red1", "Red2", "Red3", "Yellow1", "Yellow2", "Yellow3"] try: s.init_tty() s.enable_mouse() s.attr_color(C_WHITE, C_BLUE) s.cls() s.attr_reset() d = Dialog(5, 5, 20, 12) # DropDown and ListBox widgets d.add(1, 1, "Dropdown:") w_dropdown = WDropDown(10, ["All", "Red", "Green", "Yellow"]) d.add(11, 1, w_dropdown) d.add(1, 3, "List:") w_listbox = WListBox(16, 4, choices) d.add(1, 4, w_listbox) # Filter the ListBox based on the DropDown selection def dropdown_changed(w):
def __init__(self): Screen.attr_color(C_WHITE, None) Screen.cls() Screen.attr_reset() self.stopping = False self.kbuf = b"" self.last_rftime = 0 self.window = Dialog(0, 0, 48, 20) UWBDATA_Y = 1 self.window.add(2, UWBDATA_Y, WFrame(44, 4, "UWB Data")) self.window.add(6, UWBDATA_Y + 1, WLabel("Distance")) self.window.add(18, UWBDATA_Y + 1, WLabel("Angual")) self.window.add(32, UWBDATA_Y + 1, WLabel("Updated")) ## Value self.lbl_uwb_dist = FormatLabel("{:8.1f}", 0.0) self.lbl_uwb_ang = FormatLabel("{:6.1f}", 0) self.lbl_uwb_time = FormatLabel("{:4.2f} sec", 0.0) self.window.add(6, UWBDATA_Y + 2, self.lbl_uwb_dist) self.window.add(18, UWBDATA_Y + 2, self.lbl_uwb_ang) self.window.add(36, UWBDATA_Y + 2, self.lbl_uwb_time) TOFDATA_Y = 6 self.window.add(2, TOFDATA_Y, WFrame(44, 4, "TOF Data")) self.window.add(5, TOFDATA_Y + 1, WLabel(" L", 4)) self.window.add(12, TOFDATA_Y + 1, WLabel(" FL", 4)) self.window.add(19, TOFDATA_Y + 1, WLabel(" ML", 4)) self.window.add(26, TOFDATA_Y + 1, WLabel(" MR", 4)) self.window.add(33, TOFDATA_Y + 1, WLabel(" FR", 4)) self.window.add(40, TOFDATA_Y + 1, WLabel(" R", 4)) ## Value self.lbl_tof_l = FormatLabel("{:>4d}", 2000) self.lbl_tof_fl = FormatLabel("{:>4d}", 2000) self.lbl_tof_ml = FormatLabel("{:>4d}", 2000) self.lbl_tof_mr = FormatLabel("{:>4d}", 2000) self.lbl_tof_fr = FormatLabel("{:>4d}", 2000) self.lbl_tof_r = FormatLabel("{:>4d}", 2000) self.window.add(5, TOFDATA_Y + 2, self.lbl_tof_l) self.window.add(12, TOFDATA_Y + 2, self.lbl_tof_fl) self.window.add(19, TOFDATA_Y + 2, self.lbl_tof_ml) self.window.add(26, TOFDATA_Y + 2, self.lbl_tof_mr) self.window.add(33, TOFDATA_Y + 2, self.lbl_tof_fr) self.window.add(40, TOFDATA_Y + 2, self.lbl_tof_r) STATUS_Y = 11 self.window.add(2, STATUS_Y, WLabel("Status: ")) self.lbl_status = FormatLabel("{}", "Unknown", 32) self.window.add(10, STATUS_Y, self.lbl_status) STEPPER_Y = 14 self.window.add(2, STEPPER_Y, WFrame(44, 5, "Steppers")) self.window.add(4, STEPPER_Y + 1, WLabel("CurSpeed: ")) self.window.add(4, STEPPER_Y + 2, WLabel("TgtSpeed: ")) self.window.add(4, STEPPER_Y + 3, WLabel("StepToGo: ")) ## Left self.lbl_stpl_cs = FormatLabel("{:8.2f}", 0.0) self.lbl_stpl_ts = FormatLabel("{:8.2f}", 0.0) self.lbl_stpl_tg = FormatLabel("{:8d}", 0) self.window.add(20, STEPPER_Y + 1, self.lbl_stpl_cs) self.window.add(20, STEPPER_Y + 2, self.lbl_stpl_ts) self.window.add(20, STEPPER_Y + 3, self.lbl_stpl_tg) ## Right self.lbl_stpr_cs = FormatLabel("{:8.2f}", 0.0) self.lbl_stpr_ts = FormatLabel("{:8.2f}", 0.0) self.lbl_stpr_tg = FormatLabel("{:8d}", 0) self.window.add(32, STEPPER_Y + 1, self.lbl_stpr_cs) self.window.add(32, STEPPER_Y + 2, self.lbl_stpr_ts) self.window.add(32, STEPPER_Y + 3, self.lbl_stpr_tg) btn_zzz = WButton(10, "Anywhere") self.window.add(8, 19, btn_zzz) btn_stop = WButton(8, "Stop") self.window.add(32, 19, btn_stop) btn_stop.on('click', lambda w: self.stop())
def main_dialog(): global main_data global next_dialog Screen.attr_color(C_WHITE, C_BLUE) Screen.cls() Screen.attr_reset() main_data.dialog_w = DialogNew(5, 5, 70, 17, title="RR-DUINO SETUP") next_dialog = None main_data.dialog_w.add(1, 1, WFrame(35, 5, "Serial Port")) main_data.dialog_w.add(2, 2, "Port:") main_data.port_entry = WTextEntry(20, serial_port) main_data.dialog_w.add(11, 2, main_data.port_entry) main_data.dialog_w.add(2, 3, "Speed:") main_data.baudrate_entry = WTextEntry(20, str(serial_speed)) main_data.dialog_w.add(11, 3, main_data.baudrate_entry) s = "Connect" if main_data.connect_state is None: main_data.connect_state = False #begin disconnected elif main_data.connect_state: s = "Disconnect" main_data.connect_button = WButton(12, s) main_data.connect_button.on("click", connect_clicked) main_data.dialog_w.add(11, 4, main_data.connect_button) main_data.dialog_w.add(36, 1, WFrame(35, 5, "Device")) main_data.dialog_w.add(37, 2, "Address:") main_data.address_entry = WTextEntry(20, str(address)) main_data.dialog_w.add(46, 2, main_data.address_entry) set_address_button = WButton(13, "Set address") main_data.dialog_w.add(37, 3, set_address_button) set_address_button.on("click", set_address_clicked) check_device_button = WButton(15, "Check device") check_device_button.on("click", check_device_clicked) main_data.dialog_w.add(51, 3, check_device_button) main_data.dialog_w.add(37, 4, "Version:") if main_data.device_version is None: s = "Unknown" else: s = main_data.device_version main_data.device_version_label = WLabel(s, 23) main_data.dialog_w.add(45, 4, main_data.device_version_label) main_data.dialog_w.add(1, 6, WFrame(70, 4, "Device setup")) main_data.dialog_w.add(2, 7, "Status:") if main_data.status is None: s = "Unknown" else: s = main_data.status main_data.device_status = WLabel(s, 26) main_data.dialog_w.add(10, 7, main_data.device_status) main_data.eeprom_status = WLabel(eeprom_status_str(), 25) main_data.dialog_w.add(45, 7, main_data.eeprom_status) load_eeprom_button = WButton(22, "Load EEPROM") load_eeprom_button.on("click", load_eeprom_clicked) main_data.dialog_w.add(2, 8, load_eeprom_button) store_eeprom_button = WButton(22, "Store to EEPROM") store_eeprom_button.on("click", store_eeprom_clicked) main_data.dialog_w.add(25, 8, store_eeprom_button) clear_eeprom_button = WButton(22, "Clear EEPROM") clear_eeprom_button.on("click", clear_eeprom_clicked) main_data.dialog_w.add(48, 8, clear_eeprom_button) main_data.dialog_w.add(1, 10, WFrame(70, 3, "Setup")) turnout_button = WButton(22, "Turnouts setup") turnout_button.on("click", turnout_clicked) main_data.dialog_w.add(2, 11, turnout_button) sensor_button = WButton(22, "Sensors setup") sensor_button.on("click", sensor_clicked) main_data.dialog_w.add(25, 11, sensor_button) test_button = WButton(22, "Test setup") test_button.on("click", test_clicked) main_data.dialog_w.add(48, 11, test_button) main_data.dialog_w.add(1, 13, WFrame(70, 3, "Backup")) backup_button = WButton(33, "Backup node to file") backup_button.on("click", backup_clicked) main_data.dialog_w.add(2, 14, backup_button) restore_button = WButton(34, "Restore node from file") restore_button.on("click", restore_clicked) main_data.dialog_w.add(36, 14, restore_button) main_data.dialog_w.loop()
def turnout_dialog(): global turnout_data Screen.attr_color(C_WHITE, C_BLUE) Screen.cls() Screen.attr_reset() turnout_data.dialog_w = DialogNew(1, 1, 70, 20, title="RR-DUINO TURNOUT SETUP") turnout_data.dialog_w.add( 1, 1, WFrame(58, 3, "Device setup address " + str(address))) turnout_data.dialog_w.add(2, 2, "Status:") turnout_data.device_status = WLabel("Unknown state", 22) turnout_data.dialog_w.add(10, 2, turnout_data.device_status) turnout_data.eeprom_status = WLabel("Not loaded / Not storing", 25) set_eeprom_status(turnout_data.eeprom_status) turnout_data.dialog_w.add(32, 2, turnout_data.eeprom_status) turnout_data.dialog_w.add(1, 4, WFrame(25, 12, "New turnout")) turnout_data.dialog_w.add(2, 5, "Subaddress:") turnout_data.subadd_entry = WTextEntry(5, "0") turnout_data.dialog_w.add(16, 5, turnout_data.subadd_entry) turnout_data.dialog_w.add(2, 6, "Servo pin:") turnout_data.servo_pin_entry = WTextEntry(5, "0") turnout_data.dialog_w.add(16, 6, turnout_data.servo_pin_entry) turnout_data.dialog_w.add(2, 7, "Straight pos:") turnout_data.straight_pos_entry = WTextEntry(5, "0") turnout_data.dialog_w.add(16, 7, turnout_data.straight_pos_entry) turnout_data.dialog_w.add(2, 8, "Thrown pos:") turnout_data.thrown_pos_entry = WTextEntry(5, "0") turnout_data.dialog_w.add(16, 8, turnout_data.thrown_pos_entry) turnout_data.pulse_relay_pins = WCheckbox("Pulse relay pins") turnout_data.dialog_w.add(2, 10, turnout_data.pulse_relay_pins) turnout_data.relay_pins_entry = [] turnout_data.dialog_w.add(2, 11, "Relay pin 1:") turnout_data.relay_pins_entry.append(WTextEntry(5, "")) turnout_data.dialog_w.add(16, 11, turnout_data.relay_pins_entry[0]) turnout_data.dialog_w.add(2, 12, "Relay pin 2:") turnout_data.relay_pins_entry.append(WTextEntry(5, "")) turnout_data.dialog_w.add(16, 12, turnout_data.relay_pins_entry[1]) turnout_commit_button = WButton(15, "Commit turnout") turnout_commit_button.on("click", turnout_commit_clicked) turnout_data.dialog_w.add(5, 14, turnout_commit_button) turnout_data.device_status.t, turnout_data.turnouts_list = load_turnouts() turnout_data.list_wg = WListBox(40, 10, turnout_data.turnouts_list) turnout_data.dialog_w.add(26, 4, WFrame(42, 13, "Turnouts")) turnout_data.dialog_w.add(27, 5, turnout_data.list_wg) turnout_data.list_wg.on("changed", adjust_fine_tune_pos) button = WButton(40, "Delete turnout") button.on("click", turnout_delete_clicked) turnout_data.dialog_w.add(27, 16, button) turnout_data.dialog_w.add(26, 17, WFrame(42, 3, "Fine tune turnout")) fine_tune = WButton(5, "<<") fine_tune.on("click", fine_tune_turnout_MINUS) turnout_data.dialog_w.add(32, 18, fine_tune) fine_tune = WButton(5, "<") fine_tune.on("click", fine_tune_turnout_minus) turnout_data.dialog_w.add(38, 18, fine_tune) turnout_data.fine_tune_label = WLabel(pad_int(90, 3), 5) turnout_data.dialog_w.add(44, 18, turnout_data.fine_tune_label) fine_tune = WButton(5, ">") fine_tune.on("click", fine_tune_turnout_plus) turnout_data.dialog_w.add(49, 18, fine_tune) fine_tune = WButton(5, ">>") fine_tune.on("click", fine_tune_turnout_PLUS) turnout_data.dialog_w.add(56, 18, fine_tune) fine_tune = WButton(13, "Get turnout") fine_tune.on("click", get_turnout) turnout_data.dialog_w.add(27, 20, fine_tune) fine_tune = WButton(13, "As straight") fine_tune.on("click", get_straight_pos) turnout_data.dialog_w.add(41, 20, fine_tune) fine_tune = WButton(12, "As thrown") fine_tune.on("click", get_thrown_pos) turnout_data.dialog_w.add(55, 20, fine_tune) next_dialog = None turnout_data.dialog_w.loop()
class App(object): def __init__(self): self.docker_client = client.from_env() self._init_screen() self._init_widgets() def _init_screen(self): self.screen = Screen() self.screen.init_tty() self.screen.enable_mouse() self.screen.attr_color(C_WHITE, C_MAGENTA) self.screen.cls() self.screen.attr_reset() self.width, self.height = Screen.screen_size() def _init_widgets(self): # filter choices self.dialog = Dialog(0, 0, self.width, self.height, title="Docker Image list") start_x, start_y = 1, 1 self._init_image_list(start_x, start_y + 2) self._init_quit_button(start_x + 2, self.height - 5) self._init_info_bar(start_x + 1, self.height - 3) def _init_image_list(self, x, y): self.dialog.add(x, y, "Image List:") w_listbox = MyListBox(self, self.width - 5, self.height - 20, ["%s %s" % (i.short_id, i.base_url) for i in self.load_images()]) w_listbox.focus = True self.dialog.add(x, y + 1, w_listbox) def _init_info_bar(self, x, y): self.info_bar = WLabel("信息", w=self.width - 5) self.dialog.add(x, y, self.info_bar) def _init_quit_button(self, x, y): b = WButton(8, "Quit") self.dialog.add(x, y, b) b.finish_dialog = ACTION_OK def load_images(self): images = [] for i in self.docker_client.images.list(): if i.tags: for tag in i.tags: images.append(ImageObj(tag, i.short_id, i)) else: images.append(ImageObj(i.short_id, i.short_id, i)) sorted(images, key=lambda x: x.short_id) return images def delete_image(self, name): self.docker_client.images.remove(name.split()[1]) def info(self, message): self.log(message, C_GREEN) def warn(self, message): self.log(message, C_RED) def log(self, message, color): self.info_bar.attr_color(color) self.info_bar.t = str(message) self.info_bar.redraw() self.info_bar.attr_reset() def run(self): try: self.dialog.loop() finally: self.docker_client.close() self.screen.goto(0, 50) self.screen.cursor(True) self.screen.disable_mouse() self.screen.deinit_tty()
async def main(): connect_error = 0 freeze = False bit = MyBittrex() try: import termios can_term = True with Context(): Screen.attr_color(C_WHITE, C_BLACK) Screen.cls() Screen.attr_reset() d = Dialog(1, 1, 30, 11) d.add(1, 1, "Heartbeat: ") d.add(4, 2, "Candle:") d.add(1, 3, "Summaries:") d.add(3, 4, "Summary:") d.add(6, 5, "Book:") d.add(3, 6, "Tickers:") d.add(4, 7, "Ticker:") d.add(5, 8, "Trade:") d.add(6, 9, "Time:") b = WButton(8, "") d.add(12, 1, b) b.finish_dialog = ACTION_CANCEL w_candle = WLabel("", w=14) d.add(12, 2, w_candle) w_summaries = WLabel("", w=14) d.add(12, 3, w_summaries) w_summary = WLabel("", w=14) d.add(12, 4, w_summary) w_book = WLabel("", w=14) d.add(12, 5, w_book) w_tickers = WLabel("", w=14) d.add(12, 6, w_tickers) w_ticker = WLabel("", w=14) d.add(12, 7, w_ticker) w_trade = WLabel("", w=14) d.add(12, 8, w_trade) w_time = WLabel("", w=19) d.add(12, 9, w_time) d.redraw() except ImportError: can_term = False while True: if can_term: await asyncio.sleep(2) with Context(): b.disabled = bit.last_state < (bit.current_time() - 2000) b.t = str((bit.current_time() - bit.last_state) / 1000) + 's' w_candle.t = str(bit.candle) w_summaries.t = str(bit.summaries) w_summary.t = str(bit.summary) + '%' w_book.t = str(bit.book) w_tickers.t = str(bit.tickers) w_ticker.t = str(bit.ticker) w_trade.t = str("%.2f" % float(bit.trade)) w_time.t = bit.last_date d.redraw() else: await asyncio.sleep(5) if bit.last_state < (bit.current_time() - 10000) and not freeze: print( str(bit.last_date) + " — Heartbeat didn't get more than 10 sec") freeze = True connect_error = 1 if bit.con_master.started: bit.con_master.close() elif freeze and bit.last_state > (bit.current_time() - 10000): freeze = False print("Heartbeat Unfreezes") elif not freeze: print(".", end='') # print(str(bit.last_date) + ' — Candle: ' + str(bit.candle) + # ', Summaries: ' + str(bit.summaries) + # ', Summary: ' + str(bit.summary) + # '%, Book: ' + str(bit.book) + # ', Tickers: ' + str(bit.tickers) + # ', Ticker: ' + str(bit.ticker) + # ', Trade: ' + str(bit.trade) + # ' — OK: ' + str((bit.current_time() - bit.last_state) / 1000) + 's') elif connect_error > 0: print(str(bit.last_date) + ' — Reconnect try ' + str(connect_error) + ': ', end='') try: bit.restart() connect_error = 0 freeze = False print('Success.') except Exception as some_ex: print('Error: ' + str(some_ex)) connect_error += 1 await asyncio.sleep(5)
).communicate() term_h = Popen( 'tput lines', shell=True, stdout=PIPE, ).communicate() # Size variables width = int(term_w[0]) height = int(term_h[0]) mid_x = width / 2 mid_y = height / 2 # Set screen shit Screen.attr_color(C_WHITE, C_BLACK) Screen.cls() Screen.attr_reset() Screen.enable_mouse() # Base d = Dialog(0, 0, width, height) frame = WFrame(width - 2, height - 2, "Login Screen:") d.add(1, 1, frame) # Title with open("Minimal/title.txt", "r") as f: title = f.readlines() name_w = len(title[0]) name_h = len(title) - 1