Skip to content

Commit

Permalink
Show output only for currently active pane
Browse files Browse the repository at this point in the history
  • Loading branch information
kek91 committed Mar 1, 2017
1 parent 4cd5001 commit 8c014d3
Showing 1 changed file with 41 additions and 44 deletions.
85 changes: 41 additions & 44 deletions statusbarextended/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from fman import DirectoryPaneCommand, DirectoryPaneListener, \
show_status_message, load_json, save_json, show_alert
from os import stat, path, getenv, listdir
from os import stat, path, getenv
import json
import glob
from byteconverter import ByteConverter
Expand All @@ -17,49 +17,38 @@ def convert_bytes(n):
class StatusBarExtended(DirectoryPaneListener):

def refresh(self):
panes = self.pane.window.get_panes()
pane1 = panes[0].id
pane2 = panes[1].id
statusbar_pane1 = ""
statusbar_pane2 = ""

pane1_show_hidden_files = load_json('Panes.json')[pane1]['show_hidden_files']
pane1_show_hidden_files = "Show" if pane1_show_hidden_files == True else "Hide"
statusbar_pane1 += "Hidden files: " + pane1_show_hidden_files + ", "

pane2_show_hidden_files = load_json('Panes.json')[pane2]['show_hidden_files']
pane2_show_hidden_files = "Show" if pane2_show_hidden_files == True else "Hide"
statusbar_pane2 += "Hidden files: " + pane2_show_hidden_files + ", "

for p in panes:
current_dir = p.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
dir_filesize += stat(f).st_size
bc = ByteConverter(dir_filesize)
if(p.id == pane1):
statusbar_pane1 += "Dirs: " + str(dir_folders) + ", " # \t\t
statusbar_pane1 += "Files: " + str(dir_files) + ", "
statusbar_pane1 += "Size: " + str(bc.calc()) + ""
else:
statusbar_pane2 += "Dirs: " + str(dir_folders) + ", "
statusbar_pane2 += "Files: " + str(dir_files) + ", "
statusbar_pane2 += "Size: " + str(bc.calc()) + ""

pane = self.pane.id
statusbar_pane = ""

pane_show_hidden_files = load_json('Panes.json')[pane]['show_hidden_files']
pane_show_hidden_files = "✓" if pane_show_hidden_files == True else "X"

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
dir_filesize += stat(f).st_size


# TODO - simulate responsiveness
# QApplication::activeWindow(), get width, if > X... etc
bc = ByteConverter(dir_filesize)
if(pane == self.pane.window.get_panes()[0].id):
statusbar_pane += "Pane: Left "
else:
statusbar_pane += "Pane: Right "
statusbar_pane += "" + pane_show_hidden_files + " "
statusbar_pane += "Dirs: " + str(dir_folders) + " "
if dir_files > 0:
statusbar_pane += "Files: " + str(dir_files) + " "
statusbar_pane += "Size: " + str(bc.calc()) + " "

show_status_message('{:<25} {:>140}'.format(statusbar_pane1, statusbar_pane2), 5000)
show_status_message(statusbar_pane, 5000)


def show_selected_files(self):
Expand All @@ -77,9 +66,10 @@ def show_selected_files(self):
dir_filesize += stat(f).st_size

bc = ByteConverter(dir_filesize)
statusbar = str(dir_folders) + " directories \t\t"
statusbar += str(dir_files) + " files \t\t"
statusbar += str(bc.calc())
statusbar = str(dir_folders) + " directories, "
statusbar += str(dir_files) + " files "
statusbar += "selected - "
statusbar += "total filesize: " + str(bc.calc())
show_status_message(statusbar)

else:
Expand All @@ -92,3 +82,10 @@ def on_path_changed(self):
statusBarExtendedEnabledJson = json.loads(statusBarExtendedEnabled)
if statusBarExtendedEnabledJson['enabled'] == True:
StatusBarExtended.refresh(self)


class ToggleHiddenFiles(DirectoryPaneListener):
def toggle_hidden_files(self):
show_status_message("toggled")
StatusBarExtended.refresh(self)
return self.pane_info['show_hidden_files']

0 comments on commit 8c014d3

Please sign in to comment.