Tupel als Funktionsparameter übergeben

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
nördlwördl
User
Beiträge: 2
Registriert: Montag 12. Oktober 2015, 17:58

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)
mutetella
User
Beiträge: 1695
Registriert: Donnerstag 5. März 2009, 17:10
Kontaktdaten:

@nordlwördl
Das Problem liegt nicht am übergebenen tuple sondern ...
The color is a string...
mutetella
Entspanne dich und wisse, dass es Zeit für alles gibt. (YogiTea Teebeutel Weisheit ;-) )
nördlwördl
User
Beiträge: 2
Registriert: Montag 12. Oktober 2015, 17:58

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")
Antworten