File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ def get_word_count():
278278
''' Get the estimated word count '''
279279
total_words: int = 0
280280
if not validate_text():
281-
sg.PopupQuick('Enter some text to calculate the number of words.',
282-
title='Text Not Found', auto_close=False, modal=True)
281+
ShowMessageBox(title='NotepadPy+ Statistics',
282+
message='Text Not Found.\nEnter some text to calculate the number of words.')
283283
return 0
284284

285285
lines: list = VALUES['-BODY-'].splitlines()
@@ -303,8 +303,8 @@ def character_count():
303303
'''Get the total number of characters in the file.'''
304304

305305
if not validate_text():
306-
sg.PopupQuick('Enter some text to calculate the number of characters.',
307-
title='Text Not Found', auto_close=False, modal=True)
306+
ShowMessageBox(title='NotepadPy+ Statistics',
307+
message='Text Not Found.\nEnter some text to calculate the number of words.')
308308
return 0
309309

310310
chars = len(VALUES['-BODY-']) - 1
@@ -314,8 +314,8 @@ def characters_without_spaces():
314314
'''Get the total number of characters in the file.'''
315315

316316
if not validate_text():
317-
sg.PopupQuick('Enter some text to calculate the number of characters\nwithout spaces.',
318-
title='Text Not Found', auto_close=False, modal=True)
317+
ShowMessageBox(title='NotepadPy+ Statistics',
318+
message='Text Not Found.\nEnter some text to calculate the number of words.')
319319
return 0
320320

321321
chars_without_spaces: int = 0
@@ -333,8 +333,8 @@ def get_line_count():
333333
''' Get the estimated line count '''
334334

335335
if not validate_text():
336-
sg.PopupQuick('Enter some text to calculate the number of lines.',
337-
title='Text Not Found', auto_close=False, modal=True)
336+
ShowMessageBox(title='NotepadPy+ Statistics',
337+
message='Text Not Found.\nEnter some text to calculate the number of words.')
338338
return 0
339339

340340
text: str = VALUES['-BODY-']
@@ -348,11 +348,16 @@ def get_line_count():
348348
line_count: int = len(lines)
349349
return line_count
350350

351-
def about():
351+
def ShowMessageBox(title: str, message: str):
352+
'''Reusable function to show user popup.'''
353+
sg.PopupQuick(message, title=title, auto_close=False,
354+
modal=True, icon=APPLICATION_ICON)
355+
356+
def AboutNotepadPyPlus():
352357
'''About the application'''
353358

354-
sg.PopupQuick('A simple Notepad like application created using\
355-
PySimpleGUI framework.', auto_close=False, modal=True)
359+
ShowMessageBox(title='About NotepadPy+',
360+
message='A simple Notepad like application created using PySimpleGUI framework.')
356361

357362
# read the events and take appropriate actions.
358363
while True:
@@ -424,23 +429,21 @@ def about():
424429
if EVENT in ('Word Count',):
425430
WORDS = get_word_count()
426431
if WORDS != 0:
427-
sg.PopupQuick('Word Count: {:,d}'.format(WORDS), auto_close=False, modal=True)
432+
ShowMessageBox(title='NotepadPy+ Statistics', message='Word Count: {:,d}'.format(WORDS))
428433
if EVENT in ('Line Count',):
429434
LINES = get_line_count()
430435
if LINES != 0:
431-
sg.PopupQuick('Line Count: {:,d}'.format(LINES), auto_close=False, modal=True)
436+
ShowMessageBox(title='NotepadPy+ Statistics', message='Line Count: {:,d}'.format(LINES))
432437
if EVENT in ('Character With Spaces',):
433438
CHARS = character_count()
434439
if CHARS != 0:
435-
sg.PopupQuick('Characters With Spaces: {:,d}'.format(CHARS),
436-
auto_close=False, modal=True)
440+
ShowMessageBox(title='NotepadPy+ Statistics', message='Characters With Spaces: {:,d}'.format(CHARS))
437441
if EVENT in ('Character Without Spaces',):
438442
CHAR_WITHOUT_SPACES = characters_without_spaces()
439443
if CHAR_WITHOUT_SPACES != 0:
440-
sg.PopupQuick('Characters Without Spaces: {:,d}'.format(CHAR_WITHOUT_SPACES),
441-
auto_close=False, modal=True)
444+
ShowMessageBox(title='NotepadPy+ Statistics', message='Characters Without Spaces: {:,d}'.format(CHAR_WITHOUT_SPACES))
442445
if EVENT in ('About',):
443-
about()
446+
AboutNotepadPyPlus()
444447

445448
# Format Menu
446449
if EVENT in ('Font',):

0 commit comments

Comments
 (0)