Skip to content

Commit

Permalink
Merge pull request #157 from billyowo/main
Browse files Browse the repository at this point in the history
Image optimization and Refactoring code
  • Loading branch information
tomlin7 authored Oct 22, 2023
2 parents d5f72b5 + 335376f commit 450dc58
Show file tree
Hide file tree
Showing 30 changed files with 35 additions and 484 deletions.
Binary file modified .github/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/res/img1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/res/img2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/res/img3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/res/preview1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion biscuit/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def setup_tk(self) -> None:
style = style | WS_EX_APPWINDOW
windll.user32.SetWindowLongW(hwnd, GWL_EXSTYLE, style)
self.withdraw()
self.after(10, lambda:self.wm_deiconify())
self.after(10, self.wm_deiconify)

self.dpi_value = self.winfo_fpixels('1i')

Check notice on line 138 in biscuit/core/__init__.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

An instance attribute is defined outside `__init__`

Instance attribute dpi_value defined outside __init__
self.scale = self.dpi_value / 96.11191135734073

Check notice on line 139 in biscuit/core/__init__.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

An instance attribute is defined outside `__init__`

Instance attribute scale defined outside __init__
Expand Down
1 change: 0 additions & 1 deletion biscuit/core/components/editors/texteditor/highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def __init__(self, text: Text, language: str=None, *args, **kwargs) -> None:
language : str, optional
Language to highlight, by default None
"""

self.text: Text = text
self.base = text.base
self.language = language
Expand Down
16 changes: 7 additions & 9 deletions biscuit/core/components/editors/texteditor/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ def replace_current_word(self, new_word):

def check_autocomplete_keys(self, event):
"""Helper function for autocomplete.show to check triggers"""
return True if event.keysym not in [
return event.keysym not in [
"BackSpace", "Escape", "Return", "Tab", "space",
"Up", "Down", "Control_L", "Control_R"] else False
"Up", "Down", "Control_L", "Control_R"]

def cursor_screen_location(self):
"""Helper function for autocomplete.show to detect cursor location"""
Expand Down Expand Up @@ -323,9 +323,9 @@ def detect_encoding(self, file_path):

if bom.startswith(codecs.BOM_UTF8):
return 'utf-8'
elif bom.startswith(codecs.BOM_LE) or bom.startswith(codecs.BOM_BE):
if bom.startswith(codecs.BOM_LE) or bom.startswith(codecs.BOM_BE):
return 'utf-16'
elif bom.startswith(codecs.BOM32_BE) or bom.startswith(codecs.BOM32_LE):
if bom.startswith(codecs.BOM32_BE) or bom.startswith(codecs.BOM32_LE):
return 'utf-32'

self.bom = False
Expand All @@ -340,15 +340,13 @@ def detect_eol(self, path):
return "CRLF"

# Check for '\n' to detect Unix-style EOL
elif b'\n' in chunk:
if b'\n' in chunk:
return "LF"

# Check for '\r' to detect Mac-style EOL (older Macs)
elif b'\r' in chunk:
if b'\r' in chunk:
return "CR"

else:
return "UNKNOWN"
return "UNKNOWN"

def load_file(self):
if not self.path:
Expand Down
4 changes: 2 additions & 2 deletions biscuit/core/components/extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, base) -> None:
for extension_file in os.listdir(self.base.extensionsdir):
if extension_file.endswith(".py"):
extension_name = os.path.splitext(extension_file)[0]
if extension_name in self.extensions.keys():
if extension_name in self.extensions:
return
self.queue.put(extension_name)

Expand Down Expand Up @@ -72,7 +72,7 @@ def load_extension(self, file):
extension_name = os.path.splitext(file)[0]

# if an extension with same name is already loaded, skip
if extension_name in self.extensions.keys():
if extension_name in self.extensions:
return
self.queue.put(extension_name)

Expand Down
8 changes: 2 additions & 6 deletions biscuit/core/components/floating/findreplace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ def hide(self, *_):
def current(self):
if not self.text.count("1.0", self.text.index(tk.INSERT), "chars"):
return 0
else:
return self.text.count("1.0", self.text.index(tk.INSERT), "chars")[0]
return self.text.count("1.0", self.text.index(tk.INSERT), "chars")[0]

def highlight_matches(self):
self.text.tag_remove("found", "1.0", "end")
Expand Down Expand Up @@ -194,10 +193,7 @@ def replace(self, *_):

def is_on_match(self):
"""tells if the editor is currently pointing to a match"""
if self.current in self.matches.keys():
return True
else:
return False
return self.current in self.matches()

def replace_all(self, *_):
"""replaces all occurences of the string for the replace string, it will even replace partial words."""
Expand Down
1 change: 0 additions & 1 deletion biscuit/core/components/floating/palette/actionset.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def __init__(self, description: str, prompt: str, items: List[Tuple[str, Callabl
pinned : List[Tuple[str, Callable]]
The pinned items in the actionset.
"""

