Skip to content

Commit 9199af8

Browse files
committed
fix and style: Изменил настройку black и flake8
1 parent 4a4d38d commit 9199af8

File tree

8 files changed

+126
-54
lines changed

8 files changed

+126
-54
lines changed

.flake8

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[flake8]
2+
exclude =
3+
.git,
4+
__pycache__,
5+
build,
6+
dist,
7+
.venv,
8+
venv,
9+
.eggs,
10+
*.egg,
11+
.vscode,
12+
.idea,
13+
env,
14+
ENV,
15+
.env,
16+
.gitignore,
17+
requirements*.txt
18+
max-line-length = 79
19+
extend-ignore = E203, W503
20+
per-file-ignores =
21+
__init__.py: F401

db.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55

66
def get_data_path():
7-
documents_path = Path.home() / 'Documents'
8-
data_path = documents_path / 'QtLauncher_Data'
7+
documents_path = Path.home() / "Documents"
8+
data_path = documents_path / "QtLauncher_Data"
99
data_path.mkdir(exist_ok=True)
1010
return data_path
1111

1212

1313
class Database:
1414
def __init__(self):
1515
self.data_path = get_data_path()
16-
self.db_path = self.data_path / 'games.db'
16+
self.db_path = self.data_path / "games.db"
1717
self.create_tables()
1818

