[gnome-devel-docs] Port Python demos to Python 3 (with 2to3)



commit 3355a05d6884b3139a10353e7fbd473b4d9bc81c
Author: David King <amigadave amigadave com>
Date:   Mon Jan 27 11:32:01 2014 +0000

    Port Python demos to Python 3 (with 2to3)
    
    https://bugzilla.gnome.org/show_bug.cgi?id=723092

 platform-demos/C/samples/button.py                 |    2 +-
 platform-demos/C/samples/colorbutton.py            |    2 +-
 platform-demos/C/samples/combobox.py               |    2 +-
 platform-demos/C/samples/combobox_multicolumn.py   |    2 +-
 platform-demos/C/samples/dialog.py                 |    2 +-
 platform-demos/C/samples/entry.py                  |    2 +-
 platform-demos/C/samples/filechooserdialog.py      |   22 ++++++++++----------
 platform-demos/C/samples/fontchooserwidget.py      |    2 +-
 platform-demos/C/samples/gmenu.py                  |    6 ++--
 platform-demos/C/samples/menubar.py                |   18 ++++++++--------
 platform-demos/C/samples/menubar_basis.py          |    2 +-
 platform-demos/C/samples/menubutton.py             |    6 ++--
 platform-demos/C/samples/messagedialog.py          |    6 ++--
 platform-demos/C/samples/radiobutton.py            |    2 +-
 platform-demos/C/samples/toolbar.py                |    6 ++--
 platform-demos/C/samples/toolbar_builder.py        |    8 +++---
 platform-demos/C/samples/tooltip.py                |    6 ++--
 .../C/samples/treeview_advanced_liststore.py       |   10 ++++----
 18 files changed, 53 insertions(+), 53 deletions(-)
---
diff --git a/platform-demos/C/samples/button.py b/platform-demos/C/samples/button.py
index e32a93d..c67d66d 100644
--- a/platform-demos/C/samples/button.py
+++ b/platform-demos/C/samples/button.py
@@ -21,7 +21,7 @@ class MyWindow(Gtk.ApplicationWindow):
 
     # callback function connected to the signal "clicked" of the button
     def do_clicked(self, button):
-        print "You clicked me!"
+        print("You clicked me!")
 
 
 class MyApplication(Gtk.Application):
diff --git a/platform-demos/C/samples/colorbutton.py b/platform-demos/C/samples/colorbutton.py
index c311126..39ce618 100644
--- a/platform-demos/C/samples/colorbutton.py
+++ b/platform-demos/C/samples/colorbutton.py
@@ -36,7 +36,7 @@ class MyWindow(Gtk.ApplicationWindow):
 
     # if a new color is chosen, we print it as rgb(r,g,b) in the terminal
     def on_color_chosen(self, user_data):
-        print "You chose the color: " + self.button.get_rgba().to_string()
+        print("You chose the color: " + self.button.get_rgba().to_string())
 
 
 class MyApplication(Gtk.Application):
diff --git a/platform-demos/C/samples/combobox.py b/platform-demos/C/samples/combobox.py
index 418a16d..e78c8d3 100644
--- a/platform-demos/C/samples/combobox.py
+++ b/platform-demos/C/samples/combobox.py
@@ -44,7 +44,7 @@ class MyWindow(Gtk.ApplicationWindow):
         # if the row selected is not the first one, write its value on the
         # terminal
         if combo.get_active() != 0:
-            print "You chose " + str(distros[combo.get_active()][0]) + "."
+            print("You chose " + str(distros[combo.get_active()][0]) + ".")
         return True
 
 
diff --git a/platform-demos/C/samples/combobox_multicolumn.py 
b/platform-demos/C/samples/combobox_multicolumn.py
index 8e5b94e..decafbc 100644
--- a/platform-demos/C/samples/combobox_multicolumn.py
+++ b/platform-demos/C/samples/combobox_multicolumn.py
@@ -54,7 +54,7 @@ class MyWindow(Gtk.ApplicationWindow):
         # if the row selected is not the first one, write on the terminal
         # the value of the first column in the model
         if combo.get_active() != 0:
-            print "You chose " + str(actions[combo.get_active()][0]) + "\n"
+            print("You chose " + str(actions[combo.get_active()][0]) + "\n")
         return True
 
 
