Exemple #1
0
        def pickColorAsync(self,
                           callback,
                           startingcolor,
                           startingalpha,
                           screenX=None,
                           screenY=None):
            from wnd.dlgs.choosecolor import ChooseColor
            global colorDialog
            global customColors

            def _adjustWindow(hwnd, msg, wp, lp):
                #log.debug("pos = (%d, %d)", pos[0], pos[1])
                colorDialog.SetWindowPos(screenX, screenY)

            if not callback or not hasattr(callback, "handleResult"):
                raise COMException(
                    nsError.NS_ERROR_INVALID_ARG,
                    "pickColorAsync got invalid callback %r" % (callback, ))
            if screenX is not None and screenY is None:
                raise COMException(
                    nsError.NS_ERROR_INVALID_ARG,
                    "pickColorAsync: can't have screenX without screenY")

            # parse the starting colors
            try:
                startingcolor = startingcolor.lstrip("#")
                colors = [
                    int(startingcolor[x:x + 2], 16) for x in range(0, 6, 2)
                ]
            except Exception:
                raise COMException(
                    nsError.NS_ERROR_INVALID_ARG,
                    "pickColorAsync: invalid starting color %r" %
                    (startingcolor, ))

            if colorDialog is None:
                colorDialog = ChooseColor()
            bgr = colors[2] * 2**16 + colors[1] * 2**8 + colors[0]
            #log.debug("bgr in: %r -> %x (%r)", colors, bgr, bgr)
            if screenX or screenY:
                colorDialog.onINIT = _adjustWindow
            res = colorDialog.Run(None,
                                  'fullopen',
                                  'hook',
                                  customcolors=customColors,
                                  initcolor=bgr)
            if res is not None:
                b, g, r = [(res & (2**x - 1)) >> (x - 8)
                           for x in range(24, 0, -8)]
                #log.debug("bgr out: %r -> %x (%r)", [r,g,b], res, res)
                for i, x in enumerate(colorDialog._dlgs_colors):
                    customColors[i] = int(x)
                callback.handleResult("#%02x%02x%02x" % (r, g, b),
                                      startingalpha)
            else:
                callback.handleResult(None, startingalpha)
 def pickColorWithPositioning(self, startingcolor, screenX, screenY):
     from wnd.dlgs.choosecolor import ChooseColor
     global colorDialog
     global customColors
     
     if colorDialog is None:
         colorDialog = ChooseColor()
     r,g,b = startingcolor[1:3], startingcolor[3:5], startingcolor[5:]
     bgr = int(b+g+r, 16)
     #log.debug("bgr in = %x (%r)", bgr, bgr)
     colorDialog.onINIT = _adjustWindow
     res = colorDialog.Run(None, 'fullopen', 'hook',
                           customcolors=customColors, initcolor=bgr)
     if res is not None:
         bgr = "%06x" % res
         #log.debug("bgr out = %r", bgr)
         b,g,r = bgr[:2], bgr[2:4], bgr[4:]
         for i, x in enumerate(colorDialog._dlgs_colors):
             customColors[i] = int(x)
         return '#'+r+g+b
Exemple #3
0
        def pickColorWithPositioning(self, startingcolor, screenX, screenY):
            from wnd.dlgs.choosecolor import ChooseColor
            global colorDialog
            global customColors

            if colorDialog is None:
                colorDialog = ChooseColor()
            r, g, b = startingcolor[1:3], startingcolor[3:5], startingcolor[5:]
            bgr = int(b + g + r, 16)
            #log.debug("bgr in = %x (%r)", bgr, bgr)
            colorDialog.onINIT = _adjustWindow
            res = colorDialog.Run(None,
                                  'fullopen',
                                  'hook',
                                  customcolors=customColors,
                                  initcolor=bgr)
            if res is not None:
                bgr = "%06x" % res
                #log.debug("bgr out = %r", bgr)
                b, g, r = bgr[:2], bgr[2:4], bgr[4:]
                for i, x in enumerate(colorDialog._dlgs_colors):
                    customColors[i] = int(x)
                return '#' + r + g + b
        def pickColorAsync(self, callback, startingcolor, startingalpha, screenX=None, screenY=None):
            from wnd.dlgs.choosecolor import ChooseColor
            global colorDialog
            global customColors

            def _adjustWindow(hwnd, msg, wp, lp):
                #log.debug("pos = (%d, %d)", pos[0], pos[1])
                colorDialog.SetWindowPos(screenX, screenY)

            if not callback or not hasattr(callback, "handleResult"):
                raise COMException(nsError.NS_ERROR_INVALID_ARG,
                                   "pickColorAsync got invalid callback %r" % (callback,))

            # parse the starting colors
            try:
                startingcolor = startingcolor.lstrip("#")
                colors = [int(startingcolor[x:x+2], 16) for x in range(0, 6, 2)]
            except Exception:
                raise COMException(nsError.NS_ERROR_INVALID_ARG,
                                   "pickColorAsync: invalid starting color %r" % (startingcolor,))

            if colorDialog is None:
                colorDialog = ChooseColor()
            bgr = colors[2] * 2**16 + colors[1] * 2**8 + colors[0]
            #log.debug("bgr in: %r -> %x (%r)", colors, bgr, bgr)
            if screenX or screenY:
                colorDialog.onINIT = _adjustWindow
            res = colorDialog.Run(None, 'fullopen', 'hook',
                                  customcolors=customColors, initcolor=bgr)
            if res is not None:
                b, g, r = [(res & (2**x-1)) >> (x - 8) for x in range(24, 0, -8)]
                #log.debug("bgr out: %r -> %x (%r)", [r,g,b], res, res)
                for i, x in enumerate(colorDialog._dlgs_colors):
                    customColors[i] = int(x)
                callback.handleResult("#%02x%02x%02x" % (r, g, b), startingalpha)
            else:
                callback.handleResult(None, startingalpha)