1919
def get_connection(self):
@@ -23,21 +23,19 @@ def create_tables(self):
2323
conn = self.get_connection()
2424
cursor = conn.cursor()
2525
cursor.execute(
26-
'''CREATE TABLE IF NOT EXISTS Games (
26+
"""CREATE TABLE IF NOT EXISTS Games (
2727
id INTEGER PRIMARY KEY AUTOINCREMENT,
2828
name TEXT NOT NULL UNIQUE,
2929
path TEXT NOT NULL UNIQUE
30-
)'''
30+
)"""
3131
)
3232
conn.commit()
3333
conn.close()
3434

3535
def check_name_is_unique(self, name):
3636
conn = self.get_connection()
3737
cursor = conn.cursor()
38-
cursor.execute(
39-
"SELECT COUNT(*) FROM Games WHERE name = ?", (name,)
40-
)
38+
cursor.execute("SELECT COUNT(*) FROM Games WHERE name = ?", (name,))
4139
count = cursor.fetchone()[0]
4240
return count == 0
4341

@@ -56,7 +54,7 @@ def insert_game(self, name, game_path):
5654
try:
5755
cursor.execute(
5856
"INSERT INTO Games (name, path) VALUES (?, ?)",
59-
(name, game_path)
57+
(name, game_path),
6058
)
6159
conn.commit()
6260
print(f"Игра '{name}' добавлена в базу данных")
@@ -70,10 +68,7 @@ def insert_game(self, name, game_path):
7068
def delete_game(self, name):
7169
conn = self.get_connection()
7270
cursor = conn.cursor()
73-
cursor.execute(
74-
"DELETE FROM Games WHERE name = ?",
75-
(name,)
76-
)
71+
cursor.execute("DELETE FROM Games WHERE name = ?", (name,))
7772
conn.commit()
7873
conn.close()
7974

@@ -90,10 +85,7 @@ def get_games(self):
9085
def get_game(self, name):
9186
conn = self.get_connection()
9287
cursor = conn.cursor()
93-
cursor.execute(
94-
"SELECT * FROM Games WHERE name = ?",
95-
(name,)
96-
)
88+
cursor.execute("SELECT * FROM Games WHERE name = ?", (name,))
9789
row = cursor.fetchone()
9890
conn.close()
9991
return row

dialogs.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def __init__(self):
2020

2121
def choose_file(self):
2222
file_path = QFileDialog.getOpenFileName(
23-
self, 'Выбрать файл', '',
24-
'EXE - Файл (*.exe)')[0]
23+
self, "Выбрать файл", "", "EXE - Файл (*.exe)"
24+
)[0]
2525
if file_path:
2626
self.file_path.setText(file_path)
2727

@@ -38,13 +38,15 @@ def accept_dialog(self):
3838
return
3939

4040
if not database.check_name_is_unique(game_name):
41-
QMessageBox.warning(self, "Ошибка",
42-
"Игра с таким именем уже существует")
41+
QMessageBox.warning(
42+
self, "Ошибка", "Игра с таким именем уже существует"
43+
)
4344
return
4445

4546
if not database.check_path_is_unique(game_path):
46-
QMessageBox.warning(self, "Ошибка",
47-
"Игра с таким путём уке существует")
47+
QMessageBox.warning(
48+
self, "Ошибка", "Игра с таким путём уке существует"
49+
)
4850
return
4951

5052
try:
@@ -53,5 +55,6 @@ def accept_dialog(self):
5355
QMessageBox.information(self, "Успех", "Игра добавлена!")
5456

5557
except Exception as e:
56-
QMessageBox.critical(self, "Ошибка",
57-
f"Не удалось добавить игру: {str(e)}")
58+
QMessageBox.critical(
59+
self, "Ошибка", f"Не удалось добавить игру: {str(e)}"
60+
)

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def open_dialog(self):
8989
self.update_game_list()
9090

9191

92-
if __name__ == '__main__':
92+
if __name__ == "__main__":
9393
app = QApplication(sys.argv)
9494
wind = QtLauncher()
9595
wind.show()

pyproject.toml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[tool.black]
2+
line-length = 79
3+
target-version = ['py312']
4+
include = '\.pyi?$'
5+
extend-exclude = '''
6+
/(
7+
| \.git
8+
| \.venv
9+
| build
10+
| dist
11+
)/
12+
'''
13+
14+
[tool.flake8]
15+
max-line-length = 79
16+
exclude = [
17+
".git",
18+
"__pycache__",
19+
"build",
20+
"dist",
21+
".venv",
22+
"venv",
23+
"*.egg",
24+
".vscode",
25+
".idea",
26+
"env",
27+
"ENV",
28+
]
29+
ignore = [
30+
"E203",
31+
"W503",
32+
"W605",
33+
]
34+
35+
[tool.isort]
36+
profile = "black"
37+
multi_line_output = 3

ui/add_game_dialog_ui.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ def setupUi(self, Dialog):
1818
self.buttonBox = QtWidgets.QDialogButtonBox(parent=Dialog)
1919
self.buttonBox.setGeometry(QtCore.QRect(220, 80, 220, 40))
2020
self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal)
21-
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Ok)
21+
self.buttonBox.setStandardButtons(
22+
QtWidgets.QDialogButtonBox.StandardButton.Cancel
23+
| QtWidgets.QDialogButtonBox.StandardButton.Ok
24+
)
2225
self.buttonBox.setObjectName("buttonBox")
2326
self.game_name = QtWidgets.QLineEdit(parent=Dialog)
2427
self.game_name.setGeometry(QtCore.QRect(100, 20, 340, 20))
@@ -56,8 +59,8 @@ def setupUi(self, Dialog):
5659
self.file_path.setObjectName("file_path")
5760

5861
self.retranslateUi(Dialog)
59-
self.buttonBox.accepted.connect(Dialog.accept) # type: ignore
60-
self.buttonBox.rejected.connect(Dialog.reject) # type: ignore
62+
self.buttonBox.accepted.connect(Dialog.accept) # type: ignore
63+
self.buttonBox.rejected.connect(Dialog.reject) # type: ignore
6164
QtCore.QMetaObject.connectSlotsByName(Dialog)
6265

6366
def retranslateUi(self, Dialog):

ui/mainWindow_ui.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ def setupUi(self, MainWindow):
1414
MainWindow.setObjectName("MainWindow")
1515
MainWindow.setEnabled(True)
1616
MainWindow.resize(750, 380)
17-
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.Preferred)
17+
sizePolicy = QtWidgets.QSizePolicy(
18+
QtWidgets.QSizePolicy.Policy.Preferred,
19+
QtWidgets.QSizePolicy.Policy.Preferred,
20+
)
1821
sizePolicy.setHorizontalStretch(0)
1922
sizePolicy.setVerticalStretch(0)
20-
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
23+
sizePolicy.setHeightForWidth(
24+
MainWindow.sizePolicy().hasHeightForWidth()
25+
)
2126
MainWindow.setSizePolicy(sizePolicy)
2227
MainWindow.setAutoFillBackground(False)
2328
self.centralwidget = QtWidgets.QWidget(parent=MainWindow)
@@ -30,7 +35,9 @@ def setupUi(self, MainWindow):
3035
font.setBold(False)
3136
font.setWeight(50)
3237
self.list_games.setFont(font)
33-
self.list_games.setEditTriggers(QtWidgets.QAbstractItemView.EditTrigger.DoubleClicked)
38+
self.list_games.setEditTriggers(
39+
QtWidgets.QAbstractItemView.EditTrigger.DoubleClicked
40+
)
3441
self.list_games.setMovement(QtWidgets.QListView.Movement.Static)
3542
self.list_games.setFlow(QtWidgets.QListView.Flow.TopToBottom)
3643
self.list_games.setProperty("isWrapping", False)
@@ -130,9 +137,18 @@ def retranslateUi(self, MainWindow):
130137
self.list_games.setSortingEnabled(False)
131138
self.add_game.setText(_translate("MainWindow", "Добавить игру"))
132139
self.delete_game.setText(_translate("MainWindow", "Удалить игру"))
133-
self.sort_name_a_z.setText(_translate("MainWindow", "Сортировать по имени А - Я"))
134-
self.sort_name_z_a.setText(_translate("MainWindow", "Сортировать по имени Я - А"))
135-
self.label.setText(_translate("MainWindow", "Для запуска просто нажмите ДВА раза на название игры"))
140+
self.sort_name_a_z.setText(
141+
_translate("MainWindow", "Сортировать по имени А - Я")
142+
)
143+
self.sort_name_z_a.setText(
144+
_translate("MainWindow", "Сортировать по имени Я - А")
145+
)
146+
self.label.setText(
147+
_translate(
148+
"MainWindow",
149+
"Для запуска просто нажмите ДВА раза на название игры",
150+
)
151+
)
136152
self.menu.setTitle(_translate("MainWindow", "Настройки"))
137153
self.menu_2.setTitle(_translate("MainWindow", "Сменить тему"))
138154
self.action_2.setText(_translate("MainWindow", "Светлая"))

utils.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,37 @@ def __init__(self):
99

1010
def create_txt(self):
1111
if not self.path.exists():
12-
with open(self.path, 'w', encoding='utf-8') as file:
13-
file.write('')
12+
with open(self.path, "w", encoding="utf-8") as file:
13+
file.write("")
1414

1515
def get_last_games(self):
1616
try:
17-
with open(self.path, 'r', encoding='utf-8') as file:
17+
with open(self.path, "r", encoding="utf-8") as file:
1818
file_data = file.read()
1919
return file_data.split("\n")
2020
except FileNotFoundError:
2121
return []
2222

2323
def add_game_to_history(self, game_name):
2424
current_games = self.get_last_games()
25-
current_games = [game for game in current_games if
26-
game != game_name and game.strip()]
25+
current_games = [
26+
game
27+
for game in current_games
28+
if game != game_name and game.strip()
29+
]
2730
current_games.insert(0, game_name)
2831
current_games = current_games[:5]
2932
self.save_last_games(current_games)
3033

3134
def save_last_games(self, games_list):
32-
with open(self.path, 'w', encoding='utf-8') as file:
35+
with open(self.path, "w", encoding="utf-8") as file:
3336
for game in games_list:
3437
if game.strip():
35-
file.write(game + '\n')
38+
file.write(game + "\n")
3639

3740
def clear_game_history(self):
38-
with open(self.path, 'w', encoding='utf-8') as file:
39-
file.write('')
41+
with open(self.path, "w", encoding="utf-8") as file:
42+
file.write("")
4043

4144

4245
class JSONEditor:
@@ -45,33 +48,30 @@ def __init__(self):
4548

4649
def create_json(self):
4750
if not self.path.exists():
48-
default_settings = {
49-
"theme": "dark"
50-
}
51-
with open(self.path, 'w', encoding='utf-8') as file:
51+
default_settings = {"theme": "dark"}
52+
with open(self.path, "w", encoding="utf-8") as file:
5253
json.dump(default_settings, file, indent=4, ensure_ascii=False)
5354

5455
def get_theme(self):
5556
try:
56-
with open(self.path, 'r', encoding='utf-8') as file:
57+
with open(self.path, "r", encoding="utf-8") as file:
5758
settings = json.load(file)
58-
return settings.get("theme",
59-
"dark")
59+
return settings.get("theme", "dark")
6060
except (FileNotFoundError, json.JSONDecodeError):
6161
return "dark"
6262

6363
def update_setting(self, key, value):
6464
try:
65-
with open(self.path, 'r', encoding='utf-8') as file:
65+
with open(self.path, "r", encoding="utf-8") as file:
6666
settings = json.load(file)
6767
except (FileNotFoundError, json.JSONDecodeError):
6868
settings = {}
6969

7070
settings[key] = value
7171

72-
with open(self.path, 'w', encoding='utf-8') as file:
72+
with open(self.path, "w", encoding="utf-8") as file:
7373
json.dump(settings, file, indent=4, ensure_ascii=False)
7474

7575

7676
txt_editor = TXTEditor()
77-
json_editor = JSONEditor()
77+
json_editor = JSONEditor()

0 commit comments

Comments
 (0)