Jump to content


Photo

hide spinner during plugin execution


  • Please log in to reply
50 replies to this topic

#1 keratos

  • Senior Member
  • 30 posts

0
Neutral

Posted 25 August 2017 - 09:03

So i have my plugin code that performs an update (doesnt matter what) as per below...

 

my plugin.py file creates an instance of myUpdater class. The screen appears correctly, the progress bar increments correctly, but how do I prevent the spinner. I guess the core system detects that the thread is taking longer than "expected" so displays the spinner. Indeed, the enigma2 output log confirms this when running enigma2 from the command line interactively rather than a service.

 

 

 

 

from Screens.Screen import Screen

from Components.Label import Label

from Components.ProgressBar import ProgressBar

from Components.ActionMap import ActionMap


 

class myUpdater(Screen):

  skin = """

  <screen position="center,center" size="840,160" flags="wfNoBorder" backgroundColor="background">

  <widget name="status" position="20,10" size="800,70" transparent="1" font="RegularLight;46" foregroundColor="foreground" backgroundColor="background" valign="center" halign="left" noWrap="1" />

  <widget name="progress" position="0,88" size="840,6" transparent="1" alphatest="blend" pixmap="MetrixFullHD/white.png" borderWidth="0" />

  <widget name="key_red" position="20,100" size="10,60" backgroundColor="red" />

  <widget name="key_green" position="20,100" size="10,60" backgroundColor="green" />

  </screen>

  """

 

 

def __init__(self, session):

  Screen.__init__(self, session)

  self["key_red"] = Label()

  self["key_red"].hide()

  self["key_green"] = Label()

  self["key_green"].show()

 

  self["actions"] = ActionMap(["OkCancelActions","ColorActions"],

  {

   "ok": self.ok,

   "cancel": self.exit,

   "green": self.startUpdate,

   "red": self.stopUpdate

  }, -1)

 

  self["status"] = Label(_("Press green to start update!"))
  self["progress"] = ProgressBar()

  self["progress"].hide()

 

 

def ok(self):

  self.close()

 

 

def exit(self):

  self.close()

 

 

def startUpdate(self):

  self["key_red"].show()

  self["key_green"].hide()

  self["status"].setText(_("Updating......"))

  ...

  ... some code ....

  ...

  setProgress(20)

  ...

  ... some code ....

  ...

  setProgress(40)

  ...

  ... some code ....

  ...

  setProgress(60)

  ...

  ... and so on...

 
 

def setProgress(self,val):

  self["progress"].setValue(val)

  self["progress"].show()

 

 



Re: hide spinner during plugin execution #2 littlesat

  • PLi® Core member
  • 57,062 posts

+698
Excellent

Posted 25 August 2017 - 09:44

Look how I did it in FlashImage.py

WaveFrontier 28.2E | 23.5E | 19.2E | 16E | 13E | 10/9E | 7E | 5E | 1W | 4/5W | 15W


Re: hide spinner during plugin execution #3 keratos

  • Senior Member
  • 30 posts

0
Neutral

Posted 26 August 2017 - 10:24

Look how I did it in FlashImage.py

Thanks, but that file is not in the enigma2 branch ??



Re: hide spinner during plugin execution #4 WanWizard

  • PLi® Core member
  • 70,220 posts

+1,798
Excellent

Posted 26 August 2017 - 10:35

It is in the Enigma2 repo, in the develop branch. As it is a feature for 6.1.


Currently in use: VU+ Duo 4K (2xFBC S2), VU+ Solo 4K (1xFBC S2), uClan Usytm 4K Ultimate (S2+T2), Octagon SF8008 (S2+T2), Zgemma H9.2H (S2+T2)

Due to my bad health, I will not be very active at times and may be slow to respond. I will not read the forum or PM on a regular basis.

Many answers to your question can be found in our new and improved wiki.


Re: hide spinner during plugin execution #5 keratos

  • Senior Member
  • 30 posts

0
Neutral

Posted 26 August 2017 - 10:39

It is in the Enigma2 repo, in the develop branch. As it is a feature for 6.1.

Got it.

 

Thanks

 

But this isnt the same as my code.

 

FlashImage.py is using the downloader, passing the updater function. What I have is the code above, self contained and no other code called. What happens is that I click OK on my plugin on the plugin menu, my code runs, I get the spinner and only when my code completes / finished does the screen get displayed with the progress bar, and with the progress bar at 100%. Its like my code is preventing the system from updating windows or something, and that I need to call some event handler that updates screens/components???

 

Please can you help me gently, as this is my first time writing a plugin .


Edited by keratos, 26 August 2017 - 10:40.


Re: hide spinner during plugin execution #6 keratos

  • Senior Member
  • 30 posts

