Skip to content

Commit

Permalink
use Buttons_Frame
Browse files Browse the repository at this point in the history
  • Loading branch information
lversaw committed Feb 26, 2024
1 parent 0a30ca5 commit 0bb05ca
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 204 deletions.
65 changes: 24 additions & 41 deletions usfm/g_MarkParagraphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def __init__(self, parent, controller):
self.sentence_sensitive = BooleanVar(value = True)
for var in (self.model_dir, self.source_dir, self.filename):
var.trace_add("write", self._onChangeEntry)
self.columnconfigure(2, weight=1) # keep column 1 from expanding
self.columnconfigure(3, weight=1) # keep column 1 from expanding
self.columnconfigure(4, minsize=115)
self.rowconfigure(88, minsize=170, weight=1) # let the message expand vertically

model_dir_label = ttk.Label(self, text="Location of model files:", width=21)
Expand All @@ -77,14 +78,14 @@ def __init__(self, parent, controller):
model_dir__Tip = Hovertip(self.model_dir_entry, hover_delay=500,
text="Folder containing USFM files with well marked paragraphs, e.g. English UDB folder")
model_dir_find = ttk.Button(self, text="...", width=2, command=self._onFindModelDir)
model_dir_find.grid(row=3, column=4)
model_dir_find.grid(row=3, column=4, sticky=W, padx=8)

source_dir_label = ttk.Label(self, text="Location of files\n to be marked:", width=15)
source_dir_label.grid(row=4, column=1, sticky=W, pady=2)
self.source_dir_entry = ttk.Entry(self, width=43, textvariable=self.source_dir)
self.source_dir_entry.grid(row=4, column=2, columnspan=3, sticky=W)
src_dir_find = ttk.Button(self, text="...", width=2, command=self._onFindSrcDir)
src_dir_find.grid(row=4, column=4)
src_dir_find.grid(row=4, column=4, sticky=W, padx=8)

file_label = ttk.Label(self, text="File name:", width=20)
file_label.grid(row=5, column=1, sticky=W, pady=2)
Expand Down Expand Up @@ -125,34 +126,6 @@ def __init__(self, parent, controller):
ys.grid(column = 6, row = 88, sticky = 'ns')
self.message_area['yscrollcommand'] = ys.set

prev_button = ttk.Button(self, text="<<<", command=self._onBack)
prev_button.grid(row=99, column=1, sticky=(W,N,S)) #, pady=5)
prev_button_Tip = Hovertip(prev_button, hover_delay=500, text="Previous step")

self.execute_button = ttk.Button(self, text="MARK",
command=self._onExecute, padding=5)
self.execute_button['padding'] = (5, 5) # internal padding!
self.execute_button.grid(row=99, column=2, sticky=(W,N,S)) #, padx=10, pady=5)
self.execute_button_Tip = Hovertip(self.execute_button, hover_delay=500,
text="Mark paragraphs now.")

self.undo_button = ttk.Button(self, text="Undo", command=self._onUndo)
self.undo_button.grid(row=99, column=3, sticky=(W,N,S)) #, padx=0, pady=5)
self.undo_button['padding'] = (3, 3) # internal padding!
self.undo_button_Tip = Hovertip(self.undo_button, hover_delay=500,
text=f"Restore any and all .usfmorig backup files in the folder.")
self.undo_button['state'] = DISABLED
self.issues_button= ttk.Button(self, text="Open issues file", command=self._onOpenIssues)
self.issues_button.grid(row=99, column=4, sticky=(W,N,S))
self.undo_button_Tip = Hovertip(self.issues_button, hover_delay=500,
text=f"Open the issues file, which may be from the previous step!")

next_button = ttk.Button(self, text=">>>", command=self._onNext, padding=10)
next_button.grid(row=99, column=5, sticky=(N,S,E)) #, padx=0, pady=5)
next_button_Tip = Hovertip(next_button, hover_delay=500, text="Verify manifest")

# for child in parent.winfo_children():
# child.grid_configure(padx=25, pady=5)
self.model_dir_entry.focus()

def show_values(self, values):
Expand All @@ -163,14 +136,24 @@ def show_values(self, values):
self.copy_nb.set(values.get('copy_nb', fallback=False))
self.remove_s5.set(values.get('removes5markers', fallback=True))
self.sentence_sensitive.set(values.get('sentence_sensitive', fallback=True))

