পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Thursday, March 30, 2017

PyGTK - Paned Class

Paned class is the base class for widgets which can display two adjustable panes either horizontally (gtk.Hpaned) or vertically (gtk.Vpaned). Child widgets to panes are added by using pack1() and pack2() methods.
Paned widget draws a separator slider between two panes and provides a handle to adjust their relative width/height. If the resize property of child widget inside a pane is set to True, it will resize according to the size of the panes.

The following methods are available for HPaned as well as VPaned class −
  • Paned.add1(child) − This adds the widget specified by child to the top or left pane
  • Paned.add2(child) − This adds the widget specified by child to the bottom or right pane.
  • Paned.pack1(child, resize, shrink) − This adds the widget specified by child to the top or left pane with the parameters. If resize is True, child should be resized when the paned widget is resized. If shrink is True, child can be made smaller than its minimum size request.
  • Paned.pack2(child, resize, shrink) − This sets the position of the divider between the two panes.
Both types of Paned widgets emit the following signals −
accept-position This is emitted when paned has the focus causing the child widget with the focus to be activated.
cancel-position This is emitted when the Esc key is pressed while paned has the focus.
move-handle This is emitted when paned has the focus and the separator is moved.

Example

The following example uses a gtk.Hpaned widget. In the left pane, a TreeView widget is added, and in the right pane, there is a TextView widget. When any row in TreeView is selected, it will emit row_activated signal which is connected to a callback function. The on_activated()function retrieves row's text and displays in the text view panel.
Observe the code −
import gtk, gobject
class PyApp(gtk.Window):
   def __init__(self):
      super(PyApp, self).__init__()
      self.set_title("HPaned widget Demo")
      self.set_default_size(250, 200)
      vp = gtk.HPaned()
      sw = gtk.ScrolledWindow()
      sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) 
  
      tree = gtk.TreeView()
      languages = gtk.TreeViewColumn()
      languages.set_title("GUI Toolkits")
      cell = gtk.CellRendererText()
      languages.pack_start(cell, True)
      languages.add_attribute(cell, "text", 0)
      treestore = gtk.TreeStore(str)
      it = treestore.append(None, ["Python"])
  
      treestore.append(it, ["PyQt"])
      treestore.append(it, ["wxPython"])
      treestore.append(it, ["PyGTK"])
      treestore.append(it, ["Pydide"])
  
      it = treestore.append(None, ["Java"])
      treestore.append(it, ["AWT"])
      treestore.append(it, ["Swing"])
      treestore.append(it, ["JSF"])
      treestore.append(it, ["SWT"])
  
      tree.append_column(languages)
      tree.set_model(treestore)
  
      vp.add1(tree)
      self.tv = gtk.TextView()
      vp.add2(self.tv)
      vp.set_position(100)
      self.add(vp)
  
      tree.connect("row-activated", self.on_activated)
      self.connect("destroy", gtk.main_quit)
      self.show_all()
  
   def on_activated(self, widget, row, col):
      model = widget.get_model()
      text = model[row][0]
      print text
  
      buffer = gtk.TextBuffer()
      buffer.set_text(text+" is selected")
      self.tv.set_buffer(buffer)
      if __name__ == '__main__':
PyApp()
gtk.main()
The above code will generate the following output −
Hpaned Widget Demo

No comments:

Post a Comment