Skip to content

Commit

Permalink
Renamed previous "Assets" folder to "Colours"
Browse files Browse the repository at this point in the history
Update README.md
Fix sync log
  • Loading branch information
Wemmy0 committed Feb 19, 2024
1 parent 2797279 commit 1954610
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 28 deletions.
Binary file added Assets/UI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Inkwell
![](Assets/UI.png)
[![Pylint](https://github.com/Wemmy0/Inkwell/actions/workflows/pylint.yml/badge.svg)](https://github.com/Wemmy0/Inkwell/actions/workflows/pylint.yml)

A minimalistic notes app written in GTK4 and Python
A minimalistic rich text notes app written in GTK4 and Python

### Running from source (Fedora):
1. Clone repo using Github CLI
Expand Down
10 changes: 5 additions & 5 deletions src/FileView.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(self, path, colour_support):
self.colour_support = colour_support
self.blacklist = ["colours.json"]

self.palette = os.listdir("Assets")
self.palette = os.listdir("Colours")
self.files = self.scan_files(path, "json")

self.initialise_colours()
Expand Down Expand Up @@ -175,7 +175,7 @@ def __init__(self, filename, colour_support, palette, current_colours, json_file
# Image containing circle, popout to selector of colour
self.image = Gtk.Image()
self.current_colours = current_colours
self.current_colour = "Assets/" + current_colours[self.filename]
self.current_colour = "Colours/" + current_colours[self.filename]

self.image.set_from_file(self.current_colour)
self.json_file = json_file
Expand Down Expand Up @@ -208,8 +208,8 @@ def colour_popover(self):
container = Gtk.ListBox()

for i in self.palette:
container.append(Gtk.Image(file="Assets/" + i))
container.select_row(container.get_row_at_index(self.palette.index(self.current_colour.replace("Assets/", ""))))
container.append(Gtk.Image(file="Colours/" + i))
container.select_row(container.get_row_at_index(self.palette.index(self.current_colour.replace("Colours/", ""))))
container.connect("row-selected", self.change_colour)

self.popover.set_child(container)
Expand All @@ -219,7 +219,7 @@ def change_colour(self, container, row):
old_colour = self.current_colours[self.filename]

if new_colour != old_colour:
self.image.set_from_file("Assets/" + new_colour)
self.image.set_from_file("Colours/" + new_colour)
self.current_colours[self.filename] = self.palette[row.get_index()]

with open(self.json_file, "w") as file:
Expand Down
41 changes: 20 additions & 21 deletions src/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,32 @@ def compare_files(self, file):
self.cursor.execute(f"SELECT hash FROM test WHERE filename = %s", (file,))
db_hash = self.cursor.fetchall()[0][0]
local_hash = self.hash_file(file)
log("=" * 20 + file + "=" * 20)
log(f"Local Hash: {local_hash}")
log(f"DB Hash: {db_hash}")
self.log("=" * 20 + file + "=" * 20)
self.log(f"Local Hash: {local_hash}")
self.log(f"DB Hash: {db_hash}")

if local_hash == db_hash:
log("Hashes match, skipping file")
self.log("Hashes match, skipping file")
self.skipped += 1
else:
log("Hashes don't match, checking timestamps")
self.log("Hashes don't match, checking timestamps")
self.cursor.execute(f"SELECT modified FROM test WHERE filename = %s", (file,))
db_timestamp = int(self.cursor.fetchall()[0][0])
local_timestamp = round(os.path.getctime(file))
log(f"Local timestamp: {local_timestamp}")
log(f"DB timestamp: {db_timestamp}")
self.log(f"Local timestamp: {local_timestamp}")
self.log(f"DB timestamp: {db_timestamp}")

if local_timestamp > db_timestamp:
log("Local file is newer, uploading")
self.log("Local file is newer, uploading")
self.update_file(file, local_timestamp, local_hash)

elif local_timestamp < db_timestamp:
log("Local file is older, downloading")
self.log("Local file is older, downloading")
self.download_file(file)
else:
log("Timestamps match, skipping")
self.log("Timestamps match, skipping")
self.skipped += 1
log("=" * (40 + len(file)))
self.log("=" * (40 + len(file)))

def update_file(self, file, time, hash):
try:
Expand All @@ -79,7 +79,7 @@ def update_file(self, file, time, hash):
self.connection.commit()
self.uploaded += 1
except mysql.connector.errors.DataError:
log(f"⚠️ File {file} is too large, skipping")
self.log(f"⚠️ File {file} is too large, skipping")
self.skipped += 1

def create_file(self, filename, content):
Expand All @@ -101,7 +101,7 @@ def scan_files(self, path):
if not isfile(path + "/" + i): # Item is a folder
out += self.scan_files(path + "/" + i)
else:
log(f"Found file {path + '/' + i}")
self.log(f"Found file {path + '/' + i}")
out.append(path + "/" + i)
return out

Expand All @@ -121,7 +121,7 @@ def upload_file(self, file):
self.connection.commit()
self.uploaded += 1
except mysql.connector.errors.DataError:
log(f"⚠️ File {file} is too large, skipping")
self.log(f"⚠️ File {file} is too large, skipping")
self.skipped += 1

def hash_file(self, file):
Expand All @@ -137,7 +137,7 @@ def hash_file(self, file):
def do(self):
if not self.disabled:
if not os.path.exists(self.path):
log("⚠️ New Folder doesn't exist, creating")
self.log("⚠️ New Folder doesn't exist, creating")
os.makedirs(self.path)

local_files = self.scan_files(self.path)
Expand All @@ -154,13 +154,13 @@ def do(self):
self.compare_files(i)
else:
# New file in db
log(f"New file in DB, downloading {i}")
self.log(f"New file in DB, downloading {i}")
self.download_file(i)
# Find new files that aren't in the db

for i in list(set(local_files) - set(db_files)):
# New file local
log(f"{i} is new to the db and will be uploaded")
self.log(f"{i} is new to the db and will be uploaded")
self.upload_file(i)
self.report()
print("✅ Sync successful")
Expand All @@ -176,7 +176,6 @@ def close(self):
print("Closing sync connection...")
self.connection.close()


def log(self, *args):
if self.verbose:
print(*args)
def log(self, *args):
if self.verbose:
print(*args)
2 changes: 1 addition & 1 deletion src/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def __init__(self, config):
"<li>Fixed highlighting of task/list items</li>"
"<li>Sync, Elements, AI and more can be enabled/disabled in the config file</li>"
"<li>Fixed a crash when sync connection was invalid but was attempted to be closed anyway</li>"
"<li>Colours can be added/removed from the Assets/ folder</li>"
"<li>Colours can be added/removed from the Colours/ folder</li>"
"</ul>"
"<p>1.2:</p>"
"<ul>"
Expand Down

0 comments on commit 1954610

Please sign in to comment.