AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1201596
Accepted
Zany_Zachary1
Zany_Zachary1
Asked: 2020-01-09 14:42:20 +0800 CST2020-01-09 14:42:20 +0800 CST 2020-01-09 14:42:20 +0800 CST

Ubuntu 18.04 上 Dash to Dock 中的动态垃圾箱图标

  • 772

我想为我的码头制作一个垃圾桶图标。Dash to Dock没有我可以添加的垃圾桶图标,所以我打算做一个。当有东西被添加到垃圾箱时,我想要垃圾箱完整图标,当垃圾箱中没有任何东西时,我想要垃圾箱清空图标。有人可以告诉我该怎么做吗?这是我的桌面文件:

[Desktop Entry]
Type=Application
Name=Trash
Comment=Trash
Icon=user-trash
Exec=nautilus trash://
Categories=Utility;
Actions=trash;

[Desktop Action trash]
Name=Empty Trash
Exec=/home/zacharygough/trash.sh -e
trash gnome-shell ubuntu-dock 18.04 dash-to-dock
  • 1 1 个回答
  • 972 Views

1 个回答

  • Voted
  1. Best Answer
    Jacob Vlijm
    2020-01-10T13:06:58+08:002020-01-10T13:06:58+08:00

    根据垃圾桶的状态自动更改 .desktop 文件的图标

    在此处输入图像描述 在此处输入图像描述

    小脚本用于Gio.Filemonitor查看状态(空与否)trash:///

    如何使用

    1. 将下面的脚本复制到一个空文件中,命名它watchout.py
    2. 在行中替换:

      # edit path to .desktop files and icon names below
      self.fpath = "/home/jacob/Desktop/test.desktop"
      self.iconempty = "user-trash"
      self.iconfull = "user-trash-full"
      

      ... the self.fpath, 如果你想要 theself.iconempty和 theself.iconfull

    3. 使用以下命令运行脚本:

      python3 /path/to/watchout.py
      

    而已!

    如果一切正常,请将相同的命令添加到启动应用程序。

    剧本

    #!/usr/bin/env python3
    from gi.repository import Gio, GLib
    
    class SetTrashIcon:
    
        def __init__(self):
            # edit path to .desktop file and icon names below
            self.fpath = "/home/jacob/Desktop/test.desktop"
            self.iconempty = "user-trash"
            self.iconfull = "user-trash-full"
            # don't edit below
            self.trashdir = Gio.File.new_for_uri("trash:///")
            monitor = self.trashdir.monitor_directory(0, None)
            monitor.connect("changed", self.actonfile)
            self.currempty = None
            self.check_empty()
            loop = GLib.MainLoop()
            loop.run()
    
        def replace(self, newicon):
            # set the new icon, replace the Icon- line
            text = open(self.fpath).read()
            toreplace = [s for s in text.split() if s.startswith("Icon=")][0]
            newtext = text.replace(toreplace, "Icon=" + newicon)
            open(self.fpath, "wt").write(newtext)
    
        def set_icon(self, newempty):
            # if trash state changes, decide which icon to set
            if newempty != self.currempty:
                if newempty:
                    self.replace(self.iconempty)
                else:
                    self.replace(self.iconfull)
                self.currempty = newempty
    
        def check_empty(self):
            # check if trash is empty
            newempty = len(list(self.trashdir.enumerate_children(
                "standard::*", Gio.FileQueryInfoFlags.NONE, None
            ))) == 0
            self.set_icon(newempty)
    
        def actonfile(self, arg1=None, arg2=None, arg3=None, arg4=None):
            # act on changes in the trash content
            if arg4 == Gio.FileMonitorEvent.ATTRIBUTE_CHANGED:
                self.check_empty()
    
    SetTrashIcon()
    
    • 1

相关问题

  • 如何找到我的垃圾箱文件夹内容的总大小?

  • 如何将窗口控件切换到左侧(Gnome Shell)?

  • 无法在 Evolution 中清空回收站文件夹

  • 禁用鼠标悬停时自动激活 Gnome Shell 活动

  • 为什么即使里面没有任何文件,垃圾箱也会显示一些文件?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve