Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e9a0a8b

Browse files
Update notepad.py
Font settings updated and implemented to select and modify font.
1 parent db9a363 commit e9a0a8b

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

‎Sample GUI Implementation/notepad.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,22 @@
1313
WINDOW_HEIGHT: int = 25
1414
FILE_NAME: str = None
1515
font_dict = {}
16-
DEFAULT_FONT_NAME: str = '@MS Gothic'
16+
DEFAULT_FONT_NAME: str = 'Times New Roman'
1717

1818
def ShowFontDialog():
1919
'''Get a font dialog to display and return all the
2020
font settings chosen to be applied to the editor.'''
2121

22+
# the font styles supported by PySimpleGUI are mentioned
23+
# @ https://github.com/PySimpleGUI/PySimpleGUI/issues/3633#issuecomment-729675676
24+
# bold, italic, underline, and overstrike. These styles can be specified as a
25+
# string like - 'overstrike underline italic'
26+
2227
wx_app = [] # pylint: disable=unused-variable
2328
wx_app = wx.App(None)
2429

30+
font_style_modifier: str = ''
31+
2532
dialog = wx.FontDialog(None, wx.FontData())
2633
if dialog.ShowModal() == wx.ID_OK:
2734
data = dialog.GetFontData()
@@ -30,33 +37,28 @@ def ShowFontDialog():
3037
font_info = font.GetNativeFontInfoUserDesc()
3138
selected_styles = shlex.split(font_info)
3239

33-
font_underlined = font.GetUnderlined()
34-
font_dict['font_underlined'] = font_underlined
40+
if 'bold' in selected_styles:
41+
font_style_modifier += 'bold '
42+
43+
if 'italic' in selected_styles:
44+
font_style_modifier += 'italic '
3545

36-
font_strikethrogh = font.GetStrikethrough()
37-
font_dict['font_strikethrogh'] = font_strikethrogh
46+
if font.GetUnderlined():
47+
font_style_modifier += 'underline '
48+
49+
if font.GetStrikethrough():
50+
font_style_modifier += 'overstrike '
3851

3952
font_color = data.GetColour()
4053
font_color = rgb2hex(font_color[0], font_color[1], font_color[2])
41-
font_dict['font_color'] = font_color
4254

4355
font_facename = font.GetFaceName()
44-
font_dict['font_facename'] = font_facename
4556

4657
font_size = font.GetPointSize()
47-
font_dict['font_size'] = font_size
48-
49-
if 'bold' in selected_styles:
50-
font_dict['font_bold'] = True
51-
else:
52-
font_dict['font_bold'] = False
5358

54-
if 'italic' in selected_styles:
55-
font_dict['font_italic'] = True
56-
else:
57-
font_dict['font_italic'] = False
59+
WINDOW['-BODY-'].update(font=(font_facename, font_size, font_style_modifier),
60+
text_color=font_color)
5861

59-
print('')
6062

6163
def rgb2hex(r, g, b):
6264
'''Convert RGB to hex values.'''
@@ -73,9 +75,9 @@ def rgb2hex(r, g, b):
7375
['&Help', ['About']]]
7476

7577
layout: list = [[sg.Menu(menu_layout)],
76-
[sg.Text('New File:', font=(DEFAULT_FONT_NAME, 10),
78+
[sg.Text('New File:', font=('Times New Roman', 10),
7779
size=(WINDOW_WIDTH, 1), key='-FILE_INFO-')],
78-
[sg.Multiline(font=(DEFAULT_FONT_NAME, 12, 'overstrike underline italic'),
80+
[sg.Multiline(font=(DEFAULT_FONT_NAME, 12),
7981
size=(WINDOW_WIDTH, WINDOW_HEIGHT), key='-BODY-')]]
8082

8183
WINDOW = sg.Window('Notepad', layout=layout, margins=(0, 0),
@@ -205,10 +207,12 @@ def about():
205207
sg.PopupQuick('A simple Notepad like application created using\
206208
PySimpleGUI framework.', auto_close=False)
207209

210+
# read the events and take appropriate actions.
208211
while True:
209212
EVENT, VALUES = WINDOW.read()
210213

211-
if EVENT in (None, 'Exit'):
214+
if EVENT in (sg.WINDOW_CLOSED, 'Exit'):
215+
# exit out of the application is close or exit clicked.
212216
break
213217
if EVENT in (file_new, 'n:78'):
214218
new_file()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /