Python Forum
[xbmc] How to block the code from executed twice under the loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[xbmc] How to block the code from executed twice under the loop
#10
@Yoriz: Thank you very much for this, I have changed the code and I ran the test, but I still get the same results. It will keep looping when I use the same program ids as it will change the object texts and size from two different objects button where I want to change the size from one of those object size.

Here is what I use:

def GoRight(self):
   for program_id in self.program_id:
       nextprogram = int(program_id) + 1
       nextprogram1 = int(nextprogram) + 1
       nextprogram2 = int(nextprogram1) + 1
       nextprogram3 = int(nextprogram2) + 1
       program_button_1 = self.getControl(int(program_id))
       program_button_2 = self.getControl(int(nextprogram))
       program_button_3 = self.getControl(int(nextprogram1))
       program_button_4= self.getControl(int(nextprogram2))
       program_button_5 = self.getControl(int(nextprogram3))
       program_width = program_button_1.getWidth()
       programX = program_button_1.getX()
       pos_X = program_button_1.getX()
       pos_Y = program_button_1.getY()                  
       nextprogramX = program_button_2.getX()
       nextprogram_width = program_button_2.getWidth()
       nextprogram_label = program_button_2.getLabel()
       nextprogram1X = program_button_3.getX()
       nextprogram1_width = program_button_3.getWidth()
       nextprogram1_label = program_button_3.getLabel()
       nextprogram2X = program_button_4.getX()
       nextprogram2_width = program_button_4.getWidth()
       nextprogram2_label = program_button_4.getLabel()
       nextprogram3X = program_button_5.getX()
       nextprogram3_width = program_button_5.getWidth()
       nextprogram3_label = program_button_5.getLabel()
                        
       if int(ctrl.getX()) != 375:
           continue
        
      
       if int(program_width) == 691:
         programs_width = 344
         program_button_1.setWidth(int(programs_width))
         program_width = program_button_1.getWidth()
         nextprogram_width = program_button_2.getWidth()
         print "catch this goright 1"


       elif int(program_width) >= 342 and int(program_width) <= 344:
         #print "you are working on 342 and 344 button"
         print "catch this goright 2"
         program_button_1.setLabel(nextprogram_label)
         program_button_1.setWidth(nextprogram_width)

         program_button_2.setLabel(nextprogram1_label)
         program_button_2.setWidth(nextprogram1_width)
         program_button_3.setLabel(nextprogram2_label)
         program_button_3.setWidth(nextprogram2_width)
I have found the problem is coming from the loops, because I got three buttons that required to change the texts and size, so it will executing like three times. It would be much easier if I could get a single program id at a time to change the text and size at a time without looping like 3 times.

How I can get the program id at a time as I use this to store the program id?

 
   program_button = [elem.control for elem in self.program_buttons]
    programs_id = list()
    positions_X = list()

    for elem in program_button:
        programs_id.append(elem.getId())
        positions_X.append(elem.getX())
    programs_id = map(str, programs_id)
    posX = map(str, positions_X)


    #Store the list of strings in the lists
    for i in range(len(posX)):
        pos_X = posX[i]

        if pos_X == '375':
            self.program_id.append(programs_id[i]
)
Reply


Messages In This Thread
RE: How to block the code from executed twice under the loop - by chris0147 - Oct-25-2016, 05:08 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] messagebox is not being executed please help erwinsiuda 2 2,383 Apr-02-2020, 01:56 AM
Last Post: Larz60+
  [Tkinter] Window unresponsive when executed. fawazcode 2 3,894 Sep-11-2017, 12:29 AM
Last Post: Larz60+
  [WxPython] Which def is executed? merlem 10 8,049 Feb-10-2017, 11:28 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020