[Xfce4-commits] <thunarx-python:master> Implemented property pages interface, tweaked examples and added property page example

Adam Plumb noreply at xfce.org
Thu May 27 18:12:02 CEST 2010


Updating branch refs/heads/master
         to f213bcb80696d0965d505bc7dbcc42791bfae425 (commit)
       from 9afec328d6dbcaf55bc624f4dea5e141a09749ea (commit)

commit f213bcb80696d0965d505bc7dbcc42791bfae425
Author: Adam Plumb <adamplumb at gmail.com>
Date:   Wed Dec 16 09:53:13 2009 -0500

    Implemented property pages interface, tweaked examples and added property page example

 examples/thunarx-example-plugin.py       |   11 --------
 examples/thunarx-menu-plugin.py          |   12 ++++++++
 examples/thunarx-property-page-plugin.py |   42 ++++++++++++++++++++++++++++++
 src/thunarx-python-object.c              |   19 +++++++------
 src/thunarx.defs                         |   33 ++---------------------
 5 files changed, 67 insertions(+), 50 deletions(-)

diff --git a/examples/thunarx-example-plugin.py b/examples/thunarx-example-plugin.py
deleted file mode 100644
index f2a78ab..0000000
--- a/examples/thunarx-example-plugin.py
+++ /dev/null
@@ -1,11 +0,0 @@
-import thunarx
-
-class ThunarxExamplePlugin(thunarx.MenuProvider):
-  def __init__(self):
-    print "ThunarxExamplePlugin init"
-  
-  def get_file_actions(self, window, files):
-    print "in get_file_actions"
-  
-  def get_folder_actions(self, window, folder):
-    print "in get_folder_actions"
diff --git a/examples/thunarx-menu-plugin.py b/examples/thunarx-menu-plugin.py
new file mode 100644
index 0000000..ae5d974
--- /dev/null
+++ b/examples/thunarx-menu-plugin.py
@@ -0,0 +1,12 @@
+import thunarx
+import gtk
+
+class ThunarxMenuProviderPlugin(thunarx.MenuProvider):
+  def __init__(self):
+    pass
+  
+  def get_file_actions(self, window, files):
+    return [gtk.Action("TMP:TestFileAction", "PyFileAction", "Python File Action", gtk.STOCK_FILE)]
+  
+  def get_folder_actions(self, window, folder):
+    return [gtk.Action("TMP:TestFolderAction", "PyFolderAction", "Python Folder Action", gtk.STOCK_DIRECTORY)]
diff --git a/examples/thunarx-property-page-plugin.py b/examples/thunarx-property-page-plugin.py
new file mode 100644
index 0000000..2672fe6
--- /dev/null
+++ b/examples/thunarx-property-page-plugin.py
@@ -0,0 +1,42 @@
+import hashlib
+import urllib
+
+import thunarx
+import gtk
+
+class ThunarxPropertyPagePlugin(thunarx.PropertyPageProvider):
+  def __init__(self):
+    pass
+
+  def get_property_pages(self, files):
+    if len(files) != 1:
+        return
+    
+    file = files[0]
+    if file.get_uri_scheme() != 'file':
+        return
+
+    if file.is_directory():
+        return
+
+    filename = urllib.unquote(file.get_uri()[7:])
+
+    self.hbox = gtk.HBox(0, False)
+    self.hbox.show()
+
+    label = gtk.Label('MD5Sum:')
+    label.show()
+    self.hbox.pack_start(label)
+
+    self.value_label = gtk.Label()
+    self.hbox.pack_start(self.value_label)
+
+    md5sum = hashlib.md5(filename).hexdigest()
+    self.value_label.set_text(md5sum)
+    self.value_label.show()
+
+    page = thunarx.PropertyPage("MD5")
+
+    page.add(self.hbox)
+
+    return [page]
diff --git a/src/thunarx-python-object.c b/src/thunarx-python-object.c
index 1e078aa..96694c5 100644
--- a/src/thunarx-python-object.c
+++ b/src/thunarx-python-object.c
@@ -56,7 +56,7 @@ static GList *thunarx_python_object_get_dnd_actions             (ThunarxMenuProv
 
 
 static void thunarx_python_object_property_page_provider_iface_init      (ThunarxPropertyPageProviderIface *iface);
-static GList *thunarx_python_object_get_property_pages          (ThunarxMenuProviderIface *provider,
+static GList *thunarx_python_object_get_property_pages          (ThunarxPropertyPageProvider *provider,
 										                                             GList                    *files);
 
 
@@ -225,11 +225,11 @@ thunarx_python_object_menu_provider_iface_init (ThunarxMenuProviderIface *iface)
 	iface->get_dnd_actions = thunarx_python_object_get_dnd_actions;
 }
 
-/*
+
 
 #define METHOD_NAME "get_property_pages"
 static GList *
-thunarx_python_object_get_property_pages (ThunarxMenuProviderIface *provider,
+thunarx_python_object_get_property_pages (ThunarxPropertyPageProvider *provider,
 										                      GList *files)
 {
 	ThunarxPythonObject *object = (ThunarxPythonObject*)provider;
@@ -242,9 +242,10 @@ thunarx_python_object_get_property_pages (ThunarxMenuProviderIface *provider,
 	CHECK_METHOD_NAME(object->instance);
 
 	CONVERT_LIST(py_files, files);
-	
+
   py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX METHOD_NAME,
 								 "(N)", py_files);
+
 	HANDLE_RETVAL(py_ret);
 
 	HANDLE_LIST(py_ret, ThunarxPropertyPage, "thunarx.PropertyPage");
@@ -265,7 +266,7 @@ thunarx_python_object_property_page_provider_iface_init (ThunarxPropertyPageProv
 	iface->get_pages = thunarx_python_object_get_property_pages;
 }
 
-
+/*
 
 static void
 thunarx_python_object_file_info_iface_init (ThunarxFileInfoIface *iface)
@@ -340,13 +341,13 @@ thunarx_python_object_get_type (ThunarxProviderPlugin *plugin, PyObject *type)
 		NULL,
 		NULL
 	};
-
+*/
 	static const GInterfaceInfo property_page_provider_iface_info = {
 		(GInterfaceInitFunc) thunarx_python_object_property_page_provider_iface_init,
 		NULL,
 		NULL
 	};
-*/
+
 	static const GInterfaceInfo menu_provider_iface_info = {
 		(GInterfaceInitFunc) thunarx_python_object_menu_provider_iface_init,
 		NULL,
@@ -389,13 +390,13 @@ thunarx_python_object_get_type (ThunarxProviderPlugin *plugin, PyObject *type)
 									 THUNARX_TYPE_FILE_INFO,
 									 &file_info_iface_info);
 	}
