Pyglade, gtk, howto write more efficiently, and waste less code?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pipiten

    #1

    Pyglade, gtk, howto write more efficiently, and waste less code?

    Hi everybody, i` m new in this group, and python so.., my greetings to
    everybody here.
    I wrote a little program, in wich i do this:
    (I have several "Select File" buttons, one for each file (in this case,
    an image) wich has an text_entry, so i can add a comment for each
    picture.)

    def on_button1_clic ked(self,widget ):
    """Button 1 pressed"""
    image_file1 = FileSelection(s elf)
    self.path1.set_ text(image_file 1)
    self.image1.set _from_file(imag e_file1)
    self.image1.sho w()

    def on_button2_clic ked(self,widget ):
    """Button 2 pressed"""
    image_file2 = FileSelection(s elf)
    self.path2.set_ text(image_file 2)
    self.image2.set _from_file(imag e_file2)
    self.image2.sho w()

    def on_button3_clic ked(self,widget ):
    """Button 3 pressed"""
    image_file3 = FileSelection(s elf)
    self.path3.set_ text(image_file 3)
    self.image3.set _from_file(imag e_file3)
    self.image3.sho w()

    def on_button4_clic ked(self,widget ):
    """Button 4 pressed"""
    image_file4 = FileSelection(s elf)
    self.path4.set_ text(image_file 4)
    self.image4.set _from_file(imag e_file4)
    self.image4.sho w()

    def on_button5_clic ked(self,widget ):
    """Output dir button pressed"""
    outputpath = FileSelection(s elf)
    self.path5.set_ text(outputpath )


    Is there any way to do this, with a for bucle, or something like that?.
    For example, if i want to to the same, 25 times, not to copy and paste.
    Does anyone knows how to do that?, write it one time, and flexible to
    use many times.
    ( I think it should be with the variables sent by parameters, isn´t? )



    Thanks a lot, have a nice day!

  • niemand.leermann@thomas-guettler.de

    #2
    Re: Pyglade, gtk, howto write more efficiently, and waste less code?

    Pipiten wrote:
    Hi everybody, i` m new in this group, and python so.., my greetings to
    everybody here.
    I wrote a little program, in wich i do this:
    (I have several "Select File" buttons, one for each file (in this case,
    an image) wich has an text_entry, so i can add a comment for each
    picture.)
    >
    def on_button1_clic ked(self,widget ):
    """Button 1 pressed"""
    image_file1 = FileSelection(s elf)
    self.path1.set_ text(image_file 1)
    self.image1.set _from_file(imag e_file1)
    self.image1.sho w()
    ...
    You can connect all buttons to the same callback,
    and in the callback you pick they matching image.

    At least that what I would do (Up to now I don't use glade).

    HTH,
    Thomas

    Comment

    • Pipiten

      #3
      Re: Pyglade, gtk, howto write more efficiently, and waste less code?

      Thanks thomas!, i did it that way ;).

      maybe someone can help me with this, it seems simple, but i don`t know
      how to do it.

      I have:
      self.paths = ["","path1","pat h2","path3","pa th4","path5"]
      self.paths[1] = self.wTree.get_ widget("path1")
      self.paths[2] = self.wTree.get_ widget("path2")
      self.paths[3] = self.wTree.get_ widget("path3")
      self.paths[4] = self.wTree.get_ widget("path4")
      self.paths[5] = self.wTree.get_ widget("path5")

      what about if i have 30 widgets? how can i "get" them all?

      ... variables variables? ¬¬



      thanks everybody, good luck

      Comment

      • Gabriel Genellina

        #4
        Re: Pyglade, gtk, howto write more efficiently, and waste less code?

        At Wednesday 20/9/2006 10:06, Pipiten wrote:
        >I have:
        self.paths = ["","path1","pat h2","path3","pa th4","path5"]
        self.paths[1] = self.wTree.get_ widget("path1")
        self.paths[2] = self.wTree.get_ widget("path2")
        self.paths[3] = self.wTree.get_ widget("path3")
        self.paths[4] = self.wTree.get_ widget("path4")
        self.paths[5] = self.wTree.get_ widget("path5")
        >
        >what about if i have 30 widgets? how can i "get" them all?
        Is this what you want?

        for i,path in enumerate(self. paths):
        self.paths[i] = self.wTree.get_ widget(path)



        Gabriel Genellina
        Softlab SRL





        _______________ _______________ _______________ _____
        Preguntá. Respondé. Descubrí.
        Todo lo que querías saber, y lo que ni imaginabas,
        está en Yahoo! Respuestas (Beta).
        ¡Probalo ya!


        Comment

        Working...