File: thunarx-python-overview-example.xml

package info (click to toggle)
thunarx-python 0.5.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 360 kB
  • sloc: xml: 1,500; ansic: 678; python: 136; makefile: 106; sh: 11
file content (54 lines) | stat: -rw-r--r-- 2,247 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?xml version="1.0" standalone="no"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
    "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
<chapter id="thunarx-python-overview-example"
  xmlns:xi="http://www.w3.org/2001/XInclude">

    <title>A Simple Extension</title>

    <para>Create an empty file with the following code:</para>
    
    <example>
        <title>A Simple Extension</title>
        <programlisting>
from gi.repository import GObject, Gtk, Thunarx

class ThunarxMenuProviderPlugin(GObject.GObject, Thunarx.MenuProvider):
    def __init__(self):
        pass
    
    def get_file_menu_items(self, window, files):
        item = Thunarx.MenuItem(name="TMP:TestFileAction", label="Python File Action", tooltip='', icon=Gtk.STOCK_FILE)
        item.connect("activate", self.__do_something, window)

        return [item]

    def get_folder_menu_items(self, window, folder):
        return [Thunarx.MenuItem(name="TMP:TestFolderAction", label="Python Folder Action", tooltip='', icon=Gtk.STOCK_OPEN)]

    def __do_something(self, item, window):
        print("Doing something")
        </programlisting>
    </example>
    
    <para>Save this file as TestExtension.py in the $XDG_DATA_DIR/thunarx-python/extensions folder or ~/.local/share/thunarx-python/extensions.
    You may need to create this folder. To run, open the terminal and type:</para>
    
    <informalexample>
        <programlisting>
$ killall thunar
$ thunar</programlisting>
    </informalexample>

    <para>Once Thunar starts, right-click on a file and you should see a new menu item, 
    "Python File Action". It is as simple as that!</para>
    
    <para>As mentioned above, in order to 
    get loaded by Thunar, a python extension must import the Thunarx module, 
    create a class derived from a Thunarx *Provider, then create the methods that 
    will be called by Thunar when it requests information from its providers. 
    In this case, when someone right-clicks on a file, Thunar will ask all of its 
    MenuProviders for additional menu items to show the user. When folders or files are clicked, 
    the get_file_menu_items method is called and a list of Thunarx.MenuItem objects is expected.</para>

</chapter>