diff --git a/platform-demos/C/samples/dialog.py b/platform-demos/C/samples/dialog.py
index 720a41f..4042502 100644
--- a/platform-demos/C/samples/dialog.py
+++ b/platform-demos/C/samples/dialog.py
@@ -42,7 +42,7 @@ class MyWindow(Gtk.ApplicationWindow):
         dialog.show_all()
 
     def on_response(self, widget, response_id):
-        print "response_id is", response_id
+        print("response_id is", response_id)
         # destroy the widget (the dialog) when the function on_response() is called
         # (that is, when the button of the dialog has been clicked)
         widget.destroy()
diff --git a/platform-demos/C/samples/entry.py b/platform-demos/C/samples/entry.py
index 276add3..28da067 100644
--- a/platform-demos/C/samples/entry.py
+++ b/platform-demos/C/samples/entry.py
@@ -23,7 +23,7 @@ class MyWindow(Gtk.ApplicationWindow):
         # retrieve the content of the widget
         name = entry.get_text()
         # print it in a nice form in the terminal
-        print "Hello " + name + "!"
+        print("Hello " + name + "!")
 
 
 class MyApplication(Gtk.Application):
diff --git a/platform-demos/C/samples/filechooserdialog.py b/platform-demos/C/samples/filechooserdialog.py
index 5acc545..54af712 100644
--- a/platform-demos/C/samples/filechooserdialog.py
+++ b/platform-demos/C/samples/filechooserdialog.py
@@ -50,7 +50,7 @@ class MyWindow(Gtk.ApplicationWindow):
     # callback for new
     def new_callback(self, action, parameter):
         self.buffer.set_text("")
-        print "New file created"
+        print("New file created")
 
     # callback for open
     def open_callback(self, action, parameter):
@@ -88,13 +88,13 @@ class MyWindow(Gtk.ApplicationWindow):
                 # file has been modified from the version on the file system)
                 [success, content, etags] = self.file.load_contents(None)
             except GObject.GError as e:
-                print "Error: " + e.message
+                print("Error: " + e.message)
             # set the content as the text into the buffer
             self.buffer.set_text(content, len(content))
-            print "opened: " + open_dialog.get_filename()
+            print("opened: " + open_dialog.get_filename())
         # if response is "CANCEL" (the button "Cancel" has been clicked)
         elif response_id == Gtk.ResponseType.CANCEL:
-            print "cancelled: FileChooserAction.OPEN"
+            print("cancelled: FileChooserAction.OPEN")
         # destroy the FileChooserDialog
         dialog.destroy()
 
@@ -118,7 +118,7 @@ class MyWindow(Gtk.ApplicationWindow):
                 # set self.file as the current filename for the file chooser
                 save_dialog.set_file(self.file)
             except GObject.GError as e:
-                print "Error: " + e.message
+                print("Error: " + e.message)
         # connect the dialog to the callback function save_response_cb()
         save_dialog.connect("response", self.save_response_cb)
         # show the dialog
@@ -135,7 +135,7 @@ class MyWindow(Gtk.ApplicationWindow):
             self.save_to_file()
         # if response is "CANCEL" (the button "Cancel" has been clicked)
         elif response_id == Gtk.ResponseType.CANCEL:
-            print "cancelled: FileChooserAction.SAVE"
+            print("cancelled: FileChooserAction.SAVE")
         # destroy the FileChooserDialog
         dialog.destroy()
 
@@ -164,9 +164,9 @@ class MyWindow(Gtk.ApplicationWindow):
                                            False,
                                            Gio.FileCreateFlags.NONE,
                                            None)
-                print "saved: " + self.file.get_path()
+                print("saved: " + self.file.get_path())
             except GObject.GError as e:
-                print "Error: " + e.message
+                print("Error: " + e.message)
         # if the contents are empty
         else:
             # create (if the file does not exist) or overwrite the file in readwrite mode.
@@ -176,9 +176,9 @@ class MyWindow(Gtk.ApplicationWindow):
                                             False,
                                             Gio.FileCreateFlags.NONE,
                                             None)
-                print "saved: " + self.file.get_path()
+                print("saved: " + self.file.get_path())
             except GObject.GError as e:
-                print "Error: " + e.message
+                print("Error: " + e.message)
 
 
 class MyApplication(Gtk.Application):
@@ -203,7 +203,7 @@ class MyApplication(Gtk.Application):
         try:
             builder.add_from_file("filechooserdialog.ui")
         except:
-            print "file not found"
+            print("file not found")
             sys.exit()
         menu = builder.get_object("appmenu")
         self.set_app_menu(menu)
diff --git a/platform-demos/C/samples/fontchooserwidget.py b/platform-demos/C/samples/fontchooserwidget.py
index df4a68c..b70d83d 100644
--- a/platform-demos/C/samples/fontchooserwidget.py
+++ b/platform-demos/C/samples/fontchooserwidget.py
@@ -24,7 +24,7 @@ class MyWindow(Gtk.ApplicationWindow):
     # callback function:
     def font_cb(self, event, user_data):
         # print in the terminal
-        print "You chose the font " + self.font_chooser.get_font()
+        print("You chose the font " + self.font_chooser.get_font())
 
 
 class MyApplication(Gtk.Application):
diff --git a/platform-demos/C/samples/gmenu.py b/platform-demos/C/samples/gmenu.py
index a1f2583..173dc29 100644
--- a/platform-demos/C/samples/gmenu.py
+++ b/platform-demos/C/samples/gmenu.py
@@ -50,15 +50,15 @@ class MyApplication(Gtk.Application):
 
     # callback function for "new"
     def new_cb(self, action, parameter):
-        print "This does nothing. It is only a demonstration."
+        print("This does nothing. It is only a demonstration.")
 
     # callback function for "about"
     def about_cb(self, action, parameter):
-        print "No AboutDialog for you. This is only a demonstration."
+        print("No AboutDialog for you. This is only a demonstration.")
 
     # callback function for "quit"
     def quit_cb(self, action, parameter):
-        print "You have quit."
+        print("You have quit.")
         self.quit()
 
 app = MyApplication()
diff --git a/platform-demos/C/samples/menubar.py b/platform-demos/C/samples/menubar.py
index d044f79..fa180c8 100644
--- a/platform-demos/C/samples/menubar.py
+++ b/platform-demos/C/samples/menubar.py
@@ -41,15 +41,15 @@ class MyWindow(Gtk.ApplicationWindow):
 
     # callback function for copy_action
     def copy_callback(self, action, parameter):
-        print "\"Copy\" activated"
+        print("\"Copy\" activated")
 
     # callback function for paste_action
     def paste_callback(self, action, parameter):
-        print "\"Paste\" activated"
+        print("\"Paste\" activated")
 
     # callback function for shape_action
     def shape_callback(self, action, parameter):
-        print "Shape is set to", parameter.get_string()
+        print("Shape is set to", parameter.get_string())
         # Note that we set the state of the action!
         action.set_state(parameter)
 
@@ -131,7 +131,7 @@ class MyApplication(Gtk.Application):
         try:
             builder.add_from_file("menubar.ui")
         except:
-            print "file not found"
+            print("file not found")
             sys.exit()
 
         # we use the method Gtk.Application.set_menubar(menubar) to add the menubar
@@ -141,25 +141,25 @@ class MyApplication(Gtk.Application):
 
     # callback function for new
     def new_callback(self, action, parameter):
-        print "You clicked \"New\""
+        print("You clicked \"New\"")
 
     # callback function for quit
     def quit_callback(self, action, parameter):
-        print "You clicked \"Quit\""
+        print("You clicked \"Quit\"")
         sys.exit()
 
     # callback function for state
     def state_callback(self, action, parameter):
-        print "State is set to", parameter.get_string()
+        print("State is set to", parameter.get_string())
         action.set_state(parameter)
 
     # callback function for awesome
     def awesome_callback(self, action, parameter):
         action.set_state(GLib.Variant.new_boolean(not action.get_state()))
         if action.get_state().get_boolean() is True:
-            print "You checked \"Awesome\""
+            print("You checked \"Awesome\"")
         else:
-            print "You unchecked \"Awesome\""
+            print("You unchecked \"Awesome\"")
 
 
 app = MyApplication()
