コード例 #1
0
    def _createColorButtons(self):
        """Generate color buttons based on the presets defined in the `colors`
        module.

        When a user clicks on the buttons, it changes the current color the
        colorspace page is displaying.

        """
        # create buttons for each preset color
        colorList = list(colorNames)
        btnSize = wx.Size(120, 24)
        for color in colorList:
            btn = GenButton(self, size=btnSize, label=color, name=color)
            btn.colorData = col = Color(color, 'named')
            btn.SetOwnBackgroundColour(col.rgba255)

            # Compute the (perceived) luminance of the color, used to set the
            # foreground text to ensure it's legible on the background. Uses the
            # the luminance part of formula to convert RGB1 to YIQ.
            luminance = np.sum(np.asarray((0.299, 0.587, 0.114)) * col.rgb1)
            if luminance < 0.5:
                btn.SetForegroundColour(wx.WHITE)
            else:
                btn.SetForegroundColour(wx.BLACK)

            btn.SetBezelWidth(0)
            btn.SetUseFocusIndicator(False)
            btn.Bind(wx.EVT_BUTTON, self.onClick)
            self.sizer.Add(btn, 1, wx.ALL | wx.EXPAND, 0)
コード例 #2
0
ファイル: __init__.py プロジェクト: wormcode/psychopy
 def __init__(self, parent):
     ScrolledPanel.__init__(self, parent, size=(120,400), style=wx.VSCROLL | wx.BORDER_NONE)
     self.sizer = wx.GridBagSizer()
     self.parent = parent
     for i in range(len(colorNames)):
         color = list(colorNames)[i]
         btn = GenButton(self, size=(100, 30),
                            label=color, name=color)
         btn.SetOwnBackgroundColour(Color(color, 'named').rgba255)
         btn.SetBezelWidth(0)
         btn.SetUseFocusIndicator(False)
         btn.colorData = color
         #btn.SetBackgroundColour(wx.Colour(Color(color, 'named').rgba1))
         btn.Bind(wx.EVT_BUTTON, self.onClick)
         self.sizer.Add(btn, pos=(i,0))
     self.SetSizer(self.sizer)
     self.SetupScrolling()