0
Neutral

Posted 26 August 2017 - 11:11

anyone?



Re: hide spinner during plugin execution #7 littlesat

  • PLi® Core member
  • 57,062 posts

+698
Excellent

Posted 26 August 2017 - 11:34

Yes look what I did in FlashImage.py... here I also download a file from the www.... just copy and past that part... no spinners during download... look also e.g. What I did with the timer in __init__(self). I'm considering to create a function in Screen for this...

Edited by littlesat, 26 August 2017 - 11:47.

WaveFrontier 28.2E | 23.5E | 19.2E | 16E | 13E | 10/9E | 7E | 5E | 1W | 4/5W | 15W


Re: hide spinner during plugin execution #8 betacentauri

  • PLi® Core member
  • 7,185 posts

+323
Excellent

Posted 26 August 2017 - 11:55

I didn't look into your code. But you cannot have a loop or similar in which you update a progress bar. You need to exit your functions so that e2 can paint the screens. Afaik e2 GUI runs in the same thread as your code.
Use something similar to littlesats code or maybe a timer which is called every second(I guess that not the best solution), but then e2 can paint the screen when the timer is running.
Xtrend ET-9200, ET-8000, ET-10000, OpenPliPC on Ubuntu 12.04

Re: hide spinner during plugin execution #9 littlesat

  • PLi® Core member
  • 57,062 posts

+698
Excellent

Posted 26 August 2017 - 12:09

Not every second only once after the skin is build

WaveFrontier 28.2E | 23.5E | 19.2E | 16E | 13E | 10/9E | 7E | 5E | 1W | 4/5W | 15W


Re: hide spinner during plugin execution #10 pcd

  • Senior Member
  • 759 posts

+88
Good

Posted 26 August 2017 - 15:17

anyone?

In the folder /usr/share/enigma2/skin_default/spinner put some blank .png as wait.png items.



Re: hide spinner during plugin execution #11 littlesat

  • PLi® Core member
  • 57,062 posts

+698
Excellent

Posted 26 August 2017 - 15:22

Do you think this really helps?

WaveFrontier 28.2E | 23.5E | 19.2E | 16E | 13E | 10/9E | 7E | 5E | 1W | 4/5W | 15W


Re: hide spinner during plugin execution #12 betacentauri

  • PLi® Core member
  • 7,185 posts

+323
Excellent

Posted 26 August 2017 - 15:45

Not every second only once after the skin is build


Whatever. Just don't block the thread with your own code.
Xtrend ET-9200, ET-8000, ET-10000, OpenPliPC on Ubuntu 12.04

Re: hide spinner during plugin execution #13 MiLo

  • PLi® Core member
  • 14,055 posts

+298
Excellent

Posted 26 August 2017 - 19:39

Use one of the Task classes. There's one for running Python code in a thread. If you fork shell processes, use eApplicationContainer or so. If you're performing some file I/O, use twisted's methods for waiting on file or network data being available instead of blocking the main thread while waiting for input.

Takes a bit of learning to program properly, but it all will help you in the end. There's more to programming than just writing a script...
Real musicians never die - they just decompose

Re: hide spinner during plugin execution #14 littlesat

  • PLi® Core member
  • 57,062 posts

+698
Excellent

Posted 26 August 2017 - 19:48

def startUpdate(self):
  self["key_red"].show()
  self["key_green"].hide()
  self["status"].setText(_("Updating......"))
  ...
  ... some code ....
  ...
  setProgress(20)

  ...
  ... some code ....
  ...
  setProgress(40)

  ...
  ... some code ....
  ...
  setProgress(60)
  ...
  ... and so on...

What kinf of code do you want to but at ...some code.. ???

Flash Image makes a backup via a shell script, where Milo gives an example, does download a file from a website, unzip the downloaded file and then run the ofgwrite script.... And (usually) without spinners...


WaveFrontier 28.2E | 23.5E | 19.2E | 16E | 13E | 10/9E | 7E | 5E | 1W | 4/5W | 15W


Re: hide spinner during plugin execution #15 Erik Slagter

  • PLi® Core member
  • 46,969 posts

+541
Excellent

Posted 27 August 2017 - 09:24

Use one of the Task classes. There's one for running Python code in a thread. If you fork shell processes, use eApplicationContainer or so. If you're performing some file I/O, use twisted's methods for waiting on file or network data being available instead of blocking the main thread while waiting for input.

Takes a bit of learning to program properly, but it all will help you in the end. There's more to programming than just writing a script...

Those of use who are used to the programming model of non-preemptive multitasking of Windows, will probably grasp this concept more easily then those who are used to the blocking programming model of Unix.

 

In fact, it's not required to do it this way and enigma2 could have written using the blocking model as well, but it would have resulted in even more parallel threads.


