Jump to content


Photo

Changing the size and position of the Screen/Widget after creation


  • Please log in to reply
6 replies to this topic

#1 JasonM8

  • Senior Member
  • 55 posts

0
Neutral

Posted 4 July 2018 - 17:07

Hello. Is it possible to change the position and size of the screen/widget after it has been created? I am controlling position and size with self.skin variable, but it appears that this is only read during creation.

 

I tried examining screen and widget members, and found Screen.instance.size().setWidth method, but self.instance.size().setWidth(800) did not have any effect.


Edited by JasonM8, 4 July 2018 - 17:08.


Re: Changing the size and position of the Screen/Widget after creation #2 ims

  • PLi® Core member
  • 9,729 posts

+157
Excellent

Posted 4 July 2018 - 19:05

size::

wsize = (x , y)
self.instance.resize(eSize(*wsize))

position:

wx = ...
wy = ...
self.instance.move(ePoint(wx,wy))

both use f.eg. in resize and call it as:

self.onLayoutFinish.append(self.resize)

Kdo nic nedělá, nic nezkazí!

Re: Changing the size and position of the Screen/Widget after creation #3 bumperbee

  • Senior Member
  • 248 posts

+6
Neutral

Posted 5 July 2018 - 04:18

Hi Jason M8, please tell me where is this file located. Thanks



Re: Changing the size and position of the Screen/Widget after creation #4 JasonM8

  • Senior Member
  • 55 posts

0
Neutral

Posted 5 July 2018 - 13:24

 

size::

wsize = (x , y)
self.instance.resize(eSize(*wsize))

position:

wx = ...
wy = ...
self.instance.move(ePoint(wx,wy))

both use f.eg. in resize and call it as:

self.onLayoutFinish.append(self.resize)

 

That worked, thanks.



Re: Changing the size and position of the Screen/Widget after creation #5 JasonM8

  • Senior Member
  • 55 posts

0
Neutral

Posted 5 July 2018 - 13:50

Hi Jason M8, please tell me where is this file located. Thanks

 

I don't have code online yet, but here is a working minimal class definition that randomly sets position of the window:

class ScreenExample(Screen):
    skin = """
    <screen position="0,0" size="400,300" title="Screen example" >
    </screen>"""

    def __init__(self, session):
        self["actions"] = ActionMap(["OkCancelActions"],
                                    {
                                        "cancel": self.close,
                                    }, -1)
        Screen.__init__(self, session)
        self.onLayoutFinish.append(self.layoutFinished)

    def layoutFinished(self):
        x = randrange(0, 1000)
        y = randrange(100, 500)
        self.move(x, y)

    def move(self, x, y):
        self.instance.move(ePoint(x, y))

    def resize(self, width, height):
        self.instance.resize(eSize(width, height))

Edited by JasonM8, 5 July 2018 - 13:55.


Re: Changing the size and position of the Screen/Widget after creation #6 bumperbee

  • Senior Member
  • 248 posts

+6
Neutral

Posted 6 July 2018 - 05:05

ok, thanks JasonM8



Re: Changing the size and position of the Screen/Widget after creation #7 JasonM8

  • Senior Member
  • 55 posts

0
Neutral

Posted 7 July 2018 - 12:11

Why am I getting this exception if I pass lambda instead of a method name to self.onLayoutFinish.append? For testing purposes I just called method in lambda.

self.onLayoutFinish.append(self.randomPosition)             # works
self.onLayoutFinish.append(lambda: self.randomPosition())   # does not work

Trace:
  File "/usr/lib/enigma2/python/mytest.py", line 327, in open
    dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
  File "/usr/lib/enigma2/python/mytest.py", line 265, in instantiateDialog
    return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
  File "/usr/lib/enigma2/python/mytest.py", line 294, in doInstantiateDialog
    dlg.applySkin()
  File "/usr/lib/enigma2/python/Components/GUISkin.py", line 114, in applySkin
  File "/usr/lib/enigma2/python/Components/GUISkin.py", line 45, in createGUIScreen
TypeError: exec: arg 1 must be a string, file, or code object



Edited by JasonM8, 7 July 2018 - 12:14.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users