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, title, size=(-1, -1), style=VERTICAL, resizable=False, on_load=None, add_line=True): dlg_style = wx.DEFAULT_DIALOG_STYLE if resizable:dlg_style |= wx.RESIZE_BORDER self.add_line = add_line wx.Dialog.__init__(self, parent, -1, title, wx.DefaultPosition, size, style=dlg_style) sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(sizer) margin = 5 if not const.is_gtk(): margin = 10 self.box = VPanel(self) sizer.Add(self.box, 1, ALL | EXPAND, margin) if style == HORIZONTAL: self.panel = HPanel(self.box) else: self.panel = VPanel(self.box) self.box.pack(self.panel, expand=True, fill=True) self.build() self.set_dialog_buttons() if size == (-1, -1):self.Fit() self.CenterOnParent() self.Bind(wx.EVT_CLOSE, self.on_close, self) if on_load: self._timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, on_load) self._timer.Start(500)
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, title, size=(-1, -1), style=VERTICAL, resizable=False, on_load=None, add_line=True, margin=None): dlg_style = wx.DEFAULT_DIALOG_STYLE if resizable: dlg_style |= wx.RESIZE_BORDER | wx.MAXIMIZE_BOX self.add_line = add_line wx.Dialog.__init__(self, parent, -1, title, wx.DefaultPosition, size, style=dlg_style) sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(sizer) if margin is None: margin = 5 if not const.is_gtk(): margin = 10 self.box = VPanel(self) sizer.Add(self.box, 1, ALL | EXPAND, margin) if style == HORIZONTAL: self.panel = HPanel(self.box) else: self.panel = VPanel(self.box) self.box.pack(self.panel, expand=True, fill=True) self.build() self.set_dialog_buttons() if size == (-1, -1): self.Fit() self.CenterOnParent() self.panel.layout() self.Bind(wx.EVT_CLOSE, self.on_close, self) if on_load: self._timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, on_load) self._timer.Start(500)
def OnDrawItem(self, dc, rect, item, flags): if item == wx.NOT_FOUND: return r = wx.Rect(*rect) icon_size = (0, 0) if self.font_icon: icon_size = self.font_icon.GetSize() icon_x = r.x + 2 label_y = r.y + 4 label_x = icon_x + 4 + icon_size[0] icon_y = self.control_height / 2 - icon_size[1] / 2 + label_y sample_y = label_y + self.control_height + 2 if flags & wx.combo.ODCB_PAINTING_SELECTED and not \ flags & wx.combo.ODCB_PAINTING_CONTROL: dc.SetBrush( wx.Brush(wx.Colour(*const.UI_COLORS['selected_text_bg']))) dc.DrawRectangle(*r) if self.font_icon: icon = bmp_to_white(self.font_icon) dc.DrawBitmap(icon, icon_x, icon_y, True) dc.SetTextForeground(wx.WHITE) dc.DrawText(self.fontnames[item], label_x, label_y) bmp = bmp_to_white(self.sample_bitmaps[item]) dc.DrawBitmap(bmp, label_x, sample_y, True) elif flags & wx.combo.ODCB_PAINTING_CONTROL: if const.is_gtk(): icon_x += 2 label_x += 2 pdc = wx.PaintDC(self) pdc.SetPen(wx.TRANSPARENT_PEN) pdc.SetBrush(wx.Brush(wx.Colour(*self.GetBackgroundColour()))) h = self.get_size()[1] w = r.width + 3 pdc.DrawRectangle(0, 0, w, h) nr = wx.RendererNative.Get() nr.DrawTextCtrl(self, dc, (0, 0, w, h), wx.CONTROL_DIRTY) if self.font_icon: dc.DrawBitmap(self.font_icon, icon_x, icon_y, True) dc.SetTextForeground(self.fontcolor) dc.DrawText(self.fontnames[item], label_x, label_y) else: if self.font_icon: dc.DrawBitmap(self.font_icon, icon_x, icon_y, True) dc.SetTextForeground(self.fontcolor) dc.DrawText(self.fontnames[item], label_x, label_y) dc.DrawBitmap(self.sample_bitmaps[item], label_x, sample_y, True) dc.SetPen(wx.Pen(wx.Colour(240, 240, 240), 1)) val = sample_y + self.sample_bitmaps[item].GetSize()[1] dc.DrawLine(0, val, r.width, val)
def OnDrawItem(self, dc, rect, item, flags): if item == wx.NOT_FOUND:return r = wx.Rect(*rect) icon_size = (0, 0) if self.font_icon: icon_size = self.font_icon.GetSize() icon_x = r.x + 2 label_y = r.y + 4 label_x = icon_x + 4 + icon_size[0] icon_y = self.control_height / 2 - icon_size[1] / 2 + label_y sample_y = label_y + self.control_height + 2 if flags & wx.combo.ODCB_PAINTING_SELECTED and not \ flags & wx.combo.ODCB_PAINTING_CONTROL: if self.font_icon: icon = bmp_to_white(self.font_icon) dc.DrawBitmap(icon, icon_x, icon_y, True) dc.SetTextForeground(wx.WHITE) dc.DrawText(self.fontnames[item], label_x, label_y) bmp = bmp_to_white(self.sample_bitmaps[item]) dc.DrawBitmap(bmp, label_x, sample_y, True) elif flags & wx.combo.ODCB_PAINTING_CONTROL: if const.is_gtk(): icon_x += 2 label_x += 2 pdc = wx.PaintDC(self) pdc.SetPen(wx.TRANSPARENT_PEN) pdc.SetBrush(wx.Brush(wx.Colour(*self.GetBackgroundColour()))) h = self.get_size()[1] w = r.width + 3 pdc.DrawRectangle(0, 0, w, h) nr = wx.RendererNative.Get() nr.DrawTextCtrl(self, dc, (0, 0, w, h), wx.CONTROL_DIRTY) if self.font_icon: dc.DrawBitmap(self.font_icon, icon_x, icon_y, True) dc.SetTextForeground(self.fontcolor) dc.DrawText(self.fontnames[item], label_x, label_y) else: if self.font_icon: dc.DrawBitmap(self.font_icon, icon_x, icon_y, True) dc.SetTextForeground(self.fontcolor) dc.DrawText(self.fontnames[item], label_x, label_y) dc.DrawBitmap(self.sample_bitmaps[item], label_x, sample_y, True) dc.SetPen(wx.Pen(wx.Colour(240, 240, 240), 1)) val = sample_y + self.sample_bitmaps[item].GetSize()[1] dc.DrawLine(0, val, r.width, val)