File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
CURRENT_WORKING_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
2121
APPLICATION_ICON = CURRENT_WORKING_DIRECTORY + '\\notepad.ico'
2222

23+
# toggle the status bar.
24+
STATUS_BAR_SWITCH = False
25+
2326
# change the default theme.
2427
sg.theme('dark grey 9')
2528

@@ -35,6 +38,9 @@
3538
# we do not want to display the prompt for save changes.
3639
text_last_saved_manually: str = ''
3740

41+
Line: int = 1
42+
Column: int = 1
43+
3844

3945
# initialize the print data and set some default values
4046
pdata = wx.PrintData()
@@ -160,30 +166,47 @@ def rgb2hex(r, g, b):
160166
edit_delete: str = 'Delete Del'
161167

162168

163-
menu_layout: list = [['&File', [file_new, file_open, file_save, 'Save As', '______________________', 'Page Setup', file_print, '______________________', 'Exit']],
169+
hide_status_menu_layout: list = [['&File', [file_new, file_open, file_save, 'Save As', '______________________', 'Page Setup', file_print, '______________________', 'Exit']],
164170
['&Edit', [edit_cut, edit_copy, edit_paste, edit_delete]],
165171
['&Statistics', ['Word Count', 'Line Count', 'Character With Spaces', 'Character Without Spaces', ]],
166172
['F&ormat', ['Font', ]],
173+
['&View', ['Hide Status Bar', ]],
167174
['&Help', ['About']]]
168175

169-
layout: list = [[sg.Menu(menu_layout)],
176+
show_status_menu_layout: list = [['&File', [file_new, file_open, file_save, 'Save As', '______________________', 'Page Setup', file_print, '______________________', 'Exit']],
177+
['&Edit', [edit_cut, edit_copy, edit_paste, edit_delete]],
178+
['&Statistics', ['Word Count', 'Line Count', 'Character With Spaces', 'Character Without Spaces', ]],
179+
['F&ormat', ['Font', ]],
180+
['&View', ['Show Status Bar', ]],
181+
['&Help', ['About']]]
182+
183+
# Define and Create the menu layouts independently so as to
184+
# toggle between Show/Hide the applicationstatus bar.
185+
WINDOW_MENU = sg.Menu(hide_status_menu_layout)
186+
layout: list = [[WINDOW_MENU],
170187
[sg.Text('New File:', font=('Times New Roman', 10),
171188
size=(WINDOW_WIDTH, 1), key='-FILE_INFO-', visible=False)],
172189
[sg.Multiline(font=(DEFAULT_FONT_NAME, 12),
173-
size=(WINDOW_WIDTH, WINDOW_HEIGHT), key='-BODY-', reroute_cprint=True)]]
190+
size=(WINDOW_WIDTH, WINDOW_HEIGHT),
191+
key='-BODY-', reroute_cprint=True, enable_events=True)],
192+
[sg.StatusBar(text=f'| Ln{Line},Col{Column}', size=(WINDOW_WIDTH, 1),
193+
pad=(0, 0), text_color='white', relief=sg.RELIEF_FLAT,
194+
justification='right', visible=True, key='status_bar')]]
174195

175196
WINDOW = sg.Window('untitled - ' + APP_NAME, layout=layout, margins=(0, 0),
176-
resizable=True, return_keyboard_events=True, icon=APPLICATION_ICON, finalize=True)
197+
resizable=True, return_keyboard_events=True,
198+
icon=APPLICATION_ICON, finalize=True)
177199

178200
# redefine the callback for window close button by using tkinter code.
179-
# this is required to delay the event of closing the main window incase
201+
# this is required to delay the event of closing the main window incase
180202
# the text is not saved before closing.
181203
# more details @ https://.com/PySimpleGUI/PySimpleGUI/issues/3650
182204
WINDOW.TKroot.protocol("WM_DESTROY_WINDOW", lambda:WINDOW.write_event_value("WIN_CLOSE", ()))
183205
WINDOW.TKroot.protocol("WM_DELETE_WINDOW", lambda:WINDOW.write_event_value("WIN_CLOSE", ()))
184206

185207
WINDOW.read(timeout=1)
186208
WINDOW.maximize()
209+
WINDOW['status_bar'].ParentRowFrame.pack(fill='x')
187210
WINDOW['-BODY-'].expand(expand_x=True, expand_y=True)
188211

189212
def new_file() -> str:
@@ -420,6 +443,28 @@ def about():
420443
if EVENT in ('Font',):
421444
ShowFontDialog()
422445

446+
# Show/Hide Status Bar.
447+
if EVENT in ('Hide Status Bar', 'Show Status Bar'):
448+
if STATUS_BAR_SWITCH:
449+
WINDOW['status_bar'].ParentRowFrame.pack(fill='x')
450+
WINDOW['status_bar'].update(visible=True)
451+
WINDOW['status_bar'].Widget.pack(fill='x')
452+
453+
# Re-design the menu layout to show the updated
454+
# toggle effect for show/hide status bar button.
455+
# Supporting Conversation @ https://.com/PySimpleGUI/PySimpleGUI/issues/1510
456+
WINDOW_MENU.Update(hide_status_menu_layout)
457+
STATUS_BAR_SWITCH = False
458+
else:
459+
WINDOW['status_bar'].update(visible=False)
460+
WINDOW['status_bar'].ParentRowFrame.pack_forget()
461+
462+
# Re-design the menu layout to show the updated
463+
# toggle effect for show/hide status bar button.
464+
# Supporting Conversation @ https://.com/PySimpleGUI/PySimpleGUI/issues/1510
465+
WINDOW_MENU.Update(show_status_menu_layout)
466+
STATUS_BAR_SWITCH = True
467+
423468
# record the text after each event to ensure the
424469
# file/text is saved.
425470
try:

0 commit comments

Comments
 (0)