super().__init__(items, *args, **kwargs)
self.description: str = description
self.prompt: str = prompt
Expand Down
1 change: 0 additions & 1 deletion biscuit/core/components/games/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def get_game(name) -> str:

def register_game(game) -> None:

Check notice on line 25 in biscuit/core/components/games/__init__.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

Shadowing names from outer scopes

Shadows name 'game' from outer scope
"registers a game"

Check notice on line 26 in biscuit/core/components/games/__init__.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

Single quoted docstring

Triple double-quoted strings should be used for docstrings.

Check notice on line 26 in biscuit/core/components/games/__init__.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

Single quoted docstring

Triple double-quoted strings should be used for docstrings.
global games
try:
games[game.name] = game
except AttributeError:
Expand Down
2 changes: 1 addition & 1 deletion biscuit/core/components/games/snake.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def on_key_press(self, e):
):
self.direction = key
else:
if key == "r" or key == "R":
if key in ("r", "R"):
self.restart_game()

def show_game_over_text(self):
Expand Down
9 changes: 4 additions & 5 deletions biscuit/core/components/games/tetris.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def clear_lines(self):
lines = 0

all_squares = self.board.find_all()
all_squares_h = {k : v for k,v in zip(all_squares, [self.board.coords(sq)[3] for sq in all_squares])}
all_squares_h = dict(zip(all_squares, [self.board.coords(sq)[3] for sq in all_squares]))
count = Counter()
for sq in all_squares_h.values(): count[sq] += 1
full_lines = [k for k,v in count.items() if v == WIDTH/SIDE]
Expand Down Expand Up @@ -180,10 +180,9 @@ def place_on_board(self):
def move(self, x, y):
if not self.is_move_allowed(x, y):
return False
else:
for square in self.squares:
self.canvas.move(square, x * SIDE, y * SIDE)
return True
for square in self.squares:
self.canvas.move(square, x * SIDE, y * SIDE)
return True

def rotate(self):
squares = self.squares[:]
Expand Down
2 changes: 1 addition & 1 deletion biscuit/core/components/games/whoops.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def update_obstacles(self):
self.obstacles.remove(obstacle)

# spawn a new obstacle if there's enough gap between the last one and the right side of the canvas
if not len(self.obstacles) or self.obstacle_spawnpoint - (self.obstacles[-1].x + self.obstacles[-1].width) >= self.min_obstacle_gap:
if not self.obstacles or self.obstacle_spawnpoint - (self.obstacles[-1].x + self.obstacles[-1].width) >= self.min_obstacle_gap:
self.spawn_obstacle()

self.after(10, self.update_obstacles)
3 changes: 1 addition & 2 deletions biscuit/core/components/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ def clone(self, url: str, dir: str) -> None:
GitRepo.clone_from(url, dir)
return dir

else:
raise Exception(f'The url `{url}` does not point to a git repo')
raise Exception(f'The url `{url}` does not point to a git repo')

def repo_name(self, url: str) -> None:

Check notice on line 61 in biscuit/core/components/git/__init__.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

Method is not declared static

Method `repo_name` may be 'static'
match = re.search(r'/([^/]+?)(\.git)?$', url)
Expand Down
2 changes: 1 addition & 1 deletion biscuit/core/components/git/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, master=None, path=None, *args, **kwargs) -> None:
self.author = git.Actor(self.author_name, self.author_email)

