Resizable, new icon, preparing for application release
This commit is contained in:
parent
cfde122fb0
commit
1b5e94675e
|
@ -5,6 +5,24 @@ import pyfiglet
|
|||
"""
|
||||
Demo pyfiglet integration
|
||||
|
||||
'##:::::'##:'##::::'##::::'###::::'########::::'####::'######::
|
||||
##:'##: ##: ##:::: ##:::'## ##:::... ##..:::::. ##::'##... ##:
|
||||
##: ##: ##: ##:::: ##::'##:. ##::::: ##:::::::: ##:: ##:::..::
|
||||
##: ##: ##: #########:'##:::. ##:::: ##:::::::: ##::. ######::
|
||||
##: ##: ##: ##.... ##: #########:::: ##:::::::: ##:::..... ##:
|
||||
##: ##: ##: ##:::: ##: ##.... ##:::: ##:::::::: ##::'##::: ##:
|
||||
. ###. ###:: ##:::: ##: ##:::: ##:::: ##:::::::'####:. ######::
|
||||
:...::...:::..:::::..::..:::::..:::::..::::::::....:::......:::
|
||||
:::'###:::::::'########:'####::'######:::'##:::::::'########:'########::'#######::
|
||||
::'## ##:::::: ##.....::. ##::'##... ##:: ##::::::: ##.....::... ##..::'##.... ##:
|
||||
:'##:. ##::::: ##:::::::: ##:: ##:::..::: ##::::::: ##:::::::::: ##::::..:::: ##::
|
||||
'##:::. ##:::: ######:::: ##:: ##::'####: ##::::::: ######:::::: ##:::::::: ###:::
|
||||
#########:::: ##...::::: ##:: ##::: ##:: ##::::::: ##...::::::: ##::::::: ##.::::
|
||||
##.... ##:::: ##:::::::: ##:: ##::: ##:: ##::::::: ##:::::::::: ##:::::::..::::::
|
||||
##:::: ##:::: ##:::::::'####:. ######::: ########: ########:::: ##:::::::'##:::::
|
||||
..:::::..:::::..::::::::....:::......::::........::........:::::..::::::::..::::::
|
||||
|
||||
|
||||
Adapted from code originally from this fantastic repository:
|
||||
https://github.com/nycynik/ascii-font-processor
|
||||
Thank you nycynik for a fantastic headstart
|
||||
|
@ -17,23 +35,64 @@ import pyfiglet
|
|||
will use the new size of the Multiline element to compute the numiber of characters
|
||||
wide the Multiline has to work with. This number is passed to the figlet renderer.
|
||||
|
||||
|
||||
____________________________________
|
||||
______
|
||||
/ / , ,
|
||||
---/------/__-------__-----------__-
|
||||
/ / ) / (_ ` / (_ `
|
||||
_/______/___/_/___(__)_____/___(__)_
|
||||
|
||||
|
||||
___________________________________________________________
|
||||
_____ __ __ _ _____ ______
|
||||
/ ' / / ) / / ' /
|
||||
----__-------/__--------/----/--------/------/__------/----
|
||||
/ ) / / / --, / / /
|
||||
_(___(_____/________ _/_ __(____/___/____/_/____ ___/______
|
||||
|
||||
|
||||
|
||||
Copyright 2021 PySimpleGUI
|
||||
"""
|
||||
|
||||
|
||||
DEFAULT_FONT = 'nancyj-fancy'
|
||||
|
||||
def change_theme(location):
|
||||
layout = [[sg.Text(f'Current theme {sg.theme()}')],
|
||||
[sg.Listbox(values=sg.theme_list(), size=(20, 20), key='-LIST-', enable_events=True)],
|
||||
[sg.OK(), sg.Cancel()]]
|
||||
|
||||
window = sg.Window('Look and Feel Browser', layout, location=location, keep_on_top=True)
|
||||
while True: # Event Loop
|
||||
event, values = window.read()
|
||||
if event in (sg.WIN_CLOSED, 'Exit', 'OK', 'Cancel'):
|
||||
break
|
||||
window.close()
|
||||
|
||||
if event == 'OK' and values['-LIST-']:
|
||||
sg.theme(values['-LIST-'][0])
|
||||
sg.user_settings_set_entry('-theme-', values['-LIST-'][0])
|
||||
return values['-LIST-'][0]
|
||||
return None
|
||||
|
||||
|
||||
|
||||
def draw_text(font, text, width=80):
|
||||
"""Simple wrapper for the main draw function"""
|
||||
|
||||
return pyfiglet.Figlet(font=font, width=width).renderText(text)
|
||||
|
||||
def main():
|
||||
selected_font = 'computer'
|
||||
def make_window():
|
||||
selected_font = DEFAULT_FONT
|
||||
LINE_LENGTH = 100
|
||||
MULTILINE_FONT = ('Courier', 12)
|
||||
fonts = pyfiglet.FigletFont.getFonts()
|
||||
sg.theme_background_color(sg.theme_input_background_color())
|
||||
sg.theme_text_element_background_color(sg.theme_input_background_color())
|
||||
column_left = [[sg.Table(headings=['Font Name'], values=fonts, key='-FONT-LIST-',
|
||||
col_widths=[40], num_rows=30, enable_events=True), sg.VerticalSeparator(pad=((5, 5), 0))]]
|
||||
|
||||
try:
|
||||
mline_input = sg.Multiline('PySimpleGUI', size=(40,3), key='-TEXT-TO-SHOW-', no_scrollbar=True, enable_events=True, focus=True)
|
||||
except Exception as e:
|
||||
|
@ -41,15 +100,27 @@ def main():
|
|||
|
||||
column_right = [[sg.Text("Font Name:", size=(10,1)), sg.Input(selected_font, size=(12,1), key='-FONT-NAME-')],
|
||||
[sg.Text("Text:", size=(10,1)), mline_input, sg.T('Font size for display below'), sg.Combo(list(range(4,20)), 12, enable_events=True, k='-FONT-SIZE-')],
|
||||
[sg.Multiline(size=(LINE_LENGTH, 20), key='-OUTPUT-', font=MULTILINE_FONT)],]
|
||||
[sg.Multiline(size=(LINE_LENGTH, 20), key='-OUTPUT-', border_width=0, font=MULTILINE_FONT, expand_x=True, expand_y=True, pad=(40,40), )],
|
||||
[sg.B('Copy to Clipboard'), sg.B('Change Theme')],]
|
||||
|
||||
layout = [[sg.Column(column_left), sg.Column(column_right, expand_x=True, expand_y=True)],
|
||||
[sg.Button('Exit'), sg.T('PySimpleGUI ver ' + sg.version.split(' ')[0] + ' tkinter ver ' + sg.tclversion_detailed + ' Python ver ' + sys.version, font='Default 8', pad=(0,0))],]
|
||||
layout = [[sg.Column(column_left, expand_y=False, expand_x=False), sg.Column(column_right, expand_x=False, expand_y=False,k='-COL R-')],
|
||||
[sg.Button('Exit', right_click_menu=sg.MENU_RIGHT_CLICK_DISABLED), sg.T('PySimpleGUI ver ' + sg.version.split(' ')[0] + ' tkinter ver ' + sg.tclversion_detailed + ' Python ver ' + sys.version, font='Default 8', pad=(0,0))],]
|
||||
layout[-1].append(sg.Sizegrip())
|
||||
|
||||
window = sg.Window('Figlet-Me', layout, resizable=True, finalize=True, right_click_menu=['_', ['Edit Me']])
|
||||
window = sg.Window('psg-figlet', layout, resizable=True, finalize=True, right_click_menu=['_', ['Edit Me', 'Copy', 'Exit']], icon=icon)
|
||||
|
||||
window['-OUTPUT-'].expand(True, True, expand_row=True)
|
||||
window['-COL R-'].expand(True, True, True)
|
||||
# window['-OUTPUT-'].expand(True, True, False)
|
||||
# window['-FONT-LIST-'].expand(False, False, False)
|
||||
window['-OUTPUT-'].update(draw_text(selected_font, 'PySimpleGUI').strip())
|
||||
return window
|
||||
|
||||
def main():
|
||||
window = make_window()
|
||||
selected_font = DEFAULT_FONT
|
||||
LINE_LENGTH = 100
|
||||
MULTILINE_FONT = ('Courier', 12)
|
||||
fonts = pyfiglet.FigletFont.getFonts()
|
||||
|
||||
while True: # Event Loop
|
||||
event, values = window.read()
|
||||
|
@ -74,8 +145,20 @@ def main():
|
|||
# line_length = window["-OUTPUT-"].get_size()[0] // sg.Text.char_width_in_pixels(MULTILINE_FONT)
|
||||
line_length = window["-OUTPUT-"].get_size()[0] // sg.tkinter.font.Font(font=MULTILINE_FONT).measure('A')
|
||||
window['-OUTPUT-'].update(draw_text(selected_font, text, line_length).rstrip())
|
||||
|
||||
if event.startswith('Copy'):
|
||||
sg.clipboard_set(window['-OUTPUT-'].get())
|
||||
elif event == 'Change Theme':
|
||||
if change_theme(window.current_location()):
|
||||
window.close()
|
||||
window = make_window()
|
||||
window.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
# sg.theme('Dark red')
|
||||
sg.theme(sg.user_settings_get_entry('-theme-', sg.theme()))
|
||||
# sg.theme('Dark Gray 13')
|
||||
# sg.theme_input_background_color('#36393F')
|
||||
# sg.theme_background_color('#36393F')
|
||||
# sg.theme_input_text_color('white')
|
||||
icon = b'iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAMAAAC5zwKfAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAH+UExURf/YAL2gAJB5AMysAP7XAG5dAAAAAAcFAEM4AHxpAPHMALKWACUfABQQAJiAAH9rAEA2AMurAO7JAFJFAMqrACQeACMdALWZAAsJAPbQAKGIAMipAKKJAJqCALebAGtaAAo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