Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to application icon? #7

Closed
jjgalvez opened this issue Jan 23, 2019 · 9 comments
Closed

how to application icon? #7

jjgalvez opened this issue Jan 23, 2019 · 9 comments
Assignees

Comments

@jjgalvez
Copy link

How do you set the application icon? setWindowIcon does not seem to do anything

@MicBoucinha
Copy link
Collaborator

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

@jjgalvez
Copy link
Author

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?

@MicBoucinha
Copy link
Collaborator

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.

@jjgalvez
Copy link
Author

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)

@MicBoucinha
Copy link
Collaborator

MicBoucinha commented Jan 25, 2019

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.

@MicBoucinha MicBoucinha self-assigned this Jan 25, 2019
@jjgalvez
Copy link
Author

Excellent thank you!

@jjgalvez
Copy link
Author

In a similar way could you allow the use of showNormal or showMinimzed rather then showMaximized
with a setting?

@MicBoucinha
Copy link
Collaborator

You can update to the new minor version with pip right now.

@jjgalvez
Copy link
Author

Thank you this works great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants