User Tools

Site Tools


python:systray

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
python:systray [2023/01/30 12:12] Wulf Rajekpython:systray [2023/05/29 11:55] (current) – external edit 127.0.0.1
Line 41: Line 41:
         pass         pass
  
 +    icon.visible = False
     python = sys.executable     python = sys.executable
     os.execl(python, python, *sys.argv)     os.execl(python, python, *sys.argv)
     #os.execv(sys.executable, ['python'] + sys.argv)     #os.execv(sys.executable, ['python'] + sys.argv)
  
-def action_exit(): +def action_quit(): 
-    sys.exit()+    icon.visible = False 
 +    print("Exiting application"
 +    os._exit(0)
  
 def launch(): def launch():
Line 55: Line 58:
     pass     pass
  
-image = Image.open("systray-icon.png")+def resource_path(relative_path): 
 +    try: 
 +        base_path = sys._MEIPASS 
 +    except Exception: 
 +        base_path = os.path.abspath("."
 + 
 +    return os.path.join(base_path, relative_path) 
 + 
 +image = Image.open(resource_path("systrayicon.png"))
 #icon = pystray.Icon(name ="just text", icon =image, title ="Other Text", menu =None) #icon = pystray.Icon(name ="just text", icon =image, title ="Other Text", menu =None)
-menu = (item('name', action), item('Restart', action_restart), item('Exit', action_exit))+menu = (item('name', action), item('Restart', action_restart), item('Exit', action_quit))
 icon = icon("name", image, "title", menu) icon = icon("name", image, "title", menu)
  
Line 66: Line 77:
  
 icon.run(run_call) icon.run(run_call)
 +</code>
 +
 +Create version file using:
 +<code>
 +pip install pyinstaller_versionfile
 +</code>
 +
 +<code>
 +import pyinstaller_versionfile
 +
 +pyinstaller_versionfile.create_versionfile(
 +    output_file="version.txt",
 +    version="1.2.3.4",
 +    company_name="My Imaginary Company",
 +    file_description="Simple App",
 +    internal_name="Simple App",
 +    legal_copyright="© My Imaginary Company. All rights reserved.",
 +    original_filename="SimpleApp.exe",
 +    product_name="Simple App"
 +)
 +</code>
 +
 +To build as single file with additional data like images, the resource_path function needs to be included and pyinstaller needs to use the --add-data option. On Windows a semicolon is required, on linux a colon works.
 +<code>
 +wine pyinstaller.exe --onefile --icon=systrayicon.ico --add-data "systrayicon.png;." --version-file=version.txt systraytest.py
 +</code>
 +
 +Pyinstaller options:
 +<code>
 +--onefile: Creates a single file. Synonyms: -F
 +--windowed: Ensures that no console is opened during execution. Synonyms: -w and --noconsole
 +--add-data: adds data to the file using "source:target" or "source;target"
 +--version: adds exe file version information
 +--icon: adds windows application icon file
 </code> </code>
python/systray.1675080736.txt.gz · Last modified: 2023/05/29 11:53 (external edit)