|
20 | 20 | CURRENT_WORKING_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
|
21 | 21 | APPLICATION_ICON = CURRENT_WORKING_DIRECTORY + '\\notepad.ico'
|
22 | 22 |
|
| 23 | +# toggle the status bar. |
| 24 | +STATUS_BAR_SWITCH = False |
| 25 | + |
23 | 26 | # change the default theme.
|
24 | 27 | sg.theme('dark grey 9')
|
25 | 28 |
|
|
35 | 38 | # we do not want to display the prompt for save changes.
|
36 | 39 | text_last_saved_manually: str = ''
|
37 | 40 |
|
| 41 | +Line: int = 1 |
| 42 | +Column: int = 1 |
| 43 | + |
38 | 44 |
|
39 | 45 | # initialize the print data and set some default values
|
40 | 46 | pdata = wx.PrintData()
|
@@ -160,30 +166,47 @@ def rgb2hex(r, g, b):
|
160 | 166 | edit_delete: str = 'Delete Del'
|
161 | 167 |
|
162 | 168 |
|
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']], |
164 | 170 | ['&Edit', [edit_cut, edit_copy, edit_paste, edit_delete]],
|
165 | 171 | ['&Statistics', ['Word Count', 'Line Count', 'Character With Spaces', 'Character Without Spaces', ]],
|
166 | 172 | ['F&ormat', ['Font', ]],
|
| 173 | +['&View', ['Hide Status Bar', ]], |
167 | 174 | ['&Help', ['About']]]
|
168 | 175 |
|
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], |
170 | 187 | [sg.Text('New File:', font=('Times New Roman', 10),
|
171 | 188 | size=(WINDOW_WIDTH, 1), key='-FILE_INFO-', visible=False)],
|
172 | 189 | [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')]] |
174 | 195 |
|
175 | 196 | 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) |
177 | 199 |
|
178 | 200 | # 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 |
180 | 202 | # the text is not saved before closing.
|
181 | 203 | # more details @ https://.com/PySimpleGUI/PySimpleGUI/issues/3650
|
182 | 204 | WINDOW.TKroot.protocol("WM_DESTROY_WINDOW", lambda:WINDOW.write_event_value("WIN_CLOSE", ()))
|
183 | 205 | WINDOW.TKroot.protocol("WM_DELETE_WINDOW", lambda:WINDOW.write_event_value("WIN_CLOSE", ()))
|
184 | 206 |
|
185 | 207 | WINDOW.read(timeout=1)
|
186 | 208 | WINDOW.maximize()
|
| 209 | +WINDOW['status_bar'].ParentRowFrame.pack(fill='x') |
187 | 210 | WINDOW['-BODY-'].expand(expand_x=True, expand_y=True)
|
188 | 211 |
|
189 | 212 | def new_file() -> str:
|
@@ -420,6 +443,28 @@ def about():
|
420 | 443 | if EVENT in ('Font',):
|
421 | 444 | ShowFontDialog()
|
422 | 445 |
|
| 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 | + |
423 | 468 | # record the text after each event to ensure the
|
424 | 469 | # file/text is saved.
|
425 | 470 | try:
|
|
0 commit comments