# Create buttons
self.controller.showbutton(1, "<<<", tip="Verify usfm", cmd=self._onBack)
self.controller.showbutton(2, "MARK", tip="Mark paragraphs now.", cmd=self._onExecute)
self.controller.showbutton(3, "Open issues file", tip="Open the issues file (which may be from the previous step).",
cmd=self._onOpenIssues)
self.controller.showbutton(4, "Undo", tip="Restore any and all .usfmorig backup files in the folder.",
cmd=self._onUndo)
self.controller.enablebutton(4, False)
self.controller.showbutton(5, ">>>", tip="Verify manifest", cmd=self._onNext)
self._set_button_status()

# Displays status messages from the running script.
def show_progress(self, status):
self.message_area.insert('end', status + '\n')
self.message_area.see('end')
self.execute_button['state'] = DISABLED
self.issues_button['state'] = DISABLED
self.controller.enablebutton(2, False)
self.controller.enablebutton(3, False)

def onScriptEnd(self, nIssues):
issuespath = os.path.join(self.values['source_dir'], "issues.txt")
Expand All @@ -179,9 +162,9 @@ def onScriptEnd(self, nIssues):
self.message_area.insert('end', "Resolve as appropriate.\n")
self.message_area.see('end')
self.message_area['state'] = DISABLED # prevents insertions to message area
self.execute_button['state'] = NORMAL
self.issues_button['state'] = NORMAL
self.undo_button['state'] = NORMAL
self.controller.enablebutton(2, True)
self.controller.enablebutton(3, True)
self.controller.enablebutton(4, True)

# Called by the controller when script execution begins.
def clear_status(self):
Expand Down Expand Up @@ -217,23 +200,23 @@ def _onOpenIssues(self, *args):
os.startfile(path)

def _onBack(self, *args):
self.undo_button['state'] = DISABLED
self.controller.enablebutton(4, False)
self._save_values()
self.controller.onBack()
def _onNext(self, *args):
self.undo_button['state'] = DISABLED
self.controller.enablebutton(4, False)
self._save_values()
self.controller.onNext()
def _onUndo(self, *args):
self._save_values()
self.controller.revertChanges()
self.undo_button['state'] = DISABLED
self.controller.enablebutton(4, False)

def _set_button_status(self):
good_model = os.path.isdir(self.model_dir.get())
good_source = os.path.isdir(self.source_dir.get())
# self.undo_button['state'] = NORMAL if good_source else DISABLED
self.controller.enablebutton(4, good_source)
if good_source and self.filename.get():
path = os.path.join(self.source_dir.get(), self.filename.get())
good_source = os.path.isfile(path)
self.execute_button['state'] = NORMAL if good_model and good_source else DISABLED
self.controller.enablebutton(2, good_model and good_source)
55 changes: 26 additions & 29 deletions usfm/g_UsfmCleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ def __init__(self, parent, controller):

source_dir_label = ttk.Label(self, text="Location of .usfm files:", width=20)
source_dir_label.grid(row=4, column=1, sticky=W, pady=2)
self.source_dir_entry = ttk.Entry(self, width=45, textvariable=self.source_dir)
self.source_dir_entry = ttk.Entry(self, width=43, textvariable=self.source_dir)
self.source_dir_entry.grid(row=4, column=2, columnspan=3, sticky=W)
src_dir_find = ttk.Button(self, text="...", width=2, command=self._onFindSrcDir)
src_dir_find.grid(row=4, column=3, sticky=E)
src_dir_find.grid(row=4, column=4, sticky=W, padx=5)

file_label = ttk.Label(self, text="File name:", width=20)
file_label.grid(row=5, column=1, sticky=W, pady=2)
self.file_entry = ttk.Entry(self, width=24, textvariable=self.filename)
self.file_entry = ttk.Entry(self, width=21, textvariable=self.filename)
self.file_entry.grid(row=5, column=2, sticky=W)
file_Tip = Hovertip(self.file_entry, hover_delay=500,
text="Leave filename blank to clean all .usfm files in the folder.")
file_find = ttk.Button(self, text="...", width=2, command=self._onFindFile)
file_find.grid(row=5, column=2, sticky=E)
file_find.grid(row=5, column=3, sticky=W, padx=3)

