def set_data(self, data, alt_color=True): even = False i = 0 cols = len(data[0]) subheader = any(isinstance(i, str) for i in data) for item in data[1:]: if isinstance(item, list): list_item = [const.tr(label) for label in item] elif isinstance(item, str): list_item = [ const.tr(item), ] + [ '', ] * (cols - 1) else: continue self.Append(list_item) list_item = self.GetItem(i) if subheader: if isinstance(item, str): list_item.SetBackgroundColour(self.even_color) self.SetItem(list_item) elif alt_color: color = self.even_color if even else self.odd_color list_item.SetBackgroundColour(color) self.SetItem(list_item) even = not even i += 1
def __init__(self, parent, value='', size=DEF_SIZE, width=0, onchange=None, multiline=False, richtext=False, onenter=None, editable=True, no_border=False, no_wrap=False): self.value = tr(value) self.editable = editable self._callback = onchange style = wx.TE_MULTILINE if multiline else 0 style = style | wx.TE_RICH2 if richtext else style style = style | wx.NO_BORDER if no_border else style style = style | wx.TE_PROCESS_ENTER if onenter else style style = style | wx.TE_DONTWRAP if no_wrap else style size = self._set_width(size, width) wx.TextCtrl.__init__(self, parent, wx.ID_ANY, self.value, size=size, style=style) if onenter: self._callback1 = onenter self.Bind(wx.EVT_TEXT_ENTER, self._on_enter, self) if multiline: self.ScrollPages(0) self.SetEditable(editable) self.Bind(wx.EVT_TEXT, self._on_change, self)
def __init__(self, parent, title, size=(-1, -1), style=VERTICAL, resizable=False, on_load=None, add_line=True, margin=None): stl = wx.DEFAULT_DIALOG_STYLE stl = stl | wx.RESIZE_BORDER | wx.MAXIMIZE_BOX if resizable else stl self.add_line = add_line wx.Dialog.__init__(self, parent, -1, tr(title), wx.DefaultPosition, size, style=stl) sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(sizer) if margin is None: margin = 5 if const.IS_GTK else 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(200)
def paint_tab_text(self, tab): dc = self.panel s = INDICATOR_SIZE pos = tab.pos + 3 * s - 3 width = tab.get_tab_size() - 5 * s txt = const.tr(tab.text) if const.IS_MSW: if get_text_size(txt, size_incr=-1)[0] > width: while get_text_size(txt + '...', size_incr=-1)[0] > width: txt = txt[:-1] txt += '...' else: while get_text_size(txt, size_incr=-1)[0] > width: txt = txt[:-1] y = int(HTAB_HEIGHT / 2 - dc.set_font(size_incr=-1) / 2) + 1 dc.draw_text(txt, pos, y) if not const.IS_MSW: # text shade pos = tab.pos + tab.get_tab_size() - 5 * s start = self.bg_color[:-1] + (0, ) stop = self.bg_color[:-1] + (255, ) dc.gc_draw_linear_gradient((pos, 4, 3 * s, HTAB_HEIGHT), start, stop, False)
def paint_tab_text(self, tab): dc = self.panel s = INDICATOR_SIZE pos = tab.pos + 3 * s - 3 width = tab.get_tab_size() - 5 * s txt = const.tr(tab.text) if const.IS_MSW: if get_text_size(txt, size_incr=-1)[0] > width: while get_text_size(txt + '...', size_incr=-1)[0] > width: txt = txt[:-1] txt += '...' else: while get_text_size(txt, size_incr=-1)[0] > width: txt = txt[:-1] shift = 2 if tab.active else 1 shift = shift + 2 if const.IS_MSW else shift x = int(VTAB_WIDTH / 2 + dc.set_font(size_incr=-1) / 2) + shift dc.draw_rotated_text(txt, x, pos, 270) if not const.IS_MSW: # text shade pos = tab.pos + tab.get_tab_size() - 5 * s start = self.bg_color[:-1] + (0, ) stop = self.bg_color[:-1] + (255, ) dc.gc_draw_linear_gradient((4, pos, 3 * s, VTAB_WIDTH), start, stop, True)
def add_childs(self, parent, childs): for item in childs: icon = self.get_icons(item) tid = self.AppendItem(parent, const.tr(item.name), icon, NO_ICON) self.items_ref.append(item) self.items.append(tid) self.add_childs(tid, item.childs)
def get_dir_path(parent, path='~', title=''): ret = None title = title or 'Select directory' title = '' if const.IS_MAC else title path = expanduser(path) dlg = wx.DirDialog(parent, message=const.tr(title), defaultPath=const.tr(path), style=wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST) dlg.CenterOnParent() if dlg.ShowModal() == wx.ID_OK: ret = const.untr(dlg.GetPath()) dlg.Destroy() return ret
def get_open_file_name(parent, title='Open', default_dir='~', wildcard='All files (*.*)|*,*.*'): ret = None title = '' if const.IS_MAC else title style = wx.FD_CHANGE_DIR | wx.FD_FILE_MUST_EXIST | wx.FD_PREVIEW dlg = wx.FileDialog( parent, message=const.tr(title), defaultDir=expanduser(default_dir), defaultFile="", wildcard=const.tr(wildcard), style=wx.FD_OPEN | style ) dlg.CenterOnParent() if dlg.ShowModal() == wx.ID_OK: ret = const.untr(dlg.GetPath()) dlg.Destroy() return ret
def _dialog(parent, title, text, icon, yesno=False, cancel=False): ret = None if not yesno and not cancel: dlg = wx.MessageDialog(parent, tr(text), tr(title), wx.OK | icon) dlg.ShowModal() dlg.Destroy() else: buttons = 0 if yesno: buttons = wx.YES_NO if cancel: if not buttons: buttons = wx.OK | wx.CANCEL else: buttons |= wx.CANCEL dlg = wx.MessageDialog(parent, tr(text), tr(title), icon | buttons) ret = dlg.ShowModal() dlg.Destroy() return ret
def __init__(self, parent, text='', value=False, onclick=None, right=False): style = wx.ALIGN_RIGHT if right else 0 wx.CheckBox.__init__(self, parent, wx.ID_ANY, tr(text), style=style) self.SetValue(True if value else False) if onclick: self.callback = onclick self.Bind(wx.EVT_CHECKBOX, self.on_click, self)
def __init__(self, parent, txt=''): VPanel.__init__(self, parent) header = HPanel(self) self.expander = Expander(header, on_click=self.expand) header.pack(self.expander, padding=2) if txt: header.pack(wx.StaticText(header, wx.ID_ANY, tr(txt))) VPanel.pack(self, header, fill=True) self.container = VPanel(self) VPanel.pack(self, self.container, fill=True) self.container.set_visible(False) self.layout()
def get_save_file_name(parent, path, title='', wildcard='*.txt'): ret = None title = title or 'Save As...' title = '' if const.IS_MAC else title path = expanduser(path) doc_folder = os.path.dirname(path) doc_name = os.path.basename(path) style = wx.FD_CHANGE_DIR | wx.FD_OVERWRITE_PROMPT | wx.FD_PREVIEW dlg = wx.FileDialog(parent, message=const.tr(title), defaultDir=doc_folder, defaultFile=const.tr(doc_name), wildcard=const.tr(wildcard), style=wx.FD_SAVE | style) dlg.CenterOnParent() if dlg.ShowModal() == wx.ID_OK: ret = (const.untr(dlg.GetPath()), dlg.GetFilterIndex()) dlg.Destroy() return ret
def __init__(self, parent, size=DEF_SIZE, width=0, items=None, onchange=None): items = items or [] self.items = [tr(item) for item in items] size = self._set_width(size, width) wx.Choice.__init__(self, parent, wx.ID_ANY, size, choices=self.items) if onchange: self.callback = onchange self.Bind(wx.EVT_CHOICE, self.on_change, self)
def set_data(self, data, alt_color=True): even = False i = 0 for item in data: item = const.tr(item) self.Append([item]) if alt_color: list_item = self.GetItem(i) if even: list_item.SetBackgroundColour(self.even_color) else: list_item.SetBackgroundColour(self.odd_color) self.SetItem(list_item) even = not even i += 1
def __init__(self, parent, text, size=DEF_SIZE, onclick=None, tooltip='', default=False, pid=wx.ID_ANY): wx.Button.__init__(self, parent, pid, tr(text), size=size) if default: self.SetDefault() if onclick: self.callback = onclick self.Bind(wx.EVT_BUTTON, self.on_click, self) if tooltip: self.SetToolTipString(tooltip)
def set_data(self, data, alt_color=True): even = False i = 0 for item in data[1:]: if isinstance(item, list): item = [const.tr(label) for label in item] self.Append(item) if alt_color: list_item = self.GetItem(i) if even: list_item.SetBackgroundColour(self.even_color) else: list_item.SetBackgroundColour(self.odd_color) self.SetItem(list_item) even = not even i += 1
def __init__(self, parent, text='', widget=None): RoundedPanel.__init__(self, parent) self.inner_panel = VPanel(self) if widget or text: self.widget_panel = HPanel(self) self.widget = widget if text: self.widget = wx.StaticText(self.widget_panel, wx.ID_ANY, tr(text)) self.widget_panel.pack(self.widget, padding=5) self.widget_panel.Fit() self.add(self.widget_panel, 0, wx.ALIGN_LEFT | wx.LEFT, 7) self.add(self.inner_panel, 1, wx.ALIGN_LEFT | wx.LEFT | wx.BOTTOM | wx.RIGHT | wx.EXPAND, 5) self.parent.refresh()
def __init__(self, parent, bg, icon, callback, tooltip=''): self.callback = callback wx.Panel.__init__(self, parent) self.SetBackgroundColour(bg) self.icon = icon self._set_bmp() self.SetSize(self.icon.GetSize()) if tooltip: self.SetToolTipString(const.tr(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, value='', pos=(-1, 1), size=DEF_SIZE, width=0, items=None, onchange=None): items = items or [] self.items = [tr(item) for item in items] flags = wx.CB_DROPDOWN | wx.TE_PROCESS_ENTER size = self._set_width(size, width) wx.ComboBox.__init__(self, parent, wx.ID_ANY, value, pos, size, items, flags) if onchange: self.callback = onchange self.Bind(wx.EVT_COMBOBOX, self.on_change, self) self.Bind(wx.EVT_TEXT_ENTER, self.on_enter, self) self.Bind(wx.EVT_TEXT, self.on_typing, self)
def __init__(self, parent, text='', fontbold=False, fontsize=0, fg=()): wx.StaticText.__init__(self, parent, wx.ID_ANY, tr(text)) font = self.GetFont() if fontbold: font.SetWeight(wx.FONTWEIGHT_BOLD) if fontsize: if isinstance(fontsize, str): sz = int(fontsize) if font.IsUsingSizeInPixels(): font.SetPixelSize((0, sz)) else: font.SetPointSize(sz) else: if font.IsUsingSizeInPixels(): sz = font.GetPixelSize()[1] + fontsize font.SetPixelSize((0, sz)) else: sz = font.GetPointSize() + fontsize font.SetPointSize(sz) self.SetFont(font) if fg: self.SetForegroundColour(wx.Colour(*fg)) self.Wrap(-1)
def append(self, txt): self.AppendText(tr(txt)) self.value = self.GetValue()
def update(self, value, msg): self.Update(value, tr(msg))
def __init__(self, parent=None, title='', width=130): style = wx.PD_APP_MODAL | wx.PD_AUTO_HIDE wx.ProgressDialog.__init__(self, tr(title), ' ' * width, parent=parent, style=style)
def get_bitmap(self, path=''): path = const.tr(path) return wx.Bitmap(path, self.image_type) if path else wx.NullBitmap
def cursor(path, bitmap_type, x=0, y=0): return wx.Cursor(tr(path), bitmap_type, x, y)
def set_icons(self, filepath): icons = wx.IconBundle() icons.AddIconFromFile(tr(filepath), wx.BITMAP_TYPE_ANY) self.SetIcons(icons)
def append_menu(self, menu_id, txt, menu): self.Append(menu, const.tr(txt))
def __init__(self, parent, action_id, text): wx.MenuItem.__init__(self, parent, action_id, text=const.tr(text))
def append_menu(self, item_id, text, menu): self.AppendMenu(item_id, const.tr(text), menu)
def add_page(self, page, title): page.layout() self.childs.append(page) self.AddPage(page, tr(title))