# HG changeset patch # User Goffi # Date 1565679341 -7200 # Node ID 144bdf877d2180b264e6c4a9de64261f855990cc # Parent 2855123621a0b1403c19052337935721c068bbbd python 3 port (using 2to3) diff -r 2855123621a0 -r 144bdf877d21 setup.py --- a/setup.py Tue Aug 13 19:09:08 2019 +0200 +++ b/setup.py Tue Aug 13 08:55:41 2019 +0200 @@ -9,13 +9,13 @@ setup( name=name, version="0.8.0.dev0", - description=u"SàT extension widgets for Urwid", - long_description=(u"Urwid SàT extension widgets is a set of widgets for the console " - u"user interface library Urwid (http://excess.org/urwid/). This " - u"library, originaly made for the SàT project, was eventually " - u"separated so other softwares can use it. Widgets provided " - u"include password text box, tab container, dialogs, file chooser " - u"etc. Feel free to go to the project page for more informations."), + description="SàT extension widgets for Urwid", + long_description=("Urwid SàT extension widgets is a set of widgets for the console " + "user interface library Urwid (http://excess.org/urwid/). This " + "library, originaly made for the SàT project, was eventually " + "separated so other softwares can use it. Widgets provided " + "include password text box, tab container, dialogs, file chooser " + "etc. Feel free to go to the project page for more informations."), author="Goffi (Jérôme Poisson)", author_email="goffi@goffi.org", url="http://wiki.goffi.org/wiki/Urwid-satext", diff -r 2855123621a0 -r 144bdf877d21 urwid_satext/__init__.py --- a/urwid_satext/__init__.py Tue Aug 13 19:09:08 2019 +0200 +++ b/urwid_satext/__init__.py Tue Aug 13 08:55:41 2019 +0200 @@ -18,7 +18,7 @@ # along with this program. If not, see . import gettext -gettext.install('urwid_satext', unicode=True) +gettext.install('urwid_satext') __version__ = '0.7.0' diff -r 2855123621a0 -r 144bdf877d21 urwid_satext/files_management.py --- a/urwid_satext/files_management.py Tue Aug 13 19:09:08 2019 +0200 +++ b/urwid_satext/files_management.py Tue Aug 13 08:55:41 2019 +0200 @@ -18,7 +18,7 @@ # along with this program. If not, see . import urwid -import sat_widgets +from . import sat_widgets import os, os.path from xml.dom import minidom import logging as log @@ -29,9 +29,9 @@ """AdvancedEdit with manage file paths""" def keypress(self, size, key): - if key == u'~' and self.edit_pos==0: - expanded = os.path.expanduser(u'~') - self.set_edit_text(os.path.normpath(expanded+u'/'+self.edit_text)) + if key == '~' and self.edit_pos==0: + expanded = os.path.expanduser('~') + self.set_edit_text(os.path.normpath(expanded+'/'+self.edit_text)) self.set_edit_pos(len(expanded)+1) elif key == a_key['EDIT_DELETE_LAST_WORD']: if self.edit_pos<2: @@ -94,8 +94,8 @@ files = [] try: for filename in os.listdir(path): - if not isinstance(filename, unicode): - log.warning(u"file [{}] has a badly encode filename, ignoring it".format(filename.decode('utf-8', 'replace'))) + if not isinstance(filename, str): + log.warning("file [{}] has a badly encode filename, ignoring it".format(filename.decode('utf-8', 'replace'))) continue fullpath = os.path.join(path,filename) if os.path.isdir(fullpath): @@ -106,19 +106,19 @@ self.files_list.append(urwid.Text(("warning",_("Impossible to list directory")),'center')) directories.sort() files.sort() - if os.path.abspath(path)!=u'/' and os.path.abspath(path) != u'//': - previous_wid = sat_widgets.ClickableText((u'directory',u'..')) + if os.path.abspath(path)!='/' and os.path.abspath(path) != '//': + previous_wid = sat_widgets.ClickableText(('directory','..')) urwid.connect_signal(previous_wid,'click',self.onPreviousDir) self.files_list.append(previous_wid) for directory in directories: if directory.startswith('.') and not self.show_hidden: continue - dir_wid = sat_widgets.ClickableText((u'directory',directory)) + dir_wid = sat_widgets.ClickableText(('directory',directory)) urwid.connect_signal(dir_wid,'click',self.onDirClick) self.files_list.append(dir_wid) - self.files_list.append(urwid.AttrMap(urwid.Divider(u'-'),'separator')) + self.files_list.append(urwid.AttrMap(urwid.Divider('-'),'separator')) for filename in files: - if filename.startswith(u'.') and not self.show_hidden: + if filename.startswith('.') and not self.show_hidden: continue file_wid = sat_widgets.ClickableText(filename) if self.onFileClick: @@ -139,27 +139,27 @@ """ self.ok_cb = ok_cb self._type = 'dir' if 'dir' in style else 'normal' - self.__home_path = os.path.expanduser(u'~') + self.__home_path = os.path.expanduser('~') widgets = [] if message: widgets.append(urwid.Text(message)) - widgets.append(urwid.Divider(u'─')) - self.path_wid = PathEdit(_(u'Path: ')) + widgets.append(urwid.Divider('─')) + self.path_wid = PathEdit(_('Path: ')) self.path_wid.setCompletionMethod(self._directory_completion) urwid.connect_signal(self.path_wid, 'change', self.onPathChange) widgets.append(self.path_wid) - widgets.append(urwid.Divider(u'─')) + widgets.append(urwid.Divider('─')) header = urwid.Pile(widgets) bookm_list = urwid.SimpleListWalker([]) self.bookmarks = list(self.getBookmarks()) self.bookmarks.sort() for bookmark in self.bookmarks: if bookmark.startswith(self.__home_path): - bookmark=u"~"+bookmark[len(self.__home_path):] + bookmark="~"+bookmark[len(self.__home_path):] book_wid = sat_widgets.ClickableText(bookmark) urwid.connect_signal(book_wid, 'click', self.onBookmarkSelected) bookm_list.append(book_wid) - bookm_wid = urwid.Frame(urwid.ListBox(bookm_list), urwid.AttrMap(urwid.Text(_(u'Bookmarks'),'center'),'title')) + bookm_wid = urwid.Frame(urwid.ListBox(bookm_list), urwid.AttrMap(urwid.Text(_('Bookmarks'),'center'),'title')) self.files_wid = FilesViewer(self.onPreviousDir, self.onDirClick, self.onFileClick if self._type == 'normal' else None) center_row = urwid.Columns([('weight',2,bookm_wid), ('weight',8,sat_widgets.VerticalSeparator(self.files_wid))]) @@ -173,7 +173,7 @@ main_frame = sat_widgets.FocusFrame(center_row, header, buttons_wid) decorated = sat_widgets.LabelLine(main_frame, sat_widgets.SurroundedText(title)) urwid.WidgetWrap.__init__(self, decorated) - self.path_wid.set_edit_text(os.getcwdu()) + self.path_wid.set_edit_text(os.getcwd()) def _validateDir(self, wid): """ call ok callback if current path is a dir """ @@ -182,21 +182,21 @@ self.ok_cb(path) def _directory_completion(self, path, completion_data): - assert isinstance(path, unicode) + assert isinstance(path, str) path=os.path.abspath(path) if not os.path.isdir(path): head,dir_start = os.path.split(path) else: head=path - dir_start=u'' + dir_start='' try: filenames = os.listdir(head) to_remove = [] # we remove badly encoded files for filename in filenames: - if not isinstance(filename, unicode): - log.warning(u"file [{}] has a badly encode filename, ignoring it".format(filename.decode('utf-8', 'replace'))) + if not isinstance(filename, str): + log.warning("file [{}] has a badly encode filename, ignoring it".format(filename.decode('utf-8', 'replace'))) to_remove.append(filename) for filename in to_remove: filenames.remove(filename) @@ -208,7 +208,7 @@ start_idx = 0 except (KeyError,ValueError): start_idx = 0 - for idx in range(start_idx,len(filenames)) + range(0,start_idx): + for idx in list(range(start_idx,len(filenames))) + list(range(0,start_idx)): full_path = os.path.join(head,filenames[idx]) if filenames[idx].lower().startswith(dir_start.lower()) and os.path.isdir(full_path): completion_data['last_dir'] = filenames[idx] @@ -218,8 +218,8 @@ return path def getBookmarks(self): - gtk_bookm = os.path.expanduser(u"~/.gtk-bookmarks") - kde_bookm = os.path.expanduser(u"~/.kde/share/apps/kfileplaces/bookmarks.xml") + gtk_bookm = os.path.expanduser("~/.gtk-bookmarks") + kde_bookm = os.path.expanduser("~/.kde/share/apps/kfileplaces/bookmarks.xml") bookmarks = set() try: with open(gtk_bookm) as gtk_fd: @@ -227,7 +227,7 @@ if bm.startswith("file:///"): bookmarks.add(bm[7:].replace('\n','').decode('utf-8', 'replace')) except IOError: - log.info(_(u'No GTK bookmarks file found')) + log.info(_('No GTK bookmarks file found')) pass try: diff -r 2855123621a0 -r 144bdf877d21 urwid_satext/keys.py --- a/urwid_satext/keys.py Tue Aug 13 19:09:08 2019 +0200 +++ b/urwid_satext/keys.py Tue Aug 13 08:55:41 2019 +0200 @@ -18,6 +18,7 @@ # along with this program. If not, see . """This module manage action <==> key mapping and can be extended to add new actions""" +from functools import reduce class ConflictError(Exception): @@ -68,7 +69,7 @@ @param shortcut: new shortcut to use @raise KeyError: action doesn't exists """ - assert isinstance(action, basestring) + assert isinstance(action, str) if action not in self: raise ValueError("Action [{}] doesn't exist".format(action)) super(ActionMap, self).__setitem__(action, shortcut) @@ -82,10 +83,10 @@ """ if not isinstance(new_actions, dict): raise ValueError("only dictionary subclasses are accepted for update") - conflict = new_actions.viewkeys() & self.viewkeys() + conflict = new_actions.keys() & self.keys() if conflict: raise ConflictError("The actions [{}] already exists".format(','.join(conflict))) - for action, shortcut in new_actions.iteritems(): + for action, shortcut in new_actions.items(): self[action] = shortcut def replace(self, action_shortcuts_map): @@ -97,7 +98,7 @@ """ if not isinstance(action_shortcuts_map, dict): raise ValueError("only dictionary subclasses are accepted for replacing shortcuts") - for action, shortcut in action_shortcuts_map.iteritems(): + for action, shortcut in action_shortcuts_map.items(): self.replace_shortcut(action, shortcut) def set_close_namespaces(self, close_namespaces, always_check=None): diff -r 2855123621a0 -r 144bdf877d21 urwid_satext/sat_widgets.py --- a/urwid_satext/sat_widgets.py Tue Aug 13 19:09:08 2019 +0200 +++ b/urwid_satext/sat_widgets.py Tue Aug 13 08:55:41 2019 +0200 @@ -19,8 +19,6 @@ import urwid import logging as log -import encodings -utf8decode = lambda s: encodings.codecs.utf_8_decode(s)[0] import uuid @@ -121,7 +119,7 @@ """Same args than Edit.__init__ with an additional keyword arg 'hidden_char' @param hidden_char: char to show instead of what is actually entered: default '*' """ - self.hidden_char=kwargs['hidden_char'] if kwargs.has_key('hidden_char') else '*' + self.hidden_char=kwargs['hidden_char'] if 'hidden_char' in kwargs else '*' self.__real_text='' super(Password, self).__init__(*args, **kwargs) @@ -195,7 +193,7 @@ """Text centered on a repeated character (like a Divider, but with a text in the center)""" _sizing = frozenset(['flow']) - def __init__(self,text,car=utf8decode('─')): + def __init__(self,text,car='─'): self.text=text self.car=car @@ -207,7 +205,7 @@ def display_widget(self, size, focus): (maxcol,) = size - middle = (maxcol-len(self.text))/2 + middle = (maxcol-len(self.text))//2 render_text = middle * self.car + self.text + (maxcol - len(self.text) - middle) * self.car return urwid.Text(render_text) @@ -233,7 +231,7 @@ self.setState(selected) def getValue(self): - if isinstance(self.text,basestring): + if isinstance(self.text,str): return self.text list_attr = self.text if isinstance(self.text, list) else [self.text] txt = "" @@ -371,7 +369,7 @@ self.set_text([self.left_border, label, self.right_border]) -class ListOption(unicode): +class ListOption(str): """Unicode which manage label and value This class similar to unicode, but which make the difference between value and label @@ -385,7 +383,7 @@ def __new__(cls, option): if (isinstance(option, cls)): return option - elif isinstance(option, basestring): + elif isinstance(option, str): value = label = option elif (isinstance(option, tuple) and len(option) == 2): value, label = option @@ -517,7 +515,7 @@ self.__cbSingle(y, self._on_new) to_delete = parent.__getitem__(i) self.__cbSingle(to_delete, self._on_delete) - return parent.__setitem__(self, i, y) + return parent.__setitem__(i, y) def __setslice__(self, i, j, y): parent = super(SimpleListWalkerWithCb, self) @@ -819,7 +817,7 @@ self._modQueue() return - raise ValueError(u"trying to remove an unknown pop_up_widget") + raise ValueError("trying to remove an unknown pop_up_widget") def addMessage(self, message): "Add a message to the notificatio bar" @@ -958,7 +956,7 @@ return self._w.base_widget.keypress(size, key) def checkShortcuts(self, key): - for shortcut in self.shortcuts.keys(): + for shortcut in list(self.shortcuts.keys()): if key == shortcut: category, item, callback = self.shortcuts[shortcut] callback((category, item)) @@ -970,7 +968,7 @@ @param category: category of the menu (e.g. File/Edit) @param item: menu item (e.g. new/close/about) @callback: method to call when item is selected""" - if not category in self.menu.keys(): + if not category in list(self.menu.keys()): self.menu_keys.append(category) self.menu[category] = [] button = CustomButton(('menubar',category), self.onCategoryClick, @@ -981,7 +979,7 @@ return self.menu[category].append((item, callback)) if shortcut: - assert(shortcut not in self.shortcuts.keys()) + assert(shortcut not in list(self.shortcuts.keys())) self.shortcuts[shortcut] = (category, item, callback) def onItemClick(self, widget): @@ -1033,7 +1031,7 @@ self.columns.contents[1] = (urwid.Text(''), ('weight', 1, False)) else: menu_item = self.menu_items[self.selected] - name_txt = u'\u21c9 ' + menu_item.name + u' \u21c7 ' + name_txt = '\u21c9 ' + menu_item.name + ' \u21c7 ' current_name = ClickableText(name_txt) name_len = len(name_txt) current_menu = menu_item.widget @@ -1042,7 +1040,7 @@ self.columns.contents[1] = (current_menu, ('weight', 1, False)) def keypress(self, size, key): - menu_ids = self.menu_items.keys() + menu_ids = list(self.menu_items.keys()) try: idx = menu_ids.index(self.selected) except ValueError: @@ -1076,7 +1074,7 @@ @param menu_id: id to use of this menu, or None to generate @return: menu_id """ - names = {menu_item.name: id_ for id_, menu_item in self.menu_items.iteritems()} + names = {menu_item.name: id_ for id_, menu_item in self.menu_items.items()} if name not in names: id_ = menu_id or str(uuid.uuid4()) @@ -1111,13 +1109,13 @@ del self.menu_items[menu_id] if self.selected == menu_id: try: - self.selected = self.menu_items.iterkeys().next() + self.selected = next(iter(self.menu_items.keys())) except StopIteration: self.selected = None self._showSelected() def checkShortcuts(self, key): - for menu_item in self.menu_items.values(): + for menu_item in list(self.menu_items.values()): key = menu_item.widget.checkShortcuts(key) return key @@ -1142,7 +1140,7 @@ if "OK" in style: self.buttons['ok'] = urwid.Button(_("Ok"), kwargs.get('ok_cb'), kwargs.get('ok_value')) if self.buttons: - buttons_flow = urwid.GridFlow(self.buttons.values(), max([len(button.get_label()) for button in self.buttons.itervalues()])+4, 1, 1, 'center') + buttons_flow = urwid.GridFlow(list(self.buttons.values()), max([len(button.get_label()) for button in self.buttons.values()])+4, 1, 1, 'center') body_content = urwid.SimpleListWalker(widgets_lst) frame_body = UnselectableListBox(body_content) frame = FocusFrame(frame_body, frame_header, buttons_flow if self.buttons else None, 'footer' if self.buttons else 'body') @@ -1330,9 +1328,9 @@ render.append((widget.render((width,),_focus),False,_focus,width)) idx+=1 if _prev: - render.insert(0,(urwid.Text([u"◀"]).render((1,),False),False,False,1)) + render.insert(0,(urwid.Text(["◀"]).render((1,),False),False,False,1)) if _next: - render.append((urwid.Text([u"▶"],align='right').render((1+cols_left,),False),False,False,1+cols_left)) + render.append((urwid.Text(["▶"],align='right').render((1+cols_left,),False),False,False,1+cols_left)) else: render.append((urwid.SolidCanvas(" "*cols_left, size[0], 1),False,False,cols_left)) @@ -1428,7 +1426,7 @@ self._current_tab = None self._buttons_cont = ColumnsRoller() self.tabs = [] - self._frame = FocusFrame(urwid.Filler(urwid.Text('')),urwid.Pile([self._buttons_cont,urwid.Divider(u"─")])) + self._frame = FocusFrame(urwid.Filler(urwid.Text('')),urwid.Pile([self._buttons_cont,urwid.Divider("─")])) urwid.WidgetWrap.__init__(self, self._frame) def keypress(self, size, key): @@ -1676,7 +1674,7 @@ class VerticalSeparator(urwid.WidgetDecoration, urwid.WidgetWrap): - def __init__(self, original_widget, left_char = u"│", right_char = ''): + def __init__(self, original_widget, left_char = "│", right_char = ''): """Draw a separator on left and/or right of original_widget.""" widgets = [original_widget]