subheadingFont = font.Font(size=10, slant='italic') # normal size is 9
enable_label = ttk.Label(self, text="Enable these fixes?", font=subheadingFont)
Expand Down Expand Up @@ -126,45 +126,34 @@ def __init__(self, parent, controller):
ys.grid(column = 5, row = 88, sticky = 'ns')
self.message_area['yscrollcommand'] = ys.set

prev_button = ttk.Button(self, text="<<<", command=self._onBack)
prev_button.grid(row=99, column=1, sticky=(W,N,S)) #, pady=5)
prev_button_Tip = Hovertip(prev_button, hover_delay=500, text="Verify usfm")

self.execute_button = ttk.Button(self, text="CLEAN", command=self._onExecute)
self.execute_button.grid(row=99, column=2, sticky=(W,N,S)) #, padx=0, pady=5)
self.execute_button['padding'] = (5, 5) # internal padding!
self.execute_button_Tip = Hovertip(self.execute_button, hover_delay=500,
text="Run the USFM cleanup script now.")

self.undo_button = ttk.Button(self, text="Undo", command=self._onUndo)
self.undo_button_Tip = Hovertip(self.undo_button, hover_delay=500,
text=f"Restore any and all .usfm.orig backup files.")

next_button = ttk.Button(self, text=">>>", command=self._onNext)
next_button.grid(row=99, column=4, sticky=(N,S,E)) #, padx=0, pady=5)
next_button_Tip = Hovertip(next_button, hover_delay=500, text="Mark paragraphs")

def show_values(self, values):
self.values = values
self.source_dir.set(values.get('source_dir', fallback=""))
self.filename.set(values.get('filename', fallback=""))
for i in range(len(self.enable)):
configvalue = f"enable{i}"
self.enable[i].set( values.get(configvalue, fallback = False))

# Create buttons
self.controller.showbutton(1, "<<<", tip="Verify usfm", cmd=self._onBack)
self.controller.showbutton(2, "CLEAN", tip="Run the USFM cleanup script now.", cmd=self._onExecute)
self.controller.showbutton(3, "Open usfm folder", cmd=self._onOpenSourceDir)
self.controller.showbutton(4, "Undo", tip="Restore any and all .usfm.orig backup files.",
cmd=self._onUndo)
self.controller.showbutton(5, ">>>", tip="Mark paragraphs", cmd=self._onNext)
self._set_button_status()

# Displays status messages from the running script.
def show_progress(self, status):
self.message_area.insert('end', status + '\n')
self.message_area.see('end')
self.execute_button['state'] = DISABLED
self.execute_button['state'] = DISABLED
self.controller.enablebutton(2, False)

def onScriptEnd(self):
self.message_area['state'] = DISABLED # prevents insertions to message area
self.execute_button['state'] = NORMAL
self.undo_button.grid(row=99, column=3, sticky=(W,N,S)) #, padx=0, pady=5)
self.undo_button['padding'] = (5, 5) # internal padding!
self.controller.enablebutton(2, True)
nChanged = g_util.count_files(self.source_dir.get(), ".*\.usfm\.orig$")
self.controller.enablebutton(4, nChanged > 0)

# Called by the controller when script execution begins.
def clear_status(self):
Expand Down Expand Up @@ -199,25 +188,33 @@ def _onChangeEntry(self, *args):
def _onBack(self, *args):
self._save_values()
self.controller.onBack()
def _onOpenSourceDir(self, *args):
self._save_values()
os.startfile(self.values['source_dir'])
def _onUndo(self, *args):
self._save_values()
self.controller.revertChanges()
self.controller.enablebutton(4, False)
def _onNext(self, *args):
self._save_values()
self.controller.onNext()

def _onExecute(self, *args):
self._save_values()
self.controller.onExecute(self.values)

def _onOpenIssues(self, *args):
self._save_values()
path = os.path.join(self.values['source_dir'], "issues.txt")
os.startfile(path)

def _set_button_status(self):
good_source = os.path.isdir(self.source_dir.get())
self.undo_button['state'] = NORMAL if good_source else DISABLED
backup_count = g_util.count_files(self.source_dir.get(), ".*\.usfm\.orig$")
self.controller.enablebutton(3, good_source)
self.controller.enablebutton(4, backup_count > 0)

