Ejemplo n.º 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)
Ejemplo n.º 2
0
 def __init__(self, parent, font, clickedCallback, texts, default):
     self.texts = texts
     self.clickedCallback = clickedCallback 
     self.buttons = []
     btnId = 10000
     for text in self.texts:
         btn = GenButton(parent, id = btnId, label = text)
         btn.SetBezelWidth(0)
         btn.SetUseFocusIndicator(False)
         btn.SetBackgroundColour(basePurple)
         if text == default:
     		btn.SetForegroundColour(btnForegroundSel)
         else:			
            	btn.SetForegroundColour(btnForeground)
         btn.SetFont(font)
         btn.Bind(wx.EVT_LEFT_DOWN, self.OnDown)
         btn.Bind(wx.EVT_LEFT_UP, self.OnUp)
         btn.Bind(wx.EVT_LEFT_DCLICK, self.DoNothing)
         btn.Bind(wx.EVT_MOTION, self.DoNothing)
 	    self.buttons.append(btn)
         btnId+=1
 	self.current = default
Ejemplo n.º 3
0
 def create_begin(self):
     main_sizer = wx.BoxSizer(wx.VERTICAL)
     self.SetFont(
         wx.Font(25,
                 wx.FONTFAMILY_MODERN,
                 wx.FONTSTYLE_NORMAL,
                 wx.FONTWEIGHT_BOLD,
                 faceName="Roboto"))
     begin_button = GenButton(self,
                              id=-1,
                              label="Arrange",
                              size=(200, 55),
                              style=wx.BORDER_SIMPLE)
     begin_button.SetForegroundColour(wx.Colour(255, 255, 255))
     begin_button.SetBezelWidth(1)
     begin_button.SetBackgroundColour('#5f9ad8')
     begin_button.SetCursor(wx.Cursor(
         wx.CURSOR_HAND))  #StockCursor deprecated
     begin_button.SetWindowStyleFlag(wx.RAISED_BORDER)
     main_sizer.AddStretchSpacer()
     main_sizer.Add(begin_button, 0, wx.CENTER)
     main_sizer.AddStretchSpacer()
     self.SetSizer(main_sizer)
     self.Bind(wx.EVT_BUTTON, self.onDir, begin_button)
Ejemplo n.º 4
0
class MainFrame(wx.Frame):
    def __init__(self):
        super().__init__(None, title='秒表')
        self.total_seconds = 0
        self.timer = wx.Timer(self)
        self._init_ui()
        self._init_event()

    def _init_event(self):
        self.btn_run.Bind(wx.EVT_BUTTON, self._on_btn_run_clicked)
        self.btn_reset.Bind(wx.EVT_BUTTON, self._on_btn_reset_clicked)
        self.Bind(wx.EVT_TIMER, self._update_time, self.timer)

    def _on_btn_run_clicked(self, _):
        if self.timer.IsRunning():
            self.timer.Stop()
            self.btn_run.SetLabel('继续')
        else:
            self.timer.Start(1000)
            self.btn_run.SetLabel('暂停')

    def _on_btn_reset_clicked(self, _):
        self.timer.Stop()
        self.btn_run.SetLabel('开始')
        self.total_seconds = 0
        self.st_time.SetLabel('00 : 00 : 00')

    def _update_time(self, _):
        self.total_seconds += 1
        second = self.total_seconds % 60
        minute = int((self.total_seconds / 60) % 60)
        hour = int((self.total_seconds / 3600) % 24)
        self.st_time.SetLabel(f'{hour:02} : {minute:02} : {second:02}')

    def _init_ui(self):
        main_sizer = wx.BoxSizer(wx.VERTICAL)
        main_sizer.AddStretchSpacer()

        self.st_time = wx.StaticText(self, label='00 : 00 : 00')
        self.st_time.SetFont(wx.Font(wx.FontInfo(120)))

        self.btn_run = GenButton(self,
                                 label='开始',
                                 size=(100, 30),
                                 style=wx.BORDER_NONE)
        self.btn_reset = GenButton(self,
                                   label='复位',
                                   size=(100, 30),
                                   style=wx.BORDER_NONE)

        main_sizer.Add(self.st_time, flag=wx.ALIGN_CENTER_HORIZONTAL)
        main_sizer.AddSpacer(80)

        main_sizer.Add(self.btn_run, flag=wx.ALIGN_CENTER_HORIZONTAL)
        main_sizer.AddSpacer(30)
        main_sizer.Add(self.btn_reset, flag=wx.ALIGN_CENTER_HORIZONTAL)

        main_sizer.AddStretchSpacer()
        self.SetSizer(main_sizer)
        self.Maximize()

        self.st_time.SetForegroundColour('white')
        self.btn_run.SetBackgroundColour('#00CC99')
        self.btn_run.SetForegroundColour('white')
        self.btn_reset.SetBackgroundColour('#FF6666')
        self.btn_reset.SetForegroundColour('white')
        self.SetBackgroundColour('#444444')