action for the Scroll speed change please
#1
Scrolling though a ControlList using ACTION_MOVE_UP and ACTION_MOVE_DOWN
the code below, works fine

and if i hold down the MOVE_UP or MOVE_DOWN button it works fine,
until the Scroll speed changes then it loses it

ive have traked it down to (i think).
it seems to gets lost in def delfingering(self,id): function on the Scroll speed changes

so do i need to catch another action for the Scroll speed changes
if so what is the action for the Scroll speed change please


Code:
def onAction(self, action):
        if action == ACTION_MOVE_UP:
            self.delfingering(self.fingeringpicture)
            self.displayfingering(self.list.getSelectedPosition())
        if action == ACTION_MOVE_DOWN:
            self.delfingering(self.fingeringpicture)
            self.displayfingering(self.list.getSelectedPosition())

    def displayfingering(self, id):
        self.fingeringpicture=[]
        for i in range(len(chords[id][2:])):
            x = 300 - 30/2 + 6*30 - int(chords[id][2:][i][1])*30
            y = 200 - 30/2 - 50/2 + int(chords[id][2:][i][2])*50
            self.fingeringpicture.append(xbmcgui.ControlImage(x,y,30,30, RootDir + str(chords[id][2:][i][0])+".png"))
            self.addControl(self.fingeringpicture[-1])
        self.setFocus(self.list)

    def delfingering(self,id):
        for i in range(len(id)):
            self.removeControl(self.fingeringpicture[i])

thanks
Reply
#2
Don't delete then add new image controls, just use setImage()
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#3
What Nuka said would greatly speed up the update. Ive ran into this issue before and the root cause a problem with the threading.

Basically your op is taking too long and the action threads are clobbering eachother. I often hit this when one onAction thread does not return before onAction is called again. I recommend spinning off another thread from onAction that calls your main logic so onAction can return immediately. Ive had issues if that particular thread takes too long.

In addition to this or alternatively you can add a 'throttle' that will immediately return from onAction if the last time it was called has not returned. this can be done with a something like
Code:
if not returned:
  return
returned = false
....
stuff
....
returned = true
return
or you can maintain a count of how many threads are pending. If you still see threads clobbering eachother you can use a lock around critical sections of code (have a global lock object with lock.acquire() and lock.release())
Reply
#4
thanks Nuka1195
but the reason why i delete then add new image controls,
are because the number off imagecontrols, position of imagecontrols, and images are different


thanks Asteron
when you say "I recommend spinning off another thread from onAction that calls your main logic"
do you mean like this below
if so how does it take less time, its doing the same thing?
or am l missing something


Code:
def onAction(self, action):

        if action == ACTION_MOVE_UP:
            spinningoff()

        if action == ACTION_MOVE_DOWN:
            spinningoff()

    def spinningoff()
        self.delfingering(self.fingeringpicture)
        self.displayfingering(self.list.getSelectedPosition())

thank to you both
Reply
#5
thanks Asteron this works a treat

can i ask if you.
would you have set it global or is there another way

thanks


Code:
returned = 1

    def onAction(self, action):

        if action == ACTION_MOVE_UP:
            spinningoff()

        if action == ACTION_MOVE_DOWN:
            spinningoff()

    def spinningoff(self):
        global returned
        if not returned:
            return
        returned = 0
        self.delfingering(self.fingeringpicture)
        self.displayfingering(self.list.getSelectedPosition())
        returned = 1
        return
Reply
#6
yeah a member on the object would be the same

self.returned

My thing before was kinda pseudo code... but this is basically a poor mans lock.
My problem was that I ran into an issue where a timer thread and the onAction thread were running into eachother causing random lockups so I needed a real lock. However the onAction thread from XBMC is incapable of waiting on a lock for whatever reason and so I had to spawn a new thread.
Reply
#7
thanks Asteron again
i think i've got it now
every time i press an action i start a new thead whether the last one had finished or not and your code checks if the first thead i starded has finished or not before it lets another start

in the xbmcgui manual for removeControl() it says
This will not delete the control. It is only removed from the window.

as i am using removeControl() alot
does removeControl() free the memory it uses or is there a point where i will run out of memory

thanks
Reply
#8
you would have to do alot of removing and adding. You can see by booting into debug mode, the free memory counter will show.

You're still better using setImage() and setPosition().
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#9
thanks Nuka1195
i hear what you are saying but its just easer for me using removeControl()

what if i used setImage() '"" none or something before i used removeControl()
would i use less memory

thanks
Reply
#10
If you are going to use an image later you can just toggle the visibility.

Really the most expensive operation is xbmcgui.ControlImage() as that uses the disk.

The next few would probably be
xbmcgui.ControlImage.setImage()
xbmcgui.Window.addControl()
xbmcgui.Window.removeControl()

and these are practically free

xbmcgui.Control.setVisible()
xbmcgui.Control.setPosition()
xbmcgui.Control.setWidth()
xbmcgui.Control.setHeight()

If you are doing something big on animations or graphics it might be important to think about these. Even if it requires more complex code to eliminate the expensive stuff it is probably worth it if you are having performance issues.
Reply
#11
i have booting into debug mode and scroled down the list for ages
i could see i wasn't getting the memory back but it also showed i was hardly using any aswell
basically all i am doing is loading ControlImage() to show which fingers to finger the chords like this from a list which i would later won't to add bar chords and my be power chords

so should i still worry abut the memory?

Code:
F        Fm       c        B7       A7    
xx_____  xx_____  x______  x______  x______
|||||11  ||||111  |||||1|  ||1||||  |||||||
||||2||  |||||||  ||2||||  |2|3||4  |||111|
|||3|||  |||3|||  |3|||||  |||||||  ||||||2
|||||||  |||||||  |||||||  |||||||  |||||||
|||||||  |||||||  |||||||  |||||||  |||||||

4xi.png  4xi.png  3xi.png  4xi.png  4xi.png

i.png = 30x30 pixel circle with the number i on

heres my list so you can see that it would be ease to add to later
Code:
chords = ( \

('x00000','A','142','232','322'), \

('x00000','Am','121','242','332'), \

('x00000','Am7','121','242'), \

('x00000','A7','142','222'), \

('x00000','A7','142','132','122','213'), \

('x00000','B7','141','252','332','412'), \

('x00000','C','121','242','353'), \

('x00000','C7','121','242','353','433'), \

('xx0000','D','132','212','323'), \

('xx0000','Dm','111','232','323'), \

('xx0000','D7','121','232','312'), \

('xx0000','Dm7','121','111','232'), \

('000000','E','131','252','342'), \

('000000','Em','152','242'), \

('000000','E7','131','252'), \

('000000','Em7','152'), \

('xx0000','F','121','111','232','343'), \

('xx0000','Fm','131','121','111','343'), \

('000000','G','152','263','313'), \

('000000','G7','111','252','363') \

)
Reply
#12
just released i have done 7 string in my example please ignore that fact

thanks
Reply
#13
i'll just explain this
('x00000','C','121','242','353'),

x00000 = which strings to play
C = Chord Name
121 = Finger, String, Fret
242 = Finger, String, Fret
353 = Finger, String, Fret
Reply
#14
like i said, you would have to add and delete a lot of controls, but keep in mind if your playing music in the background that uses memory also.

also there is a limit of the number of controls, i'm not sure that number or if removing the control resets the count.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#15
thanks Nuka1195
I know your rigth so i have come up with this
Strech images for bar there for i only
ever need max 4 images so i can use
setVisible()
setPosition()
setWidth()
setImage()
and do away with
removeControl()
Code:
Open     Bar     Bar     Bar
   F       F       F       F
XX____  ______  ______  ______  
||||11  1|||11  111111  | 1  |   (Strech image 1 for bar
|||2||  |||2||  |||2||  |||2||   there for i only ever need
||3|||  |34|||  |34|||  |34|||   max 4 images)
||||||  ||||||  ||||||  ||||||

4xi.png 6xi.png 8xi.png 4xi.png  Images
XX3211  133211  133211  133211   TAB
XX3211  134211  134211  134211   Fingering

Open    Open    Open    Open    Open
  F       Fm      C       B7      A7    
XX____  XX____  X__0_0  X___0_  X0____
||||11  |||111  ||||1|  ||1|||  ||||||   (Strech image 1 for bar)
|||2||  ||||||  ||2|||  |2|3|4  ||111|
||3|||  ||3|||  |3||||  ||||||  |||||2
||||||  ||||||  ||||||  ||||||  ||||||

3xi.png 2xi.png 3xi.png 4xi.png 2xi.png  Images
XX3211  XX3111  X32010  X21202  X02223   TAB
XX3211  XX3111  X32010  X21304  X01112   Fingering

i.png = 30x30 pixel circle with the number i on
and change my list from a mess
('xx0000','F','121','111','232','343')
('x00000','B7','141','252','332','412')
('x00000','A7','142','132','122','213') etc

to use tab
('Chord', 'Tab', 'Fingering')
('F ','XX3211','XX3211')
('B7','X21202','X21304')
('A7','X02223','X01112')

which means i have to start all over again

Thanks
Reply

Logout Mark Read Team Forum Stats Members Help
action for the Scroll speed change please0