diff urwid_satext/files_management.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 144bdf877d21
children
line wrap: on
line diff
--- a/urwid_satext/files_management.py	Wed Dec 08 15:33:28 2021 +0100
+++ b/urwid_satext/files_management.py	Sat Apr 08 15:38:18 2023 +0200
@@ -47,13 +47,13 @@
 class FilesViewer(urwid.WidgetWrap):
     """List specialised for files"""
 
-    def __init__(self, onPreviousDir, onDirClick, onFileClick = None):
+    def __init__(self, on_previous_dir, on_dir_click, on_file_click = None):
         self.path=''
         self.key_cache = ''
         self.key_time = time()
-        self.onPreviousDir = onPreviousDir
-        self.onDirClick = onDirClick
-        self.onFileClick = onFileClick
+        self.on_previous_dir = on_previous_dir
+        self.on_dir_click = on_dir_click
+        self.on_file_click = on_file_click
         self.files_list = urwid.SimpleListWalker([])
         self.show_hidden = True
         listbox = urwid.ListBox(self.files_list)
@@ -63,7 +63,7 @@
         if key==a_key['FILES_HIDDEN_HIDE']:
             #(un)hide hidden files
             self.show_hidden = not self.show_hidden
-            self.showDirectory(self.path)
+            self.show_directory(self.path)
         elif key==a_key['FILES_JUMP_DIRECTORIES']:
             #jump to directories
             if self.files_list:
@@ -87,7 +87,7 @@
         else:
             return self._w.keypress(size, key)
 
-    def showDirectory(self, path):
+    def show_directory(self, path):
         self.path = path
         del self.files_list[:]
         directories = []
@@ -108,21 +108,21 @@
         files.sort()
         if os.path.abspath(path)!='/' and os.path.abspath(path) != '//':
             previous_wid = sat_widgets.ClickableText(('directory','..'))
-            urwid.connect_signal(previous_wid,'click',self.onPreviousDir)
+            urwid.connect_signal(previous_wid,'click',self.on_previous_dir)
             self.files_list.append(previous_wid)
         for directory in directories:
             if directory.startswith('.') and not self.show_hidden:
                 continue
             dir_wid = sat_widgets.ClickableText(('directory',directory))
-            urwid.connect_signal(dir_wid,'click',self.onDirClick)
+            urwid.connect_signal(dir_wid,'click',self.on_dir_click)
             self.files_list.append(dir_wid)
         self.files_list.append(urwid.AttrMap(urwid.Divider('-'),'separator'))
         for filename in files:
             if filename.startswith('.') and not self.show_hidden:
                 continue
             file_wid = sat_widgets.ClickableText(filename)
-            if self.onFileClick:
-                urwid.connect_signal(file_wid,'click',self.onFileClick)
+            if self.on_file_click:
+                urwid.connect_signal(file_wid,'click',self.on_file_click)
             self.files_list.append(file_wid)
 
 
@@ -145,37 +145,37 @@
             widgets.append(urwid.Text(message))
             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)
+        self.path_wid.set_completion_method(self._directory_completion)
+        urwid.connect_signal(self.path_wid, 'change', self.on_path_change)
         widgets.append(self.path_wid)
         widgets.append(urwid.Divider('─'))
         header = urwid.Pile(widgets)
         bookm_list = urwid.SimpleListWalker([])
-        self.bookmarks = list(self.getBookmarks())
+        self.bookmarks = list(self.get_bookmarks())
         self.bookmarks.sort()
         for bookmark in self.bookmarks:
             if bookmark.startswith(self.__home_path):
                 bookmark="~"+bookmark[len(self.__home_path):]
             book_wid = sat_widgets.ClickableText(bookmark)
-            urwid.connect_signal(book_wid, 'click', self.onBookmarkSelected)
+            urwid.connect_signal(book_wid, 'click', self.on_bookmark_selected)
             bookm_list.append(book_wid)
         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)
+        self.files_wid = FilesViewer(self.on_previous_dir, self.on_dir_click, self.on_file_click if self._type == 'normal' else None)
         center_row = urwid.Columns([('weight',2,bookm_wid),
                      ('weight',8,sat_widgets.VerticalSeparator(self.files_wid))])
 
         buttons = []
         if self._type == 'dir':
-            buttons.append(sat_widgets.CustomButton(_('Ok'), self._validateDir))
+            buttons.append(sat_widgets.CustomButton(_('Ok'), self._validate_dir))
         buttons.append(sat_widgets.CustomButton(_('Cancel'),cancel_cb))
-        max_len = max([button.getSize() for button in buttons])
+        max_len = max([button.get_size() for button in buttons])
         buttons_wid = urwid.GridFlow(buttons,max_len,1,0,'center')
         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.getcwd())
 
-    def _validateDir(self, wid):
+    def _validate_dir(self, wid):
         """ call ok callback if current path is a dir """
         path = os.path.abspath(self.path_wid.get_edit_text())
         if os.path.isdir(path):
@@ -217,7 +217,7 @@
             pass
         return path
 
-    def getBookmarks(self):
+    def get_bookmarks(self):
         gtk_bookm = os.path.expanduser("~/.gtk-bookmarks")
         kde_bookm = os.path.expanduser("~/.kde/share/apps/kfileplaces/bookmarks.xml")
         bookmarks = set()
@@ -242,24 +242,24 @@
 
         return bookmarks
 
-    def onBookmarkSelected(self, button):
+    def on_bookmark_selected(self, button):
         self.path_wid.set_edit_text(os.path.expanduser(button.get_text()))
 
-    def onPathChange(self, edit, path):
+    def on_path_change(self, edit, path):
         if os.path.isdir(path):
-            self.files_wid.showDirectory(path)
+            self.files_wid.show_directory(path)
 
-    def onPreviousDir(self, wid):
+    def on_previous_dir(self, wid):
         path = os.path.abspath(self.path_wid.get_edit_text())
         if not os.path.isdir(path):
             path = os.path.dirname(path)
         self.path_wid.set_edit_text(os.path.split(path)[0])
 
-    def onDirClick(self, wid):
+    def on_dir_click(self, wid):
         path = os.path.abspath(self.path_wid.get_edit_text())
         if not os.path.isdir(path):
             path = os.path.dirname(path)
         self.path_wid.set_edit_text(os.path.join(path,wid.get_text()))
 
-    def onFileClick(self, wid):
+    def on_file_click(self, wid):
         self.ok_cb(os.path.abspath(os.path.join(self.files_wid.path,wid.get_text())))