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
from docopt import docopt
from pynput.keyboard import Listener
from fishy.systems import *
import logging
from fishy.systems.config import Config
from fishy.systems.gui import GUI, GUIStreamHandler
"""
Start reading from `init.py`
"""
@ -37,15 +42,15 @@ def on_release(key):
if c[0] == Control.Keywords.StartPause:
if not G.pause:
print("PAUSED")
logging.info("PAUSED")
G.pause = True
return
if PixelLoc.config():
print("STARTED")
logging.info("STARTED")
G.pause = False
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:
G.debug = not G.debug
@ -108,6 +113,14 @@ def startFishing():
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__)
if G.arguments["--version"]:
quit()

View File

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

View File

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

View File

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

View File

@ -1,3 +1,5 @@
import logging
import cv2
import math
import win32gui
@ -48,7 +50,7 @@ class Window:
Window.titleOffset = 0
except pywintypes.error:
print("Game window not found")
logging.info("Game window not found")
quit()
@staticmethod
@ -72,7 +74,7 @@ class Window:
Window.Screen = tempScreen[crop[1]:crop[3], crop[0]:crop[2]]
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)
@staticmethod