Example #1
0
class PaletteToolTip(wx.PopupWindow):
    def __init__(self, parent):
        wx.PopupWindow.__init__(self, parent, wx.BORDER_NONE)
        self.SetBackgroundColour("#FFFFFF")
        self.label = Label(self, ' ', fontbold=True)
        self.label.SetPosition((5, 3))
        label_h = self.label.GetBestSize().height
        self.color_vals = Label(self, '')
        self.color_vals.SetPosition((5, 4 + label_h))
        self.set_text((' ', ' '))
        wx.CallAfter(self.Refresh)
        self.Bind(wx.EVT_PAINT, self._on_paint, self)

    def set_text(self, tip=()):
        name = tip[0]
        if not name: name = '---'
        self.label.set_text(name)
        sz = self.label.GetBestSize()

        clr_vals = tip[1]
        self.color_vals.set_text(clr_vals)
        sz2 = self.color_vals.GetBestSize()

        if not clr_vals:
            self.SetSize((sz.width + 8, sz.height + 6))
        else:
            height = sz.height + sz2.height + 1
            width = max(sz.width, sz2.width)
            self.SetSize((width + 8, height + 6))

    def set_position(self, pos):
        x, y = pos
        w, h = self.GetSize()
        scr_w, scr_h = wx.DisplaySize()
        if x + w + 7 > scr_w:
            x = x - w - 5
        else:
            x += 7
        if y + h + 17 > scr_h:
            y = y - h - 5
        else:
            y += 17
        self.SetPosition((x, y))

    def _on_paint(self, event):
        w, h = self.GetSize()
        pdc = wx.PaintDC(self)
        pdc.BeginDrawing()

        pdc.SetPen(wx.Pen(wx.Colour(0, 0, 0), 1))
        pdc.SetBrush(wx.TRANSPARENT_BRUSH)
        pdc.DrawRectangle(0, 0, w, h)

        pdc.EndDrawing()
        pdc = None
Example #2
0
class MacTB_ToolTip(wx.PopupWindow):

	def __init__(self, parent):
		self.parent = parent
		wx.PopupWindow.__init__(self, parent, wx.BORDER_NONE)
		bg = const.UI_COLORS['disabled_text']
		self.SetBackgroundColour(wx.Colour(*bg))
		self.label = Label(self, ' ', fontsize=-2)
		self.label.SetPosition((1, 1))
		self.set_text(' ')
		wx.CallAfter(self.Refresh)
		self.timer = wx.Timer(self)
		self.Bind(wx.EVT_TIMER, self._on_timer)
		self.Bind(wx.EVT_PAINT, self._on_paint, self)

	def set_text(self, tip=''):
		name = tip
		if not name:name = '---'
		self.label.set_text(name)
		sz = self.label.GetBestSize()
		self.SetSize((sz.width + 3, sz.height + 3))
		self.set_position()

	def hide(self):
		if self.timer.IsRunning(): self.timer.Stop()
		if self.IsShown(): self.Hide()

	def show(self):
		if not self.timer.IsRunning():
			self.timer.Start(1000)
		else:
			self.timer.Stop()
			self.timer.Start(1000)

	def _on_timer(self, event):
		self.set_position()
		self.Show()
		self.timer.Stop()

	def set_position(self):
		x, y = wx.GetMousePosition()
		w, h = self.GetSize()
		scr_w, scr_h = wx.DisplaySize()
		if x + w + 7 > scr_w: x = x - w - 5
		else: x += 7
		if y + h + 17 > scr_h: y = y - h - 5
		else:y += 17
		self.SetPosition((x, y))

	def _on_paint(self, event):
		w, h = self.GetSize()
		pdc = wx.PaintDC(self)
		pdc.BeginDrawing()

		pdc.SetPen(wx.TRANSPARENT_PEN)
		pdc.SetBrush(wx.Brush(wx.Colour(*const.UI_COLORS['tooltip_bg'])))
		pdc.DrawRectangle(0, 0, w - 1, h - 1)

		pdc.EndDrawing()
		pdc = None