diff --git a/platform-demos/C/samples/menubar_basis.py b/platform-demos/C/samples/menubar_basis.py
index a1c8675..c7b8841 100644
--- a/platform-demos/C/samples/menubar_basis.py
+++ b/platform-demos/C/samples/menubar_basis.py
@@ -27,7 +27,7 @@ class MyApplication(Gtk.Application):
         try:
             builder.add_from_file("menubar_basis.ui")
         except:
-            print "file not found"
+            print("file not found")
             sys.exit()
 
         # we use the method Gtk.Application.set_menubar(menubar) to add the menubar
diff --git a/platform-demos/C/samples/menubutton.py b/platform-demos/C/samples/menubutton.py
index 6c3af1c..fe2ed0d 100644
--- a/platform-demos/C/samples/menubutton.py
+++ b/platform-demos/C/samples/menubutton.py
@@ -39,7 +39,7 @@ class MyWindow(Gtk.ApplicationWindow):
 
     # callback for "about"
     def about_callback(self, action, parameter):
-        print "You clicked \"About\""
+        print("You clicked \"About\"")
 
 
 class MyApplication(Gtk.Application):
@@ -65,10 +65,10 @@ class MyApplication(Gtk.Application):
 
     # callback functions for the actions related to the application
     def new_callback(self, action, parameter):
-        print "You clicked \"New\""
+        print("You clicked \"New\"")
 
     def quit_callback(self, action, parameter):
-        print "You clicked \"Quit\""
+        print("You clicked \"Quit\"")
         self.quit()
 
 app = MyApplication()
diff --git a/platform-demos/C/samples/messagedialog.py b/platform-demos/C/samples/messagedialog.py
index 002736e..1fb1c4b 100644
--- a/platform-demos/C/samples/messagedialog.py
+++ b/platform-demos/C/samples/messagedialog.py
@@ -38,13 +38,13 @@ class MyWindow(Gtk.ApplicationWindow):
     def dialog_response(self, widget, response_id):
         # if the button clicked gives response OK (-5)
         if response_id == Gtk.ResponseType.OK:
-            print "*boom*"
+            print("*boom*")
         # if the button clicked gives response CANCEL (-6)
         elif response_id == Gtk.ResponseType.CANCEL:
-            print "good choice"
+            print("good choice")
         # if the messagedialog is destroyed (by pressing ESC)
         elif response_id == Gtk.ResponseType.DELETE_EVENT:
-            print "dialog closed or cancelled"
+            print("dialog closed or cancelled")
         # finally, destroy the messagedialog
         widget.destroy()
 
diff --git a/platform-demos/C/samples/radiobutton.py b/platform-demos/C/samples/radiobutton.py
index b1079c1..742ccc6 100644
--- a/platform-demos/C/samples/radiobutton.py
+++ b/platform-demos/C/samples/radiobutton.py
@@ -55,7 +55,7 @@ class MyWindow(Gtk.ApplicationWindow):
             state = "off"
         # whenever the function is called (a button is turned on or off)
         # print on the terminal which button was turned on/off
-        print button.get_label() + " was turned " + state
+        print(button.get_label() + " was turned " + state)
 
 
 class MyApplication(Gtk.Application):
diff --git a/platform-demos/C/samples/toolbar.py b/platform-demos/C/samples/toolbar.py
index efde399..b3b0f7d 100644
--- a/platform-demos/C/samples/toolbar.py
+++ b/platform-demos/C/samples/toolbar.py
@@ -85,7 +85,7 @@ class MyWindow(Gtk.ApplicationWindow):
 
     # callback method for undo
     def undo_callback(self, action, parameter):
-        print "You clicked \"Undo\"."
+        print("You clicked \"Undo\".")
 
     # callback method for fullscreen / leave fullscreen
     def fullscreen_callback(self, action, parameter):
@@ -128,11 +128,11 @@ class MyApplication(Gtk.Application):
 
     # callback method for new
     def new_callback(self, action, parameter):
-        print "You clicked \"New\"."
+        print("You clicked \"New\".")
 
     # callback method for open
     def open_callback(self, action, parameter):
-        print "You clicked \"Open\"."
+        print("You clicked \"Open\".")
 
 app = MyApplication()
 exit_status = app.run(sys.argv)