if good_source and self.filename.get():
path = os.path.join(self.source_dir.get(), self.filename.get())
good_source = os.path.isfile(path)
self.execute_button['state'] = NORMAL if good_source else DISABLED
self.controller.enablebutton(2, good_source)
24 changes: 10 additions & 14 deletions usfm/g_selectProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,27 @@ def __init__(self, parent, controller):
process4_Tip = Hovertip(process4_rb, hover_delay=500,
text="Produce a BTTW-compatible resource container from USFM.")

for col in [2,3,4]:
self.columnconfigure(col, weight=1) # keep column 1 from expanding
self.rowconfigure(88, minsize=170, weight=1) # let the message expand vertically
self.columnconfigure(1, minsize=505)
self.rowconfigure(88, minsize=150, weight=1) # let the message expand vertically

self.message_area = Text(self, height=10, width=30, wrap="word")
self.message_area = Text(self, height=10, width=60, wrap="word")
self.message_area['borderwidth'] = 2
self.message_area['relief'] = 'sunken'
self.message_area['background'] = 'grey97'
self.message_area.grid(row=88, column=1, columnspan=4, sticky='nsew', pady=6)
self.message_area.grid(row=88, column=1, sticky='nsew', pady=6)

ys = ttk.Scrollbar(self, orient = 'vertical', command = self.message_area.yview)
ys.grid(column = 5, row = 88, sticky = 'ns')
self.message_area['yscrollcommand'] = ys.set

self.next_button = ttk.Button(self, text=">>>", command=self._onNext, padding=10)
self.next_button.grid(row=99, column=4, sticky=(N,S,E)) # , padx=0, pady=5)
self.next_button_Tip = Hovertip(self.next_button, hover_delay=500, text="Begin the process you selected above.")

# Called when the frame is first activated. Populate the initial values.
def show_values(self, values):
self.values = values
self.process.set(values['selection'])
self._explain()
self.controller.showbutton(psn=5, text=">>>",
tip="Begin the process you selected above.", cmd=self._onNext)
self.controller.hidebutton(1,2,3,4)
self._set_button_status()

# Caches the current selection in self.values and calls the mainapp to save in the config file.
Expand All @@ -101,7 +99,7 @@ def _explain(self, *args):
match self.process.get():
case 'Txt2USFM':
self.message_area.insert('end',
"The “Convert text to USFM” process converts the text files generated by BTT-Writer into USFM files.\n\n\
"The “Convert text to USFM” process merges text files generated by BTT-Writer and converts them to USFM.\n\n\
It parses the manifest.json files to get the book ID and contributor names, and parses title.txt files to get the book titles. \
It creates one USFM file per book, with a proper header. \
The resulting files have standardized names, like 41-MAT.usfm and 42-MRK.usfm. \
Expand All @@ -123,7 +121,5 @@ def _explain(self, *args):
self.message_area['state'] = DISABLED # prevents editing of message area

def _set_button_status(self):
buttonstate = DISABLED
if self.process.get() in {'Txt2USFM', 'VerifyUSFM', 'Usfm2Usx'}:
buttonstate = NORMAL
self.next_button['state'] = buttonstate
okay = self.process.get() in {'Txt2USFM', 'VerifyUSFM', 'Usfm2Usx'}
self.controller.enablebutton(5, okay)
12 changes: 12 additions & 0 deletions usfm/g_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, mainframe, mainapp, stepname, title):
self.mainapp = mainapp
self.stepname = stepname
self.steptitle = title
self.buttons = mainapp.buttonsframe
self.frame = None

def show(self, values):
Expand All @@ -36,6 +37,17 @@ def onNext(self, *parms):
def onExecute(self):
pass

def showbutton(self, psn, text, tip=None, cmd=None):
self.buttons.show(psn, text, tip, cmd)
def hidebutton(self, *psns):
for psn in psns:
self.buttons.hide(psn)
def enablebutton(self, psn, enable):
if enable:
self.buttons.enable(psn)
else:
self.buttons.disable(psn)

# Called by the main app.
# Displays the specified string in the message area.
def onScriptMessage(self, progress):
Expand Down
Loading

0 comments on commit 0bb05ca

Please sign in to comment.