Skip to content

Commit

Permalink
(upd) selection options
Browse files Browse the repository at this point in the history
  • Loading branch information
javadr committed Jan 6, 2025
1 parent c7f237a commit 57c455d
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 95 deletions.
3 changes: 3 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2025-01-06 -- v0.9.8
-- Added "Select All," "Unselect All," and "Invert Selection" options to the Options menu.

2024-12-28 -- v0.9.7
-- Fixed layout issue

Expand Down
13 changes: 13 additions & 0 deletions negar_gui/Ui_mwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,12 @@ def setupUi(self, MainWindow):
icon25.addPixmap(QtGui.QPixmap(":/images/icons/save.svg"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
self.actionSave.setIcon(icon25)
self.actionSave.setObjectName("actionSave")
self.actionSelect_All = QtGui.QAction(parent=MainWindow)
self.actionSelect_All.setObjectName("actionSelect_All")
self.actionUnselect_All = QtGui.QAction(parent=MainWindow)
self.actionUnselect_All.setObjectName("actionUnselect_All")
self.actionInvert_Selection = QtGui.QAction(parent=MainWindow)
self.actionInvert_Selection.setObjectName("actionInvert_Selection")
self.menuFile.addAction(self.actionOpen)
self.menuFile.addAction(self.actionSave)
self.menuFile.addAction(self.actionExport)
Expand Down Expand Up @@ -456,6 +462,10 @@ def setupUi(self, MainWindow):
self.menuOptions.addSeparator()
self.menuOptions.addAction(self.actionExaggerating_ZWNJ)
self.menuOptions.addAction(self.actionTrim_Leading_Trailing_Whitespaces)
self.menuOptions.addSeparator()
self.menuOptions.addAction(self.actionSelect_All)
self.menuOptions.addAction(self.actionUnselect_All)
self.menuOptions.addAction(self.actionInvert_Selection)
self.menuLanguage.addAction(self.actionPersian)
self.menuLanguage.addAction(self.actionEnglish)
self.menuSetting.addAction(self.menuOptions.menuAction())
Expand Down Expand Up @@ -581,6 +591,9 @@ def retranslateUi(self, MainWindow):
self.action_Auto.setText(_translate("MainWindow", "&Auto"))
self.actionSave.setText(_translate("MainWindow", "&Save"))
self.actionSave.setShortcut(_translate("MainWindow", "Ctrl+S"))
self.actionSelect_All.setText(_translate("MainWindow", "Select All"))
self.actionUnselect_All.setText(_translate("MainWindow", "Unselect All"))
self.actionInvert_Selection.setText(_translate("MainWindow", "Invert Selection"))


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion negar_gui/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import platform
from pathlib import Path

__version__ = "0.9.7"
__version__ = "0.9.8"

APPDATA = "AppData/Roaming/" if platform.system() == "Windows" else "."
SETTING_FILE = Path.home() / f"{APPDATA}negar-gui/settings.toml"
Expand Down
72 changes: 49 additions & 23 deletions negar_gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,28 @@ def __init__(self, parent=None):
# Checks for new release
Thread(target=lambda: asyncio.run(self.updateCheck()), daemon=True).start()

self.options_action_menu = (
self.actionFix_Dashes,
self.actionFix_three_dots,
self.actionFix_English_quotes,
self.actionFix_hamzeh,
self.actionUse_Persian_yeh_to_show_hamzeh,
self.actionFix_spacing_braces_and_quotes,
self.actionFix_Arabic_numbers,
self.actionFix_English_numbers,
self.actionFix_non_Persian_chars,
self.actionFix_prefix_spacing,
self.actionFix_prefix_separating,
self.actionFix_suffix_spacing,
self.actionFix_suffix_separating,
self.actionFix_aggressive_punctuation,
self.actionCleanup_kashidas,
self.actionCleanup_extra_marks,
self.actionCleanup_spacing,
self.actionTrim_Leading_Trailing_Whitespaces,
self.actionExaggerating_ZWNJ,
)

async def updateCheck(self):
nurl = "https://raw.github.com/shahinism/python-negar/master/negar/constants.py"
ngurl = "https://raw.github.com/javadr/negar-gui/master/negar_gui/constants.py"
Expand Down Expand Up @@ -377,28 +399,8 @@ def connectSlots(self):
self.actionReport_Bugs.triggered.connect(
lambda: QDesktopServices.openUrl(QUrl("https://github.com/javadr/negar-gui/issues")),
)

for menu_item in (
self.actionFix_Dashes,
self.actionFix_three_dots,
self.actionFix_English_quotes,
self.actionFix_hamzeh,
self.actionUse_Persian_yeh_to_show_hamzeh,
self.actionFix_spacing_braces_and_quotes,
self.actionFix_Arabic_numbers,
self.actionFix_English_numbers,
self.actionFix_non_Persian_chars,
self.actionFix_prefix_spacing,
self.actionFix_prefix_separating,
self.actionFix_suffix_spacing,
self.actionFix_suffix_separating,
self.actionFix_aggressive_punctuation,
self.actionCleanup_kashidas,
self.actionCleanup_extra_marks,
self.actionCleanup_spacing,
self.actionTrim_Leading_Trailing_Whitespaces,
self.actionExaggerating_ZWNJ,
):
# connecting the option menu items to their handlers
for menu_item in self.options_action_menu:
menu_item.triggered.connect(lambda: (self.option_control(), self.autoedit_handler()))

self.actionUntouchable_Words.triggered.connect(
Expand Down Expand Up @@ -464,6 +466,26 @@ def connectSlots(self):
self.input_editor.verticalScrollBar().valueChanged.connect(self._sync_inout_scroll)
self.output_editor.verticalScrollBar().valueChanged.connect(self._sync_inout_scroll)

def check(value: bool):
return lambda: (
[checkbox.setChecked(value) for checkbox in self.options_action_menu],
self.option_control(),
self.autoedit_handler(),
)

self.actionSelect_All.triggered.connect(check(True))
self.actionUnselect_All.triggered.connect(check(False))
self.actionInvert_Selection.triggered.connect(
lambda: (
[
checkbox.setChecked(not checkbox.isChecked())
for checkbox in self.options_action_menu
],
self.option_control(),
self.autoedit_handler(),
)
)

####################### SLOTs ###############################
def _sync_inout_scroll(self, value):
max_in_scroll = self.input_editor.verticalScrollBar().maximum()
Expand Down Expand Up @@ -492,6 +514,7 @@ def full_screen_input_slot(self):

# Change GridLayout Orientation
def _grid_layout(self, layout="h"):
assert layout in ("v", "h"), "Layout must be 'v' or 'h'"
if layout == "v":
self.gridLayout.setHorizontalSpacing(5)
elif layout == "h":
Expand Down Expand Up @@ -788,7 +811,10 @@ def autoedit_handler(self):
else:
self.edit_btn.setEnabled(True)
# This line will disconnect autoedit signal and will disable autoamtic edit option
self.input_editor.textChanged.disconnect(self.edit_text)
try:
self.input_editor.textChanged.disconnect(self.edit_text)
except:
pass
self._set_font_size()

def _set_font_size(self):
Expand Down
19 changes: 19 additions & 0 deletions negar_gui/mwin.ui
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,10 @@
<addaction name="separator"/>
<addaction name="actionExaggerating_ZWNJ"/>
<addaction name="actionTrim_Leading_Trailing_Whitespaces"/>
<addaction name="separator"/>
<addaction name="actionSelect_All"/>
<addaction name="actionUnselect_All"/>
<addaction name="actionInvert_Selection"/>
</widget>
<widget class="QMenu" name="menuLanguage">
<property name="title">
Expand Down Expand Up @@ -1064,6 +1068,21 @@
<string>Ctrl+S</string>
</property>
</action>
<action name="actionSelect_All">
<property name="text">
<string>Select All</string>
</property>
</action>
<action name="actionUnselect_All">
<property name="text">
<string>Unselect All</string>
</property>
</action>
<action name="actionInvert_Selection">
<property name="text">
<string>Invert Selection</string>
</property>
</action>
</widget>
<tabstops>
<tabstop>output_editor</tabstop>
Expand Down
4 changes: 2 additions & 2 deletions negar_gui/ts/fa-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<context>
<name>Dialog</name>
<message>
<location filename="../main.py" line="361"/>
<location filename="../main.py" line="384"/>
<source>About Negar</source>
<translation>درباره نگار</translation>
</message>
<message>
<location filename="../main.py" line="245"/>
<location filename="../main.py" line="246"/>
<source>Close</source>
<translation>بستن</translation>
</message>
Expand Down
Loading

0 comments on commit 57c455d

Please sign in to comment.