Eu experimentei vários existentes, mas não encontrei um indicador funcionando Locais . Os que encontrei estavam desatualizados, os ppa não eram mais mantidos.
menu Lugares Modulares
Então, abaixo de uma nova escrita: Lugares & Indicador de arquivos para o Ubuntu .
A versão ppa é uma versão modular ; você pode escolher o que mostrar no menu:
[]
Naversãocompleta:
...ouomenor,mostrandoapenasrecentementeusado:
Instalandoapartirdoppa
sudoadd-apt-repositoryppa:vlijm/placesfilessudoapt-getupdatesudoapt-getinstallplacesfiles
Umaversãosimplificadaparamostrarummenudelocais,marcadoresearquivosusadosrecentemente
Descrição&código(inicial)
Oscript
#!/usr/bin/env python3
import signal
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('AppIndicator3', '0.1')
from gi.repository import Gtk, AppIndicator3, GObject
import time
from threading import Thread
import os
import subprocess
class Indicator():
def __init__(self):
currpath = os.path.dirname(os.path.realpath(__file__))
self.home = os.environ["HOME"]
self.bmark_file = os.path.join(self.home, ".config/gtk-3.0/bookmarks")
self.def_file = os.path.join(self.home, ".config/user-dirs.dirs")
self.recdata = os.path.join(self.home, ".local/share/recently-used.xbel")
self.n = 10
self.app = 'places'
iconpath = os.path.join(currpath, "dir_icon.png")
self.indicator = AppIndicator3.Indicator.new(
self.app, iconpath,
AppIndicator3.IndicatorCategory.OTHER)
self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
self.indicator.set_label("Places", self.app)
self.indicator.set_menu(self.create_menu())
# the thread:
self.update = Thread(target=self.check_recent)
self.update.setDaemon(True)
self.update.start()
def create_menu(self):
# creates the (initial) menu
self.menu = Gtk.Menu()
# separator
initial = Gtk.MenuItem("Fetching list...")
menu_sep = Gtk.SeparatorMenuItem()
self.menu.append(initial)
self.menu.append(menu_sep)
# item_quit.show()
self.menu.show_all()
return self.menu
def open_directory(self, *args):
index = self.menu.get_children().index(self.menu.get_active())
selection = self.menu_items2[index-2]
self.execute(["xdg-open", selection])
def open_file(self, *args):
index = self.submenu.get_children().index(self.submenu.get_active())
selection = self.submenu2[index]
self.execute(["xdg-open", selection])
def go_special(self, button, target):
self.execute(["xdg-open", target])
def connect(self, button):
self.execute("nautilus-connect-server")
def set_new(self):
# update the list, appearing in the menu
for i in self.menu.get_children():
self.menu.remove(i)
home_mention = Gtk.MenuItem("⌂ Home")
home_mention.connect("activate", self.go_special, self.home)
self.menu.append(home_mention)
# separator
menu_sep1 = Gtk.SeparatorMenuItem()
self.menu.append(menu_sep1)
for app in self.menu_items2:
sub = Gtk.MenuItem("⏍ "+app.split("/")[-1])
self.menu.append(sub)
sub.connect('activate', self.open_directory)
# separator
menu_sep2 = Gtk.SeparatorMenuItem()
self.menu.append(menu_sep2)
# network
network = "network:///"
network_mention = Gtk.MenuItem("⇄ Network")
network_mention.connect("activate", self.go_special, network)
self.menu.append(network_mention)
connect_mention = Gtk.MenuItem("⮁ Connect to server")
connect_mention.connect("activate", self.connect)
self.menu.append(connect_mention)
# separator
menu_sep3 = Gtk.SeparatorMenuItem()
self.menu.append(menu_sep3)
# computer
computer = "computer:///"
computer_mention = Gtk.MenuItem("⛁ Computer")
computer_mention.connect("activate", self.go_special, computer)
self.menu.append(computer_mention)
recent_mention = Gtk.MenuItem("⁕ Recent files")
self.menu.append(recent_mention)
self.submenu = Gtk.Menu()
for f in self.submenu2:
recent = Gtk.MenuItem(f)
recent.connect("activate", self.open_file)
self.submenu.append(recent)
recent_mention.set_submenu(self.submenu)
# separator
menu_sep6 = Gtk.SeparatorMenuItem()
self.menu.append(menu_sep6)
# quit
item_quit = Gtk.MenuItem('Quit')
item_quit.connect('activate', self.stop)
self.menu.append(item_quit)
self.menu.show_all()
def run_about(self, *args):
self.execute("/opt/upfront/code/runabout")
def check_recent(self):
self.menu_items1 = []; self.submenu1 = []
while True:
time.sleep(4)
self.menu_items2 = self.get_bookmarks()
self.submenu2 = self.get_files()
if any([self.menu_items2 != self.menu_items1,
self.submenu2 != self.submenu1]):
GObject.idle_add(
self.set_new,
priority=GObject.PRIORITY_DEFAULT
)
self.menu_items1 = self.menu_items2
self.submenu1 = self.submenu2
def stop(self, source):
Gtk.main_quit()
def get_bookmarks(self):
loc_bookmarks = [
l.replace("file://", "") for l in open(self.bmark_file).read().splitlines()\
if l.startswith("file://")
]
netw_bookmarks = [
l for l in open(self.bmark_file).read().splitlines()\
if l.startswith("smb://")
]
defaults = [
os.path.join(self.home, l.replace('"', "").split("$HOME/")[-1]) for l in \
open(self.def_file).read().splitlines() if all\
(["$HOME/" in l, l.startswith("XDG")])
]
return [self.replace_sc(m.split(" ")[0]).rstrip("/") for m in list(
set(loc_bookmarks+defaults+netw_bookmarks))]
def replace_sc(self, path):
for c in [("%23", "#"), ("%5D", "]"), ("%5E", "^"),
("file://", ""), ("%20", " ")]:
path = path.replace(c[0], c[1])
return path
def execute(self, command):
subprocess.Popen(command)
def get_files(self):
# create the list of recently used files
used = [l for l in open(self.recdata) if all([
'<bookmark href="file://' in l, not "/tmp" in l, "." in l])]
relevant = [l.split('="') for l in set(used)]
relevant = [[it[1][7:-7], it[-2][:-10]] for it in relevant]
relevant.sort(key=lambda x: x[1])
return [item[0].replace("%20", " ") for item in relevant[::-1][:self.n]]
Indicator()
GObject.threads_init()
signal.signal(signal.SIGINT, signal.SIG_DFL)
Gtk.main()
Como usar (se não instalado do ppa)
- Copie o script em um arquivo vazio, salve-o como
places_indicator.py
-
Salve o ícone (clique com o botão direito em > salvar como) exatamente chamado:
dir_icon.png
..emumeomesmodiretóriocomooscript.
Teste-executeoscriptpelocomando:
python3/path/to/places_indicator.py
Setudofuncionarbem,adicione-oaosaplicativosdeinicialização:Dash>Aplicativosdeinicialização>Adicionar.Adicioneocomando:
/bin/bash-c"sleep 10 && python3 /path/to/places_indicator.py
Sobre o indicador
O indicador mostra:
- O diretório inicial
- Todos os diretórios (marcadores locais e smb) em
-
~/.config/gtk-3.0/bookmarks
-
~/.config/user-dirs.dirs
-
- Rede
- Conectar-se à rede
- Computador
- Arquivos usados recentemente (lats 10 como são, podem ser facilmente alterados)
Os marcadores alterados / adicionados / removidos são atualizados dinamicamente