Mercurial > urwid-satext
diff urwid_satext/sat_widgets.py @ 151:6689aa54b20c default tip
refactoring from camelCase -> snake_case:
This libraries was using camelCase due for historical reasons (related to the use of
Twisted in the initial project).
This patch fixes it by using PEP8 compliant snake_case
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 15:38:18 +0200 |
parents | aa8f46b43a71 |
children |
line wrap: on
line diff
--- a/urwid_satext/sat_widgets.py Wed Dec 08 15:33:28 2021 +0100 +++ b/urwid_satext/sat_widgets.py Sat Apr 08 15:38:18 2023 +0200 @@ -30,7 +30,7 @@ FOCUS_KEYS = (a_key['FOCUS_SWITCH'], a_key['FOCUS_UP'], a_key['FOCUS_DOWN']) -def getFocusDirection(key, inversed=False): +def get_focus_direction(key, inversed=False): """Return direction and rotate boolean depending on key @param key: one of FOCUS_KEYS @param inversed: inverse directions if True @@ -56,10 +56,10 @@ new behaviour: emit a 'click' signal when enter is pressed""" signals = urwid.Edit.signals + ['click'] - def getValue(self): + def get_value(self): return self.get_edit_text() - def setCompletionMethod(self, callback): + def set_completion_method(self, callback): """Define method called when completion is asked @callback: method with 2 arguments: @@ -175,9 +175,9 @@ if not mode_key: #we are in NORMAL mode self.set_edit_text('') - def setCompletionMethod(self, callback): - """ Same as AdvancedEdit.setCompletionMethod, but with a third argument: current mode""" - super(ModalEdit, self).setCompletionMethod(lambda text,data: callback(text, data, self._mode)) + def set_completion_method(self, callback): + """ Same as AdvancedEdit.set_completion_method, but with a third argument: current mode""" + super(ModalEdit, self).set_completion_method(lambda text,data: callback(text, data, self._mode)) def keypress(self, size, key): if key == a_key['MODAL_ESCAPE']: @@ -227,10 +227,10 @@ self.header = header self.text = text urwid.WidgetWrap.__init__(self, urwid.Text("",align=align)) - self.setSelectedText(selected_text) - self.setState(selected) + self.set_selected_text(selected_text) + self.set_state(selected) - def getValue(self): + def get_value(self): if isinstance(self.text,str): return self.text list_attr = self.text if isinstance(self.text, list) else [self.text] @@ -244,23 +244,23 @@ def get_text(self): """for compatibility with urwid.Text""" - return self.getValue() + return self.get_value() def set_text(self, text): """/!\ set_text doesn't change self.selected_txt !""" self.text = text - self.setState(self._selected,invisible=True) + self.set_state(self._selected,invisible=True) - def setSelectedText(self, text=None): + def set_selected_text(self, text=None): """Text to display when selected @text: text as in urwid.Text or None for default value """ if text == None: - text = ('selected',self.getValue()) + text = ('selected',self.get_value()) self.selected_txt = text if self._selected: - self.setState(self._selected) + self.set_state(self._selected) def _set_txt(self): txt_list = [self.header] @@ -272,7 +272,7 @@ self._w.base_widget.set_text(txt_list) - def setState(self, selected, invisible=False): + def set_state(self, selected, invisible=False): """Change state @param selected: boolean state value @@ -286,7 +286,7 @@ if not invisible: self._emit("change", self._selected) - def getState(self): + def get_state(self): return self._selected def selectable(self): @@ -294,13 +294,13 @@ def keypress(self, size, key): if key in (a_key['TEXT_SELECT'], a_key['TEXT_SELECT2']): - self.setState(not self._selected) + self.set_state(not self._selected) else: return key def mouse_event(self, size, event, button, x, y, focus): if is_mouse_press(event) and button == 1: - self.setState(not self._selected) + self.set_state(not self._selected) return True return False @@ -340,8 +340,8 @@ class ClickableText(SelectableText): signals = SelectableText.signals + ['click'] - def setState(self, selected, invisible=False): - super(ClickableText,self).setState(False,True) + def set_state(self, selected, invisible=False): + super(ClickableText,self).set_state(False,True) if not invisible: self._emit('click') @@ -357,7 +357,7 @@ if on_press: urwid.connect_signal(self, 'click', on_press, user_data) - def getSize(self): + def get_size(self): """Return representation size of the button""" return self.size @@ -423,7 +423,7 @@ self._value = value @staticmethod - def fromOptions(options): + def from_options(options): """ convert a list of string/tuple options to a list of listOption @param options: list of managed option type (basestring, tuple) return: list of ListOption @@ -477,28 +477,28 @@ self._on_new = on_new self._on_delete = on_delete - def __cbSingle(self, item, cb): + def __cb_single(self, item, cb): try: cb(item) except TypeError: pass - def __cbMulti(self, items, cb): + def __cb_multi(self, items, cb): if cb is not None: for item in items: cb(item) def __add__(self, new_list): - self.__cbMulti(new_list, self._on_new) + self.__cb_multi(new_list, self._on_new) return super(SimpleListWalkerWithCb, self).__add__(new_list) def __delitem__(self, item): - self.__cbSingle(item, self._on_delete) + self.__cb_single(item, self._on_delete) return super(SimpleListWalkerWithCb, self).__delitem__(item) def __delslice__(self, i,j): items = super(SimpleListWalkerWithCb, self).__getslice__(i,j) - self.__cbMulti(items, self._on_delete) + self.__cb_multi(items, self._on_delete) return super(SimpleListWalkerWithCb, self).__delslice(i,j) def __iadd__(self, y): @@ -515,31 +515,31 @@ def __setitem__(self, i, y): parent = super(SimpleListWalkerWithCb, self) - self.__cbSingle(y, self._on_new) + self.__cb_single(y, self._on_new) to_delete = parent.__getitem__(i) - self.__cbSingle(to_delete, self._on_delete) + self.__cb_single(to_delete, self._on_delete) return parent.__setitem__(i, y) def __setslice__(self, i, j, y): parent = super(SimpleListWalkerWithCb, self) items_to_delete = parent.__getslice__(i,j) - self.__cbMulti(items_to_delete, self._on_delete) + self.__cb_multi(items_to_delete, self._on_delete) if hasattr(y, '__iter__'): - self.__cbMulti(y, self._on_new) + self.__cb_multi(y, self._on_new) else: - self.__cbSingle(y, self._on_new) + self.__cb_single(y, self._on_new) return parent.__setslice__(i, j, y) def append(self, obj): - self.__cbSingle(obj, self._on_new) + self.__cb_single(obj, self._on_new) return super(SimpleListWalkerWithCb, self).append(obj) def extend(self, it): - self.__cbMulti(it, self.__on_new) + self.__cb_multi(it, self.__on_new) return super(SimpleListWalkerWithCb, self).extend(it) def insert(self, idx, obj): - self.__cbSingle(obj, self.__on_new) + self.__cb_single(obj, self.__on_new) return super(SimpleListWalkerWithCb, self).insert(idx, obj) def pop(self, idx=None): @@ -548,12 +548,12 @@ parent = super(SimpleListWalkerWithCb, self) to_remove = parent.__getitem__(idx) - self.__cbSingle(to_remove, self._on_delete) + self.__cb_single(to_remove, self._on_delete) return parent.pop(idx) def remove(self, val): ret = super(SimpleListWalkerWithCb, self).remove(val) - self.__cbSingle(val, self._on_delete) + self.__cb_single(val, self._on_delete) return ret @@ -591,12 +591,12 @@ if on_change: urwid.connect_signal(self, 'change', on_change, user_data) - self.content = SimpleListWalkerWithCb([], self._addSignals, lambda widget: self._emit('change')) + self.content = SimpleListWalkerWithCb([], self._add_signals, lambda widget: self._emit('change')) super(GenericList, self).__init__(self.content) - self.changeValues(options) + self.change_values(options) - def _addSignals(self, widget): - for signal, callback in (('change', self._onStateChange), ('click', self._onClick)): + def _add_signals(self, widget): + for signal, callback in (('change', self._on_state_change), ('click', self._on_click)): try: urwid.connect_signal(widget, signal, callback) except NameError: @@ -606,79 +606,79 @@ def contents(self): return self.content - def _onStateChange(self, widget, selected, *args): + def _on_state_change(self, widget, selected, *args): if self.single: if not selected and not self.can_select_none: #if in single mode, it's forbidden to unselect a value - widget.setState(True, invisible=True) + widget.set_state(True, invisible=True) return if selected: - self.unselectAll(invisible=True) - widget.setState(True, invisible=True) + self.unselect_all(invisible=True) + widget.set_state(True, invisible=True) self._emit("change", widget, selected, *args) - def _onClick(self, widget, *args): + def _on_click(self, widget, *args): if widget not in self.content: - urwid.disconnect_signal(widget, "click", self._onClick) + urwid.disconnect_signal(widget, "click", self._on_click) return self._emit("click", widget, *args) - def unselectAll(self, invisible=False): + def unselect_all(self, invisible=False): for widget in self.content: - if widget.getState(): - widget.setState(False, invisible) + if widget.get_state(): + widget.set_state(False, invisible) widget._invalidate() - def deleteValue(self, value): + def delete_value(self, value): """Delete the first value equal to the param given""" for widget in self.content: - if widget.getValue() == value: + if widget.get_value() == value: self.content.remove(widget) self._emit('change') return raise ValueError("%s ==> %s" % (str(value),str(self.content))) - def getSelectedValue(self): + def get_selected_value(self): """Convenience method to get the value selected as a string in single mode, or None""" - values = self.getSelectedValues() + values = self.get_selected_values() return values[0] if values else None - def getAllValues(self): + def get_all_values(self): """Return values of all items""" - return [widget.getValue() for widget in self.content] + return [widget.get_value() for widget in self.content] - def getSelectedValues(self): + def get_selected_values(self): """Return values of selected items""" result = [] for widget in self.content: - if widget.getState(): - result.append(widget.getValue()) + if widget.get_state(): + result.append(widget.get_value()) return result def on_option_change(self, wid, *args, **kwargs): if self.single: for w in self.content: if w is not wid: - w.setState(False, invisible=True) + w.set_state(False, invisible=True) - def changeValues(self, new_values): + def change_values(self, new_values): """Change all values in one shot""" - new_values = ListOption.fromOptions(new_values) - old_selected = self.getSelectedValues() if not self.first_display else [] + new_values = ListOption.from_options(new_values) + old_selected = self.get_selected_values() if not self.first_display else [] widgets = [] for option in new_values: widget = self.option_type(option, align=self.align) urwid.connect_signal(widget, "change", self.on_option_change) if not self.first_display and option in old_selected: - widget.setState(True) + widget.set_state(True) widgets.append(widget) self.content[:] = widgets if self.first_display and self.single and new_values and not self.no_first_select: - self.content[0].setState(True) + self.content[0].set_state(True) self._emit('change') self.first_display = False - def selectValue(self, value, move_focus=True): + def select_value(self, value, move_focus=True): """Select the first item which has the given value. @param value @@ -687,17 +687,17 @@ - False to leave the focus position unchanged. """ - self.unselectAll() + self.unselect_all() idx = 0 for widget in self.content: - if widget.getValue() == value: - widget.setState(True) + if widget.get_value() == value: + widget.set_state(True) if move_focus: self.focus_position = idx return idx+=1 - def selectValues(self, values, move_focus=True): + def select_values(self, values, move_focus=True): """Select all the given values. @param values [set, list] @@ -706,14 +706,14 @@ """ if self.single: if values: - self.selectValue(values[-1], move_focus) + self.select_value(values[-1], move_focus) return - self.unselectAll() + self.unselect_all() for value in values: idx = 0 for widget in self.content: - if widget.getValue() == value: - widget.setState(True) + if widget.get_value() == value: + widget.set_state(True) if move_focus: self.focus_position = idx idx += 1 @@ -739,48 +739,48 @@ return True def get_cursor_coords(self, size): - return self.genericList.get_cursor_coords((size[0], self._getHeight(size, True))) + return self.genericList.get_cursor_coords((size[0], self._get_height(size, True))) def keypress(self, size, key): - return self.displayWidget(size,True).keypress(size, key) + return self.display_widget(size,True).keypress(size, key) - def unselectAll(self, invisible=False): - return self.genericList.unselectAll(invisible) + def unselect_all(self, invisible=False): + return self.genericList.unselect_all(invisible) - def deleteValue(self, value): - return self.genericList.deleteValue(value) + def delete_value(self, value): + return self.genericList.delete_value(value) - def getSelectedValue(self): - return self.genericList.getSelectedValue() + def get_selected_value(self): + return self.genericList.get_selected_value() - def getAllValues(self): - return self.genericList.getAllValues() + def get_all_values(self): + return self.genericList.get_all_values() - def getSelectedValues(self): - return self.genericList.getSelectedValues() + def get_selected_values(self): + return self.genericList.get_selected_values() - def changeValues(self, new_values): - return self.genericList.changeValues(new_values) + def change_values(self, new_values): + return self.genericList.change_values(new_values) - def selectValue(self, value, move_focus=True): - return self.genericList.selectValue(value, move_focus) + def select_value(self, value, move_focus=True): + return self.genericList.select_value(value, move_focus) - def selectValues(self, values, move_focus=True): - return self.genericList.selectValues(values, move_focus) + def select_values(self, values, move_focus=True): + return self.genericList.select_values(values, move_focus) def render(self, size, focus=False): - return self.displayWidget(size, focus).render(size, focus) + return self.display_widget(size, focus).render(size, focus) def rows(self, size, focus=False): - return self.displayWidget(size, focus).rows(size, focus) + return self.display_widget(size, focus).rows(size, focus) - def _getHeight(self, size, focus): + def _get_height(self, size, focus): list_size = sum([wid.rows(size, focus) for wid in self.genericList.content]) height = min(list_size,self.max_height) or 1 return height - def displayWidget(self, size, focus): - return urwid.BoxAdapter(self.genericList, self._getHeight(size, focus)) + def display_widget(self, size, focus): + return urwid.BoxAdapter(self.genericList, self._get_height(size, focus)) ## MISC ## @@ -792,18 +792,18 @@ def __init__(self): self.waitNotifs = urwid.Text('') self.message = ClickableText('') - urwid.connect_signal(self.message, 'click', lambda wid: self.showNext()) + urwid.connect_signal(self.message, 'click', lambda wid: self.show_next()) self.progress = ClickableText('') self.columns = urwid.Columns([('fixed',6,self.waitNotifs),self.message,('fixed',4,self.progress)]) urwid.WidgetWrap.__init__(self, urwid.AttrMap(self.columns,'notifs')) self.notifs = [] - def _modQueue(self): + def _mod_queue(self): """must be called each time the notifications queue is changed""" self.waitNotifs.set_text(('notifs',"(%i)" % len(self.notifs) if self.notifs else '')) self._emit('change') - def setProgress(self,percentage): + def set_progress(self,percentage): """Define the progression to show on the right side of the bar""" if percentage == None: self.progress.set_text('') @@ -813,22 +813,22 @@ self.columns.focus_position = len(self.columns.contents)-1 self._emit('change') - def addPopUp(self, pop_up_widget): + def add_pop_up(self, pop_up_widget): """Add a popup to the waiting queue""" self.notifs.append(('popup',pop_up_widget)) - self._modQueue() + self._mod_queue() - def removePopUp(self, pop_up_widget): + def remove_pop_up(self, pop_up_widget): """Remove a popup from the waiting queue""" for idx, (wid_type, widget) in enumerate(self.notifs): if widget == pop_up_widget: del self.notifs[idx] - self._modQueue() + self._mod_queue() return raise ValueError("trying to remove an unknown pop_up_widget") - def addMessage(self, message): + def add_message(self, message): "Add a message to the notificatio bar" if not self.message.get_text(): self.message.set_text(('notifs',message)) @@ -836,9 +836,9 @@ self._emit('change') else: self.notifs.append(('message',message)) - self._modQueue() + self._mod_queue() - def showNext(self): + def show_next(self): """Show next message if any, else delete current message""" found = None for notif in self.notifs: @@ -848,13 +848,13 @@ if found: self.notifs.remove(found) self.message.set_text(('notifs',found[1])) - self._modQueue() + self._mod_queue() self.focus_possition = 1 else: self.message.set_text('') self._emit('change') - def getNextPopup(self): + def get_next_popup(self): """Return next pop-up and remove it from the queue @return: pop-up or None if there is no more in the queue""" ret = None @@ -864,15 +864,15 @@ break if ret: self.notifs.remove(notif) - self._modQueue() + self._mod_queue() return ret - def isQueueEmpty(self): + def is_queue_empty(self): return not bool(self.notifs) - def canHide(self): + def can_hide(self): """Return True if there is no important information to show""" - return self.isQueueEmpty() and not self.message.get_text() and not self.progress.get_text() + return self.is_queue_empty() and not self.message.get_text() and not self.progress.get_text() class MenuBox(urwid.WidgetWrap): @@ -884,13 +884,13 @@ self.selected = None content = urwid.SimpleListWalker([ClickableText(('menuitem',text)) for text in items]) for wid in content: - urwid.connect_signal(wid, 'click', self.onClick) + urwid.connect_signal(wid, 'click', self.on_click) self.listBox = urwid.ListBox(content) menubox = urwid.LineBox(urwid.BoxAdapter(self.listBox,len(items))) urwid.WidgetWrap.__init__(self,menubox) - def getValue(self): + def get_value(self): return self.selected def keypress(self, size, key): @@ -908,8 +908,8 @@ return True return super(MenuBox,self).mouse_event(size, event, button, x, y, focus) - def onClick(self, wid): - self.selected = wid.getValue() + def on_click(self, wid): + self.selected = wid.get_value() self._emit('click') @@ -932,14 +932,14 @@ def selectable(self): return True - def getMenuSize(self): + def get_menu_size(self): """return the current number of categories in this menu""" return len(self.menu_keys) - def setOrigX(self, orig_x): + def set_orig_x(self, orig_x): self.x_orig = orig_x - def __buildOverlay(self, menu_key, columns): + def __build_overlay(self, menu_key, columns): """Build the overlay menu which show menuitems @param menu_key: name of the category @param columns: column number where the menubox must be displayed""" @@ -950,7 +950,7 @@ self.save_bottom = self.loop.widget menu_box = MenuBox(self,[item[0] for item in self.menu[menu_key]]) - urwid.connect_signal(menu_box, 'click', self.onItemClick) + urwid.connect_signal(menu_box, 'click', self.on_item_click) self.loop.widget = urwid.Overlay(urwid.AttrMap(menu_box,'menubar'),self.save_bottom,('fixed left', columns),max_len+2,('fixed top',1),None) @@ -964,14 +964,14 @@ return self._w.base_widget.keypress(size, key) - def checkShortcuts(self, key): + def check_shortcuts(self, key): for shortcut in list(self.shortcuts.keys()): if key == shortcut: category, item, callback = self.shortcuts[shortcut] callback((category, item)) return key - def addMenu(self, category, item=None, callback=None, shortcut=None): + def add_menu(self, category, item=None, callback=None, shortcut=None): """Create the category if new and add a menu item (if item is not None). @param category: category of the menu (e.g. File/Edit) @@ -980,10 +980,10 @@ if not category in list(self.menu.keys()): self.menu_keys.append(category) self.menu[category] = [] - button = CustomButton(('menubar',category), self.onCategoryClick, + button = CustomButton(('menubar',category), self.on_category_click, left_border = ('menubar',"[ "), right_border = ('menubar'," ]")) - self._w.base_widget.addWidget(button,button.getSize()) + self._w.base_widget.add_widget(button,button.get_size()) if not item: return self.menu[category].append((item, callback)) @@ -991,9 +991,9 @@ assert(shortcut not in list(self.shortcuts.keys())) self.shortcuts[shortcut] = (category, item, callback) - def onItemClick(self, widget): - category = self._w.base_widget.getSelected().get_label() - item = widget.getValue() + def on_item_click(self, widget): + category = self._w.base_widget.get_selected().get_label() + item = widget.get_value() callback = None for menu_item in self.menu[category]: if item == menu_item[0]: @@ -1003,9 +1003,9 @@ self.keypress(None, a_key['MENU_UP']) callback((category, item)) - def onCategoryClick(self, button): - self.__buildOverlay(button.get_label(), - self.x_orig + self._w.base_widget.getStartCol(button)) + def on_category_click(self, button): + self.__build_overlay(button.get_label(), + self.x_orig + self._w.base_widget.get_start_col(button)) MenuItem = collections.namedtuple('MenuItem', ('name', 'widget')) @@ -1031,9 +1031,9 @@ except ValueError: name, menu = menu_tuple id_ = None - self.addMenu(name, menu, id_) + self.add_menu(name, menu, id_) - def _showSelected(self): + def _show_selected(self): """show menu selected""" if self.selected is None: self.columns.contents[0] = (urwid.Text(''), ('given', 0, False)) @@ -1044,7 +1044,7 @@ current_name = ClickableText(name_txt) name_len = len(name_txt) current_menu = menu_item.widget - current_menu.setOrigX(name_len) + current_menu.set_orig_x(name_len) self.columns.contents[0] = (current_name, ('given', name_len, False)) self.columns.contents[1] = (current_menu, ('weight', 1, False)) @@ -1059,23 +1059,23 @@ if self.columns.get_focus_column()==0: if idx > 0: self.selected = menu_ids[idx-1] - self._showSelected() + self._show_selected() return elif key==a_key['MENU_ROLLER_DOWN']: if self.columns.get_focus_column()==0: if idx < len(menu_ids)-1: self.selected = menu_ids[idx+1] - self._showSelected() + self._show_selected() return elif key==a_key['MENU_ROLLER_RIGHT']: if self.columns.get_focus_column()==0 and \ (isinstance(self.columns.contents[1][0], urwid.Text) or \ - self.menu_items[self.selected].widget.getMenuSize()==0): + self.menu_items[self.selected].widget.get_menu_size()==0): return #if we have no menu or the menu is empty, we don't go the right column return super(MenuRoller, self).keypress(size, key) - def addMenu(self, name, widget, menu_id=None): + def add_menu(self, name, widget, menu_id=None): """Add a menu @param name: name of the menu to add, it name already exists, menu is not added @@ -1094,13 +1094,13 @@ id_ = names[name] menu_item = self.menu_items[id_] if menu_item.widget is not widget: - raise ValueError("The menu with id [{}] exists and doesn't contain the given instance. Use replaceMenu if you want to change the menu.".format(id_)) + raise ValueError("The menu with id [{}] exists and doesn't contain the given instance. Use replace_menu if you want to change the menu.".format(id_)) if self.selected is None: self.selected = id_ - self._showSelected() + self._show_selected() return id_ - def replaceMenu(self, name, widget, menu_id): + def replace_menu(self, name, widget, menu_id): """Add a menu or replace it if the id already exists @param name: name of the menu to add, it name already exists, menu is not added @@ -1110,22 +1110,22 @@ assert menu_id is not None if menu_id in self.menu_items: del self.menu_items[menu_id] - self.addMenu(name, widget, menu_id) + self.add_menu(name, widget, menu_id) if self.selected == menu_id: - self._showSelected() #if we are on the menu, we update it + self._show_selected() #if we are on the menu, we update it - def removeMenu(self, menu_id): + def remove_menu(self, menu_id): del self.menu_items[menu_id] if self.selected == menu_id: try: self.selected = next(iter(self.menu_items.keys())) except StopIteration: self.selected = None - self._showSelected() + self._show_selected() - def checkShortcuts(self, key): + def check_shortcuts(self, key): for menu_item in list(self.menu_items.values()): - key = menu_item.widget.checkShortcuts(key) + key = menu_item.widget.check_shortcuts(key) return key @@ -1156,7 +1156,7 @@ decorated_frame = urwid.LineBox(frame) urwid.WidgetWrap.__init__(self, decorated_frame) - def setCallback(self, name, callback, data=None): + def set_callback(self, name, callback, data=None): """Set the callback associated with a button press @param name: one of "ok", "cancel", "yes", "no" @@ -1216,12 +1216,12 @@ self.__start = 0 self.__next = False - def addWidget(self, widget, width): + def add_widget(self, widget, width): self.widget_list.append((width,widget)) if len(self.widget_list) == 1: self.focus_position = 0 - def getStartCol(self, widget): + def get_start_col(self, widget): """Return the column of the left corner of the widget""" start_col = 0 for wid in self.widget_list[self.__start:]: @@ -1251,7 +1251,7 @@ return self.widget_list[self.focus_column][1].keypress(size,key) return key - def getSelected(self): + def get_selected(self): """Return selected widget""" return self.widget_list[self.focus_column][1] @@ -1290,7 +1290,7 @@ end_wid-=1 cols_left = maxcol - total_wid - self.__start = start_wid #we need to keep it for getStartCol + self.__start = start_wid #we need to keep it for get_start_col return _prev,_next,start_wid,end_wid,cols_left @@ -1356,7 +1356,7 @@ return if key in FOCUS_KEYS: - direction, rotate = getFocusDirection(key, inversed = self._focus_inversed) + direction, rotate = get_focus_direction(key, inversed = self._focus_inversed) max_pos = len(self.contents) - 1 new_pos = self.focus_position + direction if rotate: @@ -1382,7 +1382,7 @@ return if key in FOCUS_KEYS: - direction, rotate = getFocusDirection(key) + direction, rotate = get_focus_direction(key) positions = [pos for pos in self.ordered_positions if pos in self] selectables = [pos for pos in positions if self.contents[pos][0].selectable()] # keep positions which exists and have a selectable widget @@ -1441,7 +1441,7 @@ def keypress(self, size, key): return self._w.keypress(size,key) - def _buttonClicked(self, button, invisible=False): + def _button_clicked(self, button, invisible=False): """Called when a button on the tab is changed, change the page @param button: button clicked @@ -1461,20 +1461,20 @@ if not invisible: self._emit('click') - def _appendButton(self, name, selected=False): + def _append_button(self, name, selected=False): """Append a button to the frame header, and link it to the page change method. @param name (unicode): button name @param selected (bool): set to True to select this tab """ - button = CustomButton(name, self._buttonClicked, left_border = '', right_border=' | ') - self._buttons_cont.addWidget(button, button.getSize()) + button = CustomButton(name, self._button_clicked, left_border = '', right_border=' | ') + self._buttons_cont.add_widget(button, button.get_size()) count = len(self._buttons_cont.widget_list) if selected or count == 1: # first/selected button: we set the focus and the body - self.selectTab(count - 1) + self.select_tab(count - 1) - def addTab(self, name, content=None, selected=False): + def add_tab(self, name, content=None, selected=False): """Add a page to the container @param name: name of the page (what appear on the tab) @@ -1490,21 +1490,21 @@ tab = content self.tabs.append([name, tab]) - self._appendButton(name, selected) + self._append_button(name, selected) return tab - def addFooter(self, widget): + def add_footer(self, widget): """Add a widget on the bottom of the tab (will be displayed on all pages) @param widget: FlowWidget""" self._w.footer = widget - def selectTab(self, index): + def select_tab(self, index): """Select a tab. @param index (int): index of the tab to select """ self._buttons_cont.focus_position = index - self._buttonClicked(self._buttons_cont.widget_list[index][1], True) + self._button_clicked(self._buttons_cont.widget_list[index][1], True) class HighlightColumns(urwid.AttrMap): @@ -1543,7 +1543,7 @@ def focus_position(self, value): self.base_widget.focus_position = value - def addWidget(self, wid, options): + def add_widget(self, wid, options): """ Add a widget to the columns Widget is wrapped with AttrMap, that's why Columns.contents should not be used directly for appending new widgets @param wid: widget to add @@ -1607,9 +1607,9 @@ self._longuest = self._columns * [0] self._next_row_idx = None for item in items: - self.addWidget(item) + self.add_widget(item) - def _getIdealSize(self, widget): + def _get_ideal_size(self, widget): """ return preferred size for widget, or 0 if we can't find it """ try: return len(widget.text) @@ -1623,7 +1623,7 @@ return super(TableContainer, self).keypress(size, key) - def addWidget(self, widget): + def add_widget(self, widget): # TODO: use a contents property ? pile = self._w col_idx = self._idx % self._columns @@ -1640,7 +1640,7 @@ if 'ADAPT' in self._options and (col_idx in self._options['ADAPT'] or self._options['ADAPT'] == ()): - current_len = self._getIdealSize(widget) + current_len = self._get_ideal_size(widget) longuest = self._longuest[col_idx] max_len = max(longuest, current_len) if max_len > longuest: @@ -1650,10 +1650,10 @@ col.contents[col_idx] = (col.contents[col_idx][0], col.options('given', max_len)) options = columns.options('given', max_len) if max_len else columns.options() - columns.addWidget(widget, options or columns.options()) + columns.add_widget(widget, options or columns.options()) if self._row_selectable and col_idx == self._columns - 1: - columns.addWidget(urwid.SelectableIcon(''), columns.options('given', 0)) + columns.add_widget(urwid.SelectableIcon(''), columns.options('given', 0)) if not columns.selectable() and columns.contents[-1][0].base_widget.selectable(): columns.focus_position = len(columns.contents)-1 @@ -1661,14 +1661,14 @@ pile.focus_position = len(pile.contents) - 1 self._idx += 1 - def setRowIndex(self, idx): + def set_row_index(self, idx): self._next_row_idx = idx - def getSelectedWidgets(self): + def get_selected_widgets(self): columns = self._w.focus return (wid for wid, _ in columns.contents) - def getSelectedIndex(self): + def get_selected_index(self): columns = self._w.focus return columns.row_idx