st3p4nb01

pysimplegui

Jun 9th, 2021
515
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import PySimpleGUI as sg
  2. import queue
  3. import logging
  4. import threading
  5. from PySimpleGUI.PySimpleGUI import WIN_CLOSED
  6. import matplotlib.dates as md
  7. import matplotlib.ticker as ticker
  8. import matplotlib.spines as ms
  9. import pandas as pd
  10. import subprocess
  11. import os, time, re, csv, discord, asyncio, config, emoji, sys, colorama, typing, signal, errno, random, gc
  12. from valve.source.a2s import ServerQuerier, NoResponseError
  13. from matplotlib import pyplot as plt
  14. from datetime import datetime, timedelta
  15. from colorama import Fore, Style, init
  16. from config import LOGCHAN_ID as lchanID
  17. from config import VCHANNEL_ID as chanID
  18. from config import KILLEDCHAN_ID as kchadID
  19. from config import REWARDCHAN_ID as rchanID
  20. from config import EVENTCHAN_ID as echanID
  21. from config import SERVERCHAN_ID as schanID
  22. from config import file
  23. from config import SERVER
  24. from config import players_log as PL
  25. from config import rewards_log as RL
  26. from config import server_log as SL
  27. from config import MAX_PLAYERS as max_players
  28. from discord.ext import commands
  29.  
  30. # == Переменные ===============================================
  31. # == re ==
  32. pdeath = '.*?Got character ZDOID from (\w+) : 0:0'
  33. sevent = '.*?Got character ZDOID from (\\w+)\\b(?!:)'
  34. pkill = '.*? (\\w+):(\\w+)\\b(?!:)'
  35. revent = '.*? (\w+):(\w+):(\w+)'
  36. cevent = '.*? Connected: (\w+) users.'
  37. # == config ==
  38. server_name = config.SERVER_NAME
  39. flog = config.file
  40. dlog = config.players_log
  41. rlog = config.rewards_log
  42. path_vdb_main = config.vdb_main
  43. path_player = 'csv/playerstats.csv'
  44. path_death = 'csv/deathlog.csv'
  45. path_killed = 'csv/killedlog.csv'
  46. path_reward = 'csv/rewardslog.csv'
  47. path_yaml = 'csv/rewardscount.yaml'
  48. path_icon_log = "C:\\Users\\Stepan\\Desktop\\VALHEIMBY BOT\\programma\\icon_log.ico"
  49. log_file = "C:\\Users\\Stepan\\Desktop\\VALHEIMBY BOT\\programma\\PVPLogs.log"
  50. # == func ==
  51. bot = commands.Bot(command_prefix=';', help_command=None)
  52. logger = logging.getLogger('MAIN')
  53. now = datetime.now()
  54. gettime = now.strftime("%d/%m/%Y | %H:%M:%S > ")
  55.  
  56. colorama.init()
  57.  
  58. root_logger= logging.getLogger()
  59. root_logger.setLevel(logging.DEBUG)
  60. handler = logging.FileHandler('PVPLog.log', 'w', 'utf-8')
  61. handler.setFormatter(logging.Formatter('%(name)s, %(asctime)s, [%(levelname)s], %(message)s'))
  62. root_logger.addHandler(handler)
  63.  
  64. def log(log):
  65.     logger.info(log)
  66.  
  67. def Start():
  68.  
  69.     import vb # << Проблема возникает
  70.  
  71. class ThreadedApp(threading.Thread):
  72.     def __init__(self):
  73.         super().__init__()
  74.         self._stop_event = threading.Event()
  75.  
  76.     def run(self):
  77.         Start()
  78.  
  79.     def stop(self):
  80.         self._stop_event.set()
  81.  
  82. class QueueHandler(logging.Handler):
  83.     def __init__(self, log_queue):
  84.         super().__init__()
  85.         self.log_queue = log_queue
  86.  
  87.     def emit(self, record):
  88.         self.log_queue.put(record)
  89.  
  90.  
  91. def main():
  92.  
  93.     layout = [
  94.             [sg.Multiline(size=(75, 35), key='-LOG-', disabled=True, autoscroll=True)],
  95.             [sg.Button('Запустить', bind_return_key=True, key='-START-'), sg.Button('Завершить', key="-EXIT-")]
  96.         ]
  97.  
  98.     window = sg.Window('Main', layout,
  99.             default_element_size=(30, 2),
  100.             font=('Consolas', ' 10'),
  101.             default_button_element_size=(8, 2),
  102.             icon=path_icon_log)
  103.  
  104.     appStarted = False
  105.  
  106.     logging.basicConfig(level=logging.DEBUG)
  107.     log_queue = queue.Queue()
  108.     queue_handler = QueueHandler(log_queue)
  109.     logger.addHandler(queue_handler)
  110.     threadedApp = ThreadedApp()
  111.  
  112.     while True:
  113.         event, values = window.read(timeout=100)
  114.  
  115.         if event == '-START-':
  116.             if appStarted is False:
  117.                 threadedApp.start()
  118.                 logger.debug('Запуск файла')
  119.                 window['-START-'].update(disabled=True)
  120.                 appStarted = True
  121.         elif event == "-EXIT-":
  122.             logger.debug('Приложение завершено!')
  123.             window['-START-'].update(disabled=False)
  124.             appStarted = False
  125.             break
  126.         elif event == WIN_CLOSED:
  127.             break
  128.  
  129.         try:
  130.             record = log_queue.get(block=False)
  131.         except queue.Empty:
  132.             pass
  133.         else:
  134.             msg = queue_handler.format(record)
  135.             window['-LOG-'].update(f'{msg}\n', append=True)
  136.  
  137.     window.close()
  138.  
  139. if __name__ == '__main__':
  140.     main()
  141.    
  142.  
RAW Paste Data