summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorYaakov Selkowitz <[email protected]>2012-12-20 00:41:24 -0600
committerStefano Karapetsas <[email protected]>2013-01-22 14:10:00 +0100
commit825c1dd01981c159368a1a7a99931146fbbe60f1 (patch)
tree13a781b2b2023d06a1d8fb52d600e71ff40f911a /examples
parent29149f504a4e5e28a19b92d9ebb831bb53100a01 (diff)
downloadpython-caja-825c1dd01981c159368a1a7a99931146fbbe60f1.tar.bz2
python-caja-825c1dd01981c159368a1a7a99931146fbbe60f1.tar.xz
Port examples to g-i and gsettings
Diffstat (limited to 'examples')
-rw-r--r--examples/background-image.py22
-rw-r--r--examples/block-size-column.py12
-rw-r--r--examples/location-widget-provider.py7
-rw-r--r--examples/md5sum-property-page.py31
-rw-r--r--examples/open-terminal.py25
-rw-r--r--examples/submenu.py33
-rw-r--r--examples/update-file-info-async.py9
7 files changed, 73 insertions, 66 deletions
diff --git a/examples/background-image.py b/examples/background-image.py
index 0f5bea6..426dc4f 100644
--- a/examples/background-image.py
+++ b/examples/background-image.py
@@ -1,22 +1,18 @@
-import urllib
-
-import mateconf
-import caja
+from gi.repository import Caja, GObject, Gio
SUPPORTED_FORMATS = 'image/jpeg', 'image/png'
-BACKGROUND_KEY = '/desktop/mate/background/picture_filename'
+BACKGROUND_SCHEMA = 'org.mate.desktop.background'
+BACKGROUND_KEY = 'picture-uri'
-class BackgroundImageExtension(caja.MenuProvider):
+class BackgroundImageExtension(GObject.GObject, Caja.MenuProvider):
def __init__(self):
- self.mateconf = mateconf.client_get_default()
+ self.bgsettings = Gio.Settings.new(BACKGROUND_SCHEMA)
def menu_activate_cb(self, menu, file):
if file.is_gone():
return
- # Strip leading file://
- filename = urllib.unquote(file.get_uri()[7:])
- self.mateconf.set_string(BACKGROUND_KEY, filename)
+ self.bgsettings[BACKGROUND_KEY] = file.get_uri()
def get_file_items(self, window, files):
if len(files) != 1:
@@ -33,8 +29,8 @@ class BackgroundImageExtension(caja.MenuProvider):
if file.get_uri_scheme() != 'file':
return
- item = caja.MenuItem('Caja::set_background_image',
- 'Use as background image',
- 'Set the current image as a background image')
+ item = Caja.MenuItem(name='Caja::set_background_image',
+ label='Use as background image',
+ tip='Set the current image as a background image')
item.connect('activate', self.menu_activate_cb, file)
return item,
diff --git a/examples/block-size-column.py b/examples/block-size-column.py
index 6f94158..3fd64ce 100644
--- a/examples/block-size-column.py
+++ b/examples/block-size-column.py
@@ -1,17 +1,17 @@
import os
import urllib
-import caja
+from gi.repository import GObject, Caja
-class ColumnExtension(caja.ColumnProvider, caja.InfoProvider):
+class ColumnExtension(GObject.GObject, Caja.ColumnProvider, Caja.InfoProvider):
def __init__(self):
pass
def get_columns(self):
- return caja.Column("CajaPython::block_size_column",
- "block_size",
- "Block size",
- "Get the block size"),
+ return Caja.Column(name="CajaPython::block_size_column",
+ attribute="block_size",
+ label="Block size",
+ description="Get the block size"),
def update_file_info(self, file):
if file.get_uri_scheme() != 'file':
diff --git a/examples/location-widget-provider.py b/examples/location-widget-provider.py
index 0e7504c..c12301c 100644
--- a/examples/location-widget-provider.py
+++ b/examples/location-widget-provider.py
@@ -1,12 +1,11 @@
-import caja
-import gtk
+from gi.repository import Caja, Gtk, GObject
-class LocationProviderExample(caja.LocationWidgetProvider):
+class LocationProviderExample(GObject.GObject, Caja.LocationWidgetProvider):
def __init__(self):
pass
def get_widget(self, uri, window):
- entry = gtk.Entry()
+ entry = Gtk.Entry()
entry.set_text(uri)
entry.show()
return entry
diff --git a/examples/md5sum-property-page.py b/examples/md5sum-property-page.py
index 13c59e7..dd2a7ee 100644
--- a/examples/md5sum-property-page.py
+++ b/examples/md5sum-property-page.py
@@ -1,10 +1,9 @@
import hashlib
import urllib
-import gtk
-import caja
+from gi.repository import Caja, Gtk, GObject
-class MD5SumPropertyPage(caja.PropertyPageProvider):
+class MD5SumPropertyPage(GObject.GObject, Caja.PropertyPageProvider):
def __init__(self):
pass
@@ -21,22 +20,28 @@ class MD5SumPropertyPage(caja.PropertyPageProvider):
filename = urllib.unquote(file.get_uri()[7:])
- self.property_label = gtk.Label('MD5Sum')
+ self.property_label = Gtk.Label('MD5Sum')
self.property_label.show()
- self.hbox = gtk.HBox(0, False)
+ self.hbox = Gtk.HBox(homogeneous=False, spacing=0)
self.hbox.show()
- label = gtk.Label('MD5Sum:')
+ label = Gtk.Label('MD5Sum:')
label.show()
- self.hbox.pack_start(label)
+ self.hbox.pack_start(label, False, False, 0)
- self.value_label = gtk.Label()
- self.hbox.pack_start(self.value_label)
+ self.value_label = Gtk.Label()
+ self.hbox.pack_start(self.value_label, False, False, 0)
- md5sum = hashlib.md5(filename).hexdigest()
- self.value_label.set_text(md5sum)
+ md5sum = hashlib.md5()
+ with open(filename,'rb') as f:
+ for chunk in iter(lambda: f.read(8192), ''):
+ md5sum.update(chunk)
+ f.close()
+
+ self.value_label.set_text(md5sum.hexdigest())
self.value_label.show()
- return caja.PropertyPage("CajaPython::md5_sum",
- self.property_label, self.hbox),
+ return Caja.PropertyPage(name="CajaPython::md5_sum",
+ label=self.property_label,
+ page=self.hbox),
diff --git a/examples/open-terminal.py b/examples/open-terminal.py
index 8e22ccf..1d0e5aa 100644
--- a/examples/open-terminal.py
+++ b/examples/open-terminal.py
@@ -2,19 +2,18 @@
import os
import urllib
-import gtk
-import caja
-import mateconf
+from gi.repository import Caja, GObject, Gio
-TERMINAL_KEY = '/desktop/mate/applications/terminal/exec'
+TERMINAL_SCHEMA = 'org.mate.applications-terminal'
+TERMINAL_KEY = 'exec'
-class OpenTerminalExtension(caja.MenuProvider):
+class OpenTerminalExtension(Caja.MenuProvider, GObject.GObject):
def __init__(self):
- self.client = mateconf.client_get_default()
+ self.gsettings = Gio.Settings.new(TERMINAL_SCHEMA)
def _open_terminal(self, file):
filename = urllib.unquote(file.get_uri()[7:])
- terminal = self.client.get_string(TERMINAL_KEY)
+ terminal = self.gsettings[TERMINAL_KEY]
os.chdir(filename)
os.system('%s &' % terminal)
@@ -33,15 +32,15 @@ class OpenTerminalExtension(caja.MenuProvider):
if not file.is_directory() or file.get_uri_scheme() != 'file':
return
- item = caja.MenuItem('CajaPython::openterminal_file_item',
- 'Open Terminal' ,
- 'Open Terminal In %s' % file.get_name())
+ item = Caja.MenuItem(name='CajaPython::openterminal_file_item',
+ label='Open Terminal' ,
+ tip='Open Terminal In %s' % file.get_name())
item.connect('activate', self.menu_activate_cb, file)
return item,
def get_background_items(self, window, file):
- item = caja.MenuItem('CajaPython::openterminal_item',
- 'Open Terminal Here',
- 'Open Terminal In This Directory')
+ item = Caja.MenuItem(name='CajaPython::openterminal_item',
+ label='Open Terminal Here',
+ tip='Open Terminal In This Directory')
item.connect('activate', self.menu_background_activate_cb, file)
return item,
diff --git a/examples/submenu.py b/examples/submenu.py
index 7b91459..9d149f5 100644
--- a/examples/submenu.py
+++ b/examples/submenu.py
@@ -1,28 +1,37 @@
-import caja
+from gi.repository import Caja, GObject
-class ExampleMenuProvider(caja.MenuProvider):
-
- # Caja crashes if a plugin doesn't implement the __init__ method.
- # See Bug #374958
+class ExampleMenuProvider(GObject.GObject, Caja.MenuProvider):
def __init__(self):
pass
def get_file_items(self, window, files):
- top_menuitem = caja.MenuItem('ExampleMenuProvider::Foo', 'Foo', '')
+ top_menuitem = Caja.MenuItem(name='ExampleMenuProvider::Foo',
+ label='Foo',
+ tip='',
+ icon='')
- submenu = caja.Menu()
+ submenu = Caja.Menu()
top_menuitem.set_submenu(submenu)
- sub_menuitem = caja.MenuItem('ExampleMenuProvider::Bar', 'Bar', '')
+ sub_menuitem = Caja.MenuItem(name='ExampleMenuProvider::Bar',
+ label='Bar',
+ tip='',
+ icon='')
submenu.append_item(sub_menuitem)
return top_menuitem,
def get_background_items(self, window, file):
- submenu = caja.Menu()
- submenu.append_item(caja.MenuItem('ExampleMenuProvider::Bar', 'Bar', ''))
-
- menuitem = caja.MenuItem('ExampleMenuProvider::Foo', 'Foo', '')
+ submenu = Caja.Menu()
+ submenu.append_item(Caja.MenuItem(name='ExampleMenuProvider::Bar2',
+ label='Bar2',
+ tip='',
+ icon=''))
+
+ menuitem = Caja.MenuItem(name='ExampleMenuProvider::Foo2',
+ label='Foo2',
+ tip='',
+ icon='')
menuitem.set_submenu(submenu)
return menuitem,
diff --git a/examples/update-file-info-async.py b/examples/update-file-info-async.py
index 349b169..e4f90c7 100644
--- a/examples/update-file-info-async.py
+++ b/examples/update-file-info-async.py
@@ -1,15 +1,14 @@
-import caja
-import gobject
+from gi.repository import Caja, GObject
-class UpdateFileInfoAsync(caja.InfoProvider):
+class UpdateFileInfoAsync(GObject.GObject, Caja.InfoProvider):
def __init__(self):
pass
def update_file_info_full(self, provider, handle, closure, file):
print "update_file_info_full"
gobject.timeout_add_seconds(3, self.update_cb, provider, handle, closure)
- return caja.OPERATION_IN_PROGRESS
+ return Caja.OperationResult.IN_PROGRESS
def update_cb(self, provider, handle, closure):
print "update_cb"
- self.update_complete_invoke(provider, handle, closure, result=caja.OPERATION_FAILED)
+ Caja.info_provider_update_complete_invoke(closure, provider, handle, Caja.OperationResult.FAILED)