diff --git a/platform-demos/C/samples/toolbar_builder.py b/platform-demos/C/samples/toolbar_builder.py
index d210556..1a29316 100644
--- a/platform-demos/C/samples/toolbar_builder.py
+++ b/platform-demos/C/samples/toolbar_builder.py
@@ -24,7 +24,7 @@ class MyWindow(Gtk.ApplicationWindow):
         try:
             builder.add_from_file("toolbar_builder.ui")
         except:
-            print "file not found"
+            print("file not found")
             sys.exit()
         # and attach it to the grid
         grid.attach(builder.get_object("toolbar"), 0, 0, 1, 1)
@@ -49,7 +49,7 @@ class MyWindow(Gtk.ApplicationWindow):
 
     # callback for undo
     def undo_callback(self, action, parameter):
-        print "You clicked \"Undo\"."
+        print("You clicked \"Undo\".")
 
     # callback for fullscreen
     def fullscreen_callback(self, action, parameter):
@@ -96,11 +96,11 @@ class MyApplication(Gtk.Application):
 
     # callback for new
     def new_callback(self, action, parameter):
-        print "You clicked \"New\"."
+        print("You clicked \"New\".")
 
     # callback for open
     def open_callback(self, action, parameter):
-        print "You clicked \"Open\"."
+        print("You clicked \"Open\".")
 
 app = MyApplication()
 exit_status = app.run(sys.argv)
diff --git a/platform-demos/C/samples/tooltip.py b/platform-demos/C/samples/tooltip.py
index 2ed0975..54de933 100644
--- a/platform-demos/C/samples/tooltip.py
+++ b/platform-demos/C/samples/tooltip.py
@@ -83,7 +83,7 @@ class MyWindow(Gtk.ApplicationWindow):
         return True
 
     def undo_callback(self, action, parameter):
-        print "You clicked \"Undo\"."
+        print("You clicked \"Undo\".")
 
     def fullscreen_callback(self, action, parameter):
         is_fullscreen = self.get_window().get_state(
@@ -117,10 +117,10 @@ class MyApplication(Gtk.Application):
         app.add_action(open_action)
 
     def new_callback(self, action, parameter):
-        print "You clicked \"New\"."
+        print("You clicked \"New\".")
 
     def open_callback(self, action, parameter):
-        print "You clicked \"Open\"."
+        print("You clicked \"Open\".")
 
 app = MyApplication()
 exit_status = app.run(sys.argv)
diff --git a/platform-demos/C/samples/treeview_advanced_liststore.py 
b/platform-demos/C/samples/treeview_advanced_liststore.py
index 8e71821..ca3399a 100644
--- a/platform-demos/C/samples/treeview_advanced_liststore.py
+++ b/platform-demos/C/samples/treeview_advanced_liststore.py
@@ -88,7 +88,7 @@ class MyWindow(Gtk.ApplicationWindow):
         title = self.entry.get_text()
         self.listmodel.append([title])
         # and print a message in the terminal
-        print "%s has been added" % (title)
+        print("%s has been added" % (title))
 
     def remove_cb(self, button):
         # if there is still an entry in the model
@@ -98,15 +98,15 @@ class MyWindow(Gtk.ApplicationWindow):
             # if there is a selection, print a message in the terminal
             # and remove it from the model
             if iter is not None:
-                print "%s has been removed" % (model[iter][0])
+                print("%s has been removed" % (model[iter][0]))
                 self.listmodel.remove(iter)
             # otherwise, ask the user to select something to remove
             else:
-                print "Select a title to remove"
+                print("Select a title to remove")
         # else, if there are no entries in the model, print "Empty list"
         # in the terminal
         else:
-            print "Empty list"
+            print("Empty list")
 
     def remove_all_cb(self, button):
         # if there is still an entry in the model
@@ -116,7 +116,7 @@ class MyWindow(Gtk.ApplicationWindow):
                 iter = self.listmodel.get_iter(0)
                 self.listmodel.remove(iter)
         # print a message in the terminal alerting that the model is empty
-        print "Empty list"
+        print("Empty list")
 
 
 class MyApplication(Gtk.Application):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]