Advertisement
medigeek

gtk2 to gtk3

Feb 11th, 2012
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 19.23 KB | None | 0 0
  1. --- forum_signature.glade   2011-11-17 11:23:19.000000000 +0100
  2. +++ future/forum_signature_gtk3.glade   2012-02-11 02:51:55.000000000 +0100
  3. @@ -1,7 +1,6 @@
  4.  <?xml version="1.0" encoding="UTF-8"?>
  5.  <interface>
  6. -  <!-- interface-requires gtk+ 2.12 -->
  7. -  <!-- interface-naming-policy project-wide -->
  8. +  <!-- interface-requires gtk+ 3.0 -->
  9.    <object class="GtkDialog" id="dialog1">
  10.      <property name="can_focus">False</property>
  11.      <property name="border_width">5</property>
  12. @@ -15,11 +14,12 @@
  13.      <property name="transient_for">window1</property>
  14.      <signal name="delete-event" handler="gtk_false" swapped="no"/>
  15.      <child internal-child="vbox">
  16. -      <object class="GtkVBox" id="dialog-vbox1">
  17. +      <object class="GtkBox" id="dialog-vbox1">
  18.          <property name="visible">True</property>
  19.          <property name="can_focus">False</property>
  20. +        <property name="orientation">vertical</property>
  21.          <child internal-child="action_area">
  22. -          <object class="GtkHButtonBox" id="dialog-action_area1">
  23. +          <object class="GtkButtonBox" id="dialog-action_area1">
  24.              <property name="visible">True</property>
  25.              <property name="can_focus">False</property>
  26.              <property name="layout_style">end</property>
  27. @@ -99,8 +99,6 @@
  28.                      <property name="invisible_char">•</property>
  29.                      <property name="primary_icon_activatable">False</property>
  30.                      <property name="secondary_icon_activatable">False</property>
  31. -                    <property name="primary_icon_sensitive">True</property>
  32. -                    <property name="secondary_icon_sensitive">True</property>
  33.                      <signal name="changed" handler="on_entry1_changed" swapped="no"/>
  34.                    </object>
  35.                  </child>
  36. @@ -133,8 +131,6 @@
  37.                      <property name="invisible_char">•</property>
  38.                      <property name="primary_icon_activatable">False</property>
  39.                      <property name="secondary_icon_activatable">False</property>
  40. -                    <property name="primary_icon_sensitive">True</property>
  41. -                    <property name="secondary_icon_sensitive">True</property>
  42.                      <signal name="changed" handler="on_entry2_changed" swapped="no"/>
  43.                    </object>
  44.                  </child>
  45. @@ -201,12 +197,13 @@
  46.      <property name="use_markup">True</property>
  47.      <property name="secondary_use_markup">True</property>
  48.      <child internal-child="vbox">
  49. -      <object class="GtkVBox" id="dialog-vbox">
  50. +      <object class="GtkBox" id="dialog-vbox">
  51.          <property name="visible">True</property>
  52.          <property name="can_focus">False</property>
  53. +        <property name="orientation">vertical</property>
  54.          <property name="spacing">2</property>
  55.          <child internal-child="action_area">
  56. -          <object class="GtkHButtonBox" id="dialog-action_area">
  57. +          <object class="GtkButtonBox" id="dialog-action_area">
  58.              <property name="visible">True</property>
  59.              <property name="can_focus">False</property>
  60.              <property name="layout_style">end</property>
  61. @@ -253,12 +250,13 @@
  62.      <property name="gravity">center</property>
  63.      <property name="transient_for">window1</property>
  64.      <child internal-child="vbox">
  65. -      <object class="GtkVBox" id="dialog-vbox4">
  66. +      <object class="GtkBox" id="dialog-vbox4">
  67.          <property name="visible">True</property>
  68.          <property name="can_focus">False</property>
  69. +        <property name="orientation">vertical</property>
  70.          <property name="spacing">2</property>
  71.          <child internal-child="action_area">
  72. -          <object class="GtkHButtonBox" id="dialog-action_area4">
  73. +          <object class="GtkButtonBox" id="dialog-action_area4">
  74.              <property name="can_focus">False</property>
  75.              <property name="layout_style">end</property>
  76.              <child>
  77. @@ -321,8 +319,6 @@
  78.              <property name="height_request">200</property>
  79.              <property name="visible">True</property>
  80.              <property name="can_focus">True</property>
  81. -            <property name="hscrollbar_policy">automatic</property>
  82. -            <property name="vscrollbar_policy">automatic</property>
  83.              <child>
  84.                <object class="GtkTextView" id="textview3">
  85.                  <property name="visible">True</property>
  86. @@ -348,7 +344,9 @@
  87.      <property name="visible">True</property>
  88.      <property name="can_focus">False</property>
  89.      <property name="title" translatable="yes">Forum signature generator</property>
  90. -    <property name="window_position">center-always</property>
  91. +    <property name="window_position">center</property>
  92. +    <property name="default_width">500</property>
  93. +    <property name="default_height">300</property>
  94.      <property name="destroy_with_parent">True</property>
  95.      <property name="icon_name">applications-utilities</property>
  96.      <property name="gravity">center</property>
  97. @@ -380,19 +378,14 @@
  98.                </packing>
  99.              </child>
  100.              <child>
  101. -              <object class="GtkComboBoxEntry" id="comboboxentry1">
  102. +              <object class="GtkComboBoxText" id="comboboxtext1">
  103.                  <property name="visible">True</property>
  104.                  <property name="can_focus">False</property>
  105. -                <property name="model">liststorecombo1</property>
  106. -                <property name="text_column">0</property>
  107. +                <property name="has_entry">True</property>
  108.                  <signal name="changed" handler="on_comboboxentry_changed" swapped="no"/>
  109.                  <child internal-child="entry">
  110. -                  <object class="GtkEntry" id="comboboxentry-entry2">
  111. +                  <object class="GtkEntry" id="comboboxtext1-entry">
  112.                      <property name="can_focus">False</property>
  113. -                    <property name="primary_icon_activatable">False</property>
  114. -                    <property name="secondary_icon_activatable">False</property>
  115. -                    <property name="primary_icon_sensitive">True</property>
  116. -                    <property name="secondary_icon_sensitive">True</property>
  117.                    </object>
  118.                  </child>
  119.                </object>
  120. @@ -423,19 +416,16 @@
  121.                </packing>
  122.              </child>
  123.              <child>
  124. -              <object class="GtkComboBoxEntry" id="comboboxentry2">
  125. +              <object class="GtkComboBoxText" id="comboboxtext2">
  126.                  <property name="visible">True</property>
  127.                  <property name="can_focus">False</property>
  128. -                <property name="model">liststorecombo1</property>
  129. -                <property name="text_column">0</property>
  130. +                <property name="has_entry">True</property>
  131.                  <signal name="changed" handler="on_comboboxentry_changed" swapped="no"/>
  132.                  <child internal-child="entry">
  133. -                  <object class="GtkEntry" id="comboboxentry-entry4">
  134. +                  <object class="GtkEntry" id="comboboxtext2-entry">
  135.                      <property name="can_focus">False</property>
  136.                      <property name="primary_icon_activatable">False</property>
  137.                      <property name="secondary_icon_activatable">False</property>
  138. -                    <property name="primary_icon_sensitive">True</property>
  139. -                    <property name="secondary_icon_sensitive">True</property>
  140.                    </object>
  141.                  </child>
  142.                </object>
  143. @@ -470,19 +460,16 @@
  144.                </packing>
  145.              </child>
  146.              <child>
  147. -              <object class="GtkComboBoxEntry" id="comboboxentry3">
  148. +              <object class="GtkComboBoxText" id="comboboxtext3">
  149.                  <property name="visible">True</property>
  150.                  <property name="can_focus">False</property>
  151. -                <property name="model">liststorecombo1</property>
  152. -                <property name="text_column">0</property>
  153. +                <property name="has_entry">True</property>
  154.                  <signal name="changed" handler="on_comboboxentry_changed" swapped="no"/>
  155.                  <child internal-child="entry">
  156. -                  <object class="GtkEntry" id="comboboxentry-entry6">
  157. +                  <object class="GtkEntry" id="comboboxtext3-entry">
  158.                      <property name="can_focus">False</property>
  159.                      <property name="primary_icon_activatable">False</property>
  160.                      <property name="secondary_icon_activatable">False</property>
  161. -                    <property name="primary_icon_sensitive">True</property>
  162. -                    <property name="secondary_icon_sensitive">True</property>
  163.                    </object>
  164.                  </child>
  165.                </object>
  166. @@ -521,8 +508,6 @@
  167.                <object class="GtkScrolledWindow" id="scrolledwindow1">
  168.                  <property name="visible">True</property>
  169.                  <property name="can_focus">True</property>
  170. -                <property name="hscrollbar_policy">automatic</property>
  171. -                <property name="vscrollbar_policy">automatic</property>
  172.                  <property name="shadow_type">in</property>
  173.                  <child>
  174.                    <object class="GtkTextView" id="textview1">
  175. @@ -619,16 +604,14 @@
  176.                <object class="GtkScrolledWindow" id="scrolledwindow2">
  177.                  <property name="visible">True</property>
  178.                  <property name="can_focus">True</property>
  179. -                <property name="hscrollbar_policy">automatic</property>
  180. -                <property name="vscrollbar_policy">automatic</property>
  181.                  <property name="shadow_type">in</property>
  182.                  <child>
  183.                    <object class="GtkTextView" id="textview2">
  184. +                    <property name="width_request">300</property>
  185. +                    <property name="height_request">100</property>
  186.                      <property name="visible">True</property>
  187.                      <property name="can_focus">True</property>
  188.                      <property name="wrap_mode">char</property>
  189. -                    <property name="width_request">300</property>
  190. -                    <property name="height_request">100</property>
  191.                    </object>
  192.                  </child>
  193.                </object>
  194. --- forum_signature.py  2011-11-15 11:48:24.000000000 +0100
  195. +++ future/forum_signature_gtk3.py  2012-02-11 03:56:57.000000000 +0100
  196. @@ -4,7 +4,7 @@
  197.  # Purpose: Proposes a signature with useful hardware/software information to forum newcomers/newbies
  198.  # Requires: python 2.5, python-gtk2, python-mechanize
  199.  
  200. -# Copyright (c) 2010-2011 Savvas Radevic <vicedar@gmail.com>
  201. +# Copyright (c) 2010-2012 Savvas Radevic <vicedar@gmail.com>
  202.  #
  203.  # This program is free software: you can redistribute it and/or modify
  204.  # it under the terms of the GNU General Public License as published by
  205. @@ -21,7 +21,7 @@
  206.  
  207.  """ Example of signature:
  208.  1 Linux: � ┃ Προγραμματισμός: � ┃ Αγγλικά: �
  209. -2 Ubuntu 11.04 natty 64bit (en_GB.utf8), Ubuntu 2.6.38-10-generic, Windows 7
  210. +2 Ubuntu 11.04 natty 64bit (en_GB.utf8), Windows 7
  211.  3 Intel Core2 Duo CPU E6550 2.33GHz ‖ RAM 3961 MiB ‖ MSI MS-7235
  212.  4 nVidia G73 [GeForce 7300 GT] [10de:0393] (rev a1)
  213.  5 eth0: Realtek RTL-8110SC/8169SC Gigabit Ethernet [10ec:8167] (rev 10) ⋮ eth1: Realtek RTL-8139/8139C/8139C+ [10ec:8139] (rev 10)
  214. @@ -44,9 +44,11 @@
  215.  
  216.  textonly = False
  217.  try:
  218. -    import pygtk
  219. -    pygtk.require('2.0')
  220. -    import gtk
  221. +    #import pygtk
  222. +    #pygtk.require('2.0')
  223. +    #import gtk
  224. +    from gi.repository import Gtk, Gdk
  225. +
  226.  except ImportError:
  227.      sys.stderr.write("ERROR: Could not load gtk module\n")
  228.      sys.stderr.flush()
  229. @@ -357,8 +359,8 @@
  230.          self.password = ""
  231.          self.sig_charlimit = 500 # Allowed number of characters
  232.          # UI FILE
  233. -        self.uifile = "forum_signature.glade"
  234. -        self.builder = gtk.Builder()
  235. +        self.uifile = "forum_signature_gtk3.glade"
  236. +        self.builder = Gtk.Builder()
  237.          self.builder.add_from_file(self.uifile)
  238.          #SIGNALS
  239.          self.builder.connect_signals(self)
  240. @@ -371,15 +373,19 @@
  241.          self.textboxbuf.set_text(text)
  242.          self.textbox2 = self.builder.get_object("textview2") # old sig
  243.          self.textboxbuf2 = self.textbox2.get_buffer()
  244. -        self.comboboxlinux = self.builder.get_object("comboboxentry1")
  245. -        self.comboboxprogramming = self.builder.get_object("comboboxentry2")
  246. -        self.comboboxenglish = self.builder.get_object("comboboxentry3")
  247. +        self.liststore = self.builder.get_object("liststorecombo1")
  248. +        self.comboboxlinux = self.builder.get_object("comboboxtext1")
  249. +        self.comboboxlinux.set_model(self.liststore)
  250. +        self.comboboxprogramming = self.builder.get_object("comboboxtext2")
  251. +        self.comboboxprogramming.set_model(self.liststore)
  252. +        self.comboboxenglish = self.builder.get_object("comboboxtext3")
  253. +        self.comboboxenglish.set_model(self.liststore)
  254.          self.statusbar = self.builder.get_object("statusbar1")
  255.          self.statusbarcid = self.statusbar.get_context_id("status")
  256.          self.oldsigpack = self.builder.get_object("expander1")
  257.          # DIALOG
  258.          self.dialog = self.builder.get_object("dialog1")
  259. -        self.dialog.set_default_response(gtk.RESPONSE_CANCEL)
  260. +        self.dialog.set_default_response(Gtk.ResponseType.CANCEL)
  261.          self.entry1 = self.builder.get_object("entry1")
  262.          self.entry2 = self.builder.get_object("entry2")
  263.          # BUG REPORT DIALOG
  264. @@ -388,15 +394,15 @@
  265.          # ERROR MESSAGE DIALOG
  266.          self.errormsg = self.builder.get_object("messagedialog1")
  267.          # Ubuntu Hardy 8.04 compatibility
  268. -        self.comboboxlinux.set_text_column(0)
  269. -        self.comboboxprogramming.set_text_column(0)
  270. -        self.comboboxenglish.set_text_column(0)
  271. +        self.comboboxlinux.set_entry_text_column(0)
  272. +        self.comboboxprogramming.set_entry_text_column(0)
  273. +        self.comboboxenglish.set_entry_text_column(0)
  274.          # CHECK WUBI
  275.          self.iswubi()
  276.  
  277.      def on_textboxbuf_changed(self, widget):
  278.          (start, end) = self.textboxbuf.get_bounds()
  279. -        sigtext = self.textboxbuf.get_text(start, end)
  280. +        sigtext = self.textboxbuf.get_text(start, end, include_hidden_chars=False)
  281.          self.sig_size = len(sigtext)
  282.          # Could use this to drop code tags: re.sub(r'\[([^\s]*).*?\](.*?)\[/\1\]', r'\2', text)
  283.          if self.sig_size > self.sig_charlimit:
  284. @@ -422,7 +428,7 @@
  285.          outlsusb = p.communicate()[0]
  286.  
  287.          (start, end) = self.textboxbuf.get_bounds()
  288. -        sigtext = self.textboxbuf.get_text(start, end)
  289. +        sigtext = self.textboxbuf.get_text(start, end, include_hidden_chars=False)
  290.  
  291.          text = "Περιγράψτε το πρόβλημα στη θέση αυτού του κειμένου.\n\
  292.  Επισυνάψτε σφάλμα από το τερματικό ή από το γραφικό περιβάλλον (αν υπάρχει).\n\n\
  293. @@ -436,8 +442,8 @@
  294.  [/code]".format(outcpu, outmem, outlspci, outlsusb, sigtext)
  295.  
  296.          # SAVE TO CLIPBOARD
  297. -        clipboard = gtk.clipboard_get()
  298. -        clipboard.set_text(text)
  299. +        clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
  300. +        clipboard.set_text(text, -1)
  301.          clipboard.store()
  302.  
  303.          buf = self.textboxbuf3.get_buffer()
  304. @@ -460,10 +466,10 @@
  305.          timeoutid2 = glib.timeout_add_seconds(4, self.statusrefresh, msgid)
  306.  
  307.      def statusrefresh(self, msgid):
  308. -        self.statusbar.remove_message(self.statusbarcid, msgid)
  309. +        self.statusbar.remove(self.statusbarcid, msgid)
  310.      
  311.      def gtk_main_quit(self, widget):
  312. -        gtk.main_quit()
  313. +        Gtk.main_quit()
  314.  
  315.      def on_comboboxentry_changed(self, widget):
  316.          linux = self.comboboxlinux.get_active_text()
  317. @@ -472,7 +478,7 @@
  318.          self.line = "Linux: %s ┃ Προγραμματισμός: %s ┃ Αγγλικά: %s" % \
  319.              (linux, programming, english)
  320.          (start, end) = self.textboxbuf.get_bounds()
  321. -        oldtext = self.textboxbuf.get_text(start, end) # get all text
  322. +        oldtext = self.textboxbuf.get_text(start, end, include_hidden_chars=False) # get all text
  323.          newtext = re.subn(
  324.              'Linux:.*┃ Προγραμματισμός:.*┃ Αγγλικά:.*',
  325.              self.line,
  326. @@ -495,12 +501,12 @@
  327.          else:
  328.              # Submit to forum
  329.              dialogreply = self.dialog.run()
  330. -            if dialogreply == gtk.RESPONSE_APPLY:
  331. +            if dialogreply == Gtk.ResponseType.APPLY:
  332.                  #print("REPLY: %s (continue)" % dialogreply)
  333.                  #print("User: %s Pass: %s" % (self.username, self.password))
  334.                  self.statusmsg("Contacting forum...")
  335.                  timeid = glib.timeout_add_seconds(1, self.webwrapper)
  336. -            #elif dialogreply == gtk.RESPONSE_CANCEL or dialogreply == gtk.RESPONSE_DELETE_EVENT:
  337. +            #elif dialogreply == Gtk.ResponseType.CANCEL or dialogreply == Gtk.ResponseType.DELETE_EVENT:
  338.                  #print("REPLY: %s (cancel)" % dialogreply)
  339.              self.dialog.hide()
  340.  
  341. @@ -515,11 +521,11 @@
  342.  
  343.      def gtk_false(self, *widget):
  344.          # DIALOG - Cancel
  345. -        self.dialog.response(gtk.RESPONSE_CANCEL)
  346. +        self.dialog.response(Gtk.ResponseType.CANCEL)
  347.  
  348.      def gtk_true(self, *widget):
  349.          # DIALOG - Continue
  350. -        self.dialog.response(gtk.RESPONSE_APPLY)
  351. +        self.dialog.response(Gtk.ResponseType.APPLY)
  352.  
  353.      def on_entry1_changed(self, widget):
  354.          # DIALOG - Username
  355. @@ -537,7 +543,7 @@
  356.  
  357.      def sendtoweb(self):
  358.          (start, end) = self.textboxbuf.get_bounds()
  359. -        text = self.textboxbuf.get_text(start, end)
  360. +        text = self.textboxbuf.get_text(start, end, include_hidden_chars=False)
  361.  
  362.          try:
  363.              m = __import__("mechanize")
  364. @@ -549,7 +555,7 @@
  365.          br = m.Browser()
  366.          #('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1'),
  367.          br.addheaders = [
  368. -            ('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'),
  369. +            ('Accept-Charset', 'UTF-8;q=0.7'),
  370.              ('Accept-Language', 'Accept-Language: en-us,en;q=0.7,el;q=0.3'),
  371.              ('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
  372.          ]
  373. @@ -571,7 +577,7 @@
  374.              logger.addHandler(logging.FileHandler("http.log"))
  375.              logger.setLevel(logging.DEBUG)
  376.  
  377. -        br.open("http://forum.ubuntu-gr.org/ucp.php?i=profile&mode=signature")
  378. +        br.open("https://forum.ubuntu-gr.org/ucp.php?i=profile&mode=signature")
  379.          #self.statusmsg("Logging in...")
  380.          br.select_form(nr=1) # Select login form (no name for the form)
  381.          br["username"] = self.username
  382. @@ -600,7 +606,7 @@
  383.          br.select_form(nr=1)
  384.          oldsig = br["signature"]
  385.          br["signature"] = text
  386. -        #print(br.form)
  387. +        print(br.form)
  388.  
  389.          r3 = br.submit(name='submit')
  390.          h3 = r3.read()
  391. @@ -776,7 +782,7 @@
  392.      else:
  393.          print(text)
  394.          siggui(text, o[2], debug=debug_app)
  395. -        gtk.main()
  396. +        Gtk.main()
  397.  
  398.  def timeit():
  399.      f = 'core(osgrubber().returnall()).returnall()'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement