Skip to content

Commit 932d229

Browse files
Merge pull request #60 from WhenLifeHandsYouLemons/v1.9.1
v1.9.1
2 parents b3dc7b2 + b9939f3 commit 932d229

8 files changed

Lines changed: 119 additions & 62 deletions

Encryptext.pyw

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Imports
99
"""
1010
import sys
1111
from os.path import abspath, join, expanduser
12-
#! from os import getenv # Not useful right now, but could be useful if translations are available
12+
# from os import getenv #! DOESN'T SEEM TO WORK IN EXE MODE
1313
import json
1414
from random import choice, randint
1515
from string import ascii_letters, digits
@@ -78,7 +78,7 @@ try:
7878
settings[key] = True
7979
except FileNotFoundError:
8080
settings = {
81-
"version": "'Encryptext Offline Mode'",
81+
"version": "'Encryptext Travel Mode'",
8282
"recentFilePaths": [],
8383
"maxRecentFiles": 0,
8484
"otherSettings": {
@@ -95,7 +95,7 @@ except FileNotFoundError:
9595
}
9696
}
9797

98-
version = settings["version"]
98+
version = f"{'.'.join(settings['version'].split('.')[0:-1])} (build {settings['version'].split('.')[-1]})"
9999
font_scale_factor = settings["otherSettings"]["fontScaleFactor"]
100100

101101
"""
@@ -111,7 +111,6 @@ class TextLineNumbers(tk.Canvas):
111111
self.textwidget = text_widget
112112

113113
def redraw(self, *args):
114-
'''redraw line numbers'''
115114
self.delete("all")
116115

117116
i = self.textwidget.index("@0,0")
@@ -157,7 +156,6 @@ class CustomText(tk.Text):
157156

158157
# https://www.reddit.com/r/learnpython/comments/6dndqz/comment/di42keo/
159158
class WrappedLabel(ttk.Label):
160-
"""a type of Label that automatically adjusts the wrap to the size"""
161159
def __init__(self, master=None, **kwargs):
162160
ttk.Label.__init__(self, master, **kwargs)
163161
self.bind("<Configure>", lambda e: self.config(wraplength=self.winfo_width()))
@@ -213,7 +211,10 @@ class PreferenceWindow(tk.Toplevel):
213211
# Language picker
214212
self.selected_language = tk.StringVar(value=settings["otherSettings"]["language"])
215213
self.language_label = WrappedLabel(self.pref_window, text="Display language: ", font=(settings["otherSettings"]["fontStyle"], int(round(11*font_scale_factor))))
216-
#! getenv("LANG").split(".")[0] # Can be useful to get the user's default language
214+
# Get the user's default language and also display that in the list
215+
# It doesn't change anything right now, but maybe it will in the future.
216+
#! DOESN'T SEEM TO WORK IN EXE MODE
217+
# getenv("LANG").split(".")[0]
217218
lang_options = ["en_US"]
218219
self.language_val = ttk.Combobox(self.language_label, textvariable=self.selected_language, values=lang_options, state="readonly", font=(settings["otherSettings"]["fontStyle"], int(round(11*font_scale_factor))))
219220

@@ -457,10 +458,14 @@ def quitApp(Event=None):
457458
with open(settings_path, "w") as file:
458459
settings = str(settings).replace("'", '"').replace("False", "false").replace("True", "true")
459460
file.write(str(settings))
460-
except FileNotFoundError: pass
461+
except FileNotFoundError or NameError as e:
462+
if debug:
463+
messagebox.askokcancel("ERROR", f"Error: {e}")
464+
except Exception as e:
465+
messagebox.askokcancel("ERROR", f"Error: {e}")
461466

462467
try:
463-
md_preview_window.destroy()
468+
preview_window.destroy()
464469
pref_window.closeWindow()
465470
finally:
466471
root.destroy()
@@ -483,10 +488,14 @@ def quitApp(Event=None):
483488
with open(settings_path, "w") as file:
484489
settings = str(settings).replace("'", '"').replace("False", "false").replace("True", "true")
485490
file.write(str(settings))
486-
except FileNotFoundError: pass
491+
except FileNotFoundError or NameError as e:
492+
if debug:
493+
messagebox.showerror("ERROR", f"Error: {e}")
494+
except Exception:
495+
messagebox.showerror("Error", "Unknown error. If this problem persists, please contact the developer at 'https://github.com/WhenLifeHandsYouLemons/Encryptext'.")
487496

488497
try:
489-
md_preview_window.destroy()
498+
preview_window.destroy()
490499
pref_window.closeWindow()
491500
finally:
492501
root.destroy()
@@ -673,9 +682,9 @@ def openFile(Event=None, current=False, file_path=None):
673682
recent_files.pop()
674683
createMenuBar()
675684
if file_extensions[current_tab] == "md":
676-
global md_preview_window
685+
global preview_window
677686
try:
678-
md_preview_window.deiconify()
687+
preview_window.deiconify()
679688
updatePreview()
680689
except:
681690
preview_window.__init__()
@@ -729,14 +738,16 @@ def newFile(Event=None):
729738

730739
updatePreview()
731740

732-
def saveFile(Event=None):
741+
def saveFile(Event=None, auto_save=False):
733742
current_tab = getCurrentTab()
734743
if current_tab == -1:
735744
return None
736745

737746
# If it's a new file
738747
if file_save_locations[current_tab] == "":
739-
saveFileAs()
748+
# If it's being saved manually, then try save as
749+
if not auto_save:
750+
saveFileAs()
740751
else:
741752
# Get the text from the current textbox
742753
text = textboxes[current_tab].get("1.0", tk.END)
@@ -1239,7 +1250,7 @@ def addNewTab(Event=None):
12391250
textboxes[-1].bindtags((bindtags[2], bindtags[0], bindtags[1], bindtags[3]))
12401251

12411252
# Track document changes and update markdown preview
1242-
textboxes[-1].bind('<Key>', trackChanges)
1253+
textboxes[-1].bind('<<Change>>', trackChanges)
12431254
if settings["otherSettings"]["showLineNumbers"] == True and settings["otherSettings"]["highlightActiveLine"] == True:
12441255
textboxes[-1].bind("<<Change>>", updateHighlightAndNumbers)
12451256
textboxes[-1].bind("<Configure>", updateHighlightAndNumbers)
@@ -1286,6 +1297,9 @@ def closeCurrentTab(Event=None):
12861297
file_format_tags.pop(current_tab)
12871298
file_format_tag_nums.pop(current_tab)
12881299
saved.pop(current_tab)
1300+
frames.pop(current_tab)
1301+
if settings["otherSettings"]["showLineNumbers"] == True:
1302+
line_number_areas.pop(current_tab)
12891303

12901304
updatePreview()
12911305

@@ -1325,6 +1339,8 @@ def captureSpecialKeys(Event=None):
13251339
cur_key = Event.keysym
13261340
mod_key = Event.state
13271341

1342+
# print(Event, cur_key, mod_key)
1343+
13281344
# Run function based on what key was pressed
13291345
if cur_key == "s":
13301346
saveFile()

Original Files/build_number.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20
21.3 MB
Binary file not shown.
21.3 MB
Binary file not shown.
21.3 MB
Binary file not shown.
21.3 MB
Binary file not shown.

encryptext_installer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from shutil import rmtree
55
import sys
66
from subprocess import run, PIPE
7-
from time import sleep
87
import json
98
from cryptography.fernet import Fernet as F
109
from random import choice, randint
@@ -13,7 +12,7 @@
1312
# https://github.com/rsalmei/alive-progress
1413
from alive_progress import alive_bar, styles
1514

16-
version = "1.9.0"
15+
version = "INSERT VERSION NUMBER HERE"
1716

1817
print("\nStarting installer...")
1918
print("Please wait...")

installer_creator.py

Lines changed: 86 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,110 @@
11
#!/usr/bin/python'
22

33
from os import rename, path, remove
4-
from shutil import rmtree
4+
from shutil import rmtree, copy
55
import hashlib
66
import PyInstaller.__main__
77

8-
version = "1.9.0"
8+
version = "1.9.1"
9+
testing = False
10+
11+
def update_build_number():
12+
with open("Original Files/build_number.txt", "r") as file:
13+
build_number = int(file.read().strip())
14+
build_number += 1
15+
with open("Original Files/build_number.txt", "w") as file:
16+
file.write(str(build_number))
17+
return build_number
18+
19+
build_number = update_build_number()
20+
version = f"{version}.{build_number}"
921

1022
# Compute hash of the input string
11-
def computeHash(input_string):
23+
def computeHash(input_string: str) -> str:
1224
hash_object = hashlib.sha256()
1325
hash_object.update(input_string.encode('utf-8'))
1426

1527
return hash_object.hexdigest()
1628

29+
def modifyInstallerFile(add: bool) -> None:
30+
if add:
31+
# Add the computed hash and version number
32+
with open("encryptext_installer.py", "r+") as file:
33+
installer_file = file.read()
34+
installer_parts = installer_file.split("INSERT COMPUTED HASH HERE")
35+
installer_file = hash_str.join(installer_parts)
36+
installer_parts = installer_file.split("INSERT VERSION NUMBER HERE")
37+
installer_file = version.join(installer_parts)
38+
39+
file.seek(0)
40+
file.write(installer_file)
41+
file.truncate()
42+
else:
43+
# Remove the computed hash and version number
44+
with open("encryptext_installer.py", "r+") as file:
45+
installer_file = file.read()
46+
installer_parts = installer_file.split(hash_str)
47+
installer_file = "INSERT COMPUTED HASH HERE".join(installer_parts)
48+
installer_parts = installer_file.split(version)
49+
installer_file = "INSERT VERSION NUMBER HERE".join(installer_parts)
50+
51+
file.seek(0)
52+
file.write(installer_file)
53+
file.truncate()
54+
1755
# Open the key.txt file and read in the key
1856
with open("Original Files/key.txt", "r") as file:
1957
key = file.read().strip()
2058
# Compute the hash of the key
2159
hash_str = computeHash(key)
2260

23-
# Add the computed hash
24-
with open("encryptext_installer.py", "r+") as file:
25-
installer_file = file.read()
26-
installer_parts = installer_file.split("INSERT COMPUTED HASH HERE")
27-
installer_file = hash_str.join(installer_parts)
28-
file.seek(0)
29-
file.write(installer_file)
30-
file.truncate()
31-
32-
# Creates an executable file
33-
PyInstaller.__main__.run([
34-
'encryptext_installer.py',
35-
'--onefile',
36-
'--clean',
37-
'--log-level',
38-
'ERROR',
39-
'--icon',
40-
'app_icon.ico',
41-
'--add-data',
42-
'app_icon.ico;.',
43-
'--add-data',
44-
'Encryptext.pyw;.',
45-
"--collect-all",
46-
"tkinterweb",
47-
"--collect-all",
48-
"alive_progress",
49-
"--collect-all",
50-
"grapheme"
51-
])
52-
53-
# Remove the computed hash
54-
with open("encryptext_installer.py", "r+") as file:
55-
installer_file = file.read()
56-
installer_parts = installer_file.split(hash_str)
57-
installer_file = "INSERT COMPUTED HASH HERE".join(installer_parts)
58-
file.seek(0)
59-
file.write(installer_file)
60-
file.truncate()
61+
# Add hash and version
62+
modifyInstallerFile(True)
6163

62-
# Move the exe out of the dist folder
6364
try:
64-
remove(f"encryptext_installer_v{version}_64bit.exe")
65-
except FileNotFoundError: pass
66-
rename(path.join("dist", "encryptext_installer.exe"), f"encryptext_installer_v{version}_64bit.exe")
65+
# Creates an executable file
66+
PyInstaller.__main__.run([
67+
'encryptext_installer.py',
68+
'--onefile',
69+
'--clean',
70+
'--log-level',
71+
'ERROR',
72+
'--icon',
73+
'app_icon.ico',
74+
'--add-data',
75+
'app_icon.ico;.',
76+
'--add-data',
77+
'Encryptext.pyw;.',
78+
"--collect-all",
79+
"tkinterweb",
80+
"--collect-all",
81+
"alive_progress",
82+
"--collect-all",
83+
"grapheme"
84+
])
85+
except Exception as e:
86+
print("Stopped for:", e)
87+
88+
# Remove hash and version
89+
modifyInstallerFile(False)
90+
91+
# Remove pyinstaller folders and files
92+
rmtree("dist")
93+
rmtree("build")
94+
remove("encryptext_installer.spec")
95+
96+
exit()
97+
98+
# Remove hash and version
99+
modifyInstallerFile(False)
100+
101+
# Move the exe out of the dist folder
102+
if testing:
103+
rename(path.join("dist", "encryptext_installer.exe"), f"builds/testing/encryptext_installer_v{version}_64bit.exe")
104+
else:
105+
copy(path.join("dist", "encryptext_installer.exe"), f"builds/testing/encryptext_installer_v{version}_64bit_release.exe")
106+
version = '.'.join(version.split('.')[0:-1])
107+
rename(path.join("dist", "encryptext_installer.exe"), f"builds/release/encryptext_installer_v{version}_64bit.exe")
67108

68109
# Remove pyinstaller folders and files
69110
rmtree("dist")

0 commit comments

Comments
 (0)