Skip to content

Commit

Permalink
ruff formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementJ18 committed Nov 26, 2023
1 parent c93a779 commit 646ba56
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 22 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ A PyQt GUI intended to supplant the outdated FinalBIG program in the manipulatin
* User settings for persistent customisation
* Open files in your default applications or use the internal editor
* Auto-compile by Github
* Scroll through multiple instances of the file list
* And many more in the future!

At this very early stage I am mostly looking for feedback so if you have any thoughts feel free to open a ticket or find me on discord @Necro#6714. I can usually be found on quite a few BFME/SAGE servers.
Expand Down
2 changes: 1 addition & 1 deletion main.spec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ a = Analysis(
['src/main.py'],
pathex=[],
binaries=[],
datas=[('./src/icon.ico','.')],
datas=[('./src/icon.ico','.'), ('./src/new_tab.png', '.')],
hiddenimports=["PyQt6.sip", "PyQt6.QtPrintSupport"],
hookspath=[],
runtime_hooks=[],
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ tbm-utils==2.6.0
pyBIG==0.1.5
https://github.com/gorakhargosh/watchdog/archive/3140f52537f9bc801d1b812ed6ded3cb36695933.tar.gz
pyqtdarktheme==2.1.0
ruff==0.1.6
Binary file modified resources/demo_dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/demo_light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Support Python 3.8+.
target-version = "py310"
# Set the maximum line length to 79.
line-length = 99
3 changes: 1 addition & 2 deletions src/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from PyQt6.QtGui import QColor, QShortcut, QKeySequence
from PyQt6.Qsci import QsciScintilla, QsciLexerLua, QsciLexerCustom, QsciLexerXML

import darkdetect

from keywords import KEYWORDS, BEHAVIORS, CODEBLOCKS, SINGLETONS

Expand Down Expand Up @@ -50,7 +49,7 @@ def selected_lines(self):
start_line = self.sci.SendScintilla(QsciScintilla.SCI_LINEFROMPOSITION, r["begin"])
end_line = self.sci.SendScintilla(QsciScintilla.SCI_LINEFROMPOSITION, r["end"])
for cur_line in range(start_line, end_line + 1):
if not cur_line in all_lines:
if cur_line not in all_lines:
all_lines.append(cur_line)
if r["begin"] <= r["end"]:
self.sel_regions.append(r)
Expand Down
71 changes: 53 additions & 18 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import re
import sys
import logging
import traceback
from typing import List

Expand Down Expand Up @@ -84,12 +83,17 @@ def run(self):
self.archive.archive.seek(0)
buffer = self.archive.archive.read().decode(self.encoding)
indexes = {
match.start() for match in re.finditer(self.search if self.regex else re.escape(self.search), buffer)
match.start()
for match in re.finditer(self.search if self.regex else re.escape(self.search), buffer)
}
match_count = len(indexes)

for name, entry in self.archive.entries.items():
matched_indexes = {index for index in indexes if entry.position <= index <= (entry.position + entry.size)}
matched_indexes = {
index
for index in indexes
if entry.position <= index <= (entry.position + entry.size)
}
if matched_indexes:
indexes -= matched_indexes
matches.append(name)
Expand Down Expand Up @@ -175,7 +179,10 @@ def _add_file(self, url, name, blank=False, skip_all=False):

def add_file(self, url, blank=False):
name, ok = QInputDialog.getText(
self, "Filename", "Save the file under the following name:", text=normalize_name(url)
self,
"Filename",
"Save the file under the following name:",
text=normalize_name(url),
)
if not ok:
return False
Expand Down Expand Up @@ -254,7 +261,9 @@ def __init__(self):
super().__init__()
self.base_name = "FinalBIG v2"
self.setWindowIcon(QIcon(os.path.join(basedir, "icon.ico")))

self.search_archive_regex_bool = False
self.tab_current_index = 0

self.settings = QSettings("Necro inc.", "FinalBIGv2")

Expand All @@ -266,14 +275,15 @@ def __init__(self):
layout = QVBoxLayout()

self.listwidget = FileListTabs(self)

self.listwidget.addTab(QTabWidget(self), QIcon(os.path.join(basedir, "new_tab.png")), "")
self.listwidget.currentChanged.connect(self.open_new_tab)
self.listwidget.tabCloseRequested.connect(self._remove_list_tab)
self.listwidget.setElideMode(Qt.TextElideMode.ElideLeft)
self.listwidget.setTabsClosable(True)
self.listwidget.tabCloseRequested.connect(self._remove_list_tab)
self.listwidget.setUsesScrollButtons(True)
self.listwidget.tabBar().setTabButton(0, self.listwidget.tabBar().ButtonPosition.RightSide, None)
self.listwidget.addTab(QWidget(self), QIcon(os.path.join(basedir, "new_tab.png")), "")
self.listwidget.tabBar().setTabButton(
0, self.listwidget.tabBar().ButtonPosition.RightSide, None
)

search_widget = QWidget(self)
search_layout = QHBoxLayout()
Expand All @@ -294,7 +304,9 @@ def __init__(self):
search_layout.addWidget(self.invert_box)

self.re_filter_box = QCheckBox("Re-filter?", self)
self.re_filter_box.setToolTip("Apply the new filter on the current list rather than clearing previous filters")
self.re_filter_box.setToolTip(
"Apply the new filter on the current list rather than clearing previous filters"
)
search_layout.addWidget(self.re_filter_box)

self.tabs = TabWidget(self)
Expand Down Expand Up @@ -345,7 +357,10 @@ def create_shortcuts(self):
),
"Create a new archive",
),
(QShortcut(QKeySequence("CTRL+O"), self, self.open), "Open a different archive"),
(
QShortcut(QKeySequence("CTRL+O"), self, self.open),
"Open a different archive",
),
(QShortcut(QKeySequence("CTRL+S"), self, self.save), "Save the archive"),
(
QShortcut(QKeySequence("CTRL+SHIFT+S"), self, self.save_editor),
Expand All @@ -359,7 +374,10 @@ def create_shortcuts(self):
QShortcut(QKeySequence("CTRL+F"), self, self.search_file),
"Search the current text editor",
),
(QShortcut(QKeySequence("CTRL+W"), self, self.close_tab_shortcut), "Close the current tab"),
(
QShortcut(QKeySequence("CTRL+W"), self, self.close_tab_shortcut),
"Close the current tab",
),
(
"CTRL+;",
"Comment/uncomment the currently selected text",
Expand All @@ -370,7 +388,9 @@ def create_shortcuts(self):
),
(
QShortcut(
QKeySequence("CTRL+SHIFT+F"), self, lambda: self.search_archive(self.search_archive_regex_bool)
QKeySequence("CTRL+SHIFT+F"),
self,
lambda: self.search_archive(self.search_archive_regex_bool),
),
"Search for text in the archive",
),
Expand Down Expand Up @@ -548,13 +568,17 @@ def add_file_list(self, name="List"):

