Updated preferences box to support Python 3, PyGObject and GTK 3
[zeroinstall/solver.git] / zeroinstall / gtkui / gtk.py
blob09a8df1d28f4829744c9b08d115e8f2854c7a457
1 """Compatibility wrapper to make Python 3's GTK look more like Python 2's version.
2 @since: 1.10
3 """
5 # Copyright (C) 2012, Thomas Leonard
6 # See the README file for details, or visit http://0install.net.
8 from __future__ import absolute_import
9 import sys
11 if sys.version_info[0] > 2:
12 # Python 3
14 from gi.repository import Gdk as gdk
15 from gi.repository.Gdk import Screen
17 from gi.repository.Gtk import MessageType, ResponseType, WindowPosition, PolicyType, ShadowType, WrapMode
18 from gi.repository.Gtk import Dialog, ScrolledWindow, TextView, TreePath
19 from gi.repository.Gtk import Builder, Menu
20 from gi.repository.Gtk import TreeStore, TreeViewColumn, CellRendererText
21 from gi.repository.Gtk import STOCK_CLOSE
22 from gi.repository.Gtk import MenuItem as GtkMenuItem
24 MESSAGE_ERROR = MessageType.ERROR
26 RESPONSE_CANCEL = ResponseType.CANCEL
27 RESPONSE_CLOSE = ResponseType.CLOSE
28 RESPONSE_HELP = ResponseType.HELP
29 RESPONSE_DELETE_EVENT = ResponseType.DELETE_EVENT
31 WIN_POS_CENTER = WindowPosition.CENTER
32 POLICY_AUTOMATIC = PolicyType.AUTOMATIC
33 POLICY_ALWAYS = PolicyType.ALWAYS
34 SHADOW_IN = ShadowType.IN
35 WRAP_WORD = WrapMode.WORD
37 gdk.screen_width = Screen.get_default().get_width
38 gdk.screen_height = Screen.get_default().get_height
40 gdk.BUTTON_PRESS = gdk.EventType.BUTTON_PRESS
42 def MenuItem(label):
43 item = GtkMenuItem()
44 item.set_label(label)
45 return item
47 def path_depth(path):
48 return path.get_depth()
50 def path_parent(path):
51 parent = path.copy()
52 parent.up()
53 return parent
54 else:
55 from gtk import * # Python 2
57 def path_depth(path):
58 return len(path)
60 def path_parent(path):
61 return path[:-1]