Edited by Erik Slagter, 27 August 2017 - 09:25.

* Wavefrontier T90 with 28E/23E/19E/13E via SCR switches 2 x 2 x 6 user bands
I don't read PM -> if you have something to ask or to report, do it in the forum so others can benefit. I don't take freelance jobs.
Ik lees geen PM -> als je iets te vragen of te melden hebt, doe het op het forum, zodat anderen er ook wat aan hebben.


Re: hide spinner during plugin execution #16 keratos

  • Senior Member
  • 30 posts

0
Neutral

Posted 27 August 2017 - 17:10

Guys, thanks. But Im stuck

You are referring me to code that does not resemble my model.

 

I dont understand eTimer , setting it for a second is only going to run code after 1 second that still blocks, or after "skin build". ?? What does that mean?

 

If you could give an example that would really help,

 

My code is just a playlist parser that has a number of functions called to model the syntax.

I dont know how to create a task in enigma that will allow it to paint.

I dont know how to prevent code from blocking

 

There is zero documentation so this is quite difficult for an enigma2 noob. Now I do have 35 years of experience in unix, C, C++, windows, MFC, .NET,  VB, Ada, Assembler, C# but these generalyl come with a reference guide and API documentation.

 

So, whilst I am learning, if you could provide examples it would help.

 

For example, in VB code can call "doevents" to relase control for painting; in C/Unix i can fork a process that does the worker, and the parent updates progress for example and repaints. 

 

Ive looked at flashimage.py yet it isnt clear other than a few screens being created, which block, and a call to Downloader , which blocks, and form Downloader calsl to twisted and reactor , none of which I can find.

 

So if youcan give a snippet of code that I would use , maybe to invoke functions within my class as tasks, this would really help



Re: hide spinner during plugin execution #17 keratos

  • Senior Member
  • 30 posts

0
Neutral

Posted 27 August 2017 - 17:25

p.s. 

 

Task.py states

 

# A Job consists of many "Tasks".   # A task is the run of an external tool, with proper methods for failure handling  

 

So Im not sure task is the right class for running python code, i.e. my functions in my class that are blocking enigma, it looks more like console orientated

 

So, imagine I want to create a code base class, with 5 functions. These perform math, string manipulation, dictionary work., tokenizing, sorting - that sort of stuff. At the moment my __init__ calls the 5 functions. But of course, the class is blocking engima



Re: hide spinner during plugin execution #18 keratos

  • Senior Member
  • 30 posts

0
Neutral

Posted 28 August 2017 - 07:24

I wondered (and this is probably not the best way in which case you might suggest good practice please), but I wondered whether this might be a way to implement execution of my functions releasing control to enigma periodically.

Not sure whether I need a delay in between the timers otherwise the next timer would run "concurrently" with the previous timers , and this is not what I want. So a series of tasks (a job) is what I need maybe, again, not sure how to implement this ensuring Im following good practice, within enigma.

The "ok" function is the start of the plugin, after user presses "OK" on the remote - that bit works!!

 

 

def ok(self):

   self.Timer = eTimer()
   self.Timer.callback.append(self.cacheM3U)
   self.Timer.start(0, True)

   <<delay ?? / wait for a semaphore set by cacheM3U>>

   self.Timer = eTimer()
   self.Timer.callback.append(self.parse)
   self.Timer.start(0, True)

   <<delay ?? / wait for a semaphore set by cacheM3U>>

   self.Timer = eTimer()
   self.Timer.callback.append(self.createChannels)
   self.Timer.start(0, True)

   <<delay ?? / wait for a semaphore set by cacheM3U>>

   self.Timer = eTimer()
   self.Timer.callback.append(self.createBouquets)
   self.Timer.start(0, True)

 



Re: hide spinner during plugin execution #19 keratos

  • Senior Member
  • 30 posts

0
Neutral

Posted 28 August 2017 - 07:42

or, can I call

   runMainLoop()

 

contained in enigma ? Will that allow like 1 iteration through the main loop to prevent the spinner; I also could call

   setSpinnerOnOff(0)

 

in addition to runMainLoop , assuming 0 = off, 1 = on

 

? Help me out here guys please ?



Re: hide spinner during plugin execution #20 littlesat

  • PLi® Core member
  • 57,062 posts

+698
Excellent

Posted 28 August 2017 - 09:41

When I have the script or code that takes the long run time... maybe I can help you.... Without having or know what you want to do it is very difficult to help.


WaveFrontier 28.2E | 23.5E | 19.2E | 16E | 13E | 10/9E | 7E | 5E | 1W | 4/5W | 15W



13 user(s) are reading this topic

0 members, 13 guests, 0 anonymous users