def open_new_tab(self):
if self.listwidget.currentIndex() != self.listwidget.count() - 1:
self.tab_current_index = self.listwidget.currentIndex()
return

name, ok = QInputDialog.getText(self, "Tab name", "Pick a name for your new tab:")
if not ok:
return False
name = "List"
if self.listwidget.count() != 1:
name, ok = QInputDialog.getText(self, "Tab name", "Pick a name for your new tab:")
if not ok:
return self.listwidget.setCurrentIndex(self.tab_current_index)

self.add_file_list(name)
self.tab_current_index = self.listwidget.currentIndex()

def show_help(self):
string = HELP_STRING.format(
Expand All @@ -570,7 +594,12 @@ def show_about(self):

def set_encoding(self):
name, ok = QInputDialog.getItem(
self, "Encoding", "Select an encoding", ENCODING_LIST, ENCODING_LIST.index(self.encoding), False
self,
"Encoding",
"Select an encoding",
ENCODING_LIST,
ENCODING_LIST.index(self.encoding),
False,
)
if not ok:
return
Expand Down Expand Up @@ -733,7 +762,11 @@ def filter_list(self):
if search == "":
return

if not any(self.search.itemText(x) for x in range(self.search.count()) if self.search.itemText(x) == search):
if not any(
self.search.itemText(x)
for x in range(self.search.count())
if self.search.itemText(x) == search
):
self.search.addItem(search)

if self.search.count() > SEARCH_HISTORY_MAX:
Expand Down Expand Up @@ -798,7 +831,9 @@ def rename(self):

original_name = self.listwidget.active_list.currentItem().text()

name, ok = QInputDialog.getText(self, "Filename", f"Rename {original_name} as:", text=original_name)
name, ok = QInputDialog.getText(
self, "Filename", f"Rename {original_name} as:", text=original_name
)
if not ok:
return

Expand Down
5 changes: 4 additions & 1 deletion src/tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ def generate_layout(self):
try:
cah = CustomHero(self.data, self.main.encoding)

powers = "\n".join(f"\t- Level {level+1}: {power} (index: {index})" for power, level, index in cah.powers)
powers = "\n".join(
f"\t- Level {level+1}: {power} (index: {index})"
for power, level, index in cah.powers
)
blings = "\n".join(f"\t- {bling}: {index}" for bling, index in cah.blings)
text = f"""
Name: {cah.name}
Expand Down

0 comments on commit 646ba56

Please sign in to comment.