Changeset 3558:8af152c4d38a in orange


Ignore:
Timestamp:
04/19/07 11:10:54 (7 years ago)
Author:
mitar
Branch:
default
Convert:
0c473b7e3320114df364a923a50ce4e0f147a44b
Message:

More handling of colors na Mac (qRed and others).

Location:
orange/OrangeWidgets
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/Associate/OWDistanceMap.py

    r3551 r3558  
    200200 
    201201    def qrgbToQColor(self, color): 
    202         return QColor(qRed(color), qGreen(color), qBlue(color)) 
     202        # we could also use QColor(positiveColor(rgb), 0xFFFFFFFF) but there is probably a reason 
     203        # why this was not used before so I am leaving it as it is 
     204             
     205        return QColor(qRed(positiveColor(color)), qGreen(positiveColor(color)), qBlue(positiveColor(color))) # on Mac color cannot be negative number in this case so we convert it manually 
    203206 
    204207    def getItemFromPos(self, i): 
  • orange/OrangeWidgets/ColorPalette.py

    r3554 r3558  
    2323paletteInterpolationColors = 250 
    2424 
    25 # On Mac OS X QRgb is really unsigned int and so Python uses long int for it (as it 
    26 # cannot store it always in signed int), but this breaks QImage as it expects palette 
    27 # of ints, so we are manually casting long unsigned ints to signed ints (even if QRgb 
    28 # should be in fact unsigned) 
     25# On Mac OS X there are problems with QRgb and whether it is long or int and even whether 
     26# it is positive or negative number (there is corelation between those) 
     27# Color can be stored in 32 bit unsigned int but Python does not have unsigned int explicitly 
     28# So Python on Mac sometimes uses long where it should use int (when the highest bit is set and 
     29# it sees the number as positive - so it cannot be stored as positive number in 31 bits) and sometimes 
     30# it needs unsigned number and so uses long and does not want a signed int 
     31def signedColor(long): 
     32    if type(long) == int: 
     33        return long 
     34    elif long > 0xFFFFFFFF: 
     35    long &= 0xFFFFFFFF 
     36     
     37    if long & 0x80000000: 
     38        return int(-((long ^ 0xFFFFFFFF) + 1)) 
     39    else: 
     40        return int(long) 
     41 
     42def positiveColor(color): 
     43    if color < 0: 
     44        return (-color - 1) ^ 0xFFFFFFFF 
     45    else: 
     46        return color 
     47 
    2948def signedPalette(palette): 
    30     def signedInt(long): 
    31         if type(long) == int: 
    32             return long 
    33         elif long > 0xFFFFFFFF: 
    34              long &= 0xFFFFFFFF 
    35          
    36     if long & 0x80000000: 
    37             return int(-((long ^ 0xFFFFFFFF) + 1)) 
    38         else: 
    39             return int(long) 
    40      
    41     return [signedInt(color) for color in palette] 
     49    return [signedColor(color) for color in palette] 
    4250 
    4351class ColorPalette(QWidget): 
     
    217225 
    218226    def rgbToQColor(self, rgb): 
    219         return QColor(qRed(rgb), qGreen(rgb), qBlue(rgb)) 
     227        # we could also use QColor(positiveColor(rgb), 0xFFFFFFFF) but there is probably a reason 
     228        # why this was not used before so I am leaving it as it is 
     229         
     230        return QColor(qRed(positiveColor(rgb)), qGreen(positiveColor(rgb)), qBlue(positiveColor(rgb))) # on Mac color cannot be negative number in this case so we convert it manually 
    220231 
    221232    def qRgbFromQColor(self, qcolor): 
  • orange/OrangeWidgets/OWDlgs.py

    r3554 r3558  
    522522 
    523523    def rgbToQColor(self, rgb): 
    524         return QColor(qRed(rgb), qGreen(rgb), qBlue(rgb)) 
     524        # we could also use QColor(positiveColor(rgb), 0xFFFFFFFF) but there is probably a reason 
     525        # why this was not used before so I am leaving it as it is 
     526         
     527        return QColor(qRed(positiveColor(rgb)), qGreen(positiveColor(rgb)), qBlue(positiveColor(rgb))) # on Mac color cannot be negative number in this case so we convert it manually 
    525528 
    526529    def qRgbFromQColor(self, qcolor): 
  • orange/OrangeWidgets/Prototypes/OWScatterPlotGraphXp.py

    r3428 r3558  
    77import OWClusterOptimization 
    88import RandomArray 
     9import ColorPalette 
    910import orngVisFuncts 
    1011from orngScaleScatterPlotData import * 
     
    634635                palette.extend([qRgb(255, 255, 255) for i in range(256-len(palette))]) 
    635636 
    636             image = QImage(imagebmp, (rx + 3) & ~3, ry, 8, palette, 256, QImage.LittleEndian) 
     637            image = QImage(imagebmp, (rx + 3) & ~3, ry, 8, ColorPalette.signedPalette(palette), 256, QImage.LittleEndian) # palette should be 32 bit, what is not so on some platforms (Mac) so we force it 
    637638            self.potentialsBmp = QPixmap() 
    638639            self.potentialsBmp.convertFromImage(image) 
  • orange/OrangeWidgets/Visualize/OWLinProjGraph.py

    r3551 r3558  
    833833                for cls in self.potentialsClassifier.classVar.values: 
    834834                    color = colors[sortedClasses.index(cls)].light(150).rgb() 
    835                     color = [f(color) for f in [qRed, qGreen, qBlue]] 
     835                    color = [f(ColorPalette.positiveColor(color)) for f in [qRed, qGreen, qBlue]] # on Mac color cannot be negative number in this case so we convert it manually 
    836836                    towhite = [255-c for c in color] 
    837837                    for s in range(nShades): 
Note: See TracChangeset for help on using the changeset viewer.