Skip to content

Commit a45e441

Browse files
authored
Merge pull request #7 from m-xim/dev
Fix theme
2 parents 9fe3ab7 + ea92c69 commit a45e441

File tree

14 files changed

+529
-155
lines changed

14 files changed

+529
-155
lines changed

.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length = 120

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
1+
# [1.3.0-dev.4](https://github.com/m-xim/fluentus/compare/v1.3.0-dev.3...v1.3.0-dev.4) (2025-02-08)
2+
3+
4+
### Bug Fixes
5+
6+
* **ui:** Update hover color for 'new_project' button and padding folder_button ([6263a8a](https://github.com/m-xim/fluentus/commit/6263a8a648811562dec00fb849dfc7277d102041))
7+
8+
# [1.3.0-dev.3](https://github.com/m-xim/fluentus/compare/v1.3.0-dev.2...v1.3.0-dev.3) (2025-02-08)
9+
10+
11+
### Bug Fixes
12+
13+
* **start_window.ui:** Adjust alternate row background in Projects table ([6864911](https://github.com/m-xim/fluentus/commit/6864911d2b2642578fb7be415046039235612cfd))
14+
15+
# [1.3.0-dev.2](https://github.com/m-xim/fluentus/compare/v1.3.0-dev.1...v1.3.0-dev.2) (2025-02-08)
16+
17+
18+
### Bug Fixes
19+
20+
* new_folder.png path ([254a470](https://github.com/m-xim/fluentus/commit/254a47095453fd127823fe05a84cce2f2c89150c))
21+
22+
# [1.3.0-dev.1](https://github.com/m-xim/fluentus/compare/v1.2.0...v1.3.0-dev.1) (2025-02-08)
23+
24+
25+
### Bug Fixes
26+
27+
* **FluentAPI:** remove debug prints ([d355745](https://github.com/m-xim/fluentus/commit/d3557456aece15a6314f332198b6bb8f2fb531f1))
28+
* **theme:** correct system operations display in light theme ([f6122ec](https://github.com/m-xim/fluentus/commit/f6122ec40b8aa0e93e95972c9123d5e275b76c68))
29+
130
# [1.3.0](https://github.com/m-xim/fluentus/compare/v1.2.0...v1.3.0) (2025-02-01)
231

332

33+
434
### Features
535

636
* **start_window:** add Delete key shortcut for removing selected projects ([e14421c](https://github.com/m-xim/fluentus/commit/e14421c7a5efda7e027c8df9d7875a21df9ca49b))

src/app.py

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55
from PyQt6.QtCore import Qt, QModelIndex, QEvent
66
from PyQt6.QtGui import QDragEnterEvent, QDropEvent, QResizeEvent, QShortcut
77
from PyQt6.QtSql import QSqlTableModel
8-
from PyQt6.QtWidgets import QApplication, QMessageBox, QFileDialog, QMainWindow, QPushButton, QTableView
8+
from PyQt6.QtWidgets import (
9+
QApplication,
10+
QMessageBox,
11+
QFileDialog,
12+
QMainWindow,
13+
QPushButton,
14+
QTableView,
15+
)
916
from loguru import logger
1017

1118
from src.database.manager import DatabaseManager
1219
from src.editor import FluentusEditor
1320
from src.logger import configure_logger
1421
from src.utils.config_reader import get_config, DatabaseConfig
22+
from src.utils.icon_utils import get_tinted_icon
1523
from src.utils.resource_path import resource_path
1624
from src.widgets.drag_overlay import DragOverlay
1725

@@ -25,14 +33,26 @@ def __init__(self) -> None:
2533
super().__init__()
2634

2735
# Initialize database config
28-
db_config: DatabaseConfig = get_config(model=DatabaseConfig, root_key="database")
36+
db_config: DatabaseConfig = get_config(
37+
model=DatabaseConfig, root_key="database"
38+
)
2939

3040
# Create database manager
31-
self.db_manager = DatabaseManager(db_name=db_config.name, table_name=db_config.tables.projects)
41+
self.db_manager = DatabaseManager(
42+
db_name=db_config.name, table_name=db_config.tables.projects
43+
)
3244

3345
# Load UI
3446
uic.loadUi(resource_path("resource/ui/start_window.ui"), self)
3547

48+
# Set theme
49+
self.new_project: QPushButton
50+
self.new_project.setIcon(
51+
get_tinted_icon(
52+
resource_path("resource/icons/new_folder.png"), self.new_project
53+
)
54+
)
55+
3656
# Retrieve required widgets
3757
self.projects: QTableView = self.findChild(QTableView, "projects")
3858
self.new_project: QPushButton = self.findChild(QPushButton, "new_project")
@@ -43,21 +63,27 @@ def __init__(self) -> None:
4363
# Initialize database (create table if it doesn't exist)
4464
if not self.db_manager.initialize_database():
4565
logger.error("Database initialization failed.")
46-
QMessageBox.critical(self, "Database Error", "Failed to initialize database.")
66+
QMessageBox.critical(
67+
self, "Database Error", "Failed to initialize database."
68+
)
4769
sys.exit(1)
4870

4971
# Connect to the database
5072
if not self.db_manager.create_connection():
5173
logger.error("Database connection failed.")
52-
QMessageBox.critical(self, "Database Error", "Failed to connect to database.")
74+
QMessageBox.critical(
75+
self, "Database Error", "Failed to connect to database."
76+
)
5377
sys.exit(1)
5478

5579
# Set up the model and link it to the table view
5680
self.model = QSqlTableModel(self)
5781
self.model.setTable(db_config.tables.projects)
5882
self.model.setEditStrategy(QSqlTableModel.EditStrategy.OnFieldChange)
5983
self.model.select()
60-
self.model.setHeaderData(self.model.fieldIndex("folder"), Qt.Orientation.Horizontal, "Folder")
84+
self.model.setHeaderData(
85+
self.model.fieldIndex("folder"), Qt.Orientation.Horizontal, "Folder"
86+
)
6187

6288
# Configure the projects table view
6389
self.projects.setModel(self.model)
@@ -68,7 +94,9 @@ def __init__(self) -> None:
6894
self.projects.doubleClicked.connect(self.open_editor)
6995

7096
shortcut_delete = QShortcut(Qt.Key.Key_Delete, self.projects)
71-
shortcut_delete.activated.connect(lambda: self.delete_rows(self.model, self.projects))
97+
shortcut_delete.activated.connect(
98+
lambda: self.delete_rows(self.model, self.projects)
99+
)
72100

73101
# Connect the "New Project" button click event
74102
self.new_project.clicked.connect(self.create_new_project)
@@ -105,11 +133,15 @@ def add_project(self, folder: str) -> None:
105133
:param folder: Path to the project folder.
106134
"""
107135
if self.db_manager.project_exists(folder):
108-
QMessageBox.warning(self, "Warning", "A project with this path already exists.")
136+
QMessageBox.warning(
137+
self, "Warning", "A project with this path already exists."
138+
)
109139
return
110140

111141
if not self.db_manager.add_project(folder):
112-
QMessageBox.critical(self, "Error", "Failed to add the project to the database.")
142+
QMessageBox.critical(
143+
self, "Error", "Failed to add the project to the database."
144+
)
113145
return
114146

115147
# Refresh the model to display the new record
@@ -129,8 +161,7 @@ def delete_rows(model: QSqlTableModel, table_view: QTableView) -> None:
129161
QMessageBox.critical(
130162
table_view,
131163
"Deletion Error",
132-
f"Unable to delete rows:"
133-
f"\n{model.lastError().text()}"
164+
f"Unable to delete rows:" f"\n{model.lastError().text()}",
134165
)
135166
else:
136167
model.select()

src/config.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ check = "check"
1313
[table_column]
1414
icon = ""
1515
variable = "Variable"
16-
translation = "Translation"
16+
translation = "Translation"
17+
18+
[colors]
19+
highlight = "#D9AD2B"

src/database/manager.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ def create_connection(self) -> bool:
5858
if not db.open():
5959
error = db.lastError().text()
6060
logger.error(f"Failed to connect to the database: {error}")
61-
QMessageBox.critical(None, "Database Error", f"Failed to connect to the database: {error}")
61+
QMessageBox.critical(
62+
None, "Database Error", f"Failed to connect to the database: {error}"
63+
)
6264
return False
6365

6466
logger.info("Database connection established.")
@@ -75,7 +77,9 @@ def project_exists(self, folder: str) -> bool:
7577
query.prepare(f"SELECT COUNT(*) FROM {self.table_name} WHERE folder = :folder")
7678
query.bindValue(":folder", folder)
7779
if not query.exec():
78-
logger.error(f"Failed to check project existence: {query.lastError().text()}")
80+
logger.error(
81+
f"Failed to check project existence: {query.lastError().text()}"
82+
)
7983
return False
8084

8185
if query.next():

src/editor.py

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33

44
from PyQt6 import uic
55
from PyQt6.QtCore import Qt
6-
from PyQt6.QtWidgets import QWidget, QMessageBox, QFileDialog, QPlainTextEdit, QCheckBox, QComboBox
6+
from PyQt6.QtWidgets import (
7+
QWidget,
8+
QMessageBox,
9+
QFileDialog,
10+
QPlainTextEdit,
11+
QCheckBox,
12+
QComboBox,
13+
)
714

815
from src.fluent_api.FluentAPI import FluentAPI
916
from src.utils.config_reader import get_config, Program
@@ -24,7 +31,7 @@ def __init__(self, folder: Optional[str] = None):
2431
self.table_manager = None
2532

2633
# Load UI
27-
uic.loadUi(resource_path('resource/ui/editor_window.ui'), self)
34+
uic.loadUi(resource_path("resource/ui/editor_window.ui"), self)
2835

2936
self.editors = [
3037
(self.value_1, "value", self.lang_1),
@@ -38,7 +45,7 @@ def __init__(self, folder: Optional[str] = None):
3845
self.key_press_filter = KeyPressFilter()
3946

4047
for editor, field, lang in self.editors:
41-
if isinstance(editor, QPlainTextEdit) and field == 'value':
48+
if isinstance(editor, QPlainTextEdit) and field == "value":
4249
editor.installEventFilter(self.key_press_filter)
4350

4451
# Connect buttons and language selectors
@@ -52,9 +59,13 @@ def __init__(self, folder: Optional[str] = None):
5259
# Connect editor signals dynamically
5360
for editor, field, lang in self.editors:
5461
if isinstance(editor, QPlainTextEdit):
55-
editor.textChanged.connect(partial(self.update_cache, editor, field, lang))
62+
editor.textChanged.connect(
63+
partial(self.update_cache, editor, field, lang)
64+
)
5665
elif isinstance(editor, QCheckBox):
57-
editor.stateChanged.connect(partial(self.update_cache, editor, field, lang))
66+
editor.stateChanged.connect(
67+
partial(self.update_cache, editor, field, lang)
68+
)
5869

5970
# Initialize with folder if provided
6071
if folder:
@@ -69,7 +80,9 @@ def _initialize_folder(self, folder: str) -> None:
6980
self.fluent_api = FluentAPI(folder)
7081

7182
# Initialize table manager
72-
self.table_manager = TableManager(self.table, self.fluent_api, self.load_variable)
83+
self.table_manager = TableManager(
84+
self.table, self.fluent_api, self.load_variable
85+
)
7386

7487
self.folder_text.setText(folder)
7588
self.refresh_editing_state()
@@ -81,7 +94,9 @@ def save_all_changes(self):
8194
"""Save all changes and notify the user."""
8295
if self.fluent_api.edited:
8396
self.fluent_api.save_all_files()
84-
QMessageBox.information(self, "Save Changes", "All changes have been saved successfully!")
97+
QMessageBox.information(
98+
self, "Save Changes", "All changes have been saved successfully!"
99+
)
85100
self.refresh_editing_state(False)
86101
else:
87102
QMessageBox.information(self, "No Changes", "No changes have been made.")
@@ -118,7 +133,7 @@ def load_variable(self):
118133
language = lang.currentText()
119134
data = self.fluent_api.get_translation(variable, language)
120135

121-
if attribute and field == 'value':
136+
if attribute and field == "value":
122137
content = data.attributes[attribute]
123138
else:
124139
content = getattr(data, field, None)
@@ -134,7 +149,7 @@ def load_variable(self):
134149
editor.setPlainText(value_new)
135150
editor.blockSignals(False)
136151

137-
if field == 'value':
152+
if field == "value":
138153
last_key = self.key_press_filter.get_last_key(editor)
139154
if last_key not in (Qt.Key.Key_Backspace, Qt.Key.Key_Space):
140155
position = min(position + 1, len(value_new))
@@ -159,16 +174,24 @@ def _open_start_window(self):
159174

160175
self.close()
161176

162-
def update_cache(self, editor: Union[QPlainTextEdit, QCheckBox], field: str, lang: QComboBox):
177+
def update_cache(
178+
self, editor: Union[QPlainTextEdit, QCheckBox], field: str, lang: QComboBox
179+
):
163180
"""Update the cache when an editor field is modified."""
164181

165182
variable, attribute = self.table_manager.get_selected_names()
166183
if not variable:
167184
return
168185

169-
new_content = editor.toPlainText() if isinstance(editor, QPlainTextEdit) else editor.isChecked()
186+
new_content = (
187+
editor.toPlainText()
188+
if isinstance(editor, QPlainTextEdit)
189+
else editor.isChecked()
190+
)
170191

171-
if self.fluent_api.update(variable, lang.currentText(), field, new_content, attribute):
192+
if self.fluent_api.update(
193+
variable, lang.currentText(), field, new_content, attribute
194+
):
172195
self.table_manager.set_current_item(lang.currentText())
173196

174197
self.load_variable()
@@ -178,12 +201,14 @@ def update_cache(self, editor: Union[QPlainTextEdit, QCheckBox], field: str, lan
178201

179202
def refresh_editing_state(self, edit_status: Optional[bool] = None) -> None:
180203
"""Refreshes the editing status in 'fluent_api' and updates the window title."""
181-
204+
182205
if edit_status is not None:
183206
self.fluent_api.edited = edit_status
184207

185-
folder_suffix = f" - {self.fluent_api.folder_path}" if self.fluent_api.folder_path else ""
186-
program = get_config(Program, 'program')
208+
folder_suffix = (
209+
f" - {self.fluent_api.folder_path}" if self.fluent_api.folder_path else ""
210+
)
211+
program = get_config(Program, "program")
187212

188213
if self.fluent_api.edited:
189214
window_title = f"*{program.title}{folder_suffix}"
@@ -196,7 +221,7 @@ def closeEvent(self, event):
196221
"""Handle the close event with unsaved changes."""
197222
if self.fluent_api.edited:
198223
dialog = CloseDialog(self)
199-
result = dialog.exec()
224+
dialog.exec()
200225

201226
if dialog.choice == "save":
202227
self.fluent_api.save_all_files()

0 commit comments

Comments
 (0)