@@ -278,8 +278,8 @@ def get_word_count():
|
278 | 278 | ''' Get the estimated word count '''
|
279 | 279 | total_words: int = 0
|
280 | 280 | 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.') |
283 | 283 | return 0
|
284 | 284 |
|
285 | 285 | lines: list = VALUES['-BODY-'].splitlines()
|
@@ -303,8 +303,8 @@ def character_count():
|
303 | 303 | '''Get the total number of characters in the file.'''
|
304 | 304 |
|
305 | 305 | 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.') |
308 | 308 | return 0
|
309 | 309 |
|
310 | 310 | chars = len(VALUES['-BODY-']) - 1
|
@@ -314,8 +314,8 @@ def characters_without_spaces():
|
314 | 314 | '''Get the total number of characters in the file.'''
|
315 | 315 |
|
316 | 316 | 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.') |
319 | 319 | return 0
|
320 | 320 |
|
321 | 321 | chars_without_spaces: int = 0
|
@@ -333,8 +333,8 @@ def get_line_count():
|
333 | 333 | ''' Get the estimated line count '''
|
334 | 334 |
|
335 | 335 | 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.') |
338 | 338 | return 0
|
339 | 339 |
|
340 | 340 | text: str = VALUES['-BODY-']
|
@@ -348,11 +348,16 @@ def get_line_count():
|
348 | 348 | line_count: int = len(lines)
|
349 | 349 | return line_count
|
350 | 350 |
|
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(): |
352 | 357 | '''About the application'''
|
353 | 358 |
|
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.') |
356 | 361 |
|
357 | 362 | # read the events and take appropriate actions.
|
358 | 363 | while True:
|
@@ -424,23 +429,21 @@ def about():
|
424 | 429 | if EVENT in ('Word Count',):
|
425 | 430 | WORDS = get_word_count()
|
426 | 431 | 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)) |
428 | 433 | if EVENT in ('Line Count',):
|
429 | 434 | LINES = get_line_count()
|
430 | 435 | 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)) |
432 | 437 | if EVENT in ('Character With Spaces',):
|
433 | 438 | CHARS = character_count()
|
434 | 439 | 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)) |
437 | 441 | if EVENT in ('Character Without Spaces',):
|
438 | 442 | CHAR_WITHOUT_SPACES = characters_without_spaces()
|
439 | 443 | 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)) |
442 | 445 | if EVENT in ('About',):
|
443 |
| -about() |
| 446 | +AboutNotepadPyPlus() |
444 | 447 |
|
445 | 448 | # Format Menu
|
446 | 449 | if EVENT in ('Font',):
|
|
0 commit comments