def cr_ui_chart_panel_show(self, chart_obj, closable=False, width=640, height=480, pos_x=400, pos_y=300): """ 展示图表 :param chart_obj: 实例化的对象 :param closable: boole :param width: 图表的宽 :param height: 图标的高 :param pos_x: 以屏幕左上角为坐系的x轴 :param pos_y: 以屏幕左上角为坐系的y轴 :return: """ panel_id = "CHART_" + str(chart_obj.chart_id) title = chart_obj.title if panel_id not in self.html_panels: # 先创建一个htmlPanel url = chart_obj.html_file msg = AtomUi.mk_ui_html_panel_show(panel_id, url, title, width, height, closable, pos_x, pos_y) self.html_panels.append(panel_id) # 用state显示图表 self.pub_state(panel_id, "", msg) time.sleep(1) init_data = chart_obj.to_json() msg = AtomUi.mk_ui_chart_init(panel_id, init_data) self.chart_panels[chart_obj.chart_id] = chart_obj return self.pub_state(WORLD_STATES.CHART_INIT, { "panel_id": panel_id, "init_data": init_data }, msg)
def cr_ui_chart_panel_close(self, chart_id): panel_id = "CHART_" + str(chart_id) msg = AtomUi.mk_ui_html_panel_close(panel_id) try: self.chart_panels.pop(chart_id) except Exception: logging.warning("Chart with id %s not exists." % chart_id) return self.pub_message(msg)
def cr_ui_chart_panel_update(self, chart_id): """ 更新图表 :param chart_id: 展示图表的名字 :return: """ panel_id = "CHART_" + str(chart_id) if chart_id in self.chart_panels: data = self.chart_panels[chart_id].to_json() msg = AtomUi.mk_ui_chart_init(panel_id, data) return self.pub_message(msg)
def cr_ui_html_panel_show(self, url, title="", closable=False, width=640, height=480, pos_x=400, pos_y=300): if url not in self.html_panels: msg = AtomUi.mk_ui_html_panel_show(url, url, title, width, height, closable, pos_x, pos_y) self.html_panels.append(url) return self.pub_message(msg)
def cr_ui_set_title(self, title=""): """ 设置顶部标题文本 :param title: 标题文本 """ # if not type(title) in [str, unicode]: # raise TypeError("argument 'title' must be str or unicode type.") msg = AtomUi.mk_ui_set_title(str(title)) self.pub_state(WORLD_STATES.TITLE, title, msg) # 发送proto2兼容数据 msg2 = AtomUi2.mk_ui_set_title(str(title)) self.pub_state(WORLD_STATES.TITLE_PROTO2, title, msg2) return True
def cr_ui_toast_message(self, message_title, message_text, toast_position=Enums.EnumPosition.left, toast_type=Enums.EnumToastType.info, duration=5): """ 设置Toast Message系统 :param message_title: 消息标题 :param message_text: 消息文本 :param toast_position: 消息位置 :param toast_type: 消息类型(封装动作) """ toast_icon = Enums.EnumToastIcon.information toast_color = "green" if toast_type == Enums.EnumToastType.info: toast_icon = Enums.EnumToastIcon.information toast_color = "blue" elif toast_type == Enums.EnumToastType.warning: toast_icon = Enums.EnumToastIcon.exclamation toast_color = "orange" elif toast_type == Enums.EnumToastType.exlamation: toast_icon = Enums.EnumToastIcon.exclamation toast_color = "pink" elif toast_type == Enums.EnumToastType.error: toast_icon = Enums.EnumToastIcon.exclamation # TODO:加一个error图标 toast_color = "red" elif toast_type == Enums.EnumToastType.question: toast_icon = Enums.EnumToastIcon.question toast_color = "yellow" msg = AtomUi.mk_ui_toast(position=toast_position, icon=toast_icon, text_title=message_title, text_content=message_text, switch=Enums.EnumOnoff.on, duration=duration, color=toast_color) self.pub_message(msg) # 发送proto2兼容数据 msg2 = AtomUi2.mk_ui_toast(position=toast_position, icon=toast_icon, text_title=message_title, text_content=message_text, switch=Enums.EnumOnoff.on, duration=duration, color=toast_color) self.pub_message(msg2) return True
def cr_ui_log_message(self, message_text, message_datetime=""): """ 显示在右下角的攻击记录 :param message_text: 攻击记录的内容 :param message_datetime: 发生的时间 选填 :return: """ if not message_datetime: message_datetime = time.strftime('%Y-%m-%d %X', time.localtime()) msg = AtomUi.mk_ui_set_message(message_text, message_datetime) self.pub_message(msg) # 发送proto2兼容数据 msg2 = AtomUi2.mk_ui_set_message(message_text, message_datetime) self.pub_message(msg2) return True
def cr_ui_set_logo(self, logo_url=""): """ 设置顶部标题的LOGO图片URL :param logo_url: """ # if not type(logo_url) is str or : # raise exceptions.TypeError("argument 'logo' must be str or unicode type.") if not logo_url.startswith("http"): raise ValueError("value 'logo_url' must starts with http/https.") msg = AtomUi.mk_ui_set_logo(logo_url) #self.save_state(WORLD_STATES.LOGO, logo_url) self.pub_state(WORLD_STATES.LOGO, logo_url, msg) # 发送proto2兼容数据 msg2 = AtomUi2.mk_ui_set_logo(logo_url) #self.save_state(WORLD_STATES.LOGO, logo_url) self.pub_state(WORLD_STATES.LOGO_PROTO2, logo_url, msg2) return True
def cr_ui_html_panel_refresh(self, url): if url in self.html_panels: msg = AtomUi.mk_ui_html_panel_reload(url) return self.pub_message(msg)
def cr_ui_html_panel_close(self, url): if url in self.html_panels: msg = AtomUi.mk_ui_html_panel_close(url) self.html_panels.remove(url) return self.pub_message(msg)