Seite 1 von 1

Tupel als Funktionsparameter übergeben

Verfasst: Montag 12. Oktober 2015, 18:58
von nördlwördl
Hallo,
ich versuche auf die Funktion "pixel_color_in_area_counter" der Bibliothek macropolo (siehe http://ubuntuforums.org/showthread.php?t=2155281) zuzugreifen. Wenn ichs recht verstehe, benötigt diese als ersten Parameter ein Tupel mit vier Werten. Leider bekomme ich es nicht hin, der Funktion ein entsprechendes Tupel als Parameter zu übergeben – was mache ich falsch?

Funktion:

Code: Alles auswählen

def pixel_color_in_area_counter(rectangle, color):
    """
    Searches the rectangle area 'rectangle' for the color 'color'.
    It returns an integer indicating the times that the 'color'
    was found inside the 'rectangle'.
    The rectangle is a tuple [x, y, width, height], where x, y the
    coordinates of the top left corner and width, height the width
    and the height of the rectangle.
    The color is a string with a hexadecimal representation of 
    a color (e.g. #000000)
    """
    x = rectangle[0]
    y = rectangle[1]
    width = rectangle[2]
    height = rectangle[3]
    color = to_lower(color)
    
    img = QPixmap.grabWindow(QApplication.desktop().winId()).toImage().copy(x, y, width+1, height+1);
    
    counter=cur_y=cur_x=0
    while( cur_y <= height ):
        cur_x=0
        while ( cur_x <= width ):
            cur_color = QColor(img.pixel(QPoint(cur_x, cur_y)))
            if(str(color)==str(cur_color.name())):
                counter+=1
            cur_x+=PIXELS_SEARCH_SPEED
        cur_y+=1
    return counter;
mein Ansatz:

Code: Alles auswählen

import macropolo.py
tup = (1,2,3,4)
print macropolo.pixel_color_in_area_counter(tup,#000000)

Re: Tupel als Funktionsparameter übergeben

Verfasst: Montag 12. Oktober 2015, 19:05
von mutetella
@nordlwördl
Das Problem liegt nicht am übergebenen tuple sondern ...
The color is a string...
mutetella

Re: Tupel als Funktionsparameter übergeben

Verfasst: Montag 12. Oktober 2015, 19:08
von nördlwördl
Ich wusste, dass der Fehler so einfach ist - stundenlang an der falschen Stelle gesucht… Ich danke dir von Herzen!

edit: Kein Thread ohne vernünftige Problemlösung: Das Problem war der zweite Parameter, der als String übergeben werden und deshalb in Anführungszeichen stehen muss:

Code: Alles auswählen

print macropolo.pixel_color_in_area_counter(tup,"#000000")