how to application icon?
Closed this issue · 9 comments
How do you set the application icon? setWindowIcon does not seem to do anything
Hi,
how are you trying to create your window?
If you created using StandAloneContainer, you are able to use the setWindowIcon over it.
If that doesn't work for you, can you post here what you tried please?
Thanks
The main window is BaseWidget class, and I think created the main window with start_app. I was looking at the start_app code and it doesn't directly expose the SandAloneContainer. How should I be creating the main window?
Have you tried accessing the main window through the object that you passed to the start_app?
There, you have a property called app_main_window, which you can call the setWindowIcon over.
If you aren't able to do that, and if you can, post the code you tried please.
not really sure how to do that, it looks like app_main_window is a property of StandAloneContainer which is created inside start_app but not directly exposed. Am I missing something? The app I am trying to create is a simple app with just a couple of buttons. I'm not sure how to access the passed object. If is initiate it with mydrives=MyDrives(), mydrives.a_main_window.setWindowIcon(icon) gives an error.
Thanks for any and all help
mydrives.py
import pyforms
from pyforms.basewidget import BaseWidget
from pyforms.controls import (
ControlButton,
ControlText
)
import yaml
import subprocess
import os
from AnyQt.QtGui import QIcon
class MyDrives(BaseWidget):
def __init__(self, *args, **kwargs):
super().__init__('MyDrives')
USER = os.environ['USER']
drives = {}
drives['home'] = {
'smb': f'smb://<drive>/user/{USER}',
'mountpoint': f'{USER}',
'name': 'Home'
}
self._formset = []
for drive in drives:
self.__dict__[drive] = ControlButton('Mount ' + drives[drive]['name'])
self.__dict__['u'+drive] = ControlButton('Unmount ' + drives[drive]['name'])
self.__dict__['mount'+drive] = self.mountCallback(drives[drive])
self.__dict__[drive].value = self.__dict__['mount'+drive]
self.__dict__['unmount'+drive] = self.unmountCallback(drives[drive])
self.__dict__['u'+drive].value = self.__dict__['unmount'+drive]
self._formset.append((drive, 'u'+drive))
def mountCallback(self, drive):
def callback():
try:
subprocess.call(['osascript', '-e', 'mount volume "{}"'.format(drive['smb'])])
subprocess.call(['open', '/Volumes/{}'.format(drive['mountpoint'])])
except:
pass
return callback
def unmountCallback(self, drive):
def callback():
try:
subprocess.call(['diskutil', 'unmount', '/Volumes/{}'.format(drive['mountpoint'])])
except:
pass
return callback
if __name__ == '__main__':
icon = os.path.join(os.path.dirname(__name__), 'MapDrives.png')
from pyforms import start_app
start_app(MyDrives)
Hi,
I added the possibility to set the main window icon through a user settings file. Currently is still in the develop branch but will soon (hopefully during next week) be released with a new update on pip for pyforms-gui.
The way that afterwards you should use it is to have a file where you would put your application settings (e.g., settings.py) in your module's folder.
There you will be able to set an entry with
SETTINGS_PRIORITY = 0
PYFORMS_MAIN_WINDOW_ICON_PATH = 'path_to_your_icon_file_either_svg_or_png'
With that, your code would change to:
if __name__ == '__main__':
import settings as user_settings
from pyforms import start_app
start_app(MyDrives, user_settings=user_settings)
start_app will handle that setting if it is defined and you should be seeing your icon as expected.
Thanks for pointing this out. I will close this issue when the new release is out.
Edited: The code to get the icon path setting so the use will be simpler.
Excellent thank you!
In a similar way could you allow the use of showNormal or showMinimzed rather then showMaximized
with a setting?
You can update to the new minor version with pip right now.
Thank you this works great