Beispiel #1
0
	def update(self):
		""" Sets up the button widget """
		if self._widget != None:
			self.removeChild(self._widget)
			self._widget = None
			
		if self._action is None:
			return
			
		widget = None
		icon = None
		text = None

		if self._action.isSeparator():
			widget = widgets.VBox()
			widget.base_color += Color(8, 8, 8)
			widget.min_size = (2, 2)
		else:
			if self._button_style != ToolBar.BUTTON_STYLE['TextOnly'] and len(self._action.icon) > 0:
				if self._action.isCheckable():
					icon = widgets.ToggleButton(hexpand=0, up_image=self._action.icon,down_image=self._action.icon,hover_image=self._action.icon,offset=(1,1))
					icon.toggled = self._action.isChecked()
				else:
					icon = widgets.ImageButton(hexpand=0, up_image=self._action.icon,down_image=self._action.icon,hover_image=self._action.icon,offset=(1,1))
				icon.capture(self._action.activate)
				
			if self._button_style != ToolBar.BUTTON_STYLE['IconOnly'] or len(self._action.icon) <= 0:
				if self._action.isCheckable():
					text = widgets.ToggleButton(hexpand=0, text=self._action.text,offset=(1,1))
					text.toggled = self._action.isChecked()
				else:
					text = widgets.Button(text=self._action.text)
				text.capture(self._action.activate)
			
			if self._button_style == ToolBar.BUTTON_STYLE['TextOnly'] or len(self._action.icon) <= 0:
				widget = text
				
			elif self._button_style == ToolBar.BUTTON_STYLE['TextUnderIcon']:
				widget = widgets.VBox()
				icon.position_technique = "center:top"
				text.position_technique = "center:bottom"
				widget.addChild(icon)
				widget.addChild(text)
				
			elif self._button_style == ToolBar.BUTTON_STYLE['TextBesideIcon']:
				widget = widgets.HBox()
				widget.addChild(icon)
				widget.addChild(text)
					
			else:
				widget = icon
			
		widget.position_technique = "left:center"
		widget.hexpand = 0
		
		self._widget = widget
		self.addChild(self._widget)
    def update(self):
        """ Sets up the button widget """
        if self._widget != None:
            self.removeChild(self._widget)
            self._widget = None

        if self._action is None:
            return

        widget = None
        icon = None
        text = None

        if self._action.isSeparator():
            widget = widgets.HBox()
            widget.base_color += Color(8, 8, 8)
            widget.min_size = (2, 2)
        else:
            hasIcon = len(self._action.icon) > 0

            if self._action.isCheckable():
                text = widgets.ToggleButton(text=self._action.text)
                text.toggled = self._action.isChecked()
                text.hexpand = 1
            else:
                text = widgets.Button(text=self._action.text)
            text.min_size = (1, MENU_ICON_SIZE)
            text.max_size = (1000, MENU_ICON_SIZE)
            text.capture(self._action.activate)

            if hasIcon:
                if self._action.isCheckable():
                    icon = widgets.ToggleButton(hexpand=0,
                                                up_image=self._action.icon,
                                                down_image=self._action.icon,
                                                hover_image=self._action.icon,
                                                offset=(1, 1))
                    icon.toggled = self._action.isChecked()
                else:
                    icon = widgets.ImageButton(hexpand=0,
                                               up_image=self._action.icon,
                                               down_image=self._action.icon,
                                               hover_image=self._action.icon,
                                               offset=(1, 1))

            else:
                if self._action.isCheckable():
                    icon = widgets.ToggleButton(hexpand=0, offset=(1, 1))
                    icon.toggled = self._action.isChecked()
                else:
                    icon = widgets.Button(text=u"", hexpand=0)

            icon.min_size = icon.max_size = (MENU_ICON_SIZE, MENU_ICON_SIZE)
            icon.capture(self._action.activate)

            widget = widgets.HBox()
            widget.addChild(icon)
            widget.addChild(text)

        widget.position_technique = "left:center"
        widget.hexpand = 1
        widget.vexpand = 0

        self._widget = widget
        self.addChild(self._widget)