Skip to content

Commit

Permalink
(feat) txt as default for save/open filedialog
Browse files Browse the repository at this point in the history
  • Loading branch information
javadr committed Aug 17, 2023
1 parent 0a1147e commit 5e87add
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2023-08-17 -- v0.8.2
-- `txt` as a default extension for saving/opening file.

2023-08-16 -- v0.8.1
-- Fixed issue with saving configurations in Windows

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.8.1"
__version__ = "0.8.2"

APPDATA = "AppData/Roaming/" if platform.system() == "Windows" else "."
SETTING_FILE = Path.home() / f"{APPDATA}negar-gui/settings.toml"
Expand Down
15 changes: 10 additions & 5 deletions negar_gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,11 @@ def _statusBar(self, notification="", timeout=0):
self.statusBar.showMessage(message, timeout)

def open_file_slot(self):
filename, _ = self.fileDialog.getOpenFileName(self, "Open File - A Plain Text", ".")
filename, _ = self.fileDialog.getOpenFileName(
self, "Open File - A Plain Text", ".", "Text Files (*.txt);;All Files (*)",
)
if filename:
with open(filename, encoding="utf-8") as f:
with Path(filename).open(encoding="utf-8") as f:
try:
self.input_editor.setPlainText(str(f.read()))
self.filename = Path(filename)
Expand All @@ -505,12 +507,15 @@ def save_file_slot(self):
def export_file_slot(self):
if not self.output_editor.toPlainText():
return
filename, _ = self.fileDialog.getSaveFileName(self, "Save File", ".")
filename, ext_type = self.fileDialog.getSaveFileName(
self, "Save File", ".", "Text Files (*.txt);;All Files (*)",
)
ext = ".txt" if ext_type.find(".txt") and not filename.endswith(".txt") else ""
if filename:
with open(filename, "w", encoding="utf-8") as f:
with Path(f"{filename}{ext}").open("w", encoding="utf-8") as f:
try:
f.write(self.output_editor.toPlainText())
self.filename = Path(filename)
self.filename = Path(f"{filename}{ext}")
MAIN_WINDOW.setWindowTitle(f"Negar - {self.filename.name}")
statusbar_timeout(self, "File Saved.")
except Exception as exception:
Expand Down

0 comments on commit 5e87add

Please sign in to comment.