def get_untracked_files(self) -> list:
return [item for item in self.untracked_files]
return list(self.untracked_files)

def get_added_files(self) -> list:
return [item.a_path for item in self.index.diff(None).iter_change_type('A')]
Expand Down
2 changes: 1 addition & 1 deletion biscuit/core/components/views/panel/terminal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,5 @@ def active_terminal(self):
return self.tabs.active_tab.terminal

def refresh(self) -> None:
if not len(self.terminals):
if not self.terminals:
self.master.toggle_panel()
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def clear_tree(self, *_) -> None:
self.items.clear()

def add_item(self, path, kind) -> None:
if path in self.items.keys():
if path in self.items:
return

new_item = ChangeItem(self.content, path, kind)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def clear_tree(self, *_) -> None:
self.items.clear()

def add_item(self, path, kind) -> None:
if path in self.items.keys():
if path in self.items:
return

new_item = StagedChangeItem(self.content, path, kind)
Expand Down
4 changes: 2 additions & 2 deletions biscuit/core/layout/base/content/editors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ def active_editor(self) -> Editor:
return self.tabs.active_tab.editor

def refresh(self) -> None:
if not len(self.editors) and self.empty:
if not self.editors and self.empty:
self.emptytab.grid()
self.base.set_title(os.path.basename(self.base.active_directory) if self.base.active_directory else None)
elif len(self.editors) and not self.empty:
elif self.editors and not self.empty:
self.emptytab.grid_remove()
self.empty = not self.empty
self.base.update_statusbar()
2 changes: 1 addition & 1 deletion biscuit/core/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def late_setup(self) -> None:

from biscuit.core.components import ActionSet
clone_actionset = ActionSet(
"Clone git repository", "clone", pinned=[[Formattable("clone {}"), lambda url: self.base.events.clone_repo(url)]]
"Clone git repository", "clone", pinned=[[Formattable("clone {}"), self.base.events.clone_repo]]
)
self.base.palette.register_actionset(lambda: clone_actionset)

Expand Down
5 changes: 1 addition & 4 deletions biscuit/core/settings/editor/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ def __init__(self, master, name="Example", default="0", *args, **kwargs) -> None
self.entry.pack(side=tk.LEFT)

def validate(self, value) -> None:

Check notice on line 54 in biscuit/core/settings/editor/items.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

Method is not declared static

Method `validate` may be 'static'
if value.isdigit() or value == "":
return True
else:
return False
return bool(value.isdigit() or value == "")

@property
def value(self) -> str:
Expand Down
7 changes: 3 additions & 4 deletions biscuit/core/utils/demo/window_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def set_appwindow():
style = style | WS_EX_APPWINDOW
res = windll.user32.SetWindowLongW(hwnd, GWL_EXSTYLE, style)

Check notice on line 19 in biscuit/core/utils/demo/window_demo.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

Unused local symbols

Local variable 'res' value is not used
root.withdraw()
root.after(10, lambda:root.wm_deiconify())
root.after(10, root.wm_deiconify)
hasstyle=True

def get_pos(event):
Expand All @@ -33,7 +33,7 @@ def move_window(event):
previousPosition = [root.winfo_x(), root.winfo_y()]

def move_window_bindings(*args, status=True):

Check notice on line 35 in biscuit/core/utils/demo/window_demo.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

Unused local symbols

Parameter 'args' value is not used
if status == True:
if status is True:
title_bar.bind("<B1-Motion>", move_window)
title_bar.bind("<Button-1>", get_pos)
title_name.bind("<B1-Motion>", move_window)
Expand All @@ -54,8 +54,7 @@ def minimize(hide=False):

def maximizeToggle():

Check notice on line 55 in biscuit/core/utils/demo/window_demo.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

PEP 8 naming convention violation

Function name should be lowercase
global maximized
global previousPosition
if maximized == False:
if not maximized:
#maximize current window
maximize_btn.config(text="❐")
hwnd = windll.user32.GetParent(root.winfo_id())
Expand Down
Loading

0 comments on commit 450dc58

Please sign in to comment.