def __init__(self, parent, value=0.0, range_val=(0.0, 1.0), step=0.01, digits=2, size=DEF_SIZE, width=0, onchange=None, onenter=None, check_focus=True): self.callback = onchange self.enter_callback = onenter spin_overlay = const.SPIN['overlay'] spin_sep = const.SPIN['sep'] if const.is_mac(): spin_overlay = False if not width and const.is_msw(): width = 5 wx.Panel.__init__(self, parent) if spin_overlay: if const.is_gtk(): self.entry = Entry(self, '', size=size, width=width, onchange=self._check_entry, onenter=self._entry_enter) size = (-1, self.entry.GetSize()[1]) self.entry.SetPosition((0, 0)) self.sb = SpinButton(self, size=size, onchange=self._check_spin) w_pos = self.entry.GetSize()[0] - 5 if spin_sep: self.line = HPanel(self) self.line.SetSize((1, self.sb.GetSize()[1] - 2)) self.line.set_bg(const.UI_COLORS['dark_shadow']) self.line.SetPosition((w_pos - 1, 1)) self.sb.SetPosition((w_pos, 0)) self.SetSize((-1, self.entry.GetSize()[1])) elif const.is_msw(): width += 2 self.entry = Entry(self, '', size=size, width=width, onchange=self._check_entry, onenter=self._entry_enter) size = (-1, self.entry.GetSize()[1] - 3) self.sb = SpinButton(self.entry, size=size, onchange=self._check_spin) w_pos = self.entry.GetSize()[0] - self.sb.GetSize()[0] - 3 self.sb.SetPosition((w_pos, 0)) w, h = self.entry.GetSize() self.entry.SetSize((w, h + 1)) else: self.box = wx.BoxSizer(const.HORIZONTAL) self.SetSizer(self.box) self.entry = Entry(self, '', size=size, width=width, onchange=self._check_entry, onenter=self._entry_enter) self.box.Add(self.entry, 0, wx.ALL) size = (-1, self.entry.GetSize()[1]) self.sb = SpinButton(self, size=size, onchange=self._check_spin) self.box.Add(self.sb, 0, wx.ALL) if check_focus: self.entry.Bind(wx.EVT_KILL_FOCUS, self._entry_lost_focus, self.entry) self.entry.Bind(wx.EVT_CONTEXT_MENU, self._ctxmenu, self.entry) self.set_step(step) self.set_range(range_val) self._set_digits(digits) self._set_value(value) self.flag = False self.Fit()
def __init__(self, parent, value=0.0, range_val=(0.0, 1.0), step=0.01, digits=2, size=DEF_SIZE, width=0, spin_overlay=True, onchange=None, onenter=None, check_focus=True): self.callback = onchange self.enter_callback = onenter if const.is_mac(): spin_overlay = False if not width and const.is_msw(): width = 5 wx.Panel.__init__(self, parent) if spin_overlay: if const.is_gtk(): self.entry = Entry(self, '', size=size, width=width, onchange=self._check_entry, onenter=self._entry_enter) size = (-1, self.entry.GetSize()[1]) self.entry.SetPosition((0, 0)) self.line = HPanel(self) self.sb = SpinButton(self, size=size, onchange=self._check_spin) w_pos = self.entry.GetSize()[0] - 5 self.line.SetSize((1, self.sb.GetSize()[1] - 2)) self.line.set_bg(const.UI_COLORS['dark_shadow']) self.line.SetPosition((w_pos - 1, 1)) self.sb.SetPosition((w_pos, 0)) self.SetSize((-1, self.entry.GetSize()[1])) elif const.is_msw(): width += 2 self.entry = Entry(self, '', size=size, width=width, onchange=self._check_entry, onenter=self._entry_enter) size = (-1, self.entry.GetSize()[1] - 3) self.sb = SpinButton(self.entry, size=size, onchange=self._check_spin) w_pos = self.entry.GetSize()[0] - self.sb.GetSize()[0] - 3 self.sb.SetPosition((w_pos, 0)) w, h = self.entry.GetSize() self.entry.SetSize((w, h + 1)) else: self.box = wx.BoxSizer(const.HORIZONTAL) self.SetSizer(self.box) self.entry = Entry(self, '', size=size, width=width, onchange=self._check_entry, onenter=self._entry_enter) self.box.Add(self.entry, 0, wx.ALL) size = (-1, self.entry.GetSize()[1]) self.sb = SpinButton(self, size=size, onchange=self._check_spin) self.box.Add(self.sb, 0, wx.ALL) if check_focus: self.entry.Bind(wx.EVT_KILL_FOCUS, self._entry_lost_focus, self.entry) self.entry.Bind(wx.EVT_CONTEXT_MENU, self._ctxmenu, self.entry) self.set_step(step) self.set_range(range_val) self._set_digits(digits) self._set_value(value) self.flag = False self.Fit()
def __init__(self, parent, text='', widget=None): VPanel.__init__(self, parent) self.inner_panel = RoundedPanel(self) if widget or text: self.widget_panel = HPanel(self) if widget: self.widget = widget elif text: self.widget = wx.StaticText(self.widget_panel, wx.ID_ANY, text) self.widget_panel.pack(self.widget, padding=5) self.widget_panel.SetPosition((7, 0)) self.widget_panel.Fit() if const.is_msw(): self.widget_panel.Raise() padding = 0 if self.widget_panel: padding = round(self.widget_panel.get_size()[1] / 2.0) self.inner_panel.pack((1, padding)) self.refresh() VPanel.pack(self, self.inner_panel, expand=True, fill=True, start_padding=padding)
def set_dialog_buttons(self): if self.add_line: self.box.pack(HLine(self.box), fill=True, padding=5) else: self.box.pack((3, 3)) self.button_box = HPanel(self.box) self.box.pack(self.button_box, fill=True) self.ok_btn = Button(self.button_box, '', onclick=self.on_ok, pid=self.action_button) self.cancel_btn = Button(self.button_box, '', onclick=self.on_cancel, default=True, pid=const.BUTTON_CANCEL) self.left_button_box = HPanel(self.button_box) self.button_box.pack(self.left_button_box, expand=True, fill=True) if const.is_mac(): self.button_box.pack(self.ok_btn, padding=5) self.button_box.pack(self.cancel_btn, padding=5) elif const.is_msw(): self.button_box.pack(self.ok_btn, padding=2) self.button_box.pack(self.cancel_btn) else: self.button_box.pack(self.cancel_btn, padding=2) self.button_box.pack(self.ok_btn)
def set_dialog_buttons(self): if self.add_line: self.box.pack(HLine(self.box), fill=True, padding=5) else: self.box.pack((3, 3)) self.button_box = HPanel(self.box) self.box.pack(self.button_box, fill=True) self.ok_btn = Button(self.button_box, '', onclick=self.on_ok, default=True, pid=self.action_button) self.cancel_btn = Button(self.button_box, '', onclick=self.on_cancel, pid=const.BUTTON_CANCEL) self.left_button_box = HPanel(self.button_box) self.button_box.pack(self.left_button_box, expand=True, fill=True) if const.is_mac(): self.button_box.pack(self.ok_btn, padding=5) self.button_box.pack(self.cancel_btn, padding=5) elif const.is_msw(): self.button_box.pack(self.ok_btn, padding=2) self.button_box.pack(self.cancel_btn) else: self.button_box.pack(self.cancel_btn, padding=2) self.button_box.pack(self.ok_btn)
def __init__(self, parent, value=0, range_val=(0, 1), size=DEF_SIZE, width=0, onchange=None, onenter=None, check_focus=True): step = 1 digits = 0 if not width and const.is_msw(): width = 5 FloatSpin.__init__(self, parent, value, range_val, step, digits, size, width, onchange, onenter, check_focus)
def __init__(self, parent, value=0, range_val=(0, 1), size=DEF_SIZE, width=0, spin_overlay=True, onchange=None, onenter=None, check_focus=True): step = 1 digits = 0 if not width and const.is_msw(): width = 5 FloatSpin.__init__(self, parent, value, range_val, step, digits, size, width, spin_overlay, onchange, onenter, check_focus)
def _start(self): self.size = self.widget.GetSize() if not self.size[0] or not self.size[1]: self.pdc = wx.PaintDC(self.widget) elif is_msw() and self.widget.IsDoubleBuffered(): self.widget.buffer = wx.EmptyBitmapRGBA(*self.size) self.pdc = wx.BufferedPaintDC(self.widget, self.widget.buffer) else: self.pdc = wx.PaintDC(self.widget) try: self.dc = wx.GCDC(self.pdc) except:self.dc = self.pdc self.dc.BeginDrawing()
def OnDrawItem(self, dc, rect, item, flags): if item == wx.NOT_FOUND:return r = wx.Rect(*rect) if flags & wx.combo.ODCB_PAINTING_SELECTED and \ flags & wx.combo.ODCB_PAINTING_CONTROL: if const.is_msw(): bitmap = self.bitmaps[item] else: bitmap = bmp_to_white(self.bitmaps[item]) elif flags & wx.combo.ODCB_PAINTING_SELECTED: bitmap = bmp_to_white(self.bitmaps[item]) else: bitmap = self.bitmaps[item] dc.DrawBitmap(bitmap, r.x + 2, r.y + 4, True)
def OnDrawItem(self, dc, rect, item, flags): if item == wx.NOT_FOUND: return r = wx.Rect(*rect) if flags & wx.combo.ODCB_PAINTING_SELECTED and \ flags & wx.combo.ODCB_PAINTING_CONTROL: if const.is_msw(): bitmap = self.bitmaps[item] else: bitmap = bmp_to_white(self.bitmaps[item]) elif flags & wx.combo.ODCB_PAINTING_SELECTED: bitmap = bmp_to_white(self.bitmaps[item]) else: bitmap = self.bitmaps[item] dc.DrawBitmap(bitmap, r.x + 2, r.y + 4, True)
def _start(self): self.size = self.widget.GetSize() if not self.size[0] or not self.size[1]: self.pdc = wx.PaintDC(self.widget) elif is_msw() and self.widget.IsDoubleBuffered(): self.widget.buffer = wx.EmptyBitmapRGBA(*self.size) self.pdc = wx.BufferedPaintDC(self.widget, self.widget.buffer) else: self.pdc = wx.PaintDC(self.widget) try: self.dc = wx.GCDC(self.pdc) except: self.dc = self.pdc self.dc.BeginDrawing()
def __init__(self, parent, tooltip='', onclick=None, repeat=False): self.parent = parent self.onclick = onclick self.repeat = repeat wx.Panel.__init__(self, parent, wx.ID_ANY) if is_msw(): self.SetDoubleBuffered(True) self.box = wx.BoxSizer(wx.HORIZONTAL) self.SetSizer(self.box) self.box.Add((1, 1)) if tooltip: self.set_tooltip(tooltip) self.timer = wx.Timer(self) self.Bind(wx.EVT_PAINT, self._on_paint, self) self.Bind(wx.EVT_ENTER_WINDOW, self._mouse_over, self) self.Bind(wx.EVT_LEFT_DOWN, self._mouse_down, self) self.Bind(wx.EVT_LEFT_UP, self._mouse_up, self) self.Bind(wx.EVT_TIMER, self._on_timer) self.Bind(wx.EVT_LEAVE_WINDOW, self._on_win_leave, self)
def __init__( self, parent, data=[], border=True, alt_color=True, use_icons=True, on_select=None, highlight_row=True ): style = wx.TR_DEFAULT_STYLE | wx.TR_HAS_BUTTONS | wx.TR_HIDE_ROOT if const.is_msw(): highlight_row = False if highlight_row: style |= wx.TR_FULL_ROW_HIGHLIGHT if not highlight_row: alt_color = False if border and not const.is_wx3(): style |= wx.BORDER_MASK wx.TreeCtrl.__init__(self, parent, wx.ID_ANY, style=style) self.alt_color = alt_color self.use_icons = use_icons self.select_cmd = on_select self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.recolor_items, self) self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.recolor_items, self) if self.select_cmd: self.Bind(wx.EVT_TREE_SEL_CHANGED, self.sel_changed, self) self.update(data)
def _draw_pressed(self): w, h = self.size color = UI_COLORS['dark_shadow'] self.dc.SetPen(wx.Pen(wx.Colour(*color), self.active_border)) self.dc.DrawLine(3, 1, w - 3, 1) self.dc.DrawLine(1, 3, 1, h - 3) color = UI_COLORS['dark_shadow'] self.dc.SetPen(wx.Pen(wx.Colour(*color), self.active_border)) self.dc.SetBrush(wx.Brush(wx.Colour(*color))) self.dc.DrawRoundedRectangle(2, 2, w - 2, h - 2, 3.0) color = UI_COLORS['hover_solid_border'] if is_msw() and self.widget.IsDoubleBuffered(): gc = self.dc.GetGraphicsContext() gc.SetAntialiasMode(wx.ANTIALIAS_NONE) self.dc.SetPen(wx.Pen(wx.Colour(*color), 1)) self.dc.SetBrush(wx.TRANSPARENT_BRUSH) self.dc.DrawRoundedRectangle(0, 0, w, h, 3.0) else: self.pdc.SetPen(wx.Pen(wx.Colour(*color), 1)) self.pdc.SetBrush(wx.TRANSPARENT_BRUSH) self.pdc.DrawRoundedRectangle(0, 0, w, h, 3.0)
def __init__(self, parent, data=[], border=True, alt_color=True, use_icons=True, on_select=None, highlight_row=True): style = wx.TR_DEFAULT_STYLE | wx.TR_HAS_BUTTONS | wx.TR_HIDE_ROOT if const.is_msw(): highlight_row = False if highlight_row: style |= wx.TR_FULL_ROW_HIGHLIGHT if not highlight_row: alt_color = False if border and not const.is_wx3(): style |= wx.BORDER_MASK wx.TreeCtrl.__init__(self, parent, wx.ID_ANY, style=style) self.alt_color = alt_color self.use_icons = use_icons self.select_cmd = on_select self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.recolor_items, self) self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.recolor_items, self) if self.select_cmd: self.Bind(wx.EVT_TREE_SEL_CHANGED, self.sel_changed, self) self.update(data)
def set_enable(self, value): WidgetMixin.set_enable(self, value) if const.is_msw(): self.set_bitmap(self.bmp)
def _get_bitmap(self): if const.is_msw() and not self.get_enabled(): return disabled_bmp(self.bmp) return self.bmp
def set_double_buffered(self): if is_msw(): self.SetDoubleBuffered(True)
def set_enable(self, value): Widget.set_enable(self, value) if const.is_msw(): self.set_bitmap(self.bmp)