Giter Site home page Giter Site logo

Comments (9)

MicBoucinha avatar MicBoucinha commented on September 4, 2024

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

from pyforms-gui.

jjgalvez avatar jjgalvez commented on September 4, 2024

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?

from pyforms-gui.

MicBoucinha avatar MicBoucinha commented on September 4, 2024

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.

from pyforms-gui.

jjgalvez avatar jjgalvez commented on September 4, 2024

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)

from pyforms-gui.

MicBoucinha avatar MicBoucinha commented on September 4, 2024

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.

from pyforms-gui.

jjgalvez avatar jjgalvez commented on September 4, 2024

Excellent thank you!

from pyforms-gui.

jjgalvez avatar jjgalvez commented on September 4, 2024

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

from pyforms-gui.

MicBoucinha avatar MicBoucinha commented on September 4, 2024

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

from pyforms-gui.

jjgalvez avatar jjgalvez commented on September 4, 2024

Thank you this works great

from pyforms-gui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.