MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / main

Function main

DemoPrograms/Demo_Emoji_Toolbar_PIL.py:161–209  ·  view source on GitHub ↗
(location=(None, None))

Source from the content-addressed store, hash-verified

159
160
161def main(location=(None, None)):
162 sg.theme('dark black')
163 window = make_toolbar(location)
164
165 while True:
166 event, values = window.read()
167 # print(event, values)
168 if event in ('Exit', sg.WIN_CLOSED):
169 break
170 elif event == 'Edit Me':
171 sg.execute_editor(__file__)
172 elif event == 'Version':
173 sg.popup_scrolled(__file__, sg.get_versions(), location=window.current_location(), keep_on_top=True, non_blocking=True)
174 elif event != sg.TIMEOUT_EVENT:
175 emoji_data = None
176 for e in all_emojis:
177 if event == e:
178 print(f'you clicked {e[0]}')
179 emoji_data = e
180 break
181 if emoji_data is None:
182 continue
183 size_index = [key for key in values.keys() if values[key]][0]
184 size = EMOJI_SIZES[size_index]
185 decoded = emoji_data[size_index + 1]
186
187 output = io.BytesIO()
188 image = PIL.Image.new("RGBA", (size, size))
189
190 win32clipboard.OpenClipboard()
191 win32clipboard.EmptyClipboard()
192
193 image.save(output, "PNG")
194 fmt = win32clipboard.RegisterClipboardFormat("PNG")
195 win32clipboard.SetClipboardData(fmt, decoded)
196
197 background = PIL.Image.new("RGB", image.size, (255, 255, 255))
198 background.paste(image, mask=image.split()[3])
199 output = io.BytesIO()
200 background.save(output, 'BMP')
201 data = output.getvalue()[14:]
202 win32clipboard.SetClipboardData(win32con.CF_DIB, data)
203
204 win32clipboard.CloseClipboard()
205 break
206 # If started in a specific location, then assume should get ONE selection then close
207 if location != (None, None):
208 break
209 window.close()
210
211
212if __name__ == '__main__':

Callers 1

Calls 6

current_locationMethod · 0.80
saveMethod · 0.80
make_toolbarFunction · 0.70
readMethod · 0.45
newMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected