Skip to content

Commit

Permalink
Merge pull request #19 from eugenesvk/master
Browse files Browse the repository at this point in the history
Update to the latest fman version (new filesystem API) and more
  • Loading branch information
kek91 authored Aug 9, 2021
2 parents eb38c45 + d921345 commit fd41197
Show file tree
Hide file tree
Showing 12 changed files with 265 additions and 113 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
README.html
Changelog.html
71 changes: 71 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Changelog
All notable changes to this project will be documented in this file

## [Unreleased]
[ Unreleased]: https://github.com/kek91/StatusBarExtended/compare/v0.3.1...HEAD

## [v0.3.1 — 07.08.2021]
[ v0.3.1 — 07.08.2021]: https://github.com/kek91/StatusBarExtended/releases/tag/v0.3.1
- __Fixed__
+ :beetle: Hidden non-dotfiles always counted; (Windows) dotfiles (even without the 'hidden' attribute) not counted if option is set to hide
+ :beetle: Status bar is NOT updated when a _visible_ hidden file/folder is _selected_ and then _hidden_ via `Toggle hidden files`

## [v0.3.0 — 07.08.2021]
[ v0.3.0 — 07.08.2021]: https://github.com/kek91/StatusBarExtended/releases/tag/v0.3.0
- __Fixed__
+ :beetle: Hidden files not counted even when they're shown
+ :beetle: Not updating on pane changes via keyboard `switch_panes` command (e.g. with a <kbd>Tab</kbd>)

## [v0.2.1 — 05.08.2021]
[ v0.2.1 — 05.08.2021]: https://github.com/kek91/StatusBarExtended/releases/tag/v0.2.1
- __Changed__
+ The currently active pane indicator from `Pane: Left`/`Pane: Right` to ``/``
+ The `Dirs:`/`Files:` indicators' to align with and without selection

## [v0.2.0 — 05.08.2021]
[ v0.2.0 — 05.08.2021]: https://github.com/kek91/StatusBarExtended/releases/tag/v0.2.0
- __Fixed__
+ :beetle: Not working with the latest fman version (`1.7.3`) and its new file system API ([blog](https://fman.io/blog/fmans-new-file-system-api/), [API](https://fman.io/docs/api#FileSystem))

## [v0.1.2 — 15.08.2017]
[ v0.1.2 — 15.08.2017]: https://github.com/kek91/StatusBarExtended/releases/tag/v0.1.2
- Shorter size indicators with lower-case for (kilo)bytes: `b, k, M, G, T`. Kibibyte (`2^10`) format is preserved
- Change the status icon of hidden files toggle to ``white (hidden files shown) and ``black (hidden files hidden) Unicode square symbols
- Align all indicator position to keep it the same regardless of the length of the indicator (file/folder count is consistent up to `9,999`)
- Remove empty folder/file numbers indicators (including labels)
![Toolbar only screenshot with a custom theme v0.1.1f](fman-plugin-StatusBarExtendedF.png)
- Add thousands separator (`,`) to file/folder numbers (e.g. `Files: 1,000`)
- Change status of selected items to be consistent with the regular view for faster read

## [v0.1.1 — 06.04.2017]
[ v0.1.1 — 06.04.2017]: https://github.com/kek91/StatusBarExtended/releases/tag/v0.1.1
- Show binary prefix instead of decimal for file size

## [v0.1.0 — 01.03.2017]
[ v0.1.0 — 01.03.2017]: https://github.com/kek91/StatusBarExtended/releases/tag/v0.1.0
- Shows output only for the currently active pane due to layout/resize issues
- Don't display "Files: n" and "Size: n xB" if there are 0 files in current directory
- Hidden status is visualized by checkmark or cross


**25.02.2017:**

- Align text to the left and right for the respective panes
- Reduce text to make the status bar smaller thus allowing resizing window smaller


**19.01.2017:**

- Shows selected directores and files/filesize when selecting files
- Restructured code for readability


**16.01.2017:**

- StatusBar shows immediately when toggled


**28.11.2016:**

- Cleaned code
- Should work in all 3 supported OS (tested on Windows and Linux only)
62 changes: 13 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,26 @@ Turn the plugin on or off by using the keyboard shortcut, default is **F3**.

Adds extra information to the status bar.

- Show number of directories and files/size in current directory for both panes
- Show "Toggle hidden files" status
- Show directories and files/size when selecting files

- Show the number of directories/files and the total size of files in the current directory for both panes
- Show "Toggle hidden files" status (`` shown `` hidden)
- Show the number of selected directories/files and the total size of selected files
- Show the currently active pane indicator (`` left `` right)

Aligns indicator positions to avoid "jitter" on selection/navigation


**Preview**

| Status Bar without selection | Status Bar with selection |
| :--------------------------------------: | :--------------------------------------: |
| ![Screenshot Win 10 v0.1.2](fman-plugin-statusbarextended-v0.1.2.png) | ![Screenshot Win 10 v0.1.2-selection](fman-plugin-statusbarextended-select-v0.1.2.png) |



**Changelog**

**v0.1.2 - 15.08.2017:**

- Shorter size indicators with lower-case for (kilo)bytes: `b, k, M, G, T`. Kibibyte (`2^10`) format is preserved
- Change status icon of hidden files toggle to ◻white (hidden files shown) and ◼black (hidden files hidden) Unicode square symbols
- Align all indicator position to keep it the same regardless of the length of the indicator (file/folder count is consistent up to `9,999`)
- Remove empty folder/file numbers indicators (including labels)
![Toolbar only screenshot with a custom theme v0.1.1f](fman-plugin-StatusBarExtendedF.png)
- Add thousands separator (`,`) to file/folder numbers (e.g. `Files: 1,000`)
- Change status of selected items to be consistent with the regular view for faster read

**v0.1.1 - 06.04.2017:**

- Show binary prefix instead of decimal for file size

**v0.1.0 - 01.03.2017:**

- Shows output only for the currently active pane due to layout/resize issues
- Don't display "Files: n" and "Size: n xB" if there are 0 files in current directory
- Hidden status is visualized by checkmark or cross


**25.02.2017:**

- Align text to the left and right for the respective panes
- Reduce text to make the status bar smaller thus allowing resizing window smaller


**19.01.2017:**

- Shows selected directores and files/filesize when selecting files
- Restructured code for readability


**16.01.2017:**

- StatusBar shows immediately when toggled
| ![Screenshot macOS 10 v0.3.0](fman-plugin-statusbarextended-v0.3.0.png) | ![Screenshot macOS 10 v0.3.0-selection](fman-plugin-statusbarextended-select-v0.3.0.png) |

| Status Bar alignment |
| :------------------------------: |
| ![Screenshot of alignment](fman-plugin-statusbarextended-alignment-v0.3.0.png) |

**28.11.2016:**
__Known issues__

- Cleaned code
- Should work in all 3 supported OS (tested on Windows and Linux only)
- fman raises `ValueError` on the first `Toggle hidden files` if a pane is _launched_ with hidden files _hidden_ (and status bar is not updated this one time)
- Status bar is NOT updated when _switching panes_ with a _mouse_ since plugins can't notice a pane switch due to a lack of the [necessary APIs](https://github.com/fman-users/fman/issues/292#issuecomment-360036718)
- Alignment of indicators only works for _monospaced_ (fixed-width) fonts since it's currently implemented using regular spaces (tip: you can change this font in your `Theme.css` file `.statusbar{font-family:"yourMonospacedFont"}`). Dir/file count alignment is limited to up to 9,999
2 changes: 1 addition & 1 deletion byteconverter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ def __init__(self, n):
def calc(self):
for x in ['b', 'k', 'M', 'G', 'T']:
if self.bytes < 1024.0:
return "%3.1f %s" % (self.bytes, x)
return "%3.1f %s" % (self.bytes, x) if x!='b' else "%5.0f" % (self.bytes)
self.bytes /= 1024.0
Binary file removed fman-plugin-StatusBarExtendedF.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed fman-plugin-statusbarextended-select-v0.1.2.png
Binary file not shown.
Binary file added fman-plugin-statusbarextended-select-v0.3.0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed fman-plugin-statusbarextended-v0.1.2.png
Binary file not shown.
Binary file added fman-plugin-statusbarextended-v0.3.0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
151 changes: 98 additions & 53 deletions statusbarextended/__init__.py
Original file line number Diff line number Diff line change
@@ -1,90 +1,135 @@
# Main class for StatusBarExtended

from fman import DirectoryPaneCommand, DirectoryPaneListener, \
show_status_message, load_json, save_json, show_alert
from os import stat, path, getenv
show_status_message, load_json, save_json, PLATFORM
from fman.url import as_url, as_human_readable
from fman.fs import is_dir, query
from core.commands.util import is_hidden # works on file_paths, not urls
import json
import glob
from byteconverter import ByteConverter
#from PyQt5.QtWidgets import QApplication

class Just: # Justify elements in the status bar
Fd = 5 # Justify Folder format: up to 9,999
Fl = 5 # Justify Folder format: up to 9,999
Sz = 7 # Justify Size format: up to 999.0 b
Fd = 5 # Justify Folder format: 5 symbols — up to 9,999
Fl = 5 # Justify File format: 5 symbols — up to 9,999
Sz = 7 # Justify Size format: 7 symbols — up to 999.0 b

class StatusBarExtended(DirectoryPaneListener):

def refresh(self):

pane = self.pane.window.get_panes().index(self.pane)
statusbar_pane = ""
panes = self.pane.window.get_panes()
pane_id = panes.index(self.pane)
statusbar_pane = ""

cfg_show_hidden_files = load_json('Panes.json')[pane_id]['show_hidden_files']
pane_show_hidden_files = "◻" if cfg_show_hidden_files else "◼" # alt: 👁🐵🙈◎◉✓✗
cur_dir_url = self.pane.get_path()
current_dir = as_human_readable(cur_dir_url)
dir_folders = 0
dir_files = 0
dir_filesize = 0
dir_files_in_dir = glob.glob(current_dir + "/*")
if PLATFORM == 'Windows': # .dotfile=regular (use 'hidden' attr to hide)
dir_files_in_dir += glob.glob(current_dir + "/.*")
elif cfg_show_hidden_files: # .dotfile=hidden
dir_files_in_dir += glob.glob(current_dir + "/.*")
f_url = ""

pane_show_hidden_files = load_json('Panes.json')[pane]['show_hidden_files']
pane_show_hidden_files = "◻" if pane_show_hidden_files == True else "◼"
#alternative icons: 👁◎◉✓✗
current_dir = self.pane.get_path()
dir_folders = 0
dir_files = 0
dir_filesize = 0
dir_files_in_dir = glob.glob(current_dir + "/*")
if dir_files_in_dir:
for f in dir_files_in_dir:
if path.isdir(f):
dir_folders += 1
else:
dir_files += 1
try:
dir_filesize += stat(f).st_size
except Exception as e:
continue
if cfg_show_hidden_files:
for f in dir_files_in_dir:
f_url = as_url(f)
if is_dir(f_url):
dir_folders += 1
else:
dir_files += 1
try:
dir_filesize += query(f_url, 'size_bytes')
except Exception as e:
continue
else:
for f in dir_files_in_dir:
f_url = as_url(f)
if not is_hidden(f):
if is_dir(f_url):
dir_folders += 1
else:
dir_files += 1
try:
dir_filesize += query(f_url, 'size_bytes')
except Exception as e:
continue

bc = ByteConverter(dir_filesize)
dir_foldersK = str("{0:,}".format(dir_folders)) # old use str(dir_folders)
dir_filesK = str("{0:,}".format(dir_files)) # ' ' instead of ',' .replace(',', ' ')
dir_foldK = str("{0:,}".format(dir_folders)) # to ','→' ' add .replace(',', ' ')
dir_fileK = str("{0:,}".format(dir_files))
if(self.pane == self.pane.window.get_panes()[0]):
statusbar_pane += "Pane: Left "
statusbar_pane += ""
else:
statusbar_pane += "Pane: Right "
statusbar_pane += "" + pane_show_hidden_files + " "
if dir_folders == 0:
statusbar_pane += " " + ''.rjust(Just.Fd, ' ') + " "
elif dir_folders > 9999:
statusbar_pane += "Dirs: " + dir_foldersK.rjust(Just.Fl, ' ') + " "
statusbar_pane += ""
statusbar_pane += " " + pane_show_hidden_files + " "
if dir_folders > 0:
statusbar_pane += "Dirs: " + dir_foldK.rjust(Just.Fd, ' ') + " "
if dir_folders <= 9999:
statusbar_pane += " "
else:
statusbar_pane += "Dirs: " + dir_foldersK.rjust(Just.Fl, ' ') + " "
if dir_files > 0:
if dir_files > 9999:
statusbar_pane += "Files: " + dir_filesK.rjust(Just.Fd, ' ') + " "
else:
statusbar_pane += "Files: " + dir_filesK.rjust(Just.Fd, ' ') + " "
statusbar_pane += " " + ''.rjust(Just.Fd, ' ') + " "
if dir_files > 0:
statusbar_pane += "Files: " + dir_fileK.rjust(Just.Fl, ' ') + " "
if dir_files <= 9999:
statusbar_pane += " "
else:
statusbar_pane += " " + ''.rjust(Just.Fl, ' ') + " "
statusbar_pane += "Size: " + str(bc.calc()).rjust(Just.Sz, ' ') + " "
statusbar_pane += " " + ''.rjust(Just.Fl, ' ') + " "
statusbar_pane += " Size: "+ str(bc.calc()).rjust(Just.Sz, ' ') + " "
# to align with "∑ Size: "

show_status_message(statusbar_pane, 5000)

def show_selected_files(self):
panes = self.pane.window.get_panes()
pane_id = panes.index(self.pane)
cfg_show_hidden_files = load_json('Panes.json')[pane_id]['show_hidden_files']
selected = self.pane.get_selected_files()
dir_folders = 0
dir_files = 0
dir_filesize = 0

if selected:
for f in selected:
if path.isdir(f):
dir_folders += 1
else:
dir_files += 1
dir_filesize += stat(f).st_size
if cfg_show_hidden_files:
for f in selected:
if is_dir(f):
dir_folders += 1
else:
dir_files += 1
dir_filesize += query(f, 'size_bytes')
else:
for f in selected:
if not is_hidden(as_human_readable(f)):
if is_dir(f):
dir_folders += 1
else:
dir_files += 1
dir_filesize += query(f, 'size_bytes')

bc = ByteConverter(dir_filesize)
dir_foldersK = str("{0:,}".format(dir_folders)) # old use str(dir_folders)
dir_filesK = str("{0:,}".format(dir_files)) # for ' ' instead of ',' .replace(',', ' ')
statusbar = "Selected* "
statusbar += "Dirs: " + dir_foldersK.rjust(Just.Fd, ' ') + " "
statusbar += "Files: " + dir_filesK.rjust(Just.Fl, ' ') + " "
statusbar += "∑ Size: " + str(bc.calc()).rjust(Just.Sz, ' ')
dir_foldK = "{0:,}".format(dir_folders)
dir_fileK = "{0:,}".format(dir_files)
statusbar = "Selected* "
if dir_folders > 0:
statusbar += "Dirs: " + dir_foldK.rjust(Just.Fd, ' ') + " "
if dir_folders <= 9999:
statusbar += " "
else:
statusbar += " " + ''.rjust(Just.Fd, ' ') + " "
if dir_files > 0:
statusbar += "Files: " + dir_fileK.rjust(Just.Fl, ' ') + " "
if dir_files <= 9999:
statusbar += " "
else:
statusbar += " " + ''.rjust(Just.Fl, ' ') + " "
statusbar += "∑ Size: " + str(bc.calc()).rjust(Just.Sz, ' ') + " "
show_status_message(statusbar)

else:
Expand Down
Loading

0 comments on commit fd41197

Please sign in to comment.