Skip to content

Commit

Permalink
don't log as much
Browse files Browse the repository at this point in the history
I also added a --debug (-d) command line parameter to show debug logs.
  • Loading branch information
ego-lay-atman-bay committed Mar 5, 2024
1 parent 4b7e282 commit 5cfb75d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 55 deletions.
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,14 @@ Once I make a full release, I will also make a wmwpy release, so this is only ne
Start by extracting your where's my water apk file into a directory. When you run the program for the first timze, it'll ask you to select the game directory. This can also be configurable in the `settings.json` file that is generated by the program.

## Build exe
### Install modules
To build an exe for wme, first install pyinstaller
### Install dependencies
To build an exe for wme, you need to install the dependencies.

```sh
pip install pyinstaller
pip install -r requirements-build.txt
```

Next install the `requirements.txt`

```sh
py -m pip install -r requirements.txt
```
Note: you need `requirements.txt` in the same directory, as this `requirements-build.txt` references `requirements.txt`.

Make sure `wmwpy` is installed from github (you shouldn't need to do this, as `wmwpy` is installed from github in the `requirements.txt`)

Expand Down
3 changes: 3 additions & 0 deletions requirements-build.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
setuptools
-r requirements.txt
pyinstaller==6.4.0
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# setuptools
wmwpy@git+https://github.com/wmw-modding/wmwpy
# wmwpy==0.2.0b0
Pillow==9.5.0
tk==0.1.0
numpy==1.24.3
numpy==1.26.0
tkmacosx==1.0.5
72 changes: 26 additions & 46 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '2.3.2'
__version__ = '2.3.3'
__author__ = 'ego-lay-atman-bay'
__credits__ = [
{
Expand Down Expand Up @@ -34,13 +34,12 @@
from datetime import datetime
import crossplatform


def createLogger(type = 'file', filename = 'logs/log.log'):
def createLogger(type = 'file', filename = 'logs/log.log', debug = False):
for handler in logging.root.handlers[:]:
logging.root.removeHandler(handler)
format = '[%(levelname)s] %(message)s'
datefmt = '%I:%M:%S %p'
level = logging.DEBUG
level = logging.DEBUG if debug else logging.INFO

# filename = 'log.log'

Expand All @@ -67,13 +66,13 @@ def createLogger(type = 'file', filename = 'logs/log.log'):

_log_filename = f'logs/{datetime.now().strftime("%m-%d-%y_%H-%M-%S")}.log'

createLogger('file', filename = _log_filename)
debug = False

def log_exception():
fileio = io.StringIO()
traceback.print_exc(file = fileio)

logging.error(fileio.getvalue())
args = sys.argv[1::]
if len(args) > 0:
if args[0] in ['-d', '--debug']:
debug = True
createLogger('file', filename = _log_filename, debug = debug)

import tkinter as tk
from tkinter import ttk, simpledialog, messagebox, filedialog
Expand Down Expand Up @@ -174,8 +173,7 @@ def __init__(self, parent):
self.style.layout("Vertical.TPanedWindow", [('Sash.Vertical', {})])

except:
logging.error('Unable to set grip image')
log_exception()
logging.exception('Unable to set grip image')

# self.style.layout("Clicked.TPanedWindow", [('Sash.xsash', {})])

Expand Down Expand Up @@ -637,8 +635,6 @@ def updateObject(self, obj : wmwpy.classes.Object):
self.updateLevelScroll()
return

logging.info(f'updating object: {obj.name}, {obj.type}')

offset = numpy.array(obj.offset)

pos = numpy.array(obj.pos)
Expand Down Expand Up @@ -700,7 +696,7 @@ def updateObject(self, obj : wmwpy.classes.Object):
tags = ('object', 'foreground', id)
)

logging.info(f"id: {id}")
# logging.info(f"id: {id}")
# logging.info(f"pos: {pos}\n")

self.updateLayers()
Expand All @@ -711,12 +707,12 @@ def updateObject(self, obj : wmwpy.classes.Object):
self.updateLevelScroll()

def onLevelClick(self, event : tk.Event):
logging.info('level')
logging.debug('level')

mouse = (self.level_canvas.canvasx(event.x), self.level_canvas.canvasy(event.y))

objects = self.level_canvas.find_overlapping(*mouse, *mouse)
logging.info(objects)
logging.debug(objects)
length = len(objects)

if length <= 1:
Expand All @@ -732,17 +728,12 @@ def createLevelContextMenu(self):
self.levelContextMenu.add_command(label = 'paste', command = self.pasteObject, accelerator = f'{crossplatform.shortModifier()}+V')

def onLevelRightClick(self, event):
logging.info('level context menu')
logging.info(f'canvas mouse pos = {(numpy.array(self.level_canvas.winfo_pointerxy()) - (self.winfo_rootx(), self.winfo_rooty())) - (self.level_canvas.winfo_x(), self.level_canvas.winfo_y())}')
logging.info(f'canvas mouse x = {self.winfo_pointerx() - self.winfo_rootx()}')
logging.info(f'canvas mouse y = {self.winfo_pointery() - self.winfo_rooty()}')
logging.info(f'event pos = {(event.x, event.y)}')
logging.info(f'canvas pos = {(self.level_canvas.winfo_x(), self.level_canvas.winfo_y())}')
logging.debug('level context menu')

mouse = (self.level_canvas.canvasx(event.x), self.level_canvas.canvasy(event.y))

objects = self.level_canvas.find_overlapping(*mouse, *mouse)
logging.info(objects)
logging.debug(objects)
length = len(objects)

if length <= 1:
Expand Down Expand Up @@ -963,7 +954,6 @@ def addObjectSelector(self, pos : tuple = (0,0)):
),
)

