Permalink
Browse files

Floating toolbar demo

  • Loading branch information...
MikeTheWatchGuy committed Oct 13, 2018
1 parent 4b8d6ff commit 72a248314d6b48a744b6d4ec590db289d581fce8
@@ -0,0 +1,38 @@
#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg

import os

BUTTON_PATH = '.'
button_names = ('close', 'cookbook', 'cpu', 'github', 'pysimplegui', 'run', 'storage', 'timer', 'checkmark', 'camera', 'house', 'download')


def ShowMeTheButtons():
button_files = [os.path.join(BUTTON_PATH, b+'.png') for b in button_names]

sg.SetOptions(auto_size_buttons=True, margins=(0,0), button_color=sg.COLOR_SYSTEM_DEFAULT)

toolbar_buttons = [[sg.RButton('{}'.format(button_names[i]), image_size=(32,32), image_filename=f, pad=(0,0), tooltip=button_names[i]) for i, f in enumerate(button_files)],]

layout = [[sg.Frame('', toolbar_buttons,)]]

form = sg.FlexForm('Toolbar',
no_titlebar=True,
grab_anywhere=True,
background_color='grey76',
keep_on_top=True,
).Layout(layout)

# ---===--- Loop taking in user input --- #
while True:
button, value = form.Read()
print(button)
if button == 'close' or button is None:
break # exit button clicked

if __name__ == '__main__':
ShowMeTheButtons()
@@ -0,0 +1,79 @@
#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg

import io
from PIL import Image
import base64
import subprocess

button_names = ('close', 'cookbook', 'cpu', 'github', 'pysimplegui', 'run', 'storage', 'timer')


house64='iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAAsSAAALEgHS3X78AAAHPklEQVRYhbVXbUxb1xl+zjn30/a9/gBsbBwCBhPAUD4W2pClSZM0TemkdZPaSf0RTfszTZv2o1qzqmqiaL82salSqzZptVVqqmRV1dEssERKxJKxLAWajEYkAcxXyoBg4xgcY8AY23c/+EgwNiTRdqTz557zPOd5n/Oe95wLPGFzOp24fPp0yeTJk4cbjxzJelIe9qTA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8XY3euo4SUXJkAFyvtEbdc+CsDn2r3Ifrrz3nHvW7Pftzy/kmxdhSCly2Qlmj66Xf88dB2qP6LRme+jauuo67rIDyvHMN4i1esmvlK6QIUTrEISbKxDnDlPkk2BK6VIDhXXaddP6Vk0H6A9wSUn0WKFn2lCgiYbDEmFVXJYjWOuU1LcHudgAASSLS0FnD4dV4TksYxNEOqsMDwgAAxELToSFZFfGaiVWzGNV6MWM4Uyc5OE8wQCr2AqwmxIuoJowX3k5CjZSd6vvxhqcBj921Fc2g8C2Mwzf5sax7zNZZjSdkcCg6/EEgacAYzlLZvRk1kW7rm39iELwZHsgLPATN311rqb7trG+65dT2FXTEg4o1NoDinZKOYQ8ICFo4ADwMJpEwBDrnKIU+YMqZQ0pAbC4QwODwCf0Rd/BQ4IATagM46oI+CeiNPPVS40EDF6M/pJ78Ap+n0PL8Cp7sGs9asgQSFDLxBmKJ6STKBVSbcZsa10gKcJHi/Hv0PWqbBbaFH/AEAAAAASUVORK5CYII='


def ExecuteCommandSubprocess(command, *args, wait=False):
# try:
if sys.platform == 'linux':
arg_string = ''
for arg in args:
arg_string += ' ' + str(arg)
sp = subprocess.Popen(['python3' + arg_string, ], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
else:
expanded_args = []
for a in args:
expanded_args += a
sp = subprocess.Popen([command, expanded_args], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if wait:
out, err = sp.communicate()
if out:
print(out.decode("utf-8"))
if err:
print(err.decode("utf-8"))
# except: pass


def get_image_bytes(image64):
image_file = io.BytesIO(base64.b64decode(image64))
img = Image.open(image_file)
bio = io.BytesIO()
img.save(bio, format='PNG')
imgbytes = bio.getvalue()
return imgbytes

def ShowMeTheButtons():

sg.SetOptions(auto_size_buttons=True, margins=(0,0), button_color=sg.COLOR_SYSTEM_DEFAULT)

toolbar_buttons = [[sg.RButton('', image_data=get_image_bytes(close64),button_color=('white', 'black'), pad=(0,0), key='_close_'),
sg.RButton('', image_data=get_image_bytes(timer64), button_color=('white', 'black'), pad=(0, 0), key='_timer_'),
sg.RButton('', image_data=get_image_bytes(house64), button_color=('white', 'black'), pad=(0, 0), key='_house_'),
]]

# layout = toolbar_buttons
layout = [[sg.Frame('Launcher', toolbar_buttons,title_color='white', background_color='black')]]

window = sg.Window('Toolbar', no_titlebar=True, grab_anywhere=True, background_color='black').Layout(layout)

# ---===--- Loop taking in user input --- #
while True:
button, value = window.Read()
print(button)
if button == '_close_' or button is None:
break # exit button clicked
elif button == '_timer_':
pass # add your call to launch a timer program
elif button == '_cpu_':
pass # add your call to launch a CPU measuring utility
if __name__ == '__main__':
ShowMeTheButtons()

@@ -0,0 +1,27 @@
import PySimpleGUI as sg
import os

BUTTON_PATH = 'C:/Python/PycharmProjects/GooeyGUI/ButtonGraphics/Good ones/For toolbar'
button_names = ('close', 'cookbook', 'cpu', 'github', 'pysimplegui', 'run', 'storage', 'timer')


def ShowMeTheButtons():
button_files = [os.path.join(BUTTON_PATH, b+'.png') for b in button_names]

sg.SetOptions(auto_size_buttons=True, margins=(0,0), button_color=sg.COLOR_SYSTEM_DEFAULT)

toolbar_buttons = [[sg.RButton('{}'.format(button_names[i]), image_size=(32,32), image_filename=f, pad=(0,0), tooltip=button_names[i]) for i, f in enumerate(button_files)],]

layout = [[sg.Frame('', toolbar_buttons)]]

form = sg.FlexForm('Toolbar', no_titlebar=True).Layout(layout)

# ---===--- Loop taking in user input --- #
while True:
button, value = form.Read()
print(button)
if button == 'close' or button is None:
break # exit button clicked

if __name__ == '__main__':
ShowMeTheButtons()
Binary file not shown.
Binary file not shown.
BIN +1.12 KB Demo_Toolbar/close.png
Binary file not shown.
BIN +979 Bytes Demo_Toolbar/cookbook.png
Binary file not shown.
BIN +1.53 KB Demo_Toolbar/cpu.png
Binary file not shown.
Binary file not shown.
BIN +535 Bytes Demo_Toolbar/github.png
Binary file not shown.
BIN +1.89 KB Demo_Toolbar/house.png
Binary file not shown.
Binary file not shown.
BIN +772 Bytes Demo_Toolbar/run.png
Binary file not shown.
BIN +879 Bytes Demo_Toolbar/storage.png
Binary file not shown.
BIN +2.34 KB Demo_Toolbar/timer.png
Binary file not shown.

0 comments on commit 72a2483

Please sign in to comment.