From c6654ade4fa34a55a592c39cf9d3fcc478c40f2e Mon Sep 17 00:00:00 2001 From: Mat R <1577341+Ancient123@users.noreply.github.com> Date: Thu, 6 May 2021 19:35:06 -0600 Subject: [PATCH 01/20] Add a 100ms sleep to semifisher loop While the main monitor loop runs we are constantly rechecking, which drives a lot of CPU usage. By sleeping for 100ms we can significantly reduce this without significantly impacting the bot. --- fishy/engine/semifisher/engine.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fishy/engine/semifisher/engine.py b/fishy/engine/semifisher/engine.py index cf7e8c5..f4d7bb9 100644 --- a/fishy/engine/semifisher/engine.py +++ b/fishy/engine/semifisher/engine.py @@ -51,6 +51,7 @@ class SemiFisherEngine(IEngine): self.fishPixWindow.crop = PixelLoc.val fishing_mode.loop(capture[0][0]) + time.sleep(0.1) logging.info("Fishing engine stopped") self.gui.bot_started(False) From 734477dc288ccf0587e16a096b4a47e70ed3a9e6 Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Fri, 9 Apr 2021 19:30:34 +0200 Subject: [PATCH 02/20] change state detection to dict and use rgb --- fishy/engine/common/window_server.py | 2 -- fishy/engine/semifisher/engine.py | 2 +- fishy/engine/semifisher/fishing_event.py | 32 ++++++++++--------- fishy/engine/semifisher/fishing_mode.py | 39 ++++++++++++------------ 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/fishy/engine/common/window_server.py b/fishy/engine/common/window_server.py index 4b4907b..65170e3 100644 --- a/fishy/engine/common/window_server.py +++ b/fishy/engine/common/window_server.py @@ -60,8 +60,6 @@ def loop(): temp_screen = np.array(ImageGrab.grab(bbox=bbox)) - temp_screen = cv2.cvtColor(temp_screen, cv2.COLOR_BGR2RGB) - rect = win32gui.GetWindowRect(WindowServer.hwnd) crop = ( rect[0] + WindowServer.windowOffset, rect[1] + WindowServer.titleOffset, rect[2] - WindowServer.windowOffset, diff --git a/fishy/engine/semifisher/engine.py b/fishy/engine/semifisher/engine.py index f4d7bb9..b23344c 100644 --- a/fishy/engine/semifisher/engine.py +++ b/fishy/engine/semifisher/engine.py @@ -31,7 +31,7 @@ class SemiFisherEngine(IEngine): code explained in comments in detail """ fishing_event.init() - self.fishPixWindow = WindowClient(color=cv2.COLOR_RGB2HSV) + self.fishPixWindow = WindowClient() # check for game window and stuff self.gui.bot_started(True) diff --git a/fishy/engine/semifisher/fishing_event.py b/fishy/engine/semifisher/fishing_event.py index 895d566..d6dc036 100644 --- a/fishy/engine/semifisher/fishing_event.py +++ b/fishy/engine/semifisher/fishing_event.py @@ -28,7 +28,7 @@ class FishEvent: hole_start_time = 0 FishingStarted = False jitter = False - previousState = State.IDLE + previousState = "IDLE" # initialize these action_key = 'e' @@ -80,33 +80,35 @@ def subscribe(): if fisher_callback not in fishing_mode.subscribers: fishing_mode.subscribers.append(fisher_callback) - if FishingMode.CurrentMode == State.LOOKING: + if FishingMode.CurrentMode == ["LOOKING"]: fisher_callback(FishingMode.CurrentMode) def fisher_callback(event: State): callbacks_map = { - State.IDLE: on_idle, - State.LOOKAWAY: on_lookaway, - State.LOOKING: on_looking, - State.DEPLETED: on_depleted, - State.NOBAIT: on_nobait, - State.FISHING: on_fishing, - State.REELIN: on_reelin, - State.LOOT: on_loot, - State.INVFULL: on_invfull, - State.FIGHT: on_fight, - State.DEAD: on_dead + "IDLE": on_idle, + "LOOKAWAY": on_lookaway, + "LOOKING": on_looking, + "DEPLETED": on_depleted, + "NOBAIT": on_nobait, + "FISHING": on_fishing, + "REELIN": on_reelin, + "LOOT": on_loot, + "INVFULL": on_invfull, + "FIGHT": on_fight, + "DEAD": on_dead } try: callbacks_map[event]() FishEvent.previousState = event except KeyError as ex: - pass + logging.error("KeyError: State " + str(event) + " is not known.") + except TypeError as ex: + logging.error("TypeError when reading state: " + str(event)) def on_idle(): - if FishEvent.previousState in (State.FISHING, State.REELIN): + if FishEvent.previousState in ("FISHING", "REELIN"): logging.info("FISHING INTERRUPTED") _sound_and_send_fishy_data() diff --git a/fishy/engine/semifisher/fishing_mode.py b/fishy/engine/semifisher/fishing_mode.py index 7846fc7..a19c611 100644 --- a/fishy/engine/semifisher/fishing_mode.py +++ b/fishy/engine/semifisher/fishing_mode.py @@ -1,21 +1,22 @@ import time -from enum import Enum subscribers = [] -class State(Enum): - IDLE = [ 0, 0, 255] - LOOKAWAY = [150, 255, 76] - LOOKING = [100, 255, 101] - DEPLETED = [ 30, 255, 76] - NOBAIT = [ 96, 255, 255] - FISHING = [ 18, 165, 213] - REELIN = [ 60, 255, 204] - LOOT = [ 0, 255, 204] - INVFULL = [ 0, 255, 51] - FIGHT = [120, 255, 204] - DEAD = [ 0, 0, 51] +State = { + "IDLE" : [255, 255, 255], + "LOOKAWAY" : [ 76, 0, 76], + "LOOKING" : [101, 69, 0], + "DEPLETED" : [ 0, 76, 76], + "NOBAIT" : [255, 204, 0], + "FISHING" : [ 75, 156, 213], + "REELIN" : [ 0, 204, 0], + "LOOT" : [ 0, 0, 204], + "INVFULL" : [ 0, 0, 51], + "FIGHT" : [204, 0, 0], + "DEAD" : [ 51, 51, 51] +} + def _notify(event): for subscriber in subscribers: @@ -23,20 +24,20 @@ def _notify(event): class FishingMode: - CurrentMode = State.IDLE - PrevMode = State.IDLE + CurrentMode = "IDLE" + PrevMode = "IDLE" -def loop(hsv): +def loop(rgb): """ Executed in the start of the main loop in fishy.py Changes modes, calls mode events (callbacks) when mode is changed - :param hsv: hsv read by the bot + :param rgb: rgb read by the bot """ - FishingMode.CurrentMode = State.IDLE + FishingMode.CurrentMode = "IDLE" for s in State: - if all(hsv == s.value): + if all(rgb == State[s]): FishingMode.CurrentMode = s if FishingMode.CurrentMode != FishingMode.PrevMode: From f790a83acf6d21974e143e975ff64ab9886adb1a Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Fri, 7 May 2021 14:13:55 +0200 Subject: [PATCH 03/20] fixup enum-dict --- fishy/engine/semifisher/fishing_event.py | 28 ++++++++++++------------ fishy/engine/semifisher/fishing_mode.py | 24 +++++++++++++++----- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/fishy/engine/semifisher/fishing_event.py b/fishy/engine/semifisher/fishing_event.py index d6dc036..cacff0e 100644 --- a/fishy/engine/semifisher/fishing_event.py +++ b/fishy/engine/semifisher/fishing_event.py @@ -28,7 +28,7 @@ class FishEvent: hole_start_time = 0 FishingStarted = False jitter = False - previousState = "IDLE" + previousState = State.IDLE # initialize these action_key = 'e' @@ -80,23 +80,23 @@ def subscribe(): if fisher_callback not in fishing_mode.subscribers: fishing_mode.subscribers.append(fisher_callback) - if FishingMode.CurrentMode == ["LOOKING"]: + if FishingMode.CurrentMode == State.LOOKING: fisher_callback(FishingMode.CurrentMode) def fisher_callback(event: State): callbacks_map = { - "IDLE": on_idle, - "LOOKAWAY": on_lookaway, - "LOOKING": on_looking, - "DEPLETED": on_depleted, - "NOBAIT": on_nobait, - "FISHING": on_fishing, - "REELIN": on_reelin, - "LOOT": on_loot, - "INVFULL": on_invfull, - "FIGHT": on_fight, - "DEAD": on_dead + State.IDLE: on_idle, + State.LOOKAWAY: on_lookaway, + State.LOOKING: on_looking, + State.DEPLETED: on_depleted, + State.NOBAIT: on_nobait, + State.FISHING: on_fishing, + State.REELIN: on_reelin, + State.LOOT: on_loot, + State.INVFULL: on_invfull, + State.FIGHT: on_fight, + State.DEAD: on_dead } try: callbacks_map[event]() @@ -108,7 +108,7 @@ def fisher_callback(event: State): def on_idle(): - if FishEvent.previousState in ("FISHING", "REELIN"): + if FishEvent.previousState in (State.FISHING, State.REELIN): logging.info("FISHING INTERRUPTED") _sound_and_send_fishy_data() diff --git a/fishy/engine/semifisher/fishing_mode.py b/fishy/engine/semifisher/fishing_mode.py index a19c611..c78230e 100644 --- a/fishy/engine/semifisher/fishing_mode.py +++ b/fishy/engine/semifisher/fishing_mode.py @@ -1,9 +1,23 @@ import time +from enum import Enum subscribers = [] -State = { +class State(Enum): + IDLE = 0 + LOOKAWAY = 1 + LOOKING = 2 + DEPLETED = 3 + NOBAIT = 5 + FISHING = 6 + REELIN = 7 + LOOT = 8 + INVFULL = 9 + FIGHT = 14 + DEAD = 15 + +Colors = { "IDLE" : [255, 255, 255], "LOOKAWAY" : [ 76, 0, 76], "LOOKING" : [101, 69, 0], @@ -24,8 +38,8 @@ def _notify(event): class FishingMode: - CurrentMode = "IDLE" - PrevMode = "IDLE" + CurrentMode = State.IDLE + PrevMode = State.IDLE def loop(rgb): @@ -35,9 +49,9 @@ def loop(rgb): :param rgb: rgb read by the bot """ - FishingMode.CurrentMode = "IDLE" + FishingMode.CurrentMode = State.IDLE for s in State: - if all(rgb == State[s]): + if all(rgb == Colors[s.name]): FishingMode.CurrentMode = s if FishingMode.CurrentMode != FishingMode.PrevMode: From ac18f3f2ccf843ca3e0c24d3971cc967ec80edfb Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Fri, 7 May 2021 15:16:21 +0200 Subject: [PATCH 04/20] fixupfixup enum-dict --- fishy/engine/semifisher/fishing_mode.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/fishy/engine/semifisher/fishing_mode.py b/fishy/engine/semifisher/fishing_mode.py index c78230e..4049dfe 100644 --- a/fishy/engine/semifisher/fishing_mode.py +++ b/fishy/engine/semifisher/fishing_mode.py @@ -18,17 +18,17 @@ class State(Enum): DEAD = 15 Colors = { - "IDLE" : [255, 255, 255], - "LOOKAWAY" : [ 76, 0, 76], - "LOOKING" : [101, 69, 0], - "DEPLETED" : [ 0, 76, 76], - "NOBAIT" : [255, 204, 0], - "FISHING" : [ 75, 156, 213], - "REELIN" : [ 0, 204, 0], - "LOOT" : [ 0, 0, 204], - "INVFULL" : [ 0, 0, 51], - "FIGHT" : [204, 0, 0], - "DEAD" : [ 51, 51, 51] + State.IDLE : [255, 255, 255], + State.LOOKAWAY : [ 76, 0, 76], + State.LOOKING : [101, 69, 0], + State.DEPLETED : [ 0, 76, 76], + State.NOBAIT : [255, 204, 0], + State.FISHING : [ 75, 156, 213], + State.REELIN : [ 0, 204, 0], + State.LOOT : [ 0, 0, 204], + State.INVFULL : [ 0, 0, 51], + State.FIGHT : [204, 0, 0], + State.DEAD : [ 51, 51, 51] } @@ -51,7 +51,7 @@ def loop(rgb): """ FishingMode.CurrentMode = State.IDLE for s in State: - if all(rgb == Colors[s.name]): + if all(rgb == Colors[s]): FishingMode.CurrentMode = s if FishingMode.CurrentMode != FishingMode.PrevMode: From b6a375f486ad9ba61023096142d74f20dc878b37 Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Fri, 9 Apr 2021 20:50:53 +0200 Subject: [PATCH 05/20] add luaparser and read saved var --- fishy/engine/semifisher/engine.py | 6 +- fishy/engine/semifisher/fishing_event.py | 1 + fishy/helper/__init__.py | 4 +- fishy/helper/helper.py | 9 ++- fishy/helper/luaparser.py | 79 ++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 fishy/helper/luaparser.py diff --git a/fishy/engine/semifisher/engine.py b/fishy/engine/semifisher/engine.py index b23344c..7f23215 100644 --- a/fishy/engine/semifisher/engine.py +++ b/fishy/engine/semifisher/engine.py @@ -10,12 +10,14 @@ import logging from fishy.engine.semifisher.fishing_event import FishEvent from fishy.engine.common.window import WindowClient -from fishy.engine.semifisher.fishing_mode import FishingMode +from fishy.engine.semifisher.fishing_mode import State, FishingMode from fishy.engine.common.IEngine import IEngine from fishy.engine.semifisher import fishing_mode, fishing_event from fishy.engine.semifisher.pixel_loc import PixelLoc +from fishy.helper.luaparser import sv_color_extract + if typing.TYPE_CHECKING: from fishy.gui import GUI @@ -36,6 +38,8 @@ class SemiFisherEngine(IEngine): # check for game window and stuff self.gui.bot_started(True) + sv_color_extract(State) + if self.get_gui: logging.info("Starting the bot engine, look at the fishing hole to start fishing") Thread(target=self._wait_and_check).start() diff --git a/fishy/engine/semifisher/fishing_event.py b/fishy/engine/semifisher/fishing_event.py index cacff0e..5c6527e 100644 --- a/fishy/engine/semifisher/fishing_event.py +++ b/fishy/engine/semifisher/fishing_event.py @@ -98,6 +98,7 @@ def fisher_callback(event: State): State.FIGHT: on_fight, State.DEAD: on_dead } + try: callbacks_map[event]() FishEvent.previousState = event diff --git a/fishy/helper/__init__.py b/fishy/helper/__init__.py index dabfc52..2d3f6cf 100644 --- a/fishy/helper/__init__.py +++ b/fishy/helper/__init__.py @@ -1,4 +1,6 @@ from .auto_update import auto_upgrade, upgrade_avail, versions from .config import Config from .helper import open_web, initialize_uid, install_thread_excepthook, unhandled_exception_logging, manifest_file, \ - create_shortcut_first, addon_exists, get_addonversion, install_addon, remove_addon, restart, create_shortcut, not_implemented, update + create_shortcut_first, addon_exists, get_addonversion, install_addon, remove_addon, restart, create_shortcut, \ + not_implemented, update, get_savedvarsdir +from .luaparser import sv_color_extract diff --git a/fishy/helper/helper.py b/fishy/helper/helper.py index fb0b591..66b6036 100644 --- a/fishy/helper/helper.py +++ b/fishy/helper/helper.py @@ -145,11 +145,18 @@ def create_shortcut(anti_ghosting: bool): logging.error("Couldn't create shortcut") +def get_savedvarsdir(): + # noinspection PyUnresolvedReferences + from win32com.shell import shell, shellcon + documents = shell.SHGetFolderPath(0, shellcon.CSIDL_PERSONAL, None, 0) + return os.path.join(documents, "Elder Scrolls Online", "live", "SavedVariables") + + def get_addondir(): # noinspection PyUnresolvedReferences from win32com.shell import shell, shellcon documents = shell.SHGetFolderPath(0, shellcon.CSIDL_PERSONAL, None, 0) - return os.path.join(documents, "Elder Scrolls Online", "live", "Addons") + return os.path.join(documents, "Elder Scrolls Online", "live", "Addons") def addon_exists(name, url=None, v=None): diff --git a/fishy/helper/luaparser.py b/fishy/helper/luaparser.py new file mode 100644 index 0000000..7e8d5a5 --- /dev/null +++ b/fishy/helper/luaparser.py @@ -0,0 +1,79 @@ +import os +import logging +from math import floor +from .helper import get_savedvarsdir + + +def _sv_parser(path): + try: + with open(path, "r") as f: + lua = f.read() + + """ + bring lua saved-var file into a useable format: + - one line per expression (add \n where needed) + - remove all redundant characters + - make lowercase, split into list of expressions + - remove empty expressions + EXPRESSIONS: A) List-Start "name=", B) Variable assignment "name=val", C) List End "}" + """ + for old, new in ((",","\n"), ("{","{\n"), ("}","}\n"), ("{",""), (",", ""), ("[", ""), ("]", ""), ('"', ""), (" ", "")): + lua = lua.replace(old, new) + lua = lua.lower().split("\n") + lua = [expression for expression in lua if expression] + + """ + the lua saved-var file is parsed to a tree of dicts + each line represents either one node in the tree or the end of a subtree + the last symbol of each line decides the type of the node (branch vertex or leaf) + """ + stack = [] + root = (dict(),"root") + stack.append(root) + for line in lua: + if line == "": + break + if line[-1] == '=': #subtree start + t = dict() + tname = line.split("=")[0] + stack.append((t,tname)) + elif line[-1] == '}': #subtree end + t = stack.pop() + tp = stack.pop() + tp[0][t[1]] = t[0] + stack.append(tp) + else: #new element in tree + name,val = line.split("=") + t = stack.pop() + t[0][name] = val + stack.append(t) + return root[0] + + except Exception as ex: + logging.error("Error: '" + str(ex) + "' occured, while parsing ESO variables.") + return None + + +def sv_color_extract(states): + root = _sv_parser(os.path.join(get_savedvarsdir(), "Chalutier.lua")) + if root == None: + return states + + for i in range(4): + name, root = root.popitem() + colors = [] + for i in root["colors"]: + """ + ingame representation of colors range from 0 to 1 in float + these values are scaled by 255 + """ + rgb=[ + floor(float(root["colors"][i]["r"])*255), + floor(float(root["colors"][i]["g"])*255), + floor(float(root["colors"][i]["b"])*255) + ] + colors.append(rgb) + for i,s in enumerate(states): + states[s] = colors[i] + return states + From 58457ef7980bf9dcc3f28ac459207c14ae299952 Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Fri, 7 May 2021 14:07:09 +0200 Subject: [PATCH 06/20] fixup luaparser --- fishy/engine/semifisher/engine.py | 4 ++-- fishy/helper/luaparser.py | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fishy/engine/semifisher/engine.py b/fishy/engine/semifisher/engine.py index 7f23215..17270ca 100644 --- a/fishy/engine/semifisher/engine.py +++ b/fishy/engine/semifisher/engine.py @@ -10,7 +10,7 @@ import logging from fishy.engine.semifisher.fishing_event import FishEvent from fishy.engine.common.window import WindowClient -from fishy.engine.semifisher.fishing_mode import State, FishingMode +from fishy.engine.semifisher.fishing_mode import Colors, FishingMode from fishy.engine.common.IEngine import IEngine from fishy.engine.semifisher import fishing_mode, fishing_event @@ -38,7 +38,7 @@ class SemiFisherEngine(IEngine): # check for game window and stuff self.gui.bot_started(True) - sv_color_extract(State) + sv_color_extract(Colors) if self.get_gui: logging.info("Starting the bot engine, look at the fishing hole to start fishing") diff --git a/fishy/helper/luaparser.py b/fishy/helper/luaparser.py index 7e8d5a5..ec621a8 100644 --- a/fishy/helper/luaparser.py +++ b/fishy/helper/luaparser.py @@ -18,7 +18,7 @@ def _sv_parser(path): EXPRESSIONS: A) List-Start "name=", B) Variable assignment "name=val", C) List End "}" """ for old, new in ((",","\n"), ("{","{\n"), ("}","}\n"), ("{",""), (",", ""), ("[", ""), ("]", ""), ('"', ""), (" ", "")): - lua = lua.replace(old, new) + lua = lua.replace(old, new) lua = lua.lower().split("\n") lua = [expression for expression in lua if expression] @@ -54,10 +54,10 @@ def _sv_parser(path): return None -def sv_color_extract(states): +def sv_color_extract(Colors): root = _sv_parser(os.path.join(get_savedvarsdir(), "Chalutier.lua")) if root == None: - return states + return Colors for i in range(4): name, root = root.popitem() @@ -73,7 +73,7 @@ def sv_color_extract(states): floor(float(root["colors"][i]["b"])*255) ] colors.append(rgb) - for i,s in enumerate(states): - states[s] = colors[i] - return states + for i,c in enumerate(Colors): + Colors[c] = colors[i] + return Colors From a1ce1ccae925bd15bb4ca8e57401760bd83b2166 Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Mon, 12 Apr 2021 23:12:39 +0200 Subject: [PATCH 07/20] update chalutier addon for default dead color --- fishy/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fishy/constants.py b/fishy/constants.py index 20ae28b..e1b74bb 100644 --- a/fishy/constants.py +++ b/fishy/constants.py @@ -1,5 +1,5 @@ apiversion = 2 -chalutier = ("Chalutier", "https://github.com/fishyboteso/Chalutier/raw/619b4ab0b8ff91746afda855542e886d27b7a794/Chalutier_1.1.2.zip", 112) +chalutier = ("Chalutier", "https://github.com/fishyboteso/Chalutier/raw/main/Chalutier_1.1.3.zip", 113) lam2 = ("LibAddonMenu-2.0", "https://www.esoui.com/downloads/dl7/LibAddonMenu-2.0r32.zip", 32) fishyqr = ("FishyQR", "https://github.com/fishyboteso/FishyQR/files/6329586/FishyQR.zip", 100) From fe3715b21b2fb014f3e75b91905db7499127c0a0 Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Fri, 7 May 2021 11:49:54 +0200 Subject: [PATCH 08/20] fixup chalutier version --- fishy/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fishy/constants.py b/fishy/constants.py index e1b74bb..ec39bc7 100644 --- a/fishy/constants.py +++ b/fishy/constants.py @@ -1,5 +1,5 @@ apiversion = 2 -chalutier = ("Chalutier", "https://github.com/fishyboteso/Chalutier/raw/main/Chalutier_1.1.3.zip", 113) +chalutier = ("Chalutier", "https://www.esoui.com/downloads/dl2934/Chalutier_1.1.4.zip", 114) lam2 = ("LibAddonMenu-2.0", "https://www.esoui.com/downloads/dl7/LibAddonMenu-2.0r32.zip", 32) fishyqr = ("FishyQR", "https://github.com/fishyboteso/FishyQR/files/6329586/FishyQR.zip", 100) From b2d43df57e13a715c155f15230dac40759904191 Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Thu, 15 Apr 2021 17:03:08 +0200 Subject: [PATCH 09/20] playsound whenever user interaction is required --- fishy/engine/semifisher/fishing_event.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fishy/engine/semifisher/fishing_event.py b/fishy/engine/semifisher/fishing_event.py index 5c6527e..1a09ba5 100644 --- a/fishy/engine/semifisher/fishing_event.py +++ b/fishy/engine/semifisher/fishing_event.py @@ -137,6 +137,9 @@ def on_nobait(): logging.info(msg) web.send_notification(msg) + if FishEvent.sound: + playsound(helper.manifest_file("sound.mp3"), False) + def on_fishing(): FishEvent.stickInitTime = time.time() @@ -177,14 +180,23 @@ def on_invfull(): logging.info(msg) web.send_notification(msg) + if FishEvent.sound: + playsound(helper.manifest_file("sound.mp3"), False) + def on_fight(): msg = "FIGHTING!" logging.info(msg) web.send_notification(msg) + if FishEvent.sound: + playsound(helper.manifest_file("sound.mp3"), False) + def on_dead(): msg = "Character is dead!" logging.info(msg) web.send_notification(msg) + + if FishEvent.sound: + playsound(helper.manifest_file("sound.mp3"), False) From 708f64fd7b1df650c2f0f800e64c65a26568503d Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Thu, 15 Apr 2021 20:24:01 +0200 Subject: [PATCH 10/20] act on lookaway as on idle --- fishy/engine/semifisher/fishing_event.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/fishy/engine/semifisher/fishing_event.py b/fishy/engine/semifisher/fishing_event.py index 1a09ba5..d1b21ca 100644 --- a/fishy/engine/semifisher/fishing_event.py +++ b/fishy/engine/semifisher/fishing_event.py @@ -87,7 +87,7 @@ def subscribe(): def fisher_callback(event: State): callbacks_map = { State.IDLE: on_idle, - State.LOOKAWAY: on_lookaway, + State.LOOKAWAY: on_idle, State.LOOKING: on_looking, State.DEPLETED: on_depleted, State.NOBAIT: on_nobait, @@ -119,10 +119,6 @@ def on_depleted(): _sound_and_send_fishy_data() -def on_lookaway(): - return - - @if_eso_is_focused def on_looking(): """ From 363a0dd1bd34c15e7238bf3e2bba6762aa666d24 Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Thu, 15 Apr 2021 20:26:35 +0200 Subject: [PATCH 11/20] reorder imports --- fishy/engine/semifisher/engine.py | 9 ++++----- fishy/engine/semifisher/fishing_event.py | 15 ++++++--------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/fishy/engine/semifisher/engine.py b/fishy/engine/semifisher/engine.py index 17270ca..b5453f4 100644 --- a/fishy/engine/semifisher/engine.py +++ b/fishy/engine/semifisher/engine.py @@ -1,18 +1,17 @@ import time import typing +import cv2 +import logging from threading import Thread from typing import Callable from typing import Optional -import cv2 -import logging - -from fishy.engine.semifisher.fishing_event import FishEvent - from fishy.engine.common.window import WindowClient from fishy.engine.semifisher.fishing_mode import Colors, FishingMode from fishy.engine.common.IEngine import IEngine +from fishy.engine.semifisher.fishing_mode import FishingMode +from fishy.engine.semifisher.fishing_event import FishEvent from fishy.engine.semifisher import fishing_mode, fishing_event from fishy.engine.semifisher.pixel_loc import PixelLoc diff --git a/fishy/engine/semifisher/fishing_event.py b/fishy/engine/semifisher/fishing_event.py index d1b21ca..3a407a9 100644 --- a/fishy/engine/semifisher/fishing_event.py +++ b/fishy/engine/semifisher/fishing_event.py @@ -5,20 +5,17 @@ also implements callbacks which is called when states are changed """ import logging import time - -from fishy.engine.semifisher import fishing_mode -from playsound import playsound - -from fishy import web -from fishy.engine.semifisher.fishing_mode import State, FishingMode -from fishy.helper import helper +import random import keyboard +from playsound import playsound from win32gui import GetWindowText, GetForegroundWindow +from fishy import web +from fishy.engine.semifisher import fishing_mode +from fishy.engine.semifisher.fishing_mode import State, FishingMode +from fishy.helper import helper from fishy.helper.config import config -import random - class FishEvent: fishCaught = 0 From 0396ea3239bf88ec1ae53de18db822f9c9aa21ae Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Thu, 15 Apr 2021 20:27:08 +0200 Subject: [PATCH 12/20] playsond beep twice, moved from hotkey to engine --- fishy/engine/semifisher/engine.py | 5 +++++ fishy/helper/__init__.py | 2 +- fishy/helper/helper.py | 14 ++++++++++++++ fishy/helper/hotkey.py | 4 ---- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/fishy/engine/semifisher/engine.py b/fishy/engine/semifisher/engine.py index b5453f4..4f62e61 100644 --- a/fishy/engine/semifisher/engine.py +++ b/fishy/engine/semifisher/engine.py @@ -5,6 +5,7 @@ import logging from threading import Thread from typing import Callable from typing import Optional +from playsound import playsound from fishy.engine.common.window import WindowClient from fishy.engine.semifisher.fishing_mode import Colors, FishingMode @@ -14,6 +15,7 @@ from fishy.engine.semifisher.fishing_mode import FishingMode from fishy.engine.semifisher.fishing_event import FishEvent from fishy.engine.semifisher import fishing_mode, fishing_event from fishy.engine.semifisher.pixel_loc import PixelLoc +from fishy.helper import helper from fishy.helper.luaparser import sv_color_extract @@ -84,6 +86,9 @@ class SemiFisherEngine(IEngine): if self.start: self.thread = Thread(target=self.run) self.thread.start() + playsound(helper.manifest_file("beep.wav"), False) + else: + helper.playsound_multiple(helper.manifest_file("beep.wav")) if __name__ == '__main__': diff --git a/fishy/helper/__init__.py b/fishy/helper/__init__.py index 2d3f6cf..07bc150 100644 --- a/fishy/helper/__init__.py +++ b/fishy/helper/__init__.py @@ -2,5 +2,5 @@ from .auto_update import auto_upgrade, upgrade_avail, versions from .config import Config from .helper import open_web, initialize_uid, install_thread_excepthook, unhandled_exception_logging, manifest_file, \ create_shortcut_first, addon_exists, get_addonversion, install_addon, remove_addon, restart, create_shortcut, \ - not_implemented, update, get_savedvarsdir + not_implemented, update, get_savedvarsdir, playsound_multiple from .luaparser import sv_color_extract diff --git a/fishy/helper/helper.py b/fishy/helper/helper.py index 66b6036..39fdfd2 100644 --- a/fishy/helper/helper.py +++ b/fishy/helper/helper.py @@ -7,6 +7,7 @@ import time import traceback import webbrowser import requests +from playsound import playsound from io import BytesIO from threading import Thread from zipfile import ZipFile @@ -23,6 +24,19 @@ import winshell from fishy import web +def playsound_multiple(path, count=2): + if count < 1: + logging.debug("Please don't make me beep 0 times or less.") + return + + def _ps_m(): + for i in range(count-1): + playsound(path, True) + playsound(path, False) + + Thread(target=_ps_m).start() + + def not_implemented(): logging.error("Not Implemented") diff --git a/fishy/helper/hotkey.py b/fishy/helper/hotkey.py index 74c57c3..5c6a7f3 100644 --- a/fishy/helper/hotkey.py +++ b/fishy/helper/hotkey.py @@ -3,9 +3,6 @@ from threading import Thread from typing import Dict, Callable, Optional import keyboard -from playsound import playsound - -from fishy.helper import helper class Key(Enum): @@ -27,7 +24,6 @@ def _get_callback(k): if not _hotkeys[k]: return - playsound(helper.manifest_file("beep.wav"), False) Thread(target=_hotkeys[k]).start() return callback From 699354cd0b5e7a168b479c8ea1cf9c3ada2bf32f Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Fri, 7 May 2021 09:59:18 +0200 Subject: [PATCH 13/20] rename send_hole_deplete to send_fish_caught --- fishy/engine/semifisher/fishing_event.py | 2 +- fishy/web/__init__.py | 2 +- fishy/web/web.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fishy/engine/semifisher/fishing_event.py b/fishy/engine/semifisher/fishing_event.py index 3a407a9..1759a5d 100644 --- a/fishy/engine/semifisher/fishing_event.py +++ b/fishy/engine/semifisher/fishing_event.py @@ -52,7 +52,7 @@ def if_eso_is_focused(func): def _sound_and_send_fishy_data(): if FishEvent.fishCaught > 0: - web.send_hole_deplete(FishEvent.fishCaught, time.time() - FishEvent.hole_start_time, FishEvent.fish_times) + web.send_fish_caught(FishEvent.fishCaught, time.time() - FishEvent.hole_start_time, FishEvent.fish_times) FishEvent.fishCaught = 0 if FishEvent.sound: diff --git a/fishy/web/__init__.py b/fishy/web/__init__.py index 6912bae..ec57c9c 100644 --- a/fishy/web/__init__.py +++ b/fishy/web/__init__.py @@ -1,2 +1,2 @@ from .urls import get_notification_page, get_terms_page -from .web import register_user, send_notification, send_hole_deplete, is_subbed, unsub, get_session, sub +from .web import register_user, send_notification, send_fish_caught, is_subbed, unsub, get_session, sub diff --git a/fishy/web/web.py b/fishy/web/web.py index e714842..f79319b 100644 --- a/fishy/web/web.py +++ b/fishy/web/web.py @@ -62,7 +62,7 @@ def send_notification(message): @uses_session @fallback(None) -def send_hole_deplete(fish_caught, hole_time, fish_times): +def send_fish_caught(fish_caught, hole_time, fish_times): hole_data = { "fish_caught": fish_caught, "hole_time": hole_time, From ff39f7d9bf28eeeda7ebc729760d0e3233d6a9fa Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Fri, 7 May 2021 10:22:09 +0200 Subject: [PATCH 14/20] accumulate event functions --- fishy/engine/semifisher/fishing_event.py | 38 ++++-------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/fishy/engine/semifisher/fishing_event.py b/fishy/engine/semifisher/fishing_event.py index 1759a5d..8b97892 100644 --- a/fishy/engine/semifisher/fishing_event.py +++ b/fishy/engine/semifisher/fishing_event.py @@ -87,13 +87,13 @@ def fisher_callback(event: State): State.LOOKAWAY: on_idle, State.LOOKING: on_looking, State.DEPLETED: on_depleted, - State.NOBAIT: on_nobait, + State.NOBAIT: lambda: on_user_interact("You need to equip bait!"), State.FISHING: on_fishing, State.REELIN: on_reelin, State.LOOT: on_loot, - State.INVFULL: on_invfull, - State.FIGHT: on_fight, - State.DEAD: on_dead + State.INVFULL: lambda: on_user_interact("Inventory is full!"), + State.FIGHT: lambda: on_user_interact("Character is FIGHTING!"), + State.DEAD: lambda: on_user_interact("Character died!") } try: @@ -125,8 +125,7 @@ def on_looking(): keyboard.press_and_release(FishEvent.action_key) -def on_nobait(): - msg = "No bait equipped!" +def on_user_interact(msg): logging.info(msg) web.send_notification(msg) @@ -166,30 +165,3 @@ def on_loot(): _fishing_sleep(0) keyboard.press_and_release(FishEvent.collect_key) _fishing_sleep(0) - - -def on_invfull(): - msg = "Inventory full!" - logging.info(msg) - web.send_notification(msg) - - if FishEvent.sound: - playsound(helper.manifest_file("sound.mp3"), False) - - -def on_fight(): - msg = "FIGHTING!" - logging.info(msg) - web.send_notification(msg) - - if FishEvent.sound: - playsound(helper.manifest_file("sound.mp3"), False) - - -def on_dead(): - msg = "Character is dead!" - logging.info(msg) - web.send_notification(msg) - - if FishEvent.sound: - playsound(helper.manifest_file("sound.mp3"), False) From d9b37c5911702c9506f059187caf6288d105922e Mon Sep 17 00:00:00 2001 From: Semjon Kerner Date: Sun, 9 May 2021 08:32:36 +0200 Subject: [PATCH 15/20] remove star imports from tk and ttk --- fishy/gui/config_top.py | 46 ++++++++++++++++++------------------ fishy/gui/discord_login.py | 17 +++++++------- fishy/gui/gui.py | 6 ++--- fishy/gui/main_gui.py | 48 +++++++++++++++++++------------------- fishy/gui/splash.py | 8 +++---- fishy/gui/terms_gui.py | 32 ++++++++++++------------- fishy/gui/update_dialog.py | 16 ++++++------- 7 files changed, 86 insertions(+), 87 deletions(-) diff --git a/fishy/gui/config_top.py b/fishy/gui/config_top.py index 5001347..b5abaeb 100644 --- a/fishy/gui/config_top.py +++ b/fishy/gui/config_top.py @@ -7,8 +7,8 @@ from fishy.helper import helper from fishy import web -from tkinter import * -from tkinter.ttk import * +import tkinter as tk +import tkinter.ttk as ttk from fishy.helper.config import config from fishy.helper.popup import PopUp @@ -19,7 +19,7 @@ if typing.TYPE_CHECKING: def start_fullfisher_config(gui: 'GUI'): top = PopUp(helper.empty_function, gui._root, background=gui._root["background"]) - controls_frame = Frame(top) + controls_frame = ttk.Frame(top) top.title("Config") def file_name(): @@ -38,10 +38,10 @@ def start_fullfisher_config(gui: 'GUI'): file_name_label.set(file_name()) - file_name_label = StringVar(value=file_name()) - Label(controls_frame, textvariable=file_name_label).grid(row=0, column=0) - Button(controls_frame, text="Select fishy file", command=select_file).grid(row=0, column=1) - Label(controls_frame, text="Use semi-fisher config for rest").grid(row=2, column=0, columnspan=2) + file_name_label = tk.StringVar(value=file_name()) + ttk.Label(controls_frame, textvariable=file_name_label).grid(row=0, column=0) + ttk.Button(controls_frame, text="Select fishy file", command=select_file).grid(row=0, column=1) + ttk.Label(controls_frame, text="Use semi-fisher config for rest").grid(row=2, column=0, columnspan=2) controls_frame.pack(padx=(5, 5), pady=(5, 5)) top.start() @@ -69,42 +69,42 @@ def start_semifisher_config(gui: 'GUI'): event.widget.insert(0, str(event.char)) top = PopUp(save, gui._root, background=gui._root["background"]) - controls_frame = Frame(top) + controls_frame = ttk.Frame(top) top.title("Config") - Label(controls_frame, text="Notification:").grid(row=0, column=0) + ttk.Label(controls_frame, text="Notification:").grid(row=0, column=0) - gui._notify = IntVar(0) - gui._notify_check = Checkbutton(controls_frame, command=toggle_sub, variable=gui._notify) + gui._notify = tk.IntVar(0) + gui._notify_check = ttk.Checkbutton(controls_frame, command=toggle_sub, variable=gui._notify) gui._notify_check.grid(row=0, column=1) - gui._notify_check['state'] = DISABLED + gui._notify_check['state'] = tk.DISABLED is_subbed = web.is_subbed() if is_subbed[1]: - gui._notify_check['state'] = NORMAL + gui._notify_check['state'] = tk.NORMAL gui._notify.set(is_subbed[0]) - Label(controls_frame, text="Fullscreen: ").grid(row=1, column=0, pady=(5, 5)) - borderless = Checkbutton(controls_frame, var=BooleanVar(value=config.get("borderless"))) + ttk.Label(controls_frame, text="Fullscreen: ").grid(row=1, column=0, pady=(5, 5)) + borderless = ttk.Checkbutton(controls_frame, var=tk.BooleanVar(value=config.get("borderless"))) borderless.grid(row=1, column=1) - Label(controls_frame, text="Action Key:").grid(row=2, column=0) - action_key_entry = Entry(controls_frame, justify=CENTER) + ttk.Label(controls_frame, text="Action Key:").grid(row=2, column=0) + action_key_entry = ttk.Entry(controls_frame, justify=tk.CENTER) action_key_entry.grid(row=2, column=1) action_key_entry.insert(0, config.get("action_key", "e")) action_key_entry.bind("", del_entry_key) - Label(controls_frame, text="Looting Key:").grid(row=4, column=0, pady=(5, 5)) - collect_key_entry = Entry(controls_frame, justify=CENTER) + ttk.Label(controls_frame, text="Looting Key:").grid(row=4, column=0, pady=(5, 5)) + collect_key_entry = ttk.Entry(controls_frame, justify=tk.CENTER) collect_key_entry.grid(row=4, column=1, pady=(5, 5)) collect_key_entry.insert(0, config.get("collect_key", "r")) collect_key_entry.bind("", del_entry_key) - Label(controls_frame, text="Sound Notification: ").grid(row=5, column=0, pady=(5, 5)) - sound = Checkbutton(controls_frame, var=BooleanVar(value=config.get("sound_notification"))) + ttk.Label(controls_frame, text="Sound Notification: ").grid(row=5, column=0, pady=(5, 5)) + sound = ttk.Checkbutton(controls_frame, var=tk.BooleanVar(value=config.get("sound_notification"))) sound.grid(row=5, column=1) - Label(controls_frame, text="Human-Like Delay: ").grid(row=6, column=0, pady=(5, 5)) - jitter = Checkbutton(controls_frame, var=BooleanVar(value=config.get("jitter"))) + ttk.Label(controls_frame, text="Human-Like Delay: ").grid(row=6, column=0, pady=(5, 5)) + jitter = ttk.Checkbutton(controls_frame, var=tk.BooleanVar(value=config.get("jitter"))) jitter.grid(row=6, column=1) controls_frame.pack(padx=(5, 5), pady=(5, 5)) diff --git a/fishy/gui/discord_login.py b/fishy/gui/discord_login.py index 8de3914..116f96f 100644 --- a/fishy/gui/discord_login.py +++ b/fishy/gui/discord_login.py @@ -1,7 +1,6 @@ import time -from tkinter import * -from tkinter import messagebox -from tkinter.ttk import * +import tkinter as tk +import tkinter.ttk as ttk import typing @@ -34,14 +33,14 @@ def discord_login(gui: 'GUI'): code = int(login_code.get()) if login_code.get().isdigit() else 0 if web.login(config.get("uid"), code): gui.login.set(1) - messagebox.showinfo("Note!", "Logged in successfuly!") + tk.messagebox.showinfo("Note!", "Login successful!") quit_top() else: - messagebox.showerror("Error", "Logged wasn't successful") + tk.messagebox.showerror("Error", "Login was not successful!") top_running = [True] - top = Toplevel(background=gui._root["background"]) + top = tk.Toplevel(background=gui._root["background"]) top.minsize(width=300, height=300) top.title("Notification Setup") @@ -58,8 +57,8 @@ def discord_login(gui: 'GUI'): html_label.pack(pady=(20, 5)) html_label.fit_height() - login_code = Entry(top, justify=CENTER, font="Calibri 15") - login_code.pack(padx=(15, 15), expand=True, fill=BOTH) + login_code = ttk.Entry(top, justify=tk.CENTER, font="Calibri 15") + login_code.pack(padx=(15, 15), expand=True, fill=tk.BOTH) html_label = HTMLLabel(top, html=f'
' @@ -69,7 +68,7 @@ def discord_login(gui: 'GUI'): html_label.pack(pady=(5, 5)) html_label.fit_height() - Button(top, text="REGISTER", command=check).pack(pady=(5, 20)) + ttk.Button(top, text="REGISTER", command=check).pack(pady=(5, 20)) top.protocol("WM_DELETE_WINDOW", quit_top) top.grab_set() diff --git a/fishy/gui/gui.py b/fishy/gui/gui.py index 79d8821..7127e4e 100644 --- a/fishy/gui/gui.py +++ b/fishy/gui/gui.py @@ -1,7 +1,7 @@ import logging import uuid -from tkinter import OptionMenu, Button, IntVar from typing import List, Callable, Optional, Dict, Any +import tkinter as tk import queue import threading @@ -35,8 +35,8 @@ class GUI: self._console = None self._start_button = None self._notify_check = None - self._engine_select: Optional[OptionMenu] = None - self._config_button: Optional[Button] = None + self._engine_select: Optional[tk.OptionMenu] = None + self._config_button: Optional[tk.Button] = None self._engine_var = None self._thread = threading.Thread(target=self.create, args=()) diff --git a/fishy/gui/main_gui.py b/fishy/gui/main_gui.py index 7b57724..7f68095 100644 --- a/fishy/gui/main_gui.py +++ b/fishy/gui/main_gui.py @@ -1,7 +1,7 @@ import logging import time -from tkinter import * -from tkinter.ttk import * +import tkinter as tk +import tkinter.ttk as ttk from fishy.web import web from ttkthemes import ThemedTk @@ -36,14 +36,14 @@ def _create(gui: 'GUI'): gui._root.iconbitmap(helper.manifest_file('icon.ico')) # region menu - menubar = Menu(gui._root) + menubar = tk.Menu(gui._root) - filemenu = Menu(menubar, tearoff=0) + filemenu = tk.Menu(menubar, tearoff=0) login = web.is_logged_in() - gui.login = IntVar() + gui.login = tk.IntVar() gui.login.set(1 if login > 0 else 0) - state = DISABLED if login == -1 else ACTIVE + state = tk.DISABLED if login == -1 else tk.ACTIVE filemenu.add_checkbutton(label="Login", command=lambda: discord_login(gui), variable=gui.login, state=state) filemenu.add_command(label="Create Shortcut", command=lambda: helper.create_shortcut(False)) # filemenu.add_command(label="Create Anti-Ghost Shortcut", command=lambda: helper.create_shortcut(True)) @@ -52,7 +52,7 @@ def _create(gui: 'GUI'): config.set("dark_mode", not config.get("dark_mode", True)) gui._start_restart = True - dark_mode_var = IntVar() + dark_mode_var = tk.IntVar() dark_mode_var.set(int(config.get('dark_mode', True))) filemenu.add_checkbutton(label="Dark Mode", command=_toggle_mode, variable=dark_mode_var) @@ -72,11 +72,11 @@ def _create(gui: 'GUI'): filemenu.add_command(label=chaEntry, command=installer) menubar.add_cascade(label="Options", menu=filemenu) - debug_menu = Menu(menubar, tearoff=0) + debug_menu = tk.Menu(menubar, tearoff=0) debug_menu.add_command(label="Check PixelVal", command=lambda: gui.engine.check_pixel_val()) - debug_var = IntVar() + debug_var = tk.IntVar() debug_var.set(int(config.get('debug', False))) def keep_console(): @@ -87,7 +87,7 @@ def _create(gui: 'GUI'): debug_menu.add_command(label="Restart", command=helper.restart) menubar.add_cascade(label="Debug", menu=debug_menu) - help_menu = Menu(menubar, tearoff=0) + help_menu = tk.Menu(menubar, tearoff=0) help_menu.add_command(label="Need Help?", command=lambda: helper.open_web("http://discord.definex.in")) help_menu.add_command(label="Donate", command=lambda: helper.open_web("https://paypal.me/AdamSaudagar")) menubar.add_cascade(label="Help", menu=help_menu) @@ -96,29 +96,29 @@ def _create(gui: 'GUI'): # endregion # region console - gui._console = Text(gui._root, state='disabled', wrap='none', background="#707070", fg="#ffffff") - gui._console.pack(fill=BOTH, expand=True, pady=(15, 15), padx=(10, 10)) - gui._console.mark_set("sentinel", INSERT) - gui._console.config(state=DISABLED) + gui._console = tk.Text(gui._root, state='disabled', wrap='none', background="#707070", fg="#ffffff") + gui._console.pack(fill=tk.BOTH, expand=True, pady=(15, 15), padx=(10, 10)) + gui._console.mark_set("sentinel", tk.INSERT) + gui._console.config(state=tk.DISABLED) # endregion # region controls - start_frame = Frame(gui._root) + start_frame = ttk.Frame(gui._root) - gui._engine_var = StringVar(start_frame) + gui._engine_var = tk.StringVar(start_frame) labels = list(engines.keys()) last_started = config.get("last_started", labels[0]) - gui._engine_select = OptionMenu(start_frame, gui._engine_var, last_started, *labels) - gui._engine_select.pack(side=LEFT) + gui._engine_select = ttk.OptionMenu(start_frame, gui._engine_var, last_started, *labels) + gui._engine_select.pack(side=tk.LEFT) - gui._config_button = Button(start_frame, text="⚙", width=0, command=lambda: engines[gui._engine_var.get()][0]()) - gui._config_button.pack(side=RIGHT) + gui._config_button = ttk.Button(start_frame, text="⚙", width=0, command=lambda: engines[gui._engine_var.get()][0]()) + gui._config_button.pack(side=tk.RIGHT) - gui._start_button = Button(start_frame, text=gui._get_start_stop_text(), width=25, + gui._start_button = ttk.Button(start_frame, text=gui._get_start_stop_text(), width=25, command=gui.funcs.start_engine) - gui._start_button.pack(side=RIGHT) + gui._start_button.pack(side=tk.RIGHT) - start_frame.pack(padx=(10, 10), pady=(5, 15), fill=X) + start_frame.pack(padx=(10, 10), pady=(5, 15), fill=tk.X) # endregion _apply_theme(gui) @@ -132,7 +132,7 @@ def _create(gui: 'GUI'): # noinspection PyProtectedMember def set_destroy(): if gui._bot_running: - if not messagebox.askyesno(title="Quit?", message="Bot engine running. Quit Anyway?"): + if not tk.messagebox.askyesno(title="Quit?", message="Bot engine running. Quit Anyway?"): return config.set("win_loc", gui._root.geometry()) diff --git a/fishy/gui/splash.py b/fishy/gui/splash.py index 6ead4cf..bf87219 100644 --- a/fishy/gui/splash.py +++ b/fishy/gui/splash.py @@ -1,6 +1,6 @@ import time from multiprocessing import Process -from tkinter import * +import tkinter as tk from PIL import Image, ImageTk from fishy.helper.config import config @@ -9,7 +9,7 @@ from fishy.helper import helper def show(win_loc): dim=(300,200) - top = Tk() + top = tk.Tk() top.overrideredirect(True) top.lift() @@ -18,11 +18,11 @@ def show(win_loc): top.resizable(False, False) top.iconbitmap(helper.manifest_file('icon.ico')) - canvas = Canvas(top, width=dim[0], height=dim[1], bg='white') + canvas = tk.Canvas(top, width=dim[0], height=dim[1], bg='white') canvas.pack() top.image = Image.open(helper.manifest_file('fishybot_logo.png')).resize(dim) top.image = ImageTk.PhotoImage(top.image) - canvas.create_image(0, 0, anchor=NW, image=top.image) + canvas.create_image(0, 0, anchor=tk.NW, image=top.image) # Position splash at the center of the main window diff --git a/fishy/gui/terms_gui.py b/fishy/gui/terms_gui.py index bb1125b..5e3bf36 100644 --- a/fishy/gui/terms_gui.py +++ b/fishy/gui/terms_gui.py @@ -1,6 +1,6 @@ import webbrowser -from tkinter import * -from tkinter.ttk import * +import tkinter as tk +import tkinter.ttk as ttk import re from PIL import Image, ImageTk @@ -25,41 +25,41 @@ def _run_terms_window(): root.destroy() def disable_enable_button(): - accept_button.config(state=NORMAL if check_value.get() else DISABLED) + accept_button.config(state=tk.NORMAL if check_value.get() else tk.DISABLED) - root = Tk() + root = tk.Tk() message = f'I agree to the [Terms of Service and Privacy Policy]({web.get_terms_page()})' root.title("EULA") root.resizable(False, False) root.iconbitmap(helper.manifest_file('icon.ico')) - f = Frame(root) - canvas = Canvas(f, width=300, height=200) + f = ttk.Frame(root) + canvas = tk.Canvas(f, width=300, height=200) canvas.pack() root.image = Image.open(helper.manifest_file('fishybot_logo.png')).resize((300, 200)) root.image = ImageTk.PhotoImage(root.image) - canvas.create_image(0, 0, anchor=NW, image=root.image) + canvas.create_image(0, 0, anchor=tk.NW, image=root.image) - check_value = IntVar(0) + check_value = tk.IntVar(0) - g1 = Frame(f) - Checkbutton(g1, command=disable_enable_button, variable=check_value).pack(side=LEFT) - text = Text(g1, width=len(hyperlinkPattern.sub(r'\g', message)), + g1 = ttk.Frame(f) + ttk.Checkbutton(g1, command=disable_enable_button, variable=check_value).pack(side=tk.LEFT) + text = tk.Text(g1, width=len(hyperlinkPattern.sub(r'\g<title>', message)), height=1, borderwidth=0, highlightthickness=0) text["background"] = root["background"] _format_hyper_link(text, message) - text.config(state=DISABLED) - text.pack(side=LEFT) + text.config(state=tk.DISABLED) + text.pack(side=tk.LEFT) g1.pack() f.pack(padx=(10, 10), pady=(20, 20)) - g2 = Frame(f) - accept_button = Button(g2, text="Accept", + g2 = ttk.Frame(f) + accept_button = ttk.Button(g2, text="Accept", command=accept) accept_button.grid(row=0, column=0) - Button(g2, text="Deny", + ttk.Button(g2, text="Deny", command=lambda: root.destroy()).grid(row=0, column=1) g2.pack(pady=(5, 0)) disable_enable_button() diff --git a/fishy/gui/update_dialog.py b/fishy/gui/update_dialog.py index b9dd244..d8c98d1 100644 --- a/fishy/gui/update_dialog.py +++ b/fishy/gui/update_dialog.py @@ -1,19 +1,19 @@ from multiprocessing import Process, Manager -from tkinter import * +import tkinter as tk import time from fishy import helper def show(currentversion, newversion, returns): - top = Tk() + top = tk.Tk() top.title("A wild fishy update appeared!") top.iconbitmap(helper.manifest_file('icon.ico')) - dialogLabel = Label(top, text="There is a new fishy update available ("+currentversion+"->"+newversion+"). Do you want to update now?") + dialogLabel = tk.Label(top, text="There is a new fishy update available ("+currentversion+"->"+newversion+"). Do you want to update now?") dialogLabel.grid(row=0, columnspan=2, padx=5, pady=5) - cbVar = IntVar() - dialogCheckbutton = Checkbutton(top, text="don't ask again", variable=cbVar) + cbVar = tk.IntVar() + dialogCheckbutton = tk.Checkbutton(top, text="don't ask again", variable=cbVar) dialogCheckbutton.grid(row=1, columnspan=2, padx=5, pady=0) top.update() buttonWidth = int(dialogLabel.winfo_width()/2)-20 @@ -26,10 +26,10 @@ def show(currentversion, newversion, returns): returns[0],returns[1]=False, bool(cbVar.get()) top.destroy() - pixelVirtual = PhotoImage(width=1, height=1) # trick to use buttonWidth as pixels, not #symbols - dialogBtnNo = Button(top, text="No " + str(chr(10005)), fg='red4', command=_clickNo, image=pixelVirtual, width=buttonWidth, compound="c") + pixelVirtual = tk.PhotoImage(width=1, height=1) # trick to use buttonWidth as pixels, not #symbols + dialogBtnNo = tk.Button(top, text="No " + str(chr(10005)), fg='red4', command=_clickNo, image=pixelVirtual, width=buttonWidth, compound="c") dialogBtnNo.grid(row=2, column=0, padx=5, pady=5) - dialogBtnYes = Button(top, text="Yes " + str(chr(10003)), fg='green', command=_clickYes, image=pixelVirtual, width=buttonWidth, compound="c") + dialogBtnYes = tk.Button(top, text="Yes " + str(chr(10003)), fg='green', command=_clickYes, image=pixelVirtual, width=buttonWidth, compound="c") dialogBtnYes.grid(row=2, column=1, padx=5, pady=5) dialogBtnYes.focus_set() From fb89fdf4fb233e1e3196b7642b3745641f1abc73 Mon Sep 17 00:00:00 2001 From: Semjon Kerner <Semjon.Kerner@gmx.net> Date: Sun, 9 May 2021 08:41:39 +0200 Subject: [PATCH 16/20] remove unused imports --- fishy/engine/semifisher/engine.py | 2 -- fishy/engine/semifisher/fishing_mode.py | 1 - fishy/gui/discord_login.py | 2 -- fishy/gui/gui.py | 2 +- fishy/gui/update_dialog.py | 1 - fishy/helper/config.py | 1 - 6 files changed, 1 insertion(+), 8 deletions(-) diff --git a/fishy/engine/semifisher/engine.py b/fishy/engine/semifisher/engine.py index 4f62e61..b4860d5 100644 --- a/fishy/engine/semifisher/engine.py +++ b/fishy/engine/semifisher/engine.py @@ -1,6 +1,5 @@ import time import typing -import cv2 import logging from threading import Thread from typing import Callable @@ -11,7 +10,6 @@ from fishy.engine.common.window import WindowClient from fishy.engine.semifisher.fishing_mode import Colors, FishingMode from fishy.engine.common.IEngine import IEngine -from fishy.engine.semifisher.fishing_mode import FishingMode from fishy.engine.semifisher.fishing_event import FishEvent from fishy.engine.semifisher import fishing_mode, fishing_event from fishy.engine.semifisher.pixel_loc import PixelLoc diff --git a/fishy/engine/semifisher/fishing_mode.py b/fishy/engine/semifisher/fishing_mode.py index 4049dfe..9a6c397 100644 --- a/fishy/engine/semifisher/fishing_mode.py +++ b/fishy/engine/semifisher/fishing_mode.py @@ -1,4 +1,3 @@ -import time from enum import Enum subscribers = [] diff --git a/fishy/gui/discord_login.py b/fishy/gui/discord_login.py index 116f96f..5c48191 100644 --- a/fishy/gui/discord_login.py +++ b/fishy/gui/discord_login.py @@ -4,8 +4,6 @@ import tkinter.ttk as ttk import typing -from fishy.helper import helper - from fishy.web import web from fishy.libs.tkhtmlview import HTMLLabel diff --git a/fishy/gui/gui.py b/fishy/gui/gui.py index 7127e4e..4c2f375 100644 --- a/fishy/gui/gui.py +++ b/fishy/gui/gui.py @@ -1,7 +1,7 @@ import logging import uuid -from typing import List, Callable, Optional, Dict, Any import tkinter as tk +from typing import Callable, Optional, Dict, Any import queue import threading diff --git a/fishy/gui/update_dialog.py b/fishy/gui/update_dialog.py index d8c98d1..c406dd5 100644 --- a/fishy/gui/update_dialog.py +++ b/fishy/gui/update_dialog.py @@ -1,6 +1,5 @@ from multiprocessing import Process, Manager import tkinter as tk -import time from fishy import helper diff --git a/fishy/helper/config.py b/fishy/helper/config.py index 896fbc8..84db0d2 100644 --- a/fishy/helper/config.py +++ b/fishy/helper/config.py @@ -3,7 +3,6 @@ config.py Saves configuration in file as json file """ import json -import logging import os # path to save the configuration file From 3172b30d98160219a7ea015bc8e1aeb890e006d0 Mon Sep 17 00:00:00 2001 From: Semjon Kerner <Semjon.Kerner@gmx.net> Date: Sun, 9 May 2021 09:05:51 +0200 Subject: [PATCH 17/20] sort imports with isort --- fishy/__main__.py | 5 ++-- fishy/engine/common/window.py | 2 +- fishy/engine/common/window_server.py | 8 +++---- fishy/engine/fullautofisher/calibrator.py | 5 ++-- fishy/engine/fullautofisher/controls.py | 5 ++-- fishy/engine/fullautofisher/engine.py | 26 ++++++++++----------- fishy/engine/fullautofisher/player.py | 4 +--- fishy/engine/fullautofisher/qr_detection.py | 5 ++-- fishy/engine/fullautofisher/recorder.py | 1 - fishy/engine/semifisher/engine.py | 14 +++++------ fishy/engine/semifisher/fishing_event.py | 7 +++--- fishy/gui/config_top.py | 9 +++---- fishy/gui/discord_login.py | 3 +-- fishy/gui/funcs.py | 3 +-- fishy/gui/gui.py | 13 ++++++----- fishy/gui/log_config.py | 3 +-- fishy/gui/main_gui.py | 11 ++++----- fishy/gui/splash.py | 5 ++-- fishy/gui/terms_gui.py | 4 ++-- fishy/gui/update_dialog.py | 3 ++- fishy/helper/__init__.py | 9 ++++--- fishy/helper/auto_update.py | 1 + fishy/helper/config.py | 2 +- fishy/helper/helper.py | 12 ++++------ fishy/helper/hotkey.py | 2 +- fishy/helper/hotkey_process.py | 2 +- fishy/helper/luaparser.py | 3 ++- fishy/web/__init__.py | 3 ++- fishy/web/web.py | 5 ++-- setup.py | 8 ++++--- 30 files changed, 88 insertions(+), 95 deletions(-) diff --git a/fishy/__main__.py b/fishy/__main__.py index d3a7da1..1159945 100644 --- a/fishy/__main__.py +++ b/fishy/__main__.py @@ -3,16 +3,17 @@ import logging import os import sys import traceback + import win32con import win32gui import fishy -from fishy import web, helper, gui +from fishy import gui, helper, web +from fishy.constants import chalutier, lam2 from fishy.engine.common.event_handler import EngineEventHandler from fishy.gui import GUI, splash, update_dialog from fishy.helper import hotkey from fishy.helper.config import config -from fishy.constants import chalutier, lam2 def check_window_name(title): diff --git a/fishy/engine/common/window.py b/fishy/engine/common/window.py index 53409a7..405695d 100644 --- a/fishy/engine/common/window.py +++ b/fishy/engine/common/window.py @@ -5,7 +5,7 @@ import cv2 import imutils from fishy.engine.common import window_server -from fishy.engine.common.window_server import WindowServer, Status +from fishy.engine.common.window_server import Status, WindowServer from fishy.helper import helper diff --git a/fishy/engine/common/window_server.py b/fishy/engine/common/window_server.py index 65170e3..b4bb0c7 100644 --- a/fishy/engine/common/window_server.py +++ b/fishy/engine/common/window_server.py @@ -1,16 +1,14 @@ import logging +import math from enum import Enum from threading import Thread import cv2 -import math - +import numpy as np import pywintypes import win32gui -from win32api import GetSystemMetrics - -import numpy as np from PIL import ImageGrab +from win32api import GetSystemMetrics from fishy.helper.config import config diff --git a/fishy/engine/fullautofisher/calibrator.py b/fishy/engine/fullautofisher/calibrator.py index a660529..c09025a 100644 --- a/fishy/engine/fullautofisher/calibrator.py +++ b/fishy/engine/fullautofisher/calibrator.py @@ -1,13 +1,12 @@ -import math import logging +import math import time import cv2 import numpy as np - -from fishy.engine.fullautofisher.engine import FullAuto from pynput import keyboard, mouse +from fishy.engine.fullautofisher.engine import FullAuto from fishy.helper.config import config mse = mouse.Controller() diff --git a/fishy/engine/fullautofisher/controls.py b/fishy/engine/fullautofisher/controls.py index a05cb1b..8949466 100644 --- a/fishy/engine/fullautofisher/controls.py +++ b/fishy/engine/fullautofisher/controls.py @@ -1,14 +1,13 @@ import logging -from fishy.helper import hotkey - from fishy.engine.fullautofisher.engine import FullAuto, State +from fishy.helper import hotkey from fishy.helper.hotkey import Key def get_controls(engine: FullAuto): - from fishy.engine.fullautofisher.recorder import Recorder from fishy.engine.fullautofisher.player import Player + from fishy.engine.fullautofisher.recorder import Recorder controls = [ ("MODE_SELECT", { Key.RIGHT: (Recorder(engine).toggle_recording, "start/stop record"), diff --git a/fishy/engine/fullautofisher/engine.py b/fishy/engine/fullautofisher/engine.py index dea0233..c8c47e3 100644 --- a/fishy/engine/fullautofisher/engine.py +++ b/fishy/engine/fullautofisher/engine.py @@ -1,24 +1,22 @@ +import logging import math +import time import traceback from enum import Enum from threading import Thread import cv2 -import logging -import time - -from fishy.constants import libgps, fishyqr, lam2 -from fishy.engine.fullautofisher.qr_detection import get_values_from_image, get_qr_location -from fishy.engine.semifisher.fishing_mode import FishingMode - -from fishy.engine import SemiFisherEngine -from fishy.engine.common.window import WindowClient -from fishy.engine.semifisher import fishing_mode, fishing_event - -from fishy.engine.common.IEngine import IEngine from pynput import keyboard, mouse -from fishy.helper import hotkey, helper +from fishy.constants import fishyqr, lam2, libgps +from fishy.engine import SemiFisherEngine +from fishy.engine.common.IEngine import IEngine +from fishy.engine.common.window import WindowClient +from fishy.engine.fullautofisher.qr_detection import (get_qr_location, + get_values_from_image) +from fishy.engine.semifisher import fishing_event, fishing_mode +from fishy.engine.semifisher.fishing_mode import FishingMode +from fishy.helper import helper, hotkey from fishy.helper.helper import sign mse = mouse.Controller() @@ -46,9 +44,9 @@ class FullAuto(IEngine): state = State.NONE def __init__(self, gui_ref): - from fishy.engine.fullautofisher.controls import Controls from fishy.engine.fullautofisher import controls from fishy.engine.fullautofisher.calibrator import Calibrator + from fishy.engine.fullautofisher.controls import Controls from fishy.engine.fullautofisher.test import Test super().__init__(gui_ref) diff --git a/fishy/engine/fullautofisher/player.py b/fishy/engine/fullautofisher/player.py index 402ebb8..2322b9e 100644 --- a/fishy/engine/fullautofisher/player.py +++ b/fishy/engine/fullautofisher/player.py @@ -2,10 +2,8 @@ import logging import pickle from pprint import pprint -from fishy.engine.semifisher import fishing_event, fishing_mode - from fishy.engine.fullautofisher.engine import FullAuto, State - +from fishy.engine.semifisher import fishing_event, fishing_mode from fishy.helper import helper from fishy.helper.config import config diff --git a/fishy/engine/fullautofisher/qr_detection.py b/fishy/engine/fullautofisher/qr_detection.py index 8dedac5..ca6838b 100644 --- a/fishy/engine/fullautofisher/qr_detection.py +++ b/fishy/engine/fullautofisher/qr_detection.py @@ -3,12 +3,11 @@ import os from datetime import datetime import cv2 - -from fishy.helper.helper import get_documents - import numpy as np from pyzbar.pyzbar import decode +from fishy.helper.helper import get_documents + def get_qr_location(og_img): """ diff --git a/fishy/engine/fullautofisher/recorder.py b/fishy/engine/fullautofisher/recorder.py index 279f69b..6bf8471 100644 --- a/fishy/engine/fullautofisher/recorder.py +++ b/fishy/engine/fullautofisher/recorder.py @@ -5,7 +5,6 @@ from pprint import pprint from tkinter.filedialog import asksaveasfile from fishy.engine.fullautofisher.engine import FullAuto, State - from fishy.helper.hotkey import Key from fishy.helper.hotkey_process import HotKey diff --git a/fishy/engine/semifisher/engine.py b/fishy/engine/semifisher/engine.py index b4860d5..4c0a2f6 100644 --- a/fishy/engine/semifisher/engine.py +++ b/fishy/engine/semifisher/engine.py @@ -1,20 +1,18 @@ +import logging import time import typing -import logging from threading import Thread -from typing import Callable -from typing import Optional +from typing import Callable, Optional + from playsound import playsound -from fishy.engine.common.window import WindowClient -from fishy.engine.semifisher.fishing_mode import Colors, FishingMode - from fishy.engine.common.IEngine import IEngine +from fishy.engine.common.window import WindowClient +from fishy.engine.semifisher import fishing_event, fishing_mode from fishy.engine.semifisher.fishing_event import FishEvent -from fishy.engine.semifisher import fishing_mode, fishing_event +from fishy.engine.semifisher.fishing_mode import Colors, FishingMode from fishy.engine.semifisher.pixel_loc import PixelLoc from fishy.helper import helper - from fishy.helper.luaparser import sv_color_extract if typing.TYPE_CHECKING: diff --git a/fishy/engine/semifisher/fishing_event.py b/fishy/engine/semifisher/fishing_event.py index 8b97892..aaa064c 100644 --- a/fishy/engine/semifisher/fishing_event.py +++ b/fishy/engine/semifisher/fishing_event.py @@ -4,15 +4,16 @@ 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 import random +import time + import keyboard from playsound import playsound -from win32gui import GetWindowText, GetForegroundWindow +from win32gui import GetForegroundWindow, GetWindowText from fishy import web from fishy.engine.semifisher import fishing_mode -from fishy.engine.semifisher.fishing_mode import State, FishingMode +from fishy.engine.semifisher.fishing_mode import FishingMode, State from fishy.helper import helper from fishy.helper.config import config diff --git a/fishy/gui/config_top.py b/fishy/gui/config_top.py index b5abaeb..aba92a0 100644 --- a/fishy/gui/config_top.py +++ b/fishy/gui/config_top.py @@ -1,15 +1,12 @@ import logging import os +import tkinter as tk +import tkinter.ttk as ttk import typing from tkinter.filedialog import askopenfilename -from fishy.helper import helper - from fishy import web - -import tkinter as tk -import tkinter.ttk as ttk - +from fishy.helper import helper from fishy.helper.config import config from fishy.helper.popup import PopUp diff --git a/fishy/gui/discord_login.py b/fishy/gui/discord_login.py index 5c48191..d353266 100644 --- a/fishy/gui/discord_login.py +++ b/fishy/gui/discord_login.py @@ -1,12 +1,11 @@ import time import tkinter as tk import tkinter.ttk as ttk - import typing +from fishy.libs.tkhtmlview import HTMLLabel from fishy.web import web -from fishy.libs.tkhtmlview import HTMLLabel from ..helper.config import config if typing.TYPE_CHECKING: diff --git a/fishy/gui/funcs.py b/fishy/gui/funcs.py index 40ef022..a4dd5d4 100644 --- a/fishy/gui/funcs.py +++ b/fishy/gui/funcs.py @@ -1,6 +1,5 @@ -from tkinter import messagebox - import typing +from tkinter import messagebox from fishy.helper.config import config diff --git a/fishy/gui/gui.py b/fishy/gui/gui.py index 4c2f375..dc6ed5c 100644 --- a/fishy/gui/gui.py +++ b/fishy/gui/gui.py @@ -1,20 +1,21 @@ import logging -import uuid -import tkinter as tk -from typing import Callable, Optional, Dict, Any import queue import threading +import tkinter as tk +import uuid +from typing import Any, Callable, Dict, Optional -from fishy.web import web from ttkthemes import ThemedTk from fishy.engine.common.event_handler import EngineEventHandler from fishy.gui import config_top from fishy.gui.funcs import GUIFuncs -from . import main_gui -from .log_config import GUIStreamHandler +from fishy.web import web + from ..helper.config import config from ..helper.helper import wait_until +from . import main_gui +from .log_config import GUIStreamHandler class GUI: diff --git a/fishy/gui/log_config.py b/fishy/gui/log_config.py index 585a9b4..0a93050 100644 --- a/fishy/gui/log_config.py +++ b/fishy/gui/log_config.py @@ -1,6 +1,5 @@ -from logging import StreamHandler - import typing +from logging import StreamHandler if typing.TYPE_CHECKING: from . import GUI diff --git a/fishy/gui/main_gui.py b/fishy/gui/main_gui.py index 7f68095..3cdc1d8 100644 --- a/fishy/gui/main_gui.py +++ b/fishy/gui/main_gui.py @@ -2,19 +2,18 @@ import logging import time import tkinter as tk import tkinter.ttk as ttk +import typing -from fishy.web import web from ttkthemes import ThemedTk from fishy import helper - -import typing - from fishy.helper import hotkey -from .discord_login import discord_login +from fishy.web import web + +from ..constants import chalutier, lam2 from ..helper.config import config from ..helper.hotkey import Key -from ..constants import chalutier, lam2 +from .discord_login import discord_login if typing.TYPE_CHECKING: from . import GUI diff --git a/fishy/gui/splash.py b/fishy/gui/splash.py index bf87219..20efe75 100644 --- a/fishy/gui/splash.py +++ b/fishy/gui/splash.py @@ -1,10 +1,11 @@ import time -from multiprocessing import Process import tkinter as tk +from multiprocessing import Process + from PIL import Image, ImageTk -from fishy.helper.config import config from fishy.helper import helper +from fishy.helper.config import config def show(win_loc): diff --git a/fishy/gui/terms_gui.py b/fishy/gui/terms_gui.py index 5e3bf36..e84bd26 100644 --- a/fishy/gui/terms_gui.py +++ b/fishy/gui/terms_gui.py @@ -1,7 +1,7 @@ -import webbrowser +import re import tkinter as tk import tkinter.ttk as ttk -import re +import webbrowser from PIL import Image, ImageTk diff --git a/fishy/gui/update_dialog.py b/fishy/gui/update_dialog.py index c406dd5..105e7f8 100644 --- a/fishy/gui/update_dialog.py +++ b/fishy/gui/update_dialog.py @@ -1,8 +1,9 @@ -from multiprocessing import Process, Manager import tkinter as tk +from multiprocessing import Manager, Process from fishy import helper + def show(currentversion, newversion, returns): top = tk.Tk() top.title("A wild fishy update appeared!") diff --git a/fishy/helper/__init__.py b/fishy/helper/__init__.py index 07bc150..df42062 100644 --- a/fishy/helper/__init__.py +++ b/fishy/helper/__init__.py @@ -1,6 +1,9 @@ from .auto_update import auto_upgrade, upgrade_avail, versions from .config import Config -from .helper import open_web, initialize_uid, install_thread_excepthook, unhandled_exception_logging, manifest_file, \ - create_shortcut_first, addon_exists, get_addonversion, install_addon, remove_addon, restart, create_shortcut, \ - not_implemented, update, get_savedvarsdir, playsound_multiple +from .helper import (addon_exists, create_shortcut, create_shortcut_first, + get_addonversion, get_savedvarsdir, initialize_uid, + install_addon, install_thread_excepthook, manifest_file, + not_implemented, open_web, playsound_multiple, + remove_addon, restart, unhandled_exception_logging, + update) from .luaparser import sv_color_extract diff --git a/fishy/helper/auto_update.py b/fishy/helper/auto_update.py index 16701d6..155f984 100644 --- a/fishy/helper/auto_update.py +++ b/fishy/helper/auto_update.py @@ -11,6 +11,7 @@ from os import execl from bs4 import BeautifulSoup + def _hr_version(v): return '.'.join([str(x) for x in v]) #return str(v[0])+"."+str(v[1])+"."+str(v[2]) diff --git a/fishy/helper/config.py b/fishy/helper/config.py index 84db0d2..fa9841e 100644 --- a/fishy/helper/config.py +++ b/fishy/helper/config.py @@ -4,9 +4,9 @@ Saves configuration in file as json file """ import json import os - # path to save the configuration file from typing import Optional + from event_scheduler import EventScheduler diff --git a/fishy/helper/helper.py b/fishy/helper/helper.py index 39fdfd2..e07bdda 100644 --- a/fishy/helper/helper.py +++ b/fishy/helper/helper.py @@ -6,21 +6,19 @@ import threading import time import traceback import webbrowser -import requests -from playsound import playsound +from hashlib import md5 from io import BytesIO from threading import Thread +from uuid import uuid1 from zipfile import ZipFile -from uuid import uuid1 -from hashlib import md5 - +import requests +import winshell +from playsound import playsound from win32com.client import Dispatch from win32comext.shell import shell, shellcon import fishy -import winshell - from fishy import web diff --git a/fishy/helper/hotkey.py b/fishy/helper/hotkey.py index 5c6a7f3..7eedbdc 100644 --- a/fishy/helper/hotkey.py +++ b/fishy/helper/hotkey.py @@ -1,6 +1,6 @@ from enum import Enum from threading import Thread -from typing import Dict, Callable, Optional +from typing import Callable, Dict, Optional import keyboard diff --git a/fishy/helper/hotkey_process.py b/fishy/helper/hotkey_process.py index ad8313b..a4d5d0e 100644 --- a/fishy/helper/hotkey_process.py +++ b/fishy/helper/hotkey_process.py @@ -1,8 +1,8 @@ import time +from multiprocessing import Process, Queue from threading import Thread import mouse -from multiprocessing import Process, Queue def event_triggered(queue, e): diff --git a/fishy/helper/luaparser.py b/fishy/helper/luaparser.py index ec621a8..bdc4616 100644 --- a/fishy/helper/luaparser.py +++ b/fishy/helper/luaparser.py @@ -1,6 +1,7 @@ -import os import logging +import os from math import floor + from .helper import get_savedvarsdir diff --git a/fishy/web/__init__.py b/fishy/web/__init__.py index ec57c9c..1ab3672 100644 --- a/fishy/web/__init__.py +++ b/fishy/web/__init__.py @@ -1,2 +1,3 @@ from .urls import get_notification_page, get_terms_page -from .web import register_user, send_notification, send_fish_caught, is_subbed, unsub, get_session, sub +from .web import (get_session, is_subbed, register_user, send_fish_caught, + send_notification, sub, unsub) diff --git a/fishy/web/web.py b/fishy/web/web.py index f79319b..616352e 100644 --- a/fishy/web/web.py +++ b/fishy/web/web.py @@ -3,10 +3,11 @@ from whatsmyip.ip import get_ip from whatsmyip.providers import GoogleDnsProvider from fishy import helper + +from ..constants import apiversion +from ..helper.config import config from . import urls from .decorators import fallback, uses_session -from ..helper.config import config -from ..constants import apiversion _session_id = None diff --git a/setup.py b/setup.py index 27e426c..634467a 100644 --- a/setup.py +++ b/setup.py @@ -4,14 +4,16 @@ https://packaging.python.org/guides/distributing-packages-using-setuptools/ https://github.com/pypa/sampleproject """ -# Always prefer setuptools over distutils -from setuptools import setup, find_packages -from os import path # io.open is needed for projects that support Python 2.7 # It ensures open() defaults to text mode with universal newlines, # and accepts an argument to specify the text encoding # Python 3 only projects can skip this import from io import open +from os import path + +# Always prefer setuptools over distutils +from setuptools import find_packages, setup + from fishy import __version__ here = path.abspath(path.dirname(__file__)) From 1c5530dca46535db7912e8466571411bcdf535ac Mon Sep 17 00:00:00 2001 From: Semjon Kerner <Semjon.Kerner@gmx.net> Date: Sun, 9 May 2021 11:09:26 +0200 Subject: [PATCH 18/20] fix whitespaces according to flake8 --- fishy/__main__.py | 4 ++-- fishy/engine/fullautofisher/calibrator.py | 1 - fishy/engine/fullautofisher/recorder.py | 1 - fishy/engine/semifisher/engine.py | 1 - fishy/engine/semifisher/fishing_event.py | 8 ++++---- fishy/engine/semifisher/fishing_mode.py | 1 + fishy/gui/config_top.py | 2 +- fishy/gui/main_gui.py | 2 +- fishy/gui/splash.py | 6 +++--- fishy/gui/terms_gui.py | 8 ++++---- fishy/gui/update_dialog.py | 14 ++++++------- fishy/helper/auto_update.py | 1 + fishy/helper/helper.py | 10 ++++----- fishy/helper/luaparser.py | 25 +++++++++++------------ fishy/web/web.py | 20 +++++++++--------- setup.py | 2 +- 16 files changed, 52 insertions(+), 54 deletions(-) diff --git a/fishy/__main__.py b/fishy/__main__.py index 1159945..738bf9a 100644 --- a/fishy/__main__.py +++ b/fishy/__main__.py @@ -43,8 +43,8 @@ def initialize(window_to_hide): try: if helper.upgrade_avail() and not config.get("dont_ask_update", False): - cv,hv = helper.versions() - update_now, dont_ask_update = update_dialog.start(cv,hv) + cv, hv = helper.versions() + update_now, dont_ask_update = update_dialog.start(cv, hv) if dont_ask_update: config.set("dont_ask_update", dont_ask_update) else: diff --git a/fishy/engine/fullautofisher/calibrator.py b/fishy/engine/fullautofisher/calibrator.py index c09025a..87a0a5a 100644 --- a/fishy/engine/fullautofisher/calibrator.py +++ b/fishy/engine/fullautofisher/calibrator.py @@ -114,4 +114,3 @@ class Calibrator: def calibrate(self): self._walk_calibrate() self._rotate_calibrate() - diff --git a/fishy/engine/fullautofisher/recorder.py b/fishy/engine/fullautofisher/recorder.py index 6bf8471..b4b614b 100644 --- a/fishy/engine/fullautofisher/recorder.py +++ b/fishy/engine/fullautofisher/recorder.py @@ -68,4 +68,3 @@ class Recorder: pickle.dump(data, file) file.close() FullAuto.state = State.NONE - diff --git a/fishy/engine/semifisher/engine.py b/fishy/engine/semifisher/engine.py index 4c0a2f6..29ee8f7 100644 --- a/fishy/engine/semifisher/engine.py +++ b/fishy/engine/semifisher/engine.py @@ -92,4 +92,3 @@ if __name__ == '__main__': # noinspection PyTypeChecker fisher = SemiFisherEngine(None) fisher.toggle_start() - diff --git a/fishy/engine/semifisher/fishing_event.py b/fishy/engine/semifisher/fishing_event.py index aaa064c..e028275 100644 --- a/fishy/engine/semifisher/fishing_event.py +++ b/fishy/engine/semifisher/fishing_event.py @@ -30,15 +30,15 @@ class FishEvent: # initialize these action_key = 'e' - collect_key = 'r' + collect_key = 'r' sound = False -def _fishing_sleep(waittime, lower_limit_ms = 16, upper_limit_ms = 2500): +def _fishing_sleep(waittime, lower_limit_ms=16, upper_limit_ms=2500): reaction = 0.0 if FishEvent.jitter and upper_limit_ms > lower_limit_ms: - reaction = float( random.randrange(lower_limit_ms, upper_limit_ms) )/1000.0 - max_wait_t = waittime+reaction if waittime+reaction <= 2.5 else 2.5 + reaction = float(random.randrange(lower_limit_ms, upper_limit_ms)) / 1000.0 + max_wait_t = waittime + reaction if waittime + reaction <= 2.5 else 2.5 time.sleep(max_wait_t) diff --git a/fishy/engine/semifisher/fishing_mode.py b/fishy/engine/semifisher/fishing_mode.py index 9a6c397..bf8a05c 100644 --- a/fishy/engine/semifisher/fishing_mode.py +++ b/fishy/engine/semifisher/fishing_mode.py @@ -16,6 +16,7 @@ class State(Enum): FIGHT = 14 DEAD = 15 + Colors = { State.IDLE : [255, 255, 255], State.LOOKAWAY : [ 76, 0, 76], diff --git a/fishy/gui/config_top.py b/fishy/gui/config_top.py index aba92a0..886ec41 100644 --- a/fishy/gui/config_top.py +++ b/fishy/gui/config_top.py @@ -62,7 +62,7 @@ def start_semifisher_config(gui: 'GUI'): gui._notify.set(1) def del_entry_key(event): - event.widget.delete(0,"end") + event.widget.delete(0, "end") event.widget.insert(0, str(event.char)) top = PopUp(save, gui._root, background=gui._root["background"]) diff --git a/fishy/gui/main_gui.py b/fishy/gui/main_gui.py index 3cdc1d8..7c74c84 100644 --- a/fishy/gui/main_gui.py +++ b/fishy/gui/main_gui.py @@ -114,7 +114,7 @@ def _create(gui: 'GUI'): gui._config_button.pack(side=tk.RIGHT) gui._start_button = ttk.Button(start_frame, text=gui._get_start_stop_text(), width=25, - command=gui.funcs.start_engine) + command=gui.funcs.start_engine) gui._start_button.pack(side=tk.RIGHT) start_frame.pack(padx=(10, 10), pady=(5, 15), fill=tk.X) diff --git a/fishy/gui/splash.py b/fishy/gui/splash.py index 20efe75..f273674 100644 --- a/fishy/gui/splash.py +++ b/fishy/gui/splash.py @@ -9,7 +9,7 @@ from fishy.helper.config import config def show(win_loc): - dim=(300,200) + dim = (300, 200) top = tk.Tk() top.overrideredirect(True) @@ -27,9 +27,9 @@ def show(win_loc): # Position splash at the center of the main window - default_loc = (str(top.winfo_reqwidth())+"+"+str(top.winfo_reqheight())+"+"+"0"+"0") + default_loc = (str(top.winfo_reqwidth()) + "+" + str(top.winfo_reqheight()) + "+" + "0" + "0") loc = (win_loc or default_loc).split("+")[1:] - top.geometry("{}x{}+{}+{}".format(dim[0], dim[1], int(loc[0])+int(dim[0]/2), int(loc[1])+int(dim[1]/2))) + top.geometry("{}x{}+{}+{}".format(dim[0], dim[1], int(loc[0]) + int(dim[0] / 2), int(loc[1]) + int(dim[1] / 2))) top.update() time.sleep(3) diff --git a/fishy/gui/terms_gui.py b/fishy/gui/terms_gui.py index e84bd26..4276f4a 100644 --- a/fishy/gui/terms_gui.py +++ b/fishy/gui/terms_gui.py @@ -8,7 +8,7 @@ from PIL import Image, ImageTk from fishy import helper, web from fishy.helper.config import config -hyperlinkPattern = re.compile(r'\[(?P<title>.*?)\]\((?P<address>.*?)\)') +hyperlinkPattern = re.compile(r'\[(?P<title>.*?)\]\((?P<address>.*?)\)') def check_eula(): @@ -45,7 +45,7 @@ def _run_terms_window(): g1 = ttk.Frame(f) ttk.Checkbutton(g1, command=disable_enable_button, variable=check_value).pack(side=tk.LEFT) text = tk.Text(g1, width=len(hyperlinkPattern.sub(r'\g<title>', message)), - height=1, borderwidth=0, highlightthickness=0) + height=1, borderwidth=0, highlightthickness=0) text["background"] = root["background"] _format_hyper_link(text, message) @@ -57,10 +57,10 @@ def _run_terms_window(): g2 = ttk.Frame(f) accept_button = ttk.Button(g2, text="Accept", - command=accept) + command=accept) accept_button.grid(row=0, column=0) ttk.Button(g2, text="Deny", - command=lambda: root.destroy()).grid(row=0, column=1) + command=lambda: root.destroy()).grid(row=0, column=1) g2.pack(pady=(5, 0)) disable_enable_button() diff --git a/fishy/gui/update_dialog.py b/fishy/gui/update_dialog.py index 105e7f8..9e16ac9 100644 --- a/fishy/gui/update_dialog.py +++ b/fishy/gui/update_dialog.py @@ -9,27 +9,27 @@ def show(currentversion, newversion, returns): top.title("A wild fishy update appeared!") top.iconbitmap(helper.manifest_file('icon.ico')) - dialogLabel = tk.Label(top, text="There is a new fishy update available ("+currentversion+"->"+newversion+"). Do you want to update now?") + dialogLabel = tk.Label(top, text="There is a new fishy update available (" + currentversion + "->" + newversion + "). Do you want to update now?") dialogLabel.grid(row=0, columnspan=2, padx=5, pady=5) cbVar = tk.IntVar() dialogCheckbutton = tk.Checkbutton(top, text="don't ask again", variable=cbVar) dialogCheckbutton.grid(row=1, columnspan=2, padx=5, pady=0) top.update() - buttonWidth = int(dialogLabel.winfo_width()/2)-20 + buttonWidth = int(dialogLabel.winfo_width() / 2) - 20 def _clickYes(): - returns[0],returns[1]=True, False + returns[0], returns[1] = True, False top.destroy() def _clickNo(): - returns[0],returns[1]=False, bool(cbVar.get()) + returns[0], returns[1] = False, bool(cbVar.get()) top.destroy() - pixelVirtual = tk.PhotoImage(width=1, height=1) # trick to use buttonWidth as pixels, not #symbols - dialogBtnNo = tk.Button(top, text="No " + str(chr(10005)), fg='red4', command=_clickNo, image=pixelVirtual, width=buttonWidth, compound="c") + pixelVirtual = tk.PhotoImage(width=1, height=1) # trick to use buttonWidth as pixels, not #symbols + dialogBtnNo = tk.Button(top, text="No " + str(chr(10005)), fg='red4', command=_clickNo, image=pixelVirtual, width=buttonWidth, compound="c") dialogBtnNo.grid(row=2, column=0, padx=5, pady=5) - dialogBtnYes = tk.Button(top, text="Yes " + str(chr(10003)), fg='green', command=_clickYes, image=pixelVirtual, width=buttonWidth, compound="c") + dialogBtnYes = tk.Button(top, text="Yes " + str(chr(10003)), fg='green', command=_clickYes, image=pixelVirtual, width=buttonWidth, compound="c") dialogBtnYes.grid(row=2, column=1, padx=5, pady=5) dialogBtnYes.focus_set() diff --git a/fishy/helper/auto_update.py b/fishy/helper/auto_update.py index 155f984..cc1644e 100644 --- a/fishy/helper/auto_update.py +++ b/fishy/helper/auto_update.py @@ -76,6 +76,7 @@ def _get_current_version(): index = "https://pypi.python.org/simple" pkg = "fishy" + def versions(): return _hr_version(_get_current_version()), _hr_version(_get_highest_version(index, pkg)) diff --git a/fishy/helper/helper.py b/fishy/helper/helper.py index e07bdda..95ba88b 100644 --- a/fishy/helper/helper.py +++ b/fishy/helper/helper.py @@ -28,7 +28,7 @@ def playsound_multiple(path, count=2): return def _ps_m(): - for i in range(count-1): + for i in range(count - 1): playsound(path, True) playsound(path, False) @@ -194,21 +194,21 @@ def install_addon(name, url, v=None): r = requests.get(url, stream=True) z = ZipFile(BytesIO(r.content)) z.extractall(path=get_addondir()) - logging.info("Add-On "+name+" installed successfully!\nPlease make sure to enable \"Allow outdated addons\" in ESO") + logging.info("Add-On " + name + " installed successfully!\nPlease make sure to enable \"Allow outdated addons\" in ESO") return 0 except Exception as ex: - logging.error("Could not install Add-On "+name+", try doing it manually") + logging.error("Could not install Add-On " + name + ", try doing it manually") return 1 def remove_addon(name, url=None, v=None): try: shutil.rmtree(os.path.join(get_addondir(), name)) - logging.info("Add-On "+name+" removed!") + logging.info("Add-On " + name + " removed!") except FileNotFoundError: pass except PermissionError as ex: - logging.error("Fishy has no permission to remove "+name+" Add-On") + logging.error("Fishy has no permission to remove " + name + " Add-On") return 1 return 0 diff --git a/fishy/helper/luaparser.py b/fishy/helper/luaparser.py index bdc4616..ebebead 100644 --- a/fishy/helper/luaparser.py +++ b/fishy/helper/luaparser.py @@ -18,7 +18,7 @@ def _sv_parser(path): - remove empty expressions EXPRESSIONS: A) List-Start "name=", B) Variable assignment "name=val", C) List End "}" """ - for old, new in ((",","\n"), ("{","{\n"), ("}","}\n"), ("{",""), (",", ""), ("[", ""), ("]", ""), ('"', ""), (" ", "")): + for old, new in ((",", "\n"), ("{", "{\n"), ("}", "}\n"), ("{", ""), (",", ""), ("[", ""), ("]", ""), ('"', ""), (" ", "")): lua = lua.replace(old, new) lua = lua.lower().split("\n") lua = [expression for expression in lua if expression] @@ -29,22 +29,22 @@ def _sv_parser(path): the last symbol of each line decides the type of the node (branch vertex or leaf) """ stack = [] - root = (dict(),"root") + root = (dict(), "root") stack.append(root) for line in lua: if line == "": break - if line[-1] == '=': #subtree start + if line[-1] == '=': #subtree start t = dict() tname = line.split("=")[0] - stack.append((t,tname)) - elif line[-1] == '}': #subtree end + stack.append((t, tname)) + elif line[-1] == '}': #subtree end t = stack.pop() tp = stack.pop() tp[0][t[1]] = t[0] stack.append(tp) - else: #new element in tree - name,val = line.split("=") + else: #new element in tree + name, val = line.split("=") t = stack.pop() t[0][name] = val stack.append(t) @@ -68,13 +68,12 @@ def sv_color_extract(Colors): ingame representation of colors range from 0 to 1 in float these values are scaled by 255 """ - rgb=[ - floor(float(root["colors"][i]["r"])*255), - floor(float(root["colors"][i]["g"])*255), - floor(float(root["colors"][i]["b"])*255) + rgb = [ + floor(float(root["colors"][i]["r"]) * 255), + floor(float(root["colors"][i]["g"]) * 255), + floor(float(root["colors"][i]["b"]) * 255) ] colors.append(rgb) - for i,c in enumerate(Colors): + for i, c in enumerate(Colors): Colors[c] = colors[i] return Colors - diff --git a/fishy/web/web.py b/fishy/web/web.py index 616352e..12ae97a 100644 --- a/fishy/web/web.py +++ b/fishy/web/web.py @@ -17,7 +17,7 @@ def is_logged_in(): if config.get("uid") is None: return -1 - body = {"uid": config.get("uid"), "apiversion":apiversion} + body = {"uid": config.get("uid"), "apiversion": apiversion} response = requests.get(urls.discord, params=body) logged_in = response.json()["discord_login"] return 1 if logged_in else 0 @@ -25,7 +25,7 @@ def is_logged_in(): @fallback(False) def login(uid, login_code): - body = {"uid": uid, "login_code": login_code, "apiversion":apiversion} + body = {"uid": uid, "login_code": login_code, "apiversion": apiversion} reponse = requests.post(urls.discord, json=body) result = reponse.json() @@ -37,7 +37,7 @@ def login(uid, login_code): @fallback(False) def logout(): - body = {"uid": config.get("uid"), "apiversion":apiversion} + body = {"uid": config.get("uid"), "apiversion": apiversion} reponse = requests.delete(urls.discord, json=body) result = reponse.json() return result["success"] @@ -57,7 +57,7 @@ def send_notification(message): if not is_subbed()[0]: return False - body = {"uid": config.get("uid"), "message": message, "apiversion":apiversion} + body = {"uid": config.get("uid"), "message": message, "apiversion": apiversion} requests.post(urls.notify, json=body) @@ -71,13 +71,13 @@ def send_fish_caught(fish_caught, hole_time, fish_times): "session": get_session() } - body = {"uid": config.get("uid"), "hole_data": hole_data, "apiversion":apiversion} + body = {"uid": config.get("uid"), "hole_data": hole_data, "apiversion": apiversion} requests.post(urls.hole_depleted, json=body) @fallback(False) def sub(): - body = {"uid": config.get("uid"), "apiversion":apiversion} + body = {"uid": config.get("uid"), "apiversion": apiversion} response = requests.post(urls.subscription, json=body) result = response.json() return result["success"] @@ -94,7 +94,7 @@ def is_subbed(): if config.get("uid") is None: return False, False - body = {"uid": config.get("uid"), "apiversion":apiversion} + body = {"uid": config.get("uid"), "apiversion": apiversion} response = requests.get(urls.subscription, params=body) if response.status_code != 200: @@ -106,7 +106,7 @@ def is_subbed(): @fallback(None) def unsub(): - body = {"uid": config.get("uid"), "apiversion":apiversion} + body = {"uid": config.get("uid"), "apiversion": apiversion} response = requests.delete(urls.subscription, json=body) result = response.json() return result["success"] @@ -119,7 +119,7 @@ def get_session(lazy=True): if lazy and _session_id is not None: return _session_id - body = {"uid": config.get("uid"), "apiversion":apiversion} + body = {"uid": config.get("uid"), "apiversion": apiversion} response = requests.post(urls.session, params=body) if response.status_code == 405: @@ -133,7 +133,7 @@ def get_session(lazy=True): @fallback(False) def has_beta(): - body = {"uid": config.get("uid"), "apiversion":apiversion} + body = {"uid": config.get("uid"), "apiversion": apiversion} response = requests.get(urls.beta, params=body) result = response.json() diff --git a/setup.py b/setup.py index 634467a..13e81b3 100644 --- a/setup.py +++ b/setup.py @@ -213,4 +213,4 @@ setup( }, include_package_data=True -) \ No newline at end of file +) From b16f776749b8e57bd4acf80cebc0d14172938c29 Mon Sep 17 00:00:00 2001 From: Semjon Kerner <Semjon.Kerner@gmx.net> Date: Sun, 9 May 2021 11:44:19 +0200 Subject: [PATCH 19/20] too long lines --- fishy/engine/semifisher/engine.py | 3 ++- fishy/gui/update_dialog.py | 9 ++++++--- fishy/helper/helper.py | 3 ++- fishy/helper/luaparser.py | 4 +++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/fishy/engine/semifisher/engine.py b/fishy/engine/semifisher/engine.py index 29ee8f7..e42e9a0 100644 --- a/fishy/engine/semifisher/engine.py +++ b/fishy/engine/semifisher/engine.py @@ -62,7 +62,8 @@ class SemiFisherEngine(IEngine): def _wait_and_check(self): time.sleep(10) if not FishEvent.FishingStarted and self.start: - logging.warning("Doesn't look like fishing has started \nCheck out #read-me-first on our discord channel to troubleshoot the issue") + logging.warning("Doesn't look like fishing has started \n" + "Check out #read-me-first on our discord channel to troubleshoot the issue") def show_pixel_vals(self): def show(): diff --git a/fishy/gui/update_dialog.py b/fishy/gui/update_dialog.py index 9e16ac9..4d881d4 100644 --- a/fishy/gui/update_dialog.py +++ b/fishy/gui/update_dialog.py @@ -9,7 +9,8 @@ def show(currentversion, newversion, returns): top.title("A wild fishy update appeared!") top.iconbitmap(helper.manifest_file('icon.ico')) - dialogLabel = tk.Label(top, text="There is a new fishy update available (" + currentversion + "->" + newversion + "). Do you want to update now?") + dialogLabel = tk.Label(top, text="There is a new fishy update available (" + + currentversion + "->" + newversion + "). Do you want to update now?") dialogLabel.grid(row=0, columnspan=2, padx=5, pady=5) cbVar = tk.IntVar() @@ -27,9 +28,11 @@ def show(currentversion, newversion, returns): top.destroy() pixelVirtual = tk.PhotoImage(width=1, height=1) # trick to use buttonWidth as pixels, not #symbols - dialogBtnNo = tk.Button(top, text="No " + str(chr(10005)), fg='red4', command=_clickNo, image=pixelVirtual, width=buttonWidth, compound="c") + dialogBtnNo = tk.Button(top, text="No " + str(chr(10005)), fg='red4', command=_clickNo, image=pixelVirtual, + width=buttonWidth, compound="c") dialogBtnNo.grid(row=2, column=0, padx=5, pady=5) - dialogBtnYes = tk.Button(top, text="Yes " + str(chr(10003)), fg='green', command=_clickYes, image=pixelVirtual, width=buttonWidth, compound="c") + dialogBtnYes = tk.Button(top, text="Yes " + str(chr(10003)), fg='green', command=_clickYes, image=pixelVirtual, + width=buttonWidth, compound="c") dialogBtnYes.grid(row=2, column=1, padx=5, pady=5) dialogBtnYes.focus_set() diff --git a/fishy/helper/helper.py b/fishy/helper/helper.py index 95ba88b..e085ca9 100644 --- a/fishy/helper/helper.py +++ b/fishy/helper/helper.py @@ -194,7 +194,8 @@ def install_addon(name, url, v=None): r = requests.get(url, stream=True) z = ZipFile(BytesIO(r.content)) z.extractall(path=get_addondir()) - logging.info("Add-On " + name + " installed successfully!\nPlease make sure to enable \"Allow outdated addons\" in ESO") + logging.info("Add-On " + name + + " installed successfully!\nPlease make sure to enable \"Allow outdated addons\" in ESO") return 0 except Exception as ex: logging.error("Could not install Add-On " + name + ", try doing it manually") diff --git a/fishy/helper/luaparser.py b/fishy/helper/luaparser.py index ebebead..a095ae7 100644 --- a/fishy/helper/luaparser.py +++ b/fishy/helper/luaparser.py @@ -18,7 +18,9 @@ def _sv_parser(path): - remove empty expressions EXPRESSIONS: A) List-Start "name=", B) Variable assignment "name=val", C) List End "}" """ - for old, new in ((",", "\n"), ("{", "{\n"), ("}", "}\n"), ("{", ""), (",", ""), ("[", ""), ("]", ""), ('"', ""), (" ", "")): + subs = ((",", "\n"), ("{", "{\n"), ("}", "}\n"), + ("{", ""), (",", ""), ("[", ""), ("]", ""), ('"', ""), (" ", "")) + for old, new in subs: lua = lua.replace(old, new) lua = lua.lower().split("\n") lua = [expression for expression in lua if expression] From fa83c1039436e897802013e74b5b6d35dc002636 Mon Sep 17 00:00:00 2001 From: Semjon Kerner <Semjon.Kerner@gmx.net> Date: Sun, 9 May 2021 11:48:35 +0200 Subject: [PATCH 20/20] fix flake8: F841, E111 E711, E262 --- fishy/engine/semifisher/fishing_event.py | 4 ++-- fishy/gui/funcs.py | 2 +- fishy/helper/auto_update.py | 1 - fishy/helper/helper.py | 4 ++-- fishy/helper/luaparser.py | 8 ++++---- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/fishy/engine/semifisher/fishing_event.py b/fishy/engine/semifisher/fishing_event.py index e028275..c81486e 100644 --- a/fishy/engine/semifisher/fishing_event.py +++ b/fishy/engine/semifisher/fishing_event.py @@ -100,9 +100,9 @@ def fisher_callback(event: State): try: callbacks_map[event]() FishEvent.previousState = event - except KeyError as ex: + except KeyError: logging.error("KeyError: State " + str(event) + " is not known.") - except TypeError as ex: + except TypeError: logging.error("TypeError when reading state: " + str(event)) diff --git a/fishy/gui/funcs.py b/fishy/gui/funcs.py index a4dd5d4..c9c03c9 100644 --- a/fishy/gui/funcs.py +++ b/fishy/gui/funcs.py @@ -15,7 +15,7 @@ class GUIFuncsMock: ... def bot_started(self, started): - ... + ... def quit(self): ... diff --git a/fishy/helper/auto_update.py b/fishy/helper/auto_update.py index cc1644e..c6be7d0 100644 --- a/fishy/helper/auto_update.py +++ b/fishy/helper/auto_update.py @@ -14,7 +14,6 @@ from bs4 import BeautifulSoup def _hr_version(v): return '.'.join([str(x) for x in v]) - #return str(v[0])+"."+str(v[1])+"."+str(v[2]) def _normalize_version(v): diff --git a/fishy/helper/helper.py b/fishy/helper/helper.py index e085ca9..5536976 100644 --- a/fishy/helper/helper.py +++ b/fishy/helper/helper.py @@ -197,7 +197,7 @@ def install_addon(name, url, v=None): logging.info("Add-On " + name + " installed successfully!\nPlease make sure to enable \"Allow outdated addons\" in ESO") return 0 - except Exception as ex: + except Exception: logging.error("Could not install Add-On " + name + ", try doing it manually") return 1 @@ -208,7 +208,7 @@ def remove_addon(name, url=None, v=None): logging.info("Add-On " + name + " removed!") except FileNotFoundError: pass - except PermissionError as ex: + except PermissionError: logging.error("Fishy has no permission to remove " + name + " Add-On") return 1 return 0 diff --git a/fishy/helper/luaparser.py b/fishy/helper/luaparser.py index a095ae7..7d066b8 100644 --- a/fishy/helper/luaparser.py +++ b/fishy/helper/luaparser.py @@ -36,16 +36,16 @@ def _sv_parser(path): for line in lua: if line == "": break - if line[-1] == '=': #subtree start + if line[-1] == '=': # subtree start t = dict() tname = line.split("=")[0] stack.append((t, tname)) - elif line[-1] == '}': #subtree end + elif line[-1] == '}': # subtree end t = stack.pop() tp = stack.pop() tp[0][t[1]] = t[0] stack.append(tp) - else: #new element in tree + else: # new element in tree name, val = line.split("=") t = stack.pop() t[0][name] = val @@ -59,7 +59,7 @@ def _sv_parser(path): def sv_color_extract(Colors): root = _sv_parser(os.path.join(get_savedvarsdir(), "Chalutier.lua")) - if root == None: + if root is None: return Colors for i in range(4):