Beispiel #1
0
 def auto(cls, plot_param, detail=False):
     cls.plot_param = plot_param
     only_image = "TkAgg" if detail else "Agg"
     plt.close('all')
     matplotlib.use(only_image)
     plt.rcParams['font.sans-serif'] = [u'SimHei']
     plt.rcParams['axes.unicode_minus'] = False
     instance, file_name, plot_size = plot_param
     width, height = (plot_size[0] - 120) / 100, plot_size[1] / 100 - 0.5
     download_dir = view_gate.query_env_define_data('G_DOWNLOAD_DIR')
     pid_dir = view_gate.query_env_define_data('G_PID_DIR')
     for ip, inst in instance.items():
         file = "{}\\{}\\__FILE_DATA__\\{}".format(download_dir, ip,
                                                   file_name)
         if not Common.is_file(file):
             raise Exception("{} 不存在\n请稍候重试".format(file))
         png = "{}\\{}_{}.png".format(pid_dir, ip, file_name.split('.')[0])
         data = pd.read_csv(file, parse_dates=True, index_col=0)
         data.plot(title="{}: {}".format(ip, file_name),
                   grid=True,
                   figsize=(width, height))
         if not detail:
             plt.savefig(png, dpi=100)
             view_gate.add_image_data.set_data(
                 ['AUTOPLOT_{}'.format(ip), png])
             inst.image_create('0.0',
                               image=view_gate.query_photo_image_data(
                                   'AUTOPLOT_{}'.format(ip)))
         else:
             plt.show()
Beispiel #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)
Beispiel #3
0
 def _mutex(self, ip, lock=True):
     """ 防重入 """
     _lock_file = '{0}\\{1}-{2}.lock'.format(Global.G_PID_DIR, self.task,
                                             ip)
     # 释放锁
     if not lock:
         try:
             Common.remove(_lock_file)
         except:
             pass
         return True
     # 尝试加锁
     if Common.is_file(_lock_file):
         return False
     Common.write_to_file(_lock_file, 'lock')
     return True
Beispiel #4
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))
Beispiel #5
0
 def images(self, image_data):
     for key, path in image_data.items():
         path = "{}\\{}".format(Global.G_RESOURCE_DIR, path)
         if not Common.is_file(path):
             raise Exception("%s is not exist !" % path)
         self.append_photo_image((key, path))