From 5c931922961ccb4810d84b16c6af0ff6180dc416 Mon Sep 17 00:00:00 2001 From: Billy Date: Fri, 2 Feb 2024 21:29:30 +0530 Subject: [PATCH] chore: Move games to extension centre --- biscuit/__init__.py | 6 +- biscuit/core/__init__.py | 23 +- biscuit/core/api/__init__.py | 3 + biscuit/core/api/editors.py | 25 +- biscuit/core/api/utils.py | 14 +- biscuit/core/components/games/__init__.py | 4 +- biscuit/core/components/games/moonlander.py | 66 ----- biscuit/core/components/games/snake.py | 145 ----------- .../core/components/games/stackengineer.py | 89 ------- biscuit/core/components/games/tetris.py | 240 ------------------ biscuit/core/events.py | 27 +- pyproject.toml | 2 +- 12 files changed, 62 insertions(+), 582 deletions(-) delete mode 100644 biscuit/core/components/games/moonlander.py delete mode 100644 biscuit/core/components/games/snake.py delete mode 100644 biscuit/core/components/games/stackengineer.py delete mode 100644 biscuit/core/components/games/tetris.py diff --git a/biscuit/__init__.py b/biscuit/__init__.py index fd3c36ca..18370944 100644 --- a/biscuit/__init__.py +++ b/biscuit/__init__.py @@ -1,11 +1,11 @@ -__version__ = '2.61.0' -__version_info__ = tuple([ int(num) for num in __version__.split('.')]) +__version__ = "2.61.3" +__version_info__ = tuple([int(num) for num in __version__.split(".")]) # For tests to run successfully import sys from os.path import abspath, dirname, join -sys.path.append(abspath(join(dirname(__file__), '.'))) +sys.path.append(abspath(join(dirname(__file__), "."))) from .core import * diff --git a/biscuit/core/__init__.py b/biscuit/core/__init__.py index a1ee6d5d..d904bf68 100644 --- a/biscuit/core/__init__.py +++ b/biscuit/core/__init__.py @@ -10,33 +10,33 @@ class App(EventManager, GUIManager, ConfigManager): Manages App Configuration, GUI (Tkinter), Events of the App. - Single point of access to all the important parts of the app. Holds reference to all the components + Single point of access to all the important parts of the app. Holds reference to all the components of Biscuit and every class of biscuit have a reference back to this `base` class. i.e. `self.base` is the reference to this class from any other class of biscuit. Usage ----- - + Example: In order to access the open editor from the git: class Git: def foo(self): - editor = self.base.editorsmanager.active_editor + editor = self.base.editorsmanager.active_editor if editor.content and editor.content.exists: print(editor.path) - - Example: Accessing the active editor instance from Foo class of biscuit: - + + Example: Accessing the active editor instance from Foo class of biscuit: + class Foo: def foo(self): - editor = self.base.editorsmanager.active_editor + editor = self.base.editorsmanager.active_editor if (editor.content and editor.content.exists): print(editor.path) if (editor.content.editable): self.base.notifications.info(":)") """ - def __init__(self, appdir: str="", dir: str="", *args, **kwargs) -> None: + def __init__(self, appdir: str = "", dir: str = "", *args, **kwargs) -> None: """ Parameters ---------- @@ -45,14 +45,14 @@ def __init__(self, appdir: str="", dir: str="", *args, **kwargs) -> None: dir optional argument to open a folder from cli """ - + super().__init__(*args, **kwargs) self.base = self self.appdir = appdir self.setup() self.late_setup() - self.initialize_editor(dir) + self.initialize_editor(dir) def run(self) -> None: self.mainloop() @@ -69,9 +69,10 @@ def initialize_editor(self, dir: str) -> None: self.initialized = True self.palette.generate_help_actionset() - self.logger.info('Initializing editor finished.') + self.logger.info("Initializing editor finished.") self.update_idletasks() self.menubar.update() self.set_title() self.open_directory(dir) + diff --git a/biscuit/core/api/__init__.py b/biscuit/core/api/__init__.py index 8010d625..96db43a9 100644 --- a/biscuit/core/api/__init__.py +++ b/biscuit/core/api/__init__.py @@ -2,6 +2,8 @@ import typing +from biscuit.core.api.editors import Editors + if typing.TYPE_CHECKING: from biscuit.core import App @@ -30,6 +32,7 @@ def __init__(self, base: App) -> None: self.commands = Commands(self.base) self.logger = Logger(self.base) + self.editors = Editors(self.base) self.notifications = Notifications(self.base) self.utils = Utils(self.base) self.views = Views(self.base) diff --git a/biscuit/core/api/editors.py b/biscuit/core/api/editors.py index 1f013142..ab15f186 100644 --- a/biscuit/core/api/editors.py +++ b/biscuit/core/api/editors.py @@ -1,3 +1,5 @@ +from biscuit.core.components.editors import (DiffEditor, Editor, ImageViewer, + MDEditor, TextEditor) from biscuit.core.components.views import PanelView, SidebarView from .endpoint import Endpoint @@ -6,33 +8,38 @@ class Editors(Endpoint): def __init__(self, *a) -> None: super().__init__(*a) - self.__editors = self._Endpoint__base.editorsmanager + self.editors = self.base.editorsmanager self.PanelView = PanelView self.SidebarView = SidebarView + self.TextEditor = TextEditor + self.MDEditor = MDEditor + self.DiffEditor = DiffEditor + self.ImageViewer = ImageViewer + self.Editor = Editor self.theme = self.base.theme def add_editor(self, editor) -> None: - self.__editors.add_editor(editor) + self.editors.add_editor(editor) def open_editor(self, path=None, exists=True) -> None: - self.__editors.open_editor(path, exists) + self.editors.open_editor(path, exists) def open_diff_editor(self, path, exists) -> None: - self.__editors.open_diff_editor(path, exists) + self.editors.open_diff_editor(path, exists) def refresh(self) -> None: - self.__editors.refresh() + self.editors.refresh() def active_editor(self): - return self.__editors.active_editor + return self.editors.active_editor def set_active_editor(self, editor) -> None: - self.__editors.set_active_editor(editor) + self.editors.set_active_editor(editor) def close_editor(self, editor) -> None: - self.__editors.close_editor(editor) + self.editors.close_editor(editor) def close_active_editor(self) -> None: - self.__editors.close_active_editor() + self.editors.close_active_editor() diff --git a/biscuit/core/api/utils.py b/biscuit/core/api/utils.py index 763038d2..dcbb2d2b 100644 --- a/biscuit/core/api/utils.py +++ b/biscuit/core/api/utils.py @@ -7,17 +7,25 @@ class Utils(Endpoint): def __init__(self, *a) -> None: super().__init__(*a) + self.Bubble = Bubble self.Button = Button self.ButtonsEntry = ButtonsEntry + self.caller_name = caller_name + self.Canvas = Canvas + self.get_codicon = get_codicon self.colorize = colorize self.Entry = Entry self.FileType = FileType - self.get_codicon = get_codicon + self.FixedSizeStack = FixedSizeStack + self.Frame = Frame self.Icon = Icon self.IconButton = IconButton self.IconLabelButton = IconLabelButton - self.Scrollbar = Scrollbar + self.Label = Label, TruncatedLabel, WrappingLabel + self.Menubutton = Menubutton self.ScrollableFrame = ScrollableFrame + self.Scrollbar = Scrollbar self.Shortcut = Shortcut + self.Text = Text + self.Toplevel = Toplevel self.Tree = Tree - self.WrappingLabel = WrappingLabel diff --git a/biscuit/core/components/games/__init__.py b/biscuit/core/components/games/__init__.py index a6370959..84881fe9 100644 --- a/biscuit/core/components/games/__init__.py +++ b/biscuit/core/components/games/__init__.py @@ -5,12 +5,10 @@ from .gameoflife import GameOfLife from .minesweeper import Minesweeper from .pong import Pong -from .snake import Snake -from .tetris import Tetris from .ttt import TicTacToe from .whoops import Whoops -games = {i.name:i for i in (Tetris, GameOfLife, Pong, TicTacToe, Snake, Minesweeper)} +games = {i.name:i for i in (GameOfLife, Pong, TicTacToe, Minesweeper)} def get_games(base) -> list: diff --git a/biscuit/core/components/games/moonlander.py b/biscuit/core/components/games/moonlander.py deleted file mode 100644 index 4546d18f..00000000 --- a/biscuit/core/components/games/moonlander.py +++ /dev/null @@ -1,66 +0,0 @@ -import tkinter as tk - -GRAVITY = 0.1 -THRUST_POWER = 0.2 - -class MoonlanderGame: - def __init__(self): - self.window = tk.Tk() - self.window.title("Moonlander") - self.window.geometry("600x600") - - self.canvas = tk.Canvas(self.window, width=600, height=600) - self.canvas.pack() - - self.background_img = tk.PhotoImage(file="background.png") - self.canvas.create_image(0, 0, anchor=tk.NW, image=self.background_img) - - self.rocketship_img = tk.PhotoImage(file="rocketship.png") - self.rocketship = self.canvas.create_image(300, 100, image=self.rocketship_img) - - self.fuel_gauge = self.canvas.create_rectangle(10, 10, 110, 20, fill="green") - - self.fuel = 100.0 - self.velocity = 0.0 - self.position = 100.0 - self.game_over = False - - self.window.bind("", self.thrust) - self.window.bind("", self.restart_game) - - self.update() - self.window.mainloop() - - def thrust(self, event: tk.Event): - if self.fuel > 0 and not self.game_over: - self.velocity -= THRUST_POWER - self.fuel -= 1 - self.canvas.move(self.fuel_gauge, 1, 0) - - def restart_game(self, event: tk.Event): - self.fuel = 100.0 - self.velocity = 0.0 - self.position = 100.0 - self.game_over = False - self.canvas.delete("all") - self.canvas.create_image(0, 0, anchor=tk.NW, image=self.background_img) - self.rocketship = self.canvas.create_image(300, 100, image=self.rocketship_img) - self.fuel_gauge = self.canvas.create_rectangle(10, 10, 110, 20, fill="green") - self.update() - - def update(self): - if not self.game_over: - self.velocity += GRAVITY - self.position += self.velocity - self.canvas.move(self.rocketship, 0, self.velocity) - - if self.position > 550: - self.game_over = True - self.canvas.create_text(300, 300, text="Crashed!", fill="red", font=("Arial", 30)) - elif self.fuel <= 0: - self.game_over = True - self.canvas.create_text(300, 300, text="Out of fuel!", fill="red", font=("Arial", 30)) - else: - self.window.after(20, self.update) - -game = MoonlanderGame() diff --git a/biscuit/core/components/games/snake.py b/biscuit/core/components/games/snake.py deleted file mode 100644 index 466e0560..00000000 --- a/biscuit/core/components/games/snake.py +++ /dev/null @@ -1,145 +0,0 @@ -import random -import tkinter as tk - -from biscuit.core.components.utils import Button, Canvas - -from .game import BaseGame - -# Constants -WIDTH = 600 -HEIGHT = 600 -DELAY = 150 -DOT_SIZE = 10 -RAND_POS = WIDTH // DOT_SIZE - -class Snake(BaseGame): - name = "Snake!" - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - self.bg = self.base.theme.editors.background - self.ui = self.base.theme.biscuit_dark - self.head_color = self.base.theme.biscuit - self.body_color = self.base.theme.biscuit_dark - self.food_color = self.base.theme.primary_foreground_highlight - - self.canvas = Canvas(self, width=WIDTH, height=HEIGHT, **self.base.theme.editors) - self.canvas.pack(pady=30) - - self.snake_pos = [(100, 50), (90, 50), (80, 50)] - self.food_pos = self.random_food_pos() - self.direction = "Right" - self.in_game = True - self.score = 0 - - self.bind_all("", self.on_key_press) - self.create_objects() - self.update_game() - - def create_objects(self): - for x, y in self.snake_pos: - self.canvas.create_rectangle(x, y, x + DOT_SIZE, y + DOT_SIZE, fill=self.body_color, tag="snake", outline="") - - self.canvas.create_rectangle(*self.snake_pos[0], self.snake_pos[0][0] + DOT_SIZE, self.snake_pos[0][1] + DOT_SIZE, fill=self.head_color, outline="", tag="snake") - self.food = self.canvas.create_rectangle(*self.food_pos, self.food_pos[0] + DOT_SIZE, self.food_pos[1] + DOT_SIZE, fill=self.food_color, outline="", tag="food") - - self.canvas.create_text(100, 20, text="Score: 0", tag="score", font=("Fixedsys", 20), fill=self.ui) - self.game_over_text = self.canvas.create_text(WIDTH / 2, HEIGHT / 2, text="Game Over!", fill=self.ui, font=("Fixedsys", 40), state=tk.HIDDEN) - restart = Button(self.canvas, "Retry!", self.restart_game) - restart.config(font=("Fixedsys", 20)) - self.game_over_btn = self.canvas.create_window(WIDTH / 2, HEIGHT / 2 + 100, window=restart, state=tk.HIDDEN) - - def update_game(self): - if self.in_game: - self.check_collisions() - self.move_snake() - self.check_food_collision() - self.after(DELAY, self.update_game) - else: - self.show_game_over_text() - - def move_snake(self): - head_x, head_y = self.snake_pos[0] - - if self.direction == "Left": - new_head = (head_x - DOT_SIZE, head_y) - elif self.direction == "Right": - new_head = (head_x + DOT_SIZE, head_y) - elif self.direction == "Up": - new_head = (head_x, head_y - DOT_SIZE) - elif self.direction == "Down": - new_head = (head_x, head_y + DOT_SIZE) - - self.snake_pos = [new_head] + self.snake_pos[:-1] - - self.canvas.delete("snake") - - for x, y in self.snake_pos: - self.canvas.create_rectangle(x, y, x + DOT_SIZE, y + DOT_SIZE, fill=self.body_color, outline=self.bg, tag="snake") - - self.canvas.create_rectangle(*self.snake_pos[0], self.snake_pos[0][0] + DOT_SIZE, self.snake_pos[0][1] + DOT_SIZE, fill=self.head_color, outline=self.bg, tag="snake") - - def check_collisions(self): - head_x, head_y = self.snake_pos[0] - - if ( - head_x < 0 - or head_x >= WIDTH - or head_y < 0 - or head_y >= HEIGHT - or (head_x, head_y) in self.snake_pos[1:] - ): - self.in_game = False - - def check_food_collision(self): - if self.snake_pos[0] == self.food_pos: - self.snake_pos.append((0, 0)) - self.food_pos = self.random_food_pos() - self.canvas.coords(self.food, *self.food_pos, self.food_pos[0] + DOT_SIZE, self.food_pos[1] + DOT_SIZE) - self.score += 1 - self.canvas.itemconfigure("score", text=f"Score: {self.score}") - - def random_food_pos(self): - x = random.randint(1, RAND_POS - 1) * DOT_SIZE - y = random.randint(1, RAND_POS - 1) * DOT_SIZE - return x, y - - def on_key_press(self, e: tk.Event): - key = e.keysym - - if self.in_game: - if ( - key == "Left" - and self.direction != "Right" - or key == "Right" - and self.direction != "Left" - or key == "Up" - and self.direction != "Down" - or key == "Down" - and self.direction != "Up" - ): - self.direction = key - else: - if key in ("r", "R"): - self.restart_game() - - def show_game_over_text(self): - self.canvas.itemconfigure(self.game_over_text, state=tk.NORMAL) - self.canvas.itemconfigure(self.game_over_btn, state=tk.NORMAL) - - def restart_game(self, *_): - self.canvas.delete("food") - self.in_game = True - self.score = 0 - self.canvas.itemconfigure("score", text="Score: 0") - self.canvas.itemconfigure(self.game_over_text, state=tk.HIDDEN) - self.canvas.itemconfigure(self.game_over_btn, state=tk.HIDDEN) - self.snake_pos = [(100, 50), (90, 50), (80, 50)] - self.direction = "Right" - self.canvas.delete("snake") - self.canvas.delete(self.food) - self.food_pos = self.random_food_pos() - self.food = self.canvas.create_rectangle(*self.food_pos, self.food_pos[0] + DOT_SIZE, self.food_pos[1] + DOT_SIZE, fill=self.food_color, outline="", tag="food") - self.create_objects() - self.update_game() diff --git a/biscuit/core/components/games/stackengineer.py b/biscuit/core/components/games/stackengineer.py deleted file mode 100644 index 5930e265..00000000 --- a/biscuit/core/components/games/stackengineer.py +++ /dev/null @@ -1,89 +0,0 @@ -__author__ = "cid0rz" -version = "0.1" - -import random -import tkinter as tk -from collections import Counter, deque -from tkinter import messagebox, ttk - -from biscuit.core.components.editors.texteditor import TextEditor - -from .game import BaseGame - - -class Stack(ttk.LabelFrame): - stack_n = 1 - - def __init__(self, parent, text=f'Stack {stack_n}', borderwidth=4, width=300, - height=200, columns=[("ID", 20, 'center'), ("Value", 50, 'center')], - selectmode='none', values=[], index=0): - super().__init__(parent, text=text, borderwidth=borderwidth, width=width, height=height) - - self.twscroll = tk.Scrollbar(self) - self.twscroll.pack(side='right', fill='y') - self.tw = ttk.Treeview(self, columns=[col[0] for col in columns], - yscrollcommand=self.twscroll.set, selectmode=selectmode, - displaycolumns=[col[0] for col in columns]) - self.tw.pack() - self.tw.column("#0", width=0, stretch='no') - for col in columns: - self.tw.column(col[0], width=col[1], anchor=col[2]) - for col in columns: - self.tw.heading(col[0], text=col[0]) - - self.twscroll.config(command=self.tw.yview) - - self.values = deque(values) - self.index = index - - def read(self): - return self.values[self.index] - def write(self, value, index): - self.values[index] = value - self.update() - def insert(self, value, index): - self.values.insert(index, value) - self.update() - def push(self, value): - self.values.appendleft(value) - self.update() - def pop(self): - val = self.values.popleft() - self.update() - return val - - def update(self): - self.tw.delete(*self.tw.get_children()) - for i,val in enumerate(self.values): - self.tw.insert("", index=i, iid=str(i), values=(i,val)) - - -class StackEngineer(BaseGame): - name = "Stack Engineer" - - def __init__(self, master, *args, **kwargs): - super().__init__(master, *args, **kwargs) - self.config(**self.base.theme.editors) - self.m_registers = {'R1' : None} - s1 = Stack(self, values=[5,7]) - self.m_stacks = {'S1' : s1} - self.target = [] - self.cost = 0 - self.score = 0 - - self.editor = TextEditor(self, exists=False, minimalist=True) - self.draw() - - #print(se.m_stacks['S1'].pop()) - self.m_stacks['S1'].insert(10, 1) - - def draw(self): - for stack in self.m_stacks: - stack = self.m_stacks[stack] - stack.update() - stack.grid(row=0, column=1) - editor = self.editor - editor.grid(row=1) - - # text widget functions are available under editor.text - # eg. editor.text.tag_add diff --git a/biscuit/core/components/games/tetris.py b/biscuit/core/components/games/tetris.py deleted file mode 100644 index 756d2eb6..00000000 --- a/biscuit/core/components/games/tetris.py +++ /dev/null @@ -1,240 +0,0 @@ -__author__ = "cid0rz" - - -import random -import tkinter as tk -from collections import Counter -from tkinter import messagebox - -from .game import BaseGame - -SIDE = 25 -WIDTH = 20 * SIDE -HEIGHT = 20 * SIDE - - -class Tetris(BaseGame): - name = "Tetris!" - - def __init__(self, master, *args, **kwargs): - super().__init__(master, None, None, *args, **kwargs) - bg = self.base.theme.editors.background - self.loop = None - - self.status_var = tk.StringVar() - self.status_label = tk.Label(self, textvariable=self.status_var, font='Fixedsys 18', fg=self.base.theme.biscuit, bg=bg) - self.status_label.pack(pady=5) - - self.board = tk.Canvas(self, width=WIDTH, height=HEIGHT, bg=bg) - self.board.pack(side='left', padx=(40, 20), expand=True) - - self.preview = tk.Canvas(self, width=5*SIDE, height=5*SIDE, bg=bg) - self.preview.pack(padx=(0, 40), expand=True, side=tk.TOP) - - self.bind_all("", self.handle_events) - self.start() - - def start(self): - self.board.delete('all') - self.score = 0 - self.level = 1 - self.speed = 500 - self.pieces = {} - self.lines_cleared = [0] - self.total_lines = 0 - self.update_status() - self.falling_piece = Piece(self.preview) - self.preview.delete('all') - self.falling_piece.canvas = self.board - self.falling_piece.place_on_board() - self.next_piece = Piece(self.preview) - self.run() - - def run(self): - if not self.falling_piece.move(0, 1): - self.clear_lines() - self.update_status() - self.falling_piece = self.next_piece - self.falling_piece.canvas = self.board - self.falling_piece.place_on_board() - self.preview.delete('all') - self.next_piece = Piece(self.preview) - if not self.falling_piece.is_move_allowed(0,1): - self.game_over() - return - - self.loop = self.after(self.speed, self.run) - - def game_over(self): - res = messagebox.askyesno(title="GAME OVER", message = f"Level: {self.level} Score: {self.score}\nRetry?") - if res: - self.start() - else: - return - - def destroy(self): - self.after_cancel(self.loop) - return super().destroy() - - def clear_lines(self): - lines = 0 - - all_squares = self.board.find_all() - 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] - - if full_lines: - lines = len(full_lines) - remaining_squares_h = {} - for k,v in all_squares_h.items(): - if v in full_lines: - self.board.delete(k) - else: - remaining_squares_h[k] = v - all_squares_h = remaining_squares_h - - for sq, h in all_squares_h.items(): - for line in full_lines: - if h < line: - self.board.move(sq, 0, SIDE) - - self.lines_cleared.append(lines) - self.total_lines += lines - - def handle_events(self, event: tk.Event): - if event.keysym in ("Left", "a"): - self.falling_piece.move(-1, 0) - if event.keysym in ("Right", "d"): - self.falling_piece.move(1, 0) - if event.keysym in ("Down", "s"): - self.falling_piece.move(0, 1) - if event.keysym in ("Up", "w"): - self.falling_piece.rotate() - - return "break" - - def update_status(self): - - points = [0, 40, 100, 300, 1200] - self.score += self.level * points[self.lines_cleared[-1]] - self.level = 1 + divmod(self.total_lines, 10)[0] - self.status_var.set(f"Level: {self.level} Score: {self.score}") - self.speed = 500 - 20*self.level - - -class Piece: - START_PT = 10 * SIDE // 2 // SIDE * SIDE - SIDE - - def __init__(self, canvas): - self.PIECES = [ - ["#A9907E", (0, 0), (1, 0), (0, 1), (1, 1)], # square - ["#698269", (0, 0), (1, 0), (2, 0), (3, 0)], # line - ["#ABC4AA", (2, 0), (0, 1), (1, 1), (2, 1)], # right el - ["#675D50", (0, 0), (0, 1), (1, 1), (2, 1)], # left el - ["#609966", (0, 1), (1, 1), (1, 0), (2, 0)], # right wedge - ["#B99B6B", (0, 0), (1, 0), (1, 1), (2, 1)], # left wedge - ["#AA5656", (1, 0), (0, 1), (1, 1), (2, 1)], # symmetrical wedge - ] - self.bag = self.PIECES.copy() - random.shuffle(self.bag) - - self.squares = [] - self.piece = None - self.color = None - self.canvas = canvas - self.rotation_state = 0 - - self.generate_piece() - - def generate_piece(self): - if not self.bag: - self.bag = self.PIECES.copy() - random.shuffle(self.bag) - - self.piece = self.bag.pop(0) - self.color = self.piece[0] - self.piece = self.piece[1:] - - for point in self.piece: - square = self.canvas.create_rectangle( - point[0] * SIDE + 10, - point[1] * SIDE + 10, - point[0] * SIDE + SIDE + 10, - point[1] * SIDE + SIDE + 10, - fill=self.color, outline=self.color) - self.squares.append(square) - - def place_on_board(self): - self.squares = [] - for point in self.piece: - square = self.canvas.create_rectangle( - point[0] * SIDE + Piece.START_PT, - point[1] * SIDE, - point[0] * SIDE + SIDE + Piece.START_PT, - point[1] * SIDE + SIDE, - fill=self.color, outline=self.color) - self.squares.append(square) - - def move(self, x, y): - if not self.is_move_allowed(x, y): - return False - for square in self.squares: - self.canvas.move(square, x * SIDE, y * SIDE) - return True - - def rotate(self): - squares = self.squares[:] - pivot = squares.pop(2) - - def get_move_coords(square, pivot): - sq_coords = self.canvas.coords(square) - pivot_coords = self.canvas.coords(pivot) - x_diff = sq_coords[0] - pivot_coords[0] - y_diff = sq_coords[1] - pivot_coords[1] - x_move = (- x_diff - y_diff) / SIDE - y_move = (x_diff - y_diff) / SIDE - return x_move, y_move - - for sq in squares: - xmove, ymove = get_move_coords(sq, pivot) - if not self.is_sq_allowed(sq, xmove, ymove): - return False - - for sq in squares: - xmove, ymove = get_move_coords(sq, pivot) - self.canvas.move(sq, xmove*SIDE, ymove*SIDE) - - def is_sq_allowed(self, sq, x, y): - - x = x * SIDE - y = y * SIDE - coords = self.canvas.coords(sq) - - if coords[3] + y > HEIGHT: - return False - if coords[2] + x <= 0: - return False - if coords[2] + x > WIDTH: - return False - - overlap = set(self.canvas.find_overlapping( - (coords[0] + coords[2]) / 2 + x, - (coords[1] + coords[3]) / 2 + y, - (coords[0] + coords[2]) / 2 + x, - (coords[1] + coords[3]) / 2 + y)) - set(self.squares) - - other = set(self.canvas.find_all()) - set(self.squares) - - if overlap and other: - return False - - return True - - def is_move_allowed(self, x, y): - - for sq in self.squares: - if not self.is_sq_allowed(sq, x, y): - return False - return True diff --git a/biscuit/core/events.py b/biscuit/core/events.py index 192cbeeb..0c39eb7a 100644 --- a/biscuit/core/events.py +++ b/biscuit/core/events.py @@ -34,27 +34,27 @@ class EventManager(GUIManager, ConfigManager): outline: Outline source_control: SourceControl extensionsGUI: Extensions - + panel: Panel terminalmanager: Terminal logger: Logs - def set_title(self, title: str=None) -> None: + def set_title(self, title: str = None) -> None: if not self.initialized: return self.menubar.set_title(title) self.menubar.reposition_title() - + def open(self, path: str) -> None: if not path: return - + if os.path.isdir(path): return self.open_directory(path) - + if os.path.isfile(path): return self.open_editor(path) - + self.notifications.error(f"Path does not exist: {path}") def open_directory(self, dir: str) -> None: @@ -83,6 +83,7 @@ def update_git(self) -> None: def clone_repo(self, url: str, dir: str) -> None: try: + def clone() -> None: repodir = self.git.clone(url, dir) self.open_directory(repodir) @@ -120,14 +121,14 @@ def goto_location(self, path: str, position: int) -> None: editor = self.open_editor(path, exists=True) editor.bind("<>", lambda e: editor.content.goto(position)) - def open_editor(self, path: str, exists: bool=True) -> Editor | BaseEditor: + def open_editor(self, path: str, exists: bool = True) -> Editor | BaseEditor: if exists and not os.path.isfile(path): return return self.editorsmanager.open_editor(path, exists) def open_diff(self, path: str, kind: str) -> None: - self.editorsmanager.open_diff_editor(path, kind) # type: ignore + self.editorsmanager.open_diff_editor(path, kind) # type: ignore def open_settings(self, *_) -> None: self.editorsmanager.add_editor(SettingsEditor(self.editorsmanager)) @@ -136,7 +137,7 @@ def open_game(self, name: str) -> None: self.editorsmanager.open_game(name) def register_game(self, game: BaseGame) -> None: - #TODO game manager class + # TODO game manager class register_game(game) self.settings.gen_actionset() @@ -144,7 +145,7 @@ def register_langserver(self, language: str, command: str) -> None: self.language_server_manager.register_langserver(language, command) def open_in_new_window(self, dir: str) -> None: - #Process(target=App(sys.argv[0], dir).run).start() + # Process(target=App(sys.argv[0], dir).run).start() self.notifications.show("Feature not available in this version.") def open_new_window(self) -> None: @@ -162,6 +163,8 @@ def update_statusbar(self) -> None: active_text = editor.content.text self.statusbar.set_encoding(active_text.encoding) return self.statusbar.set_line_col_info( - active_text.line, active_text.column, len(active_text.selection)) + active_text.line, active_text.column, len(active_text.selection) + ) + + self.statusbar.toggle_editmode(False) - self.statusbar.toggle_editmode(False) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index fe112069..02982644 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "biscuit" -version = "2.61.0" +version = "2.61.3" description = "The uncompromising code editor" authors = ["Billy "] license = "MIT"