[pygobject] overrides for all subclasses of dialog
- From: John Palmieri <johnp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] overrides for all subclasses of dialog
- Date: Thu, 21 Oct 2010 17:33:30 +0000 (UTC)
commit a3d6212b0abccef58f05d454c091936776413d98
Author: John (J5) Palmieri <johnp redhat com>
Date: Thu Oct 7 11:43:27 2010 -0400
overrides for all subclasses of dialog
https://bugzilla.gnome.org/show_bug.cgi?id=631634
gi/overrides/Gtk.py | 94 ++++++++++++++++++++++++++++++++++++++++++++---
tests/test_overrides.py | 64 +++++++++++++++++++++++++++++++-
2 files changed, 151 insertions(+), 7 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 5988166..69a0342 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -252,10 +252,17 @@ class Builder(Gtk.Builder):
Builder = override(Builder)
__all__.append('Builder')
+
class Dialog(Gtk.Dialog):
- def __init__(self, title=None, parent=None, flags=0, buttons=None):
- Gtk.Dialog.__init__(self)
+ def __init__(self,
+ title=None,
+ parent=None,
+ flags=0,
+ buttons=None,
+ **kwds):
+
+ Gtk.Dialog.__init__(self, **kwds)
if title:
self.set_title(title)
if parent:
@@ -272,7 +279,7 @@ class Dialog(Gtk.Dialog):
except AttributeError:
pass
- if buttons:
+ if buttons is not None:
self.add_buttons(*buttons)
def add_buttons(self, *args):
@@ -287,15 +294,14 @@ class Dialog(Gtk.Dialog):
will add "Open" and "Close" buttons to dialog.
"""
-
- def buttons(b):
+ def _button(b):
while b:
t, r = b[0:2]
b = b[2:]
yield t, r
try:
- for text, response in buttons(args):
+ for text, response in _button(args):
self.add_button(text, response)
except (IndexError):
raise TypeError('Must pass an even number of arguments')
@@ -303,6 +309,82 @@ class Dialog(Gtk.Dialog):
Dialog = override(Dialog)
__all__.append('Dialog')
+class MessageDialog(Gtk.MessageDialog, Dialog):
+ def __init__(self,
+ parent=None,
+ flags=0,
+ type=Gtk.MessageType.INFO,
+ buttons=Gtk.ButtonsType.NONE,
+ message_format=None,
+ **kwds):
+
+ if message_format != None:
+ kwds['text'] = message_format
+ Gtk.MessageDialog.__init__(self,
+ buttons=buttons,
+ **kwds)
+ Dialog.__init__(self, parent=parent, flags=flags)
+
+MessageDialog = override(MessageDialog)
+__all__.append('MessageDialog')
+
+class AboutDialog(Gtk.AboutDialog, Dialog):
+ def __init__(self, **kwds):
+ Gtk.AboutDialog.__init__(self, **kwds)
+ Dialog.__init__(self)
+
+AboutDialog = override(AboutDialog)
+__all__.append('AboutDialog')
+
+class ColorSelectionDialog(Gtk.ColorSelectionDialog, Dialog):
+ def __init__(self, title=None, **kwds):
+ Gtk.ColorSelectionDialog.__init__(self, **kwds)
+ Dialog.__init__(self, title=title)
+
+ColorSelectionDialog = override(ColorSelectionDialog)
+__all__.append('ColorSelectionDialog')
+
+class FileChooserDialog(Gtk.FileChooserDialog, Dialog):
+ def __init__(self,
+ title=None,
+ parent=None,
+ action=Gtk.FileChooserAction.OPEN,
+ buttons=None,
+ **kwds):
+ Gtk.FileChooserDialog.__init__(self,
+ action=action,
+ **kwds)
+ Dialog.__init__(self, title=title, parent=parent, buttons=buttons)
+
+FileChooserDialog = override(FileChooserDialog)
+__all__.append('FileChooserDialog')
+
+class FontSelectionDialog(Gtk.FontSelectionDialog, Dialog):
+ def __init__(self, title=None, **kwds):
+ Gtk.FontSelectionDialog.__init__(self, **kwds)
+ Dialog.__init__(self, title=title)
+
+FontSelectionDialog = override(FontSelectionDialog)
+__all__.append('FontSelectionDialog')
+
+class RecentChooserDialog(Gtk.RecentChooserDialog, Dialog):
+ def __init__(self,
+ title=None,
+ parent=None,
+ manager=None,
+ buttons=None,
+ **kwds):
+
+ Gtk.RecentChooserDialog.__init__(self, recent_manager=manager, **kwds)
+ Dialog.__init__(self,
+ title=title,
+ parent=parent,
+ buttons=buttons)
+
+RecentChooserDialog = override(RecentChooserDialog)
+__all__.append('RecentChooserDialog')
+
+
class TextBuffer(Gtk.TextBuffer):
def _get_or_create_tag_table(self):
table = self.get_tag_table()
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index ebb2eff..b86222b 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -174,8 +174,16 @@ class TestGtk(unittest.TestCase):
self.assertEquals(signal_checker.sentinel, 4)
- def test_dialog(self):
+ def test_dialogs(self):
self.assertEquals(Gtk.Dialog, overrides.Gtk.Dialog)
+ self.assertEquals(Gtk.AboutDialog, overrides.Gtk.AboutDialog)
+ self.assertEquals(Gtk.MessageDialog, overrides.Gtk.MessageDialog)
+ self.assertEquals(Gtk.ColorSelectionDialog, overrides.Gtk.ColorSelectionDialog)
+ self.assertEquals(Gtk.FileChooserDialog, overrides.Gtk.FileChooserDialog)
+ self.assertEquals(Gtk.FontSelectionDialog, overrides.Gtk.FontSelectionDialog)
+ self.assertEquals(Gtk.RecentChooserDialog, overrides.Gtk.RecentChooserDialog)
+
+ # Gtk.Dialog
dialog = Gtk.Dialog (title='Foo',
flags=Gtk.DialogFlags.MODAL,
buttons=('test-button1', 1))
@@ -191,6 +199,60 @@ class TestGtk(unittest.TestCase):
button = dialog.get_widget_for_response (Gtk.ResponseType.CLOSE)
self.assertEquals(Gtk.STOCK_CLOSE, button.get_label())
+ # Gtk.AboutDialog
+ dialog = Gtk.AboutDialog()
+
+ # Gtk.MessageDialog
+ dialog = Gtk.MessageDialog (title='message dialog test',
+ flags=Gtk.DialogFlags.MODAL,
+ buttons=Gtk.ButtonsType.OK,
+ message_format='dude!')
+
+ self.assertEquals('message dialog test', dialog.get_title())
+ self.assertTrue(dialog.get_modal())
+ text = dialog.get_property('text')
+ self.assertEquals('dude!', text)
+
+ # Gtk.ColorSelectionDialog
+ dialog = Gtk.ColorSelectionDialog("color selection dialog test")
+ self.assertEquals('color selection dialog test', dialog.get_title())
+
+ # Gtk.FileChooserDialog
+ dialog = Gtk.FileChooserDialog (title='file chooser dialog test',
+ buttons=('test-button1', 1),
+ action=Gtk.FileChooserAction.SAVE)
+
+ dialog.add_buttons ('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
+ self.assertEquals('file chooser dialog test', dialog.get_title())
+ button = dialog.get_widget_for_response (1)
+ self.assertEquals('test-button1', button.get_label())
+ button = dialog.get_widget_for_response (2)
+ self.assertEquals('test-button2', button.get_label())
+ button = dialog.get_widget_for_response (Gtk.ResponseType.CLOSE)
+ self.assertEquals(Gtk.STOCK_CLOSE, button.get_label())
+ action = dialog.get_property('action')
+ self.assertEquals(Gtk.FileChooserAction.SAVE, action)
+
+
+ # Gtk.FontSelectionDialog
+ dialog = Gtk.ColorSelectionDialog("font selection dialog test")
+ self.assertEquals('font selection dialog test', dialog.get_title())
+
+ # Gtk.RecentChooserDialog
+ test_manager = Gtk.RecentManager()
+ dialog = Gtk.RecentChooserDialog (title='recent chooser dialog test',
+ buttons=('test-button1', 1),
+ manager=test_manager)
+
+ dialog.add_buttons ('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
+ self.assertEquals('recent chooser dialog test', dialog.get_title())
+ button = dialog.get_widget_for_response (1)
+ self.assertEquals('test-button1', button.get_label())
+ button = dialog.get_widget_for_response (2)
+ self.assertEquals('test-button2', button.get_label())
+ button = dialog.get_widget_for_response (Gtk.ResponseType.CLOSE)
+ self.assertEquals(Gtk.STOCK_CLOSE, button.get_label())
+
class TestClass(GObject.GObject):
__gtype_name__ = "GIOverrideTreeAPITest"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]