logging.info(f'{pos = }')
self.addObject(
filename,
pos = self.windowPosToWMWPos(pos)
Expand Down Expand Up @@ -1142,8 +1132,8 @@ def resetProperty(property):
def updatePropertyName(property, newName, skip_unedited = False):
if newName == property and not skip_unedited:
return True
logging.info(f'{newName = }')
logging.info(f'{property = }')
logging.debug(f'{newName = }')
logging.debug(f'{property = }')

if newName in obj.properties:
messagebox.showerror(
Expand Down Expand Up @@ -1173,10 +1163,6 @@ def updatePosition(value, column):

obj.pos = tuple(pos)

logging.info(newPos)
logging.info(pos)
logging.info(obj.pos)

self.updateObject(obj)

sizes : list[int] = []
Expand Down Expand Up @@ -1353,8 +1339,6 @@ def selectObject(event):
item = self.object_selector['treeview'].focus()
item = self.object_selector['treeview'].item(item)

logging.info(item)

if 'object' in item['tags']:
id = item['values'][2]
obj = self.level.getObjectById(id)
Expand Down Expand Up @@ -1428,14 +1412,12 @@ def updateLevel(self):

for obj in self.level.objects:
self.updateObject(obj)
logging.info('')

self.updateLevelScroll()
self.level_canvas.xview_moveto(0.23)
self.level_canvas.yview_moveto(0.2)

def dragObject(self, obj : wmwpy.classes.Object, event = None):
logging.info(f'mouse pos = {(event.x, event.y)}')
obj.pos = self.windowPosToWMWPos((event.x, event.y))

self.updateObject(obj)
Expand Down Expand Up @@ -1544,7 +1526,7 @@ def openLevel(self, *args):
)

if xml in ['', None]:
logging.info('Open level canceled')
logging.debug('Open level canceled')
return

image = os.path.splitext(xml)[0] + '.png'
Expand All @@ -1570,7 +1552,7 @@ def saveLevel(self, *args, filename = None):
try:
self.level.image.save(imagePath)
except:
log_exception()
logging.exception('failed to save level image')

try:
with open(filename, 'wb') as file:
Expand Down Expand Up @@ -1675,8 +1657,7 @@ def loadGame(self):
load_callback = self.updateProgressBar,
)
except:
logging.warning(f'unable to load game: {self.settings.get("game.gamepath")}')
wmwpy.utils.logging_utils.log_exception()
logging.exception(f'unable to load game: {self.settings.get("game.gamepath")}')

self.state = 'enabled'

Expand Down Expand Up @@ -1720,13 +1701,12 @@ def loadLevel(self, xml : str, image : str):
load_callback = self.updateProgressBar,
)
except:
logging.warning('Unable to load level')
log_exception()
logging.exception('Unable to load level')
self.state = 'enabled'
return

logging.info(f'level = {self.level}')
logging.info(f'objects = {self.level.objects}')
logging.debug(f'level = {self.level}')
logging.debug(f'objects = {self.level.objects}')

self.level.scale = 5
self.updateLevel()
Expand All @@ -1745,7 +1725,7 @@ def close(self):
message = 'Do you want to save changes?',
)

logging.info(f'close option: {result}')
logging.debug(f'close option: {result}')

if result:
self.saveLevelAs()
Expand Down Expand Up @@ -1793,7 +1773,7 @@ def __call__(self, *args):
except SystemExit as msg:
raise SystemExit(msg)
except Exception as e:
log_exception()
logging.exception('tk error')

tk.CallWrapper = TkErrorCatcher

Expand All @@ -1802,7 +1782,7 @@ def main():
app = WME(None)
app.mainloop()
except Exception as e:
log_exception()
logging.exception('WME ended prematurely')

if(__name__ == '__main__'):
main()

0 comments on commit 5cfb75d

Please sign in to comment.