Skip to content

Instantly share code, notes, and snippets.

@albfan
Last active December 24, 2018 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albfan/ecd917ced76c5edd4251f83b8a700b62 to your computer and use it in GitHub Desktop.
Save albfan/ecd917ced76c5edd4251f83b8a700b62 to your computer and use it in GitHub Desktop.
Creating an UI with GtkBuilder that includes a GtkSourceView
#!/usr/bin/env python3
import gi
gi.require_version('GtkSource', '4')
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GtkSource, GObject
from os.path import abspath, dirname, join
current_dir = abspath(dirname(__file__))
class MyApp(object):
def __init__(self):
GObject.type_register(GtkSource.View)
self.builder = Gtk.Builder()
self.glade_file = join(current_dir, 'window.ui')
self.builder.add_from_file(self.glade_file)
self.window = self.builder.get_object("window")
self.window.show_all()
if __name__ == '__main__':
try:
gui = MyApp()
Gtk.main()
except KeyboardInterrupt:
pass
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtksourceview 3.0 -->
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window">
<property name="can_focus">False</property>
<child>
<object class="GtkScrolledWindow" id="left_scrolledwindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkSourceView" id="gtksourceview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_tooltip">True</property>
<property name="left_margin">2</property>
<property name="right_margin">2</property>
<property name="tab_width">4</property>
<property name="auto_indent">True</property>
<property name="indent_on_tab">False</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
</interface>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment