예제 #1
0
            def pack_sub_foot_win():
                def settings():
                    GuiSettings.pack()

                def click_login():
                    def async_login(args=None):
                        self.login_handle()
                        try:
                            login_btn.disable(False)
                        except:
                            pass

                    login_btn.disable(True)
                    Common.create_thread(func=async_login)

                # 选项按钮
                set_byn = tk.Button(foot_fm,
                                    text='☰',
                                    font=(Global.G_DEFAULT_FONT, 18),
                                    bd=0,
                                    activebackground=Global.G_DEFAULT_COLOR,
                                    bg=Global.G_DEFAULT_COLOR,
                                    command=settings)
                set_byn.pack(side='left', padx=50)
                WidgetTip.enter_tips(set_byn, '首选项', 10, 15)
                # 一键登录按钮
                login_btn = ColorButton(foot_fm,
                                        size=14,
                                        width=26,
                                        text='一  键  登  录',
                                        command=click_login)
예제 #2
0
 def press_bar_handle(key):
     if key == 'TB_EXPAND':
         tree_inst.expand_trees()
     elif key in ['TB_ABOUT', "MENU_ABOUT"]:
         TopAbout()
     elif key in ['TB_SCREEN', 'MENU_SCREEN']:
         ScreenShot()
     elif key in ['TB_HELP', 'MENU_HELP']:
         pdf = 'SystemController.pdf'
         if not Common.is_file(pdf):
             WidgetTip.error('{}不存在,请确认!'.format(pdf))
             return
         Common.create_thread(lambda: Common.system_open(pdf))
     elif key in ['MENU_SET', 'TB_SET']:
         GuiSettings.pack()
     elif key == 'MENU_EXIT':
         app_gate.close()
     elif key == 'TB_LAST':
         tree_inst.last()
     elif key == 'TB_NEXT':
         tree_inst.next()
     elif key in ["MENU_WHITE", "MENU_BLACK"]:
         WidgetTip.info("敬请期待 !")
     else:
         # 根据界面 image 值即可进入对应界面 #
         tree_inst.selection(key)
예제 #3
0
 def execute_handle(self, data):
     oper, ips, opts = data
     if not ips:
         WidgetTip.warn("请选择IP地址")
         return
     root, delay, loop = opts
     script = self.page_args[3]
     if oper == 'stop':
         view_gate.stop_exec_data.set_data([ips, script])
         return
     params = self.page_inst.combine_input(ips)
     if not params:
         return
     scripts_args, upload_list = params
     #upload_gui = False
     #for ip, up_list in upload_list.items():
     #    for file in up_list:
     #        if Common.file_size(file) > 10485760:   # 10MB以下文件不显示上传进度窗
     #            upload_gui = True
     #            break
     #    if upload_gui:
     #        break
     #if upload_gui:
     #    self.upload_inst = UploadProgress(ips)
     exec_data = [ips, script, root, delay, loop, scripts_args, upload_list]
     view_gate.start_exec_data.set_data(exec_data)
예제 #4
0
 def pack_sub_tree_fm():
     tree_view_data = view_gate.query_tree_view_data()
     try:
         treeview = TreeView(tree_fm, tree_view_data, switch_page)
     except Exception as e:
         WidgetTip.error("界面数据异常: %s" % str(e))
         view_gate.exception_data.set_data(traceback.format_exc())
         app_gate.close(ask=False)
     return treeview
예제 #5
0
 def parser_widget_actions():
     for act in actions:
         if act == 'UploadFile':
             for ip in ips:
                 # 本地的文件路径传给上传列表,同时修改脚本参数为文件名
                 _local_f = shell_params[ip][-1]
                 prev_uploads[ip].append(_local_f)
                 shell_params[ip][-1] = Common.basename(_local_f)
         else:
             WidgetTip.error("Not support WidgetAction: {}".format(act))
             continue
예제 #6
0
 def login_result(self, data):
     index, state, info = data
     if index == 'ALL':  # 最后结果
         self.top_prog.destroy()
         WidgetTip.info(info)
         if state:
             self.destroy()
             app_gate.switch_main()
     else:  # 单个登录结果
         instance = self.sub_login[index]
         self.top_prog.update(info)
         instance.set_status(Global.G_TIP_FG_COLOR[state])
예제 #7
0
 def combine_input(self, ips):
     if not ips:
         WidgetTip.warn("请勾选IP地址")
         return None
     not_set = self.exist_not_set_combox()
     if not_set:
         WidgetTip.warn("请设置夏令时参数:%s" % not_set[0])
         return None
     params_dict, upload_dict, param_str = {}, {}, self.options_combine()
     for ip in ips:
         params_dict[ip] = [param_str]
         upload_dict[ip] = []
     return [params_dict, upload_dict]
예제 #8
0
 def switch_page(args_tuple):
     # image, text, widgets, shell, ploter, buttons, window = args_tuple = self.page_args
     self.page_args = []
     [self.page_args.append(i) for i in list(args_tuple)]
     try:
         button = args_tuple[5]
         new_page = pager.switch_page(args_tuple[1:])
         if not new_page and self.last_page_key:
             tree_inst.selection(
                 self.last_page_key)  # 界面切换失败时还原到上一个可用界面
             return
         self.last_page_key = args_tuple[0]
         self.page_inst = new_page
         self.select_inst.show_button(button)
     except Exception as e:
         WidgetTip.error("切换界面异常:%s" % e)
         view_gate.exception_data.set_data(traceback.format_exc())
예제 #9
0
 def manual(cls, params):
     try:
         matplotlib.use('TkAgg')
         plt.ion()  # 开启interactive mode
         plt.close('all')
         '''
         l = len(params)
         if l == 1:
             axes = plt.subplots(figsize=(12, 6), nrows=1, ncols=1, sharey=True, sharex=True)[1]
             ax_list = [axes]
         elif 1 < l <= 2:
             axes = plt.subplots(figsize=(12, 6), nrows=2, ncols=1, sharey=True, sharex=True)[1]
             ax_list = [axes[1], axes[0]]
         else:
             axes = plt.subplots(figsize=(12, 6), nrows=2, ncols=2, sharey=True, sharex=True)[1]
             ax_list = [axes[1, 0], axes[0, 0], axes[1, 1], axes[0, 1]]
         '''
         download_dir = view_gate.query_env_define_data('G_DOWNLOAD_DIR')
         index = 0
         for ip, res_list in params.items():
             # proc, res, period = res_list
             proc, res = res_list
             file = "{}\\{}\\__FILE_DATA__\\{}.csv".format(
                 download_dir, ip, proc)
             if not Common.is_file(file):
                 raise Exception("{} 不存在\n如果是首次登录,请等待30秒再进此界面".format(file))
             data = pd.read_csv(file,
                                usecols=['Date', res],
                                parse_dates=True,
                                index_col=0)
             axes = plt.subplots(figsize=(12, 6),
                                 nrows=1,
                                 ncols=1,
                                 sharey=True,
                                 sharex=True)[1]
             data.plot(ax=axes, title="{}: {}".format(ip, proc), grid=True)
             #data.plot(ax=ax_list[index], title="{}: {}".format(ip, proc), grid=True)
             index += 1
         plt.rcParams['font.sans-serif'] = [u'SimHei']
         plt.rcParams['axes.unicode_minus'] = False
         plt.subplots_adjust(wspace=0.02, hspace=0.2)  # 调整子图间距
         # plt.savefig('aa.png', dpi=200)
         plt.show()
     except Exception as e:
         WidgetTip.error(str(e))
예제 #10
0
 def pack_sub_btn_fm():
     btn_style = {
         'master': sub_btn_fm,
         'font': (Global.G_DEFAULT_FONT, 10),
         'bd': 0
     }
     add_btn = tk.Button(text='✚',
                         command=add_sublogin,
                         **btn_style)
     add_btn.pack(side='left', padx=20)
     eye_btn = tk.Button(text='�', **btn_style)
     eye_btn.pack(side='right', padx=20)
     eye_btn.bind("<Button-1>",
                  lambda event, t=True: see_password(t))
     eye_btn.bind("<ButtonRelease-1>",
                  lambda event, t=False: see_password(t))
     WidgetTip.enter_tips(add_btn, '增加一个登录栏', 10, 15)
     WidgetTip.enter_tips(eye_btn, '显示明文密码', 10, 15)
예제 #11
0
    def confirm(cls):
        cls.top.wm_attributes('-topmost', 0)
        data = {}
        data['tool_alias'] = cls.tool_alias.get()
        data['tool_version'] = cls.tool_version.get()
        data['log_level'] = cls.log_level.get()
        data['login_count_limit'] = int(cls.count_limit.get())
        data['retry_times'] = int(cls.retry_times.get())
        data['refresh_json_period'] = int(cls.refresh_json.get())

        data['passwords'] = {}
        data['passwords']['username'] = cls.user_name.get()
        data['passwords']['userpassword'] = cls.user_password.get()
        data['passwords']['rootpassword'] = cls.root_password.get()
        data['server_home'] = cls.server_home.get()
        data['keepalive_period'] = int(cls.keepalive_period.get())
        view_gate.update_settings_data.set_data(data)
        WidgetTip.info('设置成功')
        cls.cancel()
예제 #12
0
 def check_input():
     if not all(input_list):
         WidgetTip.error('输入不可为空')
         return False
     ip, user, upwd, rpwd = input_list
     if not Common.is_ip(ip):
         WidgetTip.error('请输入正确的IP地址')
         return False
     if ip in ip_exist_list:
         WidgetTip.error('{} 输入重复'.format(ip))
         return False
     ip_exist_list.append(ip)
     return True
예제 #13
0
 def check_limit_dependence(self, key, value):
     if key not in ['SDAY', 'EDAY', 'SMONTH', 'EMONTH']:
         return True
     if key == 'SDAY':
         if 'SMONTH' not in self.opts_dict:
             return True
         if int(value) < 28:
             return True
         month = int(self.opts_dict['SMONTH'])
         if month == 2 and int(value) > 28:
             WidgetTip.error('开始月份为2月时,日期不能设置大于28号!')
             self.reset_combox_list([[1, 1]])
             self.pop_opts_dict('SDAY')
             return False
         elif month in [4, 6, 9, 11] and int(value) > 30:
             WidgetTip.error('开始月份为%s月时,日期不能设置大于30号!' % month)
             self.reset_combox_list([[1, 1]])
             self.pop_opts_dict('SDAY')
             return False
     elif key == 'EDAY':
         if 'EMONTH' not in self.opts_dict:
             return True
         if int(value) < 28:
             return True
         month = int(self.opts_dict['EMONTH'])
         if month == 2 and int(value) > 28:
             WidgetTip.error('结束月份为2月时,日期不能设置大于28号!')
             self.reset_combox_list([[1, 2]])
             self.pop_opts_dict('EDAY')
             return False
         elif month in [4, 6, 9, 11] and int(value) > 30:
             WidgetTip.error('结束月份为%s月时,日期不能设置大于30号!' % month)
             self.reset_combox_list([[1, 2]])
             self.pop_opts_dict('EDAY')
             return False
     elif key == 'SMONTH':
         if 'SDAY' not in self.opts_dict:
             return True
         day = int(self.opts_dict['SDAY'])
         if int(value) == 2 and day > 28:
             WidgetTip.error('开始月份为2月时,日期不能设置大于28号!')
             self.reset_combox_list([[0, 1]])
             self.pop_opts_dict('SMONTH')
             return False
         elif int(value) in [4, 6, 9, 11] and day > 30:
             WidgetTip.error('开始月份为%s月时,日期不能设置大于30号!' % value)
             self.reset_combox_list([[0, 1]])
             self.pop_opts_dict('SMONTH')
             return False
     elif key == 'EMONTH':
         if 'EDAY' not in self.opts_dict:
             return True
         day = int(self.opts_dict['EDAY'])
         if int(value) == 2 and day > 28:
             WidgetTip.error('开始月份为2月时,日期不能设置大于28号!')
             self.reset_combox_list([[0, 2]])
             self.pop_opts_dict('EMONTH')
             return False
         elif int(value) in [4, 6, 9, 11] and day > 30:
             WidgetTip.error('开始月份为%s月时,日期不能设置大于30号!' % value)
             self.reset_combox_list([[0, 2]])
             self.pop_opts_dict('EMONTH')
             return False
     return True
예제 #14
0
 def try_switch():
     task = view_gate.query_running_task_data()
     if task:
         WidgetTip.error("请等待任务 {} 执行结束或手动'取消'该任务后继续".format(task))
         return False
     return True
예제 #15
0
 def close(self, ask=True):
     if ask and not WidgetTip.ask("请确认是否退出?"):
         return False
     view_gate.app_close_data.set_data(True)
     self.destroy()
     return True
예제 #16
0
 def add_sublogin():
     if len(self.sub_login) >= self.count_limit:
         WidgetTip.info('最多支持%s个登录' % self.count_limit)
         return
     SubLogin(entry_fm, preference_ip, self.default_pwd,
              self.sub_login)
예제 #17
0
    def combine_input(self, ips):
        def get_widget_input():
            if widget == 'Combobox':  # 默认选择了第一个
                #[shell_params[ip].append(str(instance.current())) for ip in ips]
                [shell_params[ip].append(instance.get()) for ip in ips]
            elif widget == 'MultiCombobox':  # 默认选择第一个,但可能是”“
                for ip, inst in instance:
                    if ip not in ips:
                        continue
                    _v = inst.get()
                    if not _v and not can_be_null:
                        return False
                    shell_params[ip].append(_v)
            elif widget == 'Checkbox':  # 默认无勾选
                choose = [str(_v.get()) for _v in instance]
                # 未选择任意一项
                if not can_be_null and len(
                        set(choose)) == 1 and choose[0] == '0':
                    return False
                [shell_params[ip].append('@'.join(choose)) for ip in ips]
            elif widget == 'Entry':  # 默认为空
                for ip in ips:
                    _v = instance.get()
                    if not _v and not can_be_null:
                        return False
                    shell_params[ip].append(_v)
            elif widget == 'Text':
                _v = instance.get('1.0', 'end').strip()
                if not _v and not can_be_null:
                    return False
                f = '{0}\\__{1}_{2}__.txt'.format(pid_dir, widget, index)
                Common.write_to_file(f, _v)
                [shell_params[ip].append(f) for ip in ips]
            return True

        def parser_widget_actions():
            for act in actions:
                if act == 'UploadFile':
                    for ip in ips:
                        # 本地的文件路径传给上传列表,同时修改脚本参数为文件名
                        _local_f = shell_params[ip][-1]
                        prev_uploads[ip].append(_local_f)
                        shell_params[ip][-1] = Common.basename(_local_f)
                else:
                    WidgetTip.error("Not support WidgetAction: {}".format(act))
                    continue

        ''' 1. 校验控件输入并组装脚本参数 '''
        pid_dir = view_gate.query_env_define_data('G_PID_DIR')
        shell_params, prev_uploads, index = defaultdict(list), defaultdict(
            list), 0
        for item in self.page_instance:
            widget, instance = item[0]
            can_be_null, show_result = item[1]
            actions = item[2]
            index += 1
            if not get_widget_input():
                WidgetTip.warn("第{0}个必要控件{1}输入为空 !".format(index, widget))
                return None
            parser_widget_actions()  #  解析actions
        if self.ploter == 'ManualPlot':  # 手动触发型可视化界面
            PlotMaker.manual(shell_params)
            return None
        if self.ploter == '':  # 任务型事件
            if self.window:  # 开启Top窗体显示执行结果
                TopNotebook.pack(ips)
            return [shell_params, prev_uploads]