-
+*/
 	if (PyObject_IsSubclass(type, (PyObject*)&PyThunarxPropertyPageProvider_Type)) {
 		thunarx_provider_plugin_add_interface (plugin, gtype, 
 									 THUNARX_TYPE_PROPERTY_PAGE_PROVIDER,
 									 &property_page_provider_iface_info);
 	}
-*/
+
 	if (PyObject_IsSubclass(type, (PyObject*)&PyThunarxMenuProvider_Type)) {
 		thunarx_provider_plugin_add_interface (plugin, gtype, 
 									 THUNARX_TYPE_MENU_PROVIDER,
diff --git a/src/thunarx.defs b/src/thunarx.defs
index 10c5708..9e18e14 100644
--- a/src/thunarx.defs
+++ b/src/thunarx.defs
@@ -18,7 +18,7 @@
   (gtype-id "THUNARX_TYPE_PREFERENCES_PROVIDER")
 )
 
-(define-interface PropertyPage
+(define-object PropertyPage
   (in-module "Thunarx")
   (parent "GtkBin")
   (c-name "ThunarxPropertyPage")
@@ -37,7 +37,7 @@
   (gtype-id "THUNARX_TYPE_PROVIDER_PLUGIN")
 )
 
-(define-interface Renamer
+(define-object Renamer
   (in-module "Thunarx")
   (parent "GtkVBox")
   (c-name "ThunarxRenamer")
@@ -229,25 +229,6 @@
 )
 
 
-
-;; From thunarx-property-page-provider.h
-
-(define-function thunarx_property_page_provider_get_type
-  (c-name "thunarx_property_page_provider_get_type")
-  (return-type "GType")
-)
-
-(define-method get_pages
-  (of-object "ThunarxPropertyPageProvider")
-  (c-name "thunarx_property_page_provider_get_pages")
-  (return-type "GList*")
-  (parameters
-    '("GList*" "files")
-  )
-)
-
-
-
 ;; From thunarx-property-page.h
 
 (define-function thunarx_property_page_get_type
@@ -258,20 +239,12 @@
 (define-function thunarx_property_page_new
   (c-name "thunarx_property_page_new")
   (is-constructor-of "ThunarxPropertyPage")
-  (return-type "GtkWidget*")
+  (return-type "ThunarxPropertyPage*")
   (parameters
     '("const-gchar*" "label")
   )
 )
 
-(define-function thunarx_property_page_new_with_label_widget
-  (c-name "thunarx_property_page_new_with_label_widget")
-  (return-type "GtkWidget*")
-  (parameters
-    '("GtkWidget*" "label_widget")
-  )
-)
-
 (define-method get_label
   (of-object "ThunarxPropertyPage")
   (c-name "thunarx_property_page_get_label")



More information about the Xfce4-commits mailing list