gui logging configured

This commit is contained in:
DESKTOP-JVKHS7I\Adam 2020-04-17 18:38:26 +05:30
parent 49fa3c6294
commit e474fb0280
5 changed files with 41 additions and 13 deletions

View File

@ -14,10 +14,15 @@ Options:
""" """
import cv2 import cv2
from docopt import docopt
from pynput.keyboard import Listener
from fishy.systems import * from fishy.systems import *
import logging import logging
from fishy.systems.config import Config
from fishy.systems.gui import GUI, GUIStreamHandler
""" """
Start reading from `init.py` Start reading from `init.py`
""" """
@ -37,15 +42,15 @@ def on_release(key):
if c[0] == Control.Keywords.StartPause: if c[0] == Control.Keywords.StartPause:
if not G.pause: if not G.pause:
print("PAUSED") logging.info("PAUSED")
G.pause = True G.pause = True
return return
if PixelLoc.config(): if PixelLoc.config():
print("STARTED") logging.info("STARTED")
G.pause = False G.pause = False
else: else:
print("addon properly not installed, if it is installed try restarting the game.") logging.info("addon properly not installed, if it is installed try restarting the game.")
elif c[0] == Control.Keywords.Debug: elif c[0] == Control.Keywords.Debug:
G.debug = not G.debug G.debug = not G.debug
@ -108,6 +113,14 @@ def startFishing():
def main(): def main():
rootLogger = logging.getLogger('')
rootLogger.setLevel(logging.DEBUG)
gui = GUI(Config())
gui.start()
new_console = GUIStreamHandler(gui)
rootLogger.addHandler(new_console)
logging.info("yo")
G.arguments = docopt(__doc__) G.arguments = docopt(__doc__)
if G.arguments["--version"]: if G.arguments["--version"]:
quit() quit()

View File

@ -2,6 +2,7 @@
Defines different fishing modes (states) which acts as state for state machine Defines different fishing modes (states) which acts as state for state machine
also implements callbacks which is called when states are changed also implements callbacks which is called when states are changed
""" """
import logging
import time import time
from abc import abstractmethod, ABC from abc import abstractmethod, ABC
@ -34,7 +35,7 @@ class HookEvent(FishEvent):
G.fishCaught += 1 G.fishCaught += 1
G.totalFishCaught += 1 G.totalFishCaught += 1
timeToHook = time.time() - G.stickInitTime timeToHook = time.time() - G.stickInitTime
print("HOOOOOOOOOOOOOOOOOOOOOOOK....... " + str(G.fishCaught) + " caught " + "in " + str( logging.info("HOOOOOOOOOOOOOOOOOOOOOOOK....... " + str(G.fishCaught) + " caught " + "in " + str(
round_float(timeToHook)) + " secs. " + "Total: " + str(G.totalFishCaught)) round_float(timeToHook)) + " secs. " + "Total: " + str(G.totalFishCaught))
pyautogui.press('e') pyautogui.press('e')
@ -85,9 +86,9 @@ class IdleEvent(FishEvent):
net.sendHoleDeplete(G.fishCaught) net.sendHoleDeplete(G.fishCaught)
if previousMode.name == "hook": if previousMode.name == "hook":
print("HOLE DEPLETED") logging.info("HOLE DEPLETED")
elif previousMode.name == "stick": elif previousMode.name == "stick":
print("FISHING INTERRUPTED") logging.info("FISHING INTERRUPTED")
def onExitCallback(self, currentMode): def onExitCallback(self, currentMode):
pass pass

View File

@ -1,3 +1,4 @@
import logging
import socket import socket
import json import json
@ -20,9 +21,9 @@ def send_message(message, count=1):
sock.send(bytes(message, "utf-8")) sock.send(bytes(message, "utf-8"))
sock.close() sock.close()
except ConnectionRefusedError: except ConnectionRefusedError:
print("Connection Refused, please turn on service on mobile") logging.info("Connection Refused, please turn on service on mobile")
except TimeoutError: except TimeoutError:
print("Timeout Error") logging.info("Timeout Error")
if count < RETRY_LIMIT: if count < RETRY_LIMIT:
send_message(message, count+1) send_message(message, count+1)

View File

@ -1,5 +1,7 @@
import logging
import time import time
from enum import Enum from enum import Enum
from logging import StreamHandler
from tkinter import * from tkinter import *
from tkinter.ttk import * from tkinter.ttk import *
from ttkthemes import ThemedTk from ttkthemes import ThemedTk
@ -9,6 +11,16 @@ import threading
from fishy.systems.config import Config from fishy.systems.config import Config
class GUIStreamHandler(StreamHandler):
def __init__(self, gui):
StreamHandler.__init__(self)
self.gui = gui
def emit(self, record):
msg = self.format(record)
self.gui.writeToLog(msg)
class Callback(Enum): class Callback(Enum):
START = 0, START = 0,
SHORTCUT = 1, SHORTCUT = 1,
@ -46,8 +58,7 @@ class GUICallback:
class GUI: class GUI:
def __init__(self, gui_callback=None, def __init__(self,config: Config, gui_callback=None):
config: Config = None):
self.callbacks = GUICallback() if gui_callback is None else gui_callback self.callbacks = GUICallback() if gui_callback is None else gui_callback
self.config = config self.config = config
self.start_restart = False self.start_restart = False
@ -170,7 +181,7 @@ class GUI:
def start(ip, actionkey, fullscreen): def start(ip, actionkey, fullscreen):
print(f"{ip}, {actionkey}, {fullscreen}") logging.info(f"{ip}, {actionkey}, {fullscreen}")
def main(): def main():

View File

@ -1,3 +1,5 @@
import logging
import cv2 import cv2
import math import math
import win32gui import win32gui
@ -48,7 +50,7 @@ class Window:
Window.titleOffset = 0 Window.titleOffset = 0
except pywintypes.error: except pywintypes.error:
print("Game window not found") logging.info("Game window not found")
quit() quit()
@staticmethod @staticmethod
@ -72,7 +74,7 @@ class Window:
Window.Screen = tempScreen[crop[1]:crop[3], crop[0]:crop[2]] Window.Screen = tempScreen[crop[1]:crop[3], crop[0]:crop[2]]
if Window.Screen.size == 0: if Window.Screen.size == 0:
print("Don't minimize or drag game window outside the screen") logging.info("Don't minimize or drag game window outside the screen")
quit(1) quit(1)
@staticmethod @staticmethod