{"id":3862,"date":"2014-03-30T06:06:28","date_gmt":"2014-03-30T06:06:28","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/pygtk-textview-problems-collection-of-common-programming-errors\/"},"modified":"2014-03-30T06:06:28","modified_gmt":"2014-03-30T06:06:28","slug":"pygtk-textview-problems-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/pygtk-textview-problems-collection-of-common-programming-errors\/","title":{"rendered":"PyGTK TextView problems-Collection of common programming errors"},"content":{"rendered":"<p>I have two problems regarding the TextView widget for PyGTK. How do I dictate the size of the TextView and how do I simply get and insert text (not just set text) into TextView ?<\/p>\n<p>Below is my source code:<\/p>\n<pre><code>import sys\n\nimportStatus = False\noutput = None\n\ntry:\n    import pygtk\n    pygtk.require('2.0')\n    import gtk\n    importStatus = True\n\nexcept ImportError:\n    print \"PyGTK module does not exist. Can't launch GUI !\"\n    print \"Please download and install GTK and PyGTK.\"\n    importStatus = False\n\nif importStatus:\n\n    class gtkGUI():\n\n        def __init__(self):\n            print \"gtkGUI imported\"\n            self.startGUI()\n\n        def startGUI(self):\n            print \"GUI Started\"\n            self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)\n            self.window.set_border_width(10)\n\n            ## Buttons\n            self.btn = gtk.Button(\"Press me !\")\n\n            ## Text View with frame wrapping\n            self.page_size = gtk.Adjustment(lower=100, page_size=100)\n            self.sw = gtk.ScrolledWindow(self.page_size)\n            self.sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)\n            output = gtk.TextView()\n            self.textbuffer = output.get_buffer()\n            output.set_wrap_mode(gtk.WRAP_WORD)\n            output.set_editable(False)\n            self.sw.add(output)\n            self.frame = gtk.Frame()\n            self.frame.set_label(\" Result: \")\n            self.frame.set_shadow_type(gtk.SHADOW_ETCHED_OUT)\n            self.frame.add(self.sw)\n\n            ## Packing widgets into window\n\n            # Vertical box to contain all boxes\n            self.vbox = gtk.VBox(homogeneous=False, spacing=0)\n\n            # Output View\n            self.vbox.pack_start(self.frame, expand=False, fill=False, padding=5)\n\n            # Adding button to window\n            self.box = gtk.HBox(homogeneous=False, spacing=0)\n            self.box.pack_end(self.btn, expand=False, fill=False, padding=5)\n            self.vbox.pack_start(self.box, expand=False, fill=False, padding=5)\n\n            ## Presenting window\n            self.window.add(self.vbox)\n            self.window.show_all()\n            gtk.main()\n            self.insertText(\"helloworld\")\n            return None\n\n        def insertText(self, text):\n            if(output == None):\n                print \"Empty Output\"\n            else:\n                print \"inserting - \" + output\n<\/code><\/pre>\n<p>Output when running the above code:<\/p>\n<pre><code>Empty Output\n<\/code><\/pre>\n<p>These codes above are the core codes that I have summarized from a bigger codebase containing the essentials to the problem.<\/p>\n<p>Java has a &#8220;textarea.append(&#8220;&#8230;&#8221;);&#8221; and &#8220;textarea.getText()&#8221; for Swing. I can&#8217;t find anything similar for the TextView in PyGTK.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have two problems regarding the TextView widget for PyGTK. How do I dictate the size of the TextView and how do I simply get and insert text (not just set text) into TextView ? Below is my source code: import sys importStatus = False output = None try: import pygtk pygtk.require(&#8216;2.0&#8217;) import gtk importStatus [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3862","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3862","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3862"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3862\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}