Skip to content
This repository was archived by the owner on Jun 19, 2023. It is now read-only.

Commit b976e82

Browse files
authored
Add files via upload
1 parent 14b4d13 commit b976e82

7 files changed

Lines changed: 97 additions & 0 deletions

File tree

app.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import rumps
2+
import sys
3+
import threading
4+
5+
from utils.logger import Logger
6+
from utils.note import Note
7+
from utils.resourcePath import resource_path
8+
9+
class BarNotes(rumps.App):
10+
def __init__(self):
11+
super(BarNotes, self).__init__("BarNotes", title=" " + Note.get_note(), icon="data/icon.png", quit_button=None)
12+
13+
self.logger = Logger()
14+
self.logger.log("BarNotes initialized")
15+
16+
self.menu = ["Edit Note", "Quit"]
17+
18+
@rumps.clicked("Edit Note")
19+
def edit(self, _):
20+
window = rumps.Window(title="Edit your note", message="The max amount of characters is 100.", dimensions=(300, 85), ok="Save", cancel="Cancel")
21+
window.default_text = Note.get_note()
22+
window.icon = "data/icon.png"
23+
24+
self.logger.log("Edit Note window opened")
25+
26+
response = window.run()
27+
if response.clicked == 1:
28+
self.logger.log(f"Set note to {response.text}")
29+
Note.set_note(response.text)
30+
self.title = " " + Note.get_note()
31+
elif response.clicked == 0:
32+
self.logger.log("Note was not changed")
33+
34+
@rumps.clicked("Quit")
35+
def close(self, _):
36+
self.logger.log("BarNotes quit")
37+
self.logger.close()
38+
rumps.quit_application()
39+
40+
def start(self):
41+
self.logger.log("BarNotes running")
42+
self.run()
43+
44+
if __name__ == "__main__":
45+
app = BarNotes()
46+
app.start()

data/icon.png

151 KB
Loading

data/note.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
default note, edit this by clicking on me!

utils/logger.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import datetime
2+
import colorama
3+
4+
from .loggertype import LoggerType
5+
6+
class Logger:
7+
def __init__(self):
8+
pass
9+
10+
def log(self, message, type=LoggerType.INFO):
11+
time = datetime.datetime.now().strftime("%H:%M:%S")
12+
msg = f"[{time}] [{type}] {message}"
13+
14+
if type == LoggerType.INFO:
15+
print(colorama.Fore.BLUE + msg + colorama.Style.RESET_ALL)
16+
elif type == LoggerType.ERROR:
17+
print(colorama.Fore.RED + msg + colorama.Fore.RESET_ALL)
18+
elif type == LoggerType.WARNING:
19+
print(colorama.Fore.YELLOW + msg + colorama.Fore.RESET_ALL)
20+
elif type == LoggerType.SUCCESS:
21+
print(colorama.Fore.GREEN + msg + colorama.Fore.RESET_ALL)

utils/loggertype.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class LoggerType:
2+
INFO = "INFO"
3+
WARNING = "WARNING"
4+
ERROR = "ERROR"
5+
SUCCESS = "SUCCESS"

utils/note.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from .resourcePath import resource_path
2+
3+
class Note:
4+
def get_note():
5+
return open("data/note.txt").read()
6+
7+
def set_note(note):
8+
if note == "":
9+
note = "default note"
10+
note = note[:100]
11+
with open("data/note.txt", "w") as f:
12+
f.write(note)

utils/resourcePath.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import os
2+
import sys
3+
4+
def resource_path(relative_path):
5+
""" Get absolute path to resource, works for dev and for PyInstaller """
6+
try:
7+
# PyInstaller creates a temp folder and stores path in _MEIPASS
8+
base_path = sys._MEIPASS
9+
except Exception:
10+
base_path = os.path.abspath(".")
11+
12+
return os.path.join(base_path, relative_path)

0 commit comments

Comments
 (0)