Skip to content

Instantly share code, notes, and snippets.

@yorikvanhavre
Last active August 2, 2018 12:40

Revisions

  1. yorikvanhavre revised this gist Oct 16, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions getrecentfiles.py
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,7 @@ def geticon(filename):
    s = f1.read()
    f1.close()
    fileslist = re.findall("href=\"file\:\/\/(.*?)\"",s)[-10:]
    # this generates a fluxbox entry
    f2 = open("/home/yorik/.fluxbox/recent","wb")
    f2.write("[submenu] (Recent) {} </usr/share/icons/Clarity/16x16/places/folder-bookmarks.png>\n")
    for filename in fileslist:
  2. yorikvanhavre revised this gist Oct 16, 2016. 1 changed file with 26 additions and 33 deletions.
    59 changes: 26 additions & 33 deletions getrecentfiles.py
    Original file line number Diff line number Diff line change
    @@ -1,36 +1,29 @@
    #!/usr/bin/python
    # -*- coding: UTF-8 -*-

    import gtk,gio,magic,os
    manager = gtk.recent_manager_get_default()
    flist = [o.get_uri() for o in manager.get_items()]
    flist = [f[7:] for f in flist]
    m = magic.open(magic.MAGIC_MIME)
    m.load()
    mlist = [m.file(f).split(";")[0] for f in flist]
    nlist = [gio.content_type_get_icon(m).get_names() for m in mlist]
    ilist = []
    for n in nlist:
    if (n[0] == "qgis-mime") and (len(n) > 1):
    ilist.append(n[1])
    else:
    ilist.append(n[0])
    t = gtk.icon_theme_get_default()
    ilist = [t.lookup_icon(i, 16, gtk.ICON_LOOKUP_NO_SVG) for i in ilist]
    clist = []
    for i in ilist:
    if i:
    clist.append(i.get_filename())
    else:
    clist.append("")
    fi = open("/home/yorik/.fluxbox/recent","wb")
    fi.write("[submenu] (Recent) {} </usr/share/icons/Clarity/16x16/places/folder-bookmarks.png>\n")
    num = 0
    for it in range(len(flist)):
    if not mlist[it].startswith("cannot open"):
    if clist[it]:
    if num < 10:
    fi.write(' [exec] ('+os.path.basename(flist[it])+') {xdg-open "'+flist[it]+'"} <'+clist[it]+'>\n')
    num += 1
    fi.write('[end]\n')
    fi.close()
    import re,os,gtk,gio,magic

    def geticon(filename):
    m = magic.open(magic.MAGIC_MIME)
    m.load()
    mime = m.file(filename).split(";")[0]
    mime = gio.content_type_get_icon(mime).get_names()
    theme = gtk.icon_theme_get_default()
    for mtype in mime:
    icon = theme.lookup_icon(mtype,16,gtk.ICON_LOOKUP_NO_SVG)
    if icon:
    return icon.get_filename()
    return ""

    f1 = open("/home/yorik/.local/share/recently-used.xbel")
    s = f1.read()
    f1.close()
    fileslist = re.findall("href=\"file\:\/\/(.*?)\"",s)[-10:]
    f2 = open("/home/yorik/.fluxbox/recent","wb")
    f2.write("[submenu] (Recent) {} </usr/share/icons/Clarity/16x16/places/folder-bookmarks.png>\n")
    for filename in fileslist:
    if os.path.exists(filename):
    f2.write(' [exec] ('+ os.path.basename(filename) +') {xdg-open "'+filename+'"} <'+geticon(filename)+'>\n')
    f2.write('[end]\n')
    f2.close()

  3. yorikvanhavre revised this gist Mar 6, 2016. 1 changed file with 35 additions and 4 deletions.
    39 changes: 35 additions & 4 deletions getrecentfiles.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,36 @@
    # http://www.pygtk.org/pygtk2reference/class-gtkrecentmanager.html
    import gtk
    #!/usr/bin/python
    # -*- coding: UTF-8 -*-

    import gtk,gio,magic,os
    manager = gtk.recent_manager_get_default()
    for o in manager.get_items():
    print (o.get_uri())
    flist = [o.get_uri() for o in manager.get_items()]
    flist = [f[7:] for f in flist]
    m = magic.open(magic.MAGIC_MIME)
    m.load()
    mlist = [m.file(f).split(";")[0] for f in flist]
    nlist = [gio.content_type_get_icon(m).get_names() for m in mlist]
    ilist = []
    for n in nlist:
    if (n[0] == "qgis-mime") and (len(n) > 1):
    ilist.append(n[1])
    else:
    ilist.append(n[0])
    t = gtk.icon_theme_get_default()
    ilist = [t.lookup_icon(i, 16, gtk.ICON_LOOKUP_NO_SVG) for i in ilist]
    clist = []
    for i in ilist:
    if i:
    clist.append(i.get_filename())
    else:
    clist.append("")
    fi = open("/home/yorik/.fluxbox/recent","wb")
    fi.write("[submenu] (Recent) {} </usr/share/icons/Clarity/16x16/places/folder-bookmarks.png>\n")
    num = 0
    for it in range(len(flist)):
    if not mlist[it].startswith("cannot open"):
    if clist[it]:
    if num < 10:
    fi.write(' [exec] ('+os.path.basename(flist[it])+') {xdg-open "'+flist[it]+'"} <'+clist[it]+'>\n')
    num += 1
    fi.write('[end]\n')
    fi.close()
  4. yorikvanhavre created this gist Dec 25, 2015.
    5 changes: 5 additions & 0 deletions getrecentfiles.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    # http://www.pygtk.org/pygtk2reference/class-gtkrecentmanager.html
    import gtk
    manager = gtk.recent_manager_get_default()
    for o in manager.get_items():
    print (o.get_uri())