Skip to content

Commit

Permalink
(upd) Save menu fix issue #8
Browse files Browse the repository at this point in the history
  • Loading branch information
javadr committed Apr 7, 2023
1 parent 654652a commit 3b54568
Show file tree
Hide file tree
Showing 9 changed files with 3,303 additions and 3,176 deletions.
3 changes: 3 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
0.7 -- 2023-04-07
-- Save menu with Ctrl+S hotkey, fix issue #8

0.6.9 -- 2023-04-05
-- fix issue with fa translataion of Windows standalone

Expand Down
8 changes: 8 additions & 0 deletions negar_gui/Ui_mwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,13 @@ def setupUi(self, MainWindow):
icon24.addPixmap(QtGui.QPixmap(":/images/icons/autobrightness.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.action_Auto.setIcon(icon24)
self.action_Auto.setObjectName("action_Auto")
self.actionSave = QtWidgets.QAction(MainWindow)
icon25 = QtGui.QIcon()
icon25.addPixmap(QtGui.QPixmap(":/images/icons/save.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionSave.setIcon(icon25)
self.actionSave.setObjectName("actionSave")
self.menuFile.addAction(self.actionOpen)
self.menuFile.addAction(self.actionSave)
self.menuFile.addAction(self.actionExport)
self.menuFile.addSeparator()
self.menuFile.addAction(self.actionExit)
Expand Down Expand Up @@ -567,6 +573,8 @@ def retranslateUi(self, MainWindow):
self.action_Light.setText(_translate("MainWindow", "&Light"))
self.action_Light.setShortcut(_translate("MainWindow", "Ctrl+T, Ctrl+L"))
self.action_Auto.setText(_translate("MainWindow", "&Auto"))
self.actionSave.setText(_translate("MainWindow", "&Save"))
self.actionSave.setShortcut(_translate("MainWindow", "Ctrl+S"))
from . import resource_rc


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 @@
from pathlib import Path
import platform

__version__ = "0.6.9"
__version__ = "0.7"

if platform.system() == 'Windows':
LOGO = ":/images/icons/logo_small.png"
Expand Down
4 changes: 4 additions & 0 deletions negar_gui/icons/save.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion negar_gui/icons/theme.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 18 additions & 1 deletion negar_gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def connectSlots(self):
self.autoedit_chkbox.stateChanged.connect(self.autoedit_handler)
self.edit_btn.clicked.connect(self.edit_text)
self.actionOpen.triggered.connect(self.openFileSlot)
self.actionSave.triggered.connect(self.saveFileSlot)
self.actionExport.triggered.connect(self.exportFileSlot)
self.actionExit.triggered.connect(self.close)
self.font_slider.valueChanged.connect(self._set_font_size)
Expand Down Expand Up @@ -363,14 +364,30 @@ def openFileSlot(self):
except Exception as e:
self.input_editor.setPlainText(e.args[1])

def saveFileSlot(self):
if not self.output_editor.toPlainText():
return
if hasattr(self, 'filename') and self.filename:
with open(self.filename, "w", encoding="utf-8") as f:
try:
f.write(self.output_editor.toPlainText())
statusBar_Timeout(self,'File Saved.')
except Exception as e:
self.output_editor.setPlainText(e.args[1])
else:
self.exportFileSlot()

def exportFileSlot(self):
if not self.output_editor.toPlainText():
return
filename, _ = self.fileDialog.getSaveFileName(self, "Save File", ".", "*.txt;;*")
filename, _ = self.fileDialog.getSaveFileName(self, "Save File", ".")
if filename:
with open(filename, "w", encoding="utf-8") as f:
try:
f.write(self.output_editor.toPlainText())
self.filename = Path(filename)
MainWindow.setWindowTitle(f"Negar - {self.filename.name}")
statusBar_Timeout(self,'File Saved.')
except Exception as e:
self.output_editor.setPlainText(e.args[1])

Expand Down
13 changes: 13 additions & 0 deletions negar_gui/mwin.ui
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@
<string>&amp;File</string>
</property>
<addaction name="actionOpen"/>
<addaction name="actionSave"/>
<addaction name="actionExport"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
Expand Down Expand Up @@ -1039,6 +1040,18 @@
<string>&amp;Auto</string>
</property>
</action>
<action name="actionSave">
<property name="icon">
<iconset resource="resource.qrc">
<normaloff>:/images/icons/save.svg</normaloff>:/images/icons/save.svg</iconset>
</property>
<property name="text">
<string>&amp;Save</string>
</property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</action>
</widget>
<tabstops>
<tabstop>output_editor</tabstop>
Expand Down
3 changes: 2 additions & 1 deletion negar_gui/resource.qrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<RCC>
<qresource prefix="images">
<file>icons/theme.svg</file>
<file>icons/add_right.svg</file>
<file>icons/theme.svg</file>
<file>icons/edit.svg</file>
<file>icons/add_left.svg</file>
<file>icons/add_bottom.svg</file>
Expand All @@ -26,6 +26,7 @@
<file>icons/export.svg</file>
<file>icons/increase.svg</file>
<file>icons/Fa.svg</file>
<file>icons/save.svg</file>
<file>icons/languages.svg</file>
<file>icons/logo.ico</file>
<file>icons/logo.png</file>
Expand Down
Loading

0 comments on commit 3b54568

Please sign in to comment.