Beginnings of a C++ rewrite. We love to switch languages!
git-svn-id: https://samskivert.googlecode.com/svn/trunk@1330 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# $Id: bindings.py,v 1.2 2002/03/18 00:03:41 mdb Exp $
|
||||
# $Id: bindings.py,v 1.3 2003/11/28 21:34:59 mdb Exp $
|
||||
#
|
||||
# lookuplet - a utility for quickly looking up information
|
||||
# Copyright (C) 2001 Michael Bayne
|
||||
@@ -23,8 +23,8 @@ import re
|
||||
import string
|
||||
import urllib
|
||||
|
||||
import gnome.config
|
||||
import gnome.url
|
||||
import gnome
|
||||
import gconf
|
||||
|
||||
class Binding:
|
||||
"Contains the configuration for a particular key binding and its \
|
||||
@@ -61,7 +61,8 @@ class Binding:
|
||||
if (self.type == self.EXEC):
|
||||
posix.system(command)
|
||||
else:
|
||||
gnome.url.show(command)
|
||||
# gnome.url_show(command)
|
||||
posix.system("gnome-mozilla '%s'" % command)
|
||||
|
||||
def update (self, key, type, name, argument):
|
||||
modified = 0;
|
||||
@@ -90,22 +91,31 @@ class Binding:
|
||||
class BindingSet:
|
||||
"Maintains the set of bindings loading into the program."
|
||||
|
||||
# our gconf client instance
|
||||
gclient = None;
|
||||
|
||||
# the list of Binding objects
|
||||
bindings = [];
|
||||
|
||||
#
|
||||
# The default constructor.
|
||||
# The default constructor. Loads up our bindings from GConf.
|
||||
#
|
||||
def __init__ (self):
|
||||
gnome.config.push_prefix("/lookuplet/");
|
||||
count = gnome.config.get_int("lookuplet/bindings/count");
|
||||
for b in range(0, count):
|
||||
key = gnome.config.get_string("lookuplet/bindings/key_%.2u" % b);
|
||||
type = gnome.config.get_int("lookuplet/bindings/type_%.2u" % b);
|
||||
name = gnome.config.get_string("lookuplet/bindings/name_%.2u" % b);
|
||||
arg = gnome.config.get_string("lookuplet/bindings/arg_%.2u" % b);
|
||||
self.bindings.append(Binding(key, type, name, arg));
|
||||
gnome.config.pop_prefix();
|
||||
# connect to the gconf server
|
||||
gclient = gconf.client_get_default();
|
||||
gclient.add_dir("/apps/lookuplet", gconf.CLIENT_PRELOAD_NONE);
|
||||
|
||||
count = 0;
|
||||
|
||||
# gnome.config.push_prefix("/lookuplet/");
|
||||
# count = gnome.config.get_int("lookuplet/bindings/count");
|
||||
# for b in range(0, count):
|
||||
# key = gnome.config.get_string("lookuplet/bindings/key_%.2u" % b);
|
||||
# type = gnome.config.get_int("lookuplet/bindings/type_%.2u" % b);
|
||||
# name = gnome.config.get_string("lookuplet/bindings/name_%.2u" % b);
|
||||
# arg = gnome.config.get_string("lookuplet/bindings/arg_%.2u" % b);
|
||||
# self.bindings.append(Binding(key, type, name, arg));
|
||||
# gnome.config.pop_prefix();
|
||||
|
||||
# if we loaded no bindings, use the defaults
|
||||
if (count == 0):
|
||||
@@ -126,6 +136,11 @@ class BindingSet:
|
||||
self.bindings.append(Binding(
|
||||
"Control-i", Binding.URL, "IMDB Title search",
|
||||
"http://www.imdb.com/Tsearch?title=%U&restrict=Movies+only"));
|
||||
|
||||
# temporary hacked defaults
|
||||
self.bindings.append(Binding(
|
||||
"Control-j", Binding.EXEC, "Java doc lookup",
|
||||
"/home/mdb/bin/quickdoc.pl \"%T\""));
|
||||
return;
|
||||
|
||||
#
|
||||
@@ -142,20 +157,20 @@ class BindingSet:
|
||||
# Stores our updated bindings to our GConf preferences.
|
||||
#
|
||||
def flush (self):
|
||||
gnome.config.push_prefix("/lookuplet/");
|
||||
gnome.config.set_int("lookuplet/bindings/count", len(self.bindings));
|
||||
b = 0
|
||||
for binding in self.bindings:
|
||||
gnome.config.set_string(
|
||||
"lookuplet/bindings/key_%.2u" % b, binding.key);
|
||||
gnome.config.set_int(
|
||||
"lookuplet/bindings/type_%.2u" % b, binding.type);
|
||||
gnome.config.set_string(
|
||||
"lookuplet/bindings/name_%.2u" % b, binding.name);
|
||||
gnome.config.set_string(
|
||||
"lookuplet/bindings/arg_%.2u" % b, binding.argument);
|
||||
b += 1;
|
||||
gnome.config.sync();
|
||||
gnome.config.drop_all();
|
||||
gnome.config.pop_prefix();
|
||||
# gnome.config.push_prefix("/lookuplet/");
|
||||
# gnome.config.set_int("lookuplet/bindings/count", len(self.bindings));
|
||||
# b = 0
|
||||
# for binding in self.bindings:
|
||||
# gnome.config.set_string(
|
||||
# "lookuplet/bindings/key_%.2u" % b, binding.key);
|
||||
# gnome.config.set_int(
|
||||
# "lookuplet/bindings/type_%.2u" % b, binding.type);
|
||||
# gnome.config.set_string(
|
||||
# "lookuplet/bindings/name_%.2u" % b, binding.name);
|
||||
# gnome.config.set_string(
|
||||
# "lookuplet/bindings/arg_%.2u" % b, binding.argument);
|
||||
# b += 1;
|
||||
# gnome.config.sync();
|
||||
# gnome.config.drop_all();
|
||||
# gnome.config.pop_prefix();
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# $Id: edit_binding.py,v 1.1 2002/03/17 09:03:06 mdb Exp $
|
||||
# $Id: edit_binding.py,v 1.2 2003/11/28 21:34:59 mdb Exp $
|
||||
#
|
||||
# lookuplet - a utility for quickly looking up information
|
||||
# Copyright (C) 2001 Michael Bayne
|
||||
@@ -18,13 +18,12 @@
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
import gtk
|
||||
import GDK
|
||||
import gnome.ui
|
||||
import libglade
|
||||
import string
|
||||
import re
|
||||
|
||||
import gtk
|
||||
import gnome.ui
|
||||
|
||||
import bindings
|
||||
import keyval_util
|
||||
|
||||
@@ -41,8 +40,8 @@ class BindingEditor:
|
||||
# the grab window
|
||||
grabWindow = None;
|
||||
|
||||
# the index of the binding we're editing
|
||||
index = -1;
|
||||
# the iterator for the binding we're editing
|
||||
iterator = None;
|
||||
|
||||
# the binding we're editing
|
||||
binding = None;
|
||||
@@ -62,10 +61,9 @@ class BindingEditor:
|
||||
# the argument entry field
|
||||
argField = None;
|
||||
|
||||
def __init__ (self, xmlui, props, bindings):
|
||||
def __init__ (self, xmlui, props):
|
||||
# keep these around for later
|
||||
self.props = props;
|
||||
self.bindings = bindings;
|
||||
|
||||
# get a reference to some widgets
|
||||
self.bindPanel = xmlui.get_widget("binding");
|
||||
@@ -77,19 +75,18 @@ class BindingEditor:
|
||||
self.argField = xmlui.get_widget("argument");
|
||||
|
||||
# wire up our handlers
|
||||
nameFuncMap = {};
|
||||
for key in dir(self.__class__):
|
||||
nameFuncMap[key] = getattr(self, key);
|
||||
xmlui.signal_autoconnect(nameFuncMap);
|
||||
xmlui.signal_connect("on_ok_clicked", self.on_ok_clicked);
|
||||
xmlui.signal_connect("on_cancel_clicked", self.on_cancel_clicked);
|
||||
xmlui.signal_connect("on_key_key_press_event",
|
||||
self.on_key_key_press_event);
|
||||
|
||||
#
|
||||
# Instructs the binding panel to display itself, configured for
|
||||
# editing the supplied binding.
|
||||
#
|
||||
def editBinding (self, index):
|
||||
# keep a reference to the binding
|
||||
self.index = index;
|
||||
self.binding = self.bindings.bindings[index];
|
||||
def editBinding (self, iterator, binding):
|
||||
self.iterator = iterator;
|
||||
self.binding = binding;
|
||||
self.populateAndShow(self.binding);
|
||||
|
||||
#
|
||||
@@ -97,8 +94,8 @@ class BindingEditor:
|
||||
# available for editing by the user.
|
||||
#
|
||||
def createBinding (self):
|
||||
self.iterator = None;
|
||||
# create a blank binding and edit it
|
||||
self.index = -1;
|
||||
self.binding = bindings.Binding("", bindings.Binding.URL, "", "");
|
||||
self.populateAndShow(self.binding);
|
||||
|
||||
@@ -106,7 +103,6 @@ class BindingEditor:
|
||||
# A helper function used to populate our widgets and show the dialog.
|
||||
#
|
||||
def populateAndShow (self, binding):
|
||||
print "populating from binding " + binding.to_string();
|
||||
# populate our widgets with the binding values
|
||||
self.keyField.set_text(binding.key);
|
||||
self.nameField.set_text(binding.name);
|
||||
@@ -134,10 +130,10 @@ class BindingEditor:
|
||||
|
||||
# let the props panel know if there were any modifications
|
||||
if (modified):
|
||||
if (self.index >= 0):
|
||||
self.props.updated(self.index);
|
||||
else:
|
||||
if (self.iterator == None):
|
||||
self.props.created(self.binding);
|
||||
else:
|
||||
self.props.updated(self.iterator, self.binding);
|
||||
|
||||
# hide the binding panel
|
||||
self.bindPanel.hide();
|
||||
@@ -156,4 +152,5 @@ class BindingEditor:
|
||||
keystr = keyval_util.convert_keyval_state_to_string(
|
||||
event.keyval, event.state);
|
||||
textfield.set_text(keystr);
|
||||
return gtk.TRUE;
|
||||
return gtk.TRUE;
|
||||
return gtk.FALSE;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# $Id: history.py,v 1.1 2002/03/17 21:25:20 mdb Exp $
|
||||
# $Id: history.py,v 1.2 2003/11/28 21:34:59 mdb Exp $
|
||||
#
|
||||
# lookuplet - a utility for quickly looking up information
|
||||
# Copyright (C) 2001 Michael Bayne
|
||||
@@ -18,7 +18,7 @@
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
import gnome.config
|
||||
import gconf
|
||||
|
||||
class History:
|
||||
"Used to persistently maintain a history of entries for the \
|
||||
@@ -35,13 +35,13 @@ class History:
|
||||
# operation.
|
||||
#
|
||||
def __init__ (self):
|
||||
gnome.config.push_prefix("/lookuplet/");
|
||||
count = gnome.config.get_int("lookuplet/history/count");
|
||||
for h in range(0, count):
|
||||
self.history.append(gnome.config.get_string(
|
||||
"lookuplet/history/entry_%.2u" % h));
|
||||
# print "loaded %d: %s" % (h, self.history[h]);
|
||||
gnome.config.pop_prefix();
|
||||
# gnome.config.push_prefix("/lookuplet/");
|
||||
# count = gnome.config.get_int("lookuplet/history/count");
|
||||
# for h in range(0, count):
|
||||
# self.history.append(gnome.config.get_string(
|
||||
# "lookuplet/history/entry_%.2u" % h));
|
||||
# # print "loaded %d: %s" % (h, self.history[h]);
|
||||
# gnome.config.pop_prefix();
|
||||
return;
|
||||
|
||||
#
|
||||
@@ -61,16 +61,16 @@ class History:
|
||||
self.history.pop(0);
|
||||
|
||||
# flush our config to the configuration repository
|
||||
gnome.config.push_prefix("/lookuplet/");
|
||||
count = len(self.history);
|
||||
gnome.config.set_int("lookuplet/history/count", count);
|
||||
for h in range(0, count):
|
||||
gnome.config.set_string(
|
||||
"lookuplet/history/entry_%.2u" % h, self.history[h]);
|
||||
# print "wrote %d: %s" % (h, self.history[h]);
|
||||
gnome.config.sync();
|
||||
gnome.config.drop_all();
|
||||
gnome.config.pop_prefix();
|
||||
# gnome.config.push_prefix("/lookuplet/");
|
||||
# count = len(self.history);
|
||||
# gnome.config.set_int("lookuplet/history/count", count);
|
||||
# for h in range(0, count):
|
||||
# gnome.config.set_string(
|
||||
# "lookuplet/history/entry_%.2u" % h, self.history[h]);
|
||||
# # print "wrote %d: %s" % (h, self.history[h]);
|
||||
# gnome.config.sync();
|
||||
# gnome.config.drop_all();
|
||||
# gnome.config.pop_prefix();
|
||||
|
||||
#
|
||||
# Scans back from one before the specified index looking for a history
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# $Id: keyval_util.py,v 1.2 2002/03/19 00:22:31 mdb Exp $
|
||||
# $Id: keyval_util.py,v 1.3 2003/11/28 21:34:59 mdb Exp $
|
||||
#
|
||||
# lookuplet - a utility for quickly looking up information
|
||||
# Copyright (C) 2001 Michael Bayne
|
||||
@@ -19,12 +19,16 @@
|
||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
import string
|
||||
import GDK
|
||||
|
||||
import gtk
|
||||
import gtk.gdk
|
||||
|
||||
# these are used when doing our conversion; we specifically only care
|
||||
# about Control, Shift and Mod1; if you want to use other keys in your
|
||||
# combinations, we don't want you drinking our soda
|
||||
_CODES = [ GDK.CONTROL_MASK, GDK.SHIFT_MASK, GDK.MOD1_MASK ];
|
||||
# about Control, Shift and Mod1 (Alt); if you want to use other keys in
|
||||
# your combinations, we don't want you drinking our soda
|
||||
_CODES = [ gtk.gdk.CONTROL_MASK,
|
||||
gtk.gdk.SHIFT_MASK,
|
||||
gtk.gdk.MOD1_MASK ];
|
||||
_NAMES = [ "Control", "Shift", "Mod1" ];
|
||||
|
||||
#
|
||||
@@ -38,9 +42,9 @@ def convert_keyval_state_to_string (keyval, state):
|
||||
# start with the empty string
|
||||
modstr = "";
|
||||
|
||||
# we'd like to ask GDK to convert the key itself to a string, but they
|
||||
# don't wrap those functions. dooh!
|
||||
# key = GDK.keyval_name(keyval);
|
||||
# we'd like to ask gtk.gdk to convert the key itself to a string,
|
||||
# but they don't wrap those functions. dooh!
|
||||
# key = gtk.gdk_keyval_name(keyval);
|
||||
|
||||
# so we do this hack instead
|
||||
if (keyval < 0 or keyval > 255):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# $Id: lookuplet,v 1.2 2002/03/17 10:13:36 mdb Exp $
|
||||
# $Id: lookuplet,v 1.3 2003/11/28 21:34:59 mdb Exp $
|
||||
#
|
||||
# lookuplet - a utility for quickly looking up information
|
||||
# Copyright (C) 2001 Michael Bayne
|
||||
@@ -19,14 +19,18 @@
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
import gnome.applet
|
||||
import gtk
|
||||
import libglade
|
||||
import string
|
||||
import sys
|
||||
import re
|
||||
import os
|
||||
|
||||
import pygtk
|
||||
pygtk.require('2.0')
|
||||
|
||||
import gnome.applet
|
||||
import gtk
|
||||
import gtk.glade
|
||||
|
||||
# figure out where we were run from
|
||||
basedir = sys.argv[0];
|
||||
basedir = re.sub("/lookuplet$", "", basedir);
|
||||
@@ -43,10 +47,10 @@ import properties
|
||||
# load up our glade UI definition
|
||||
try:
|
||||
os.stat(basedir + "/lookuplet.glade");
|
||||
xmlui = libglade.GladeXML(basedir + "/lookuplet.glade");
|
||||
xmlui = gtk.glade.XML(basedir + "/lookuplet.glade");
|
||||
except OSError:
|
||||
os.stat(libdir + "/lookuplet.glade");
|
||||
xmlui = libglade.GladeXML(libdir + "/lookuplet.glade");
|
||||
xmlui = gtk.glade.XML(libdir + "/lookuplet.glade");
|
||||
|
||||
# load up our bindings
|
||||
bindings = bindings.BindingSet();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# $Id: lookuplet.py,v 1.3 2002/03/17 21:25:20 mdb Exp $
|
||||
# $Id: lookuplet.py,v 1.4 2003/11/28 21:34:59 mdb Exp $
|
||||
#
|
||||
# lookuplet - a utility for quickly looking up information
|
||||
# Copyright (C) 2001 Michael Bayne
|
||||
@@ -18,14 +18,14 @@
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
import gnome.applet
|
||||
import gtk
|
||||
import GDK
|
||||
import gnome.ui
|
||||
import gnome.uiconsts
|
||||
import string
|
||||
import re
|
||||
|
||||
import gnome.applet
|
||||
import gtk
|
||||
import gtk.keysyms
|
||||
import gnome.ui
|
||||
|
||||
import bindings
|
||||
import history
|
||||
import keyval_util
|
||||
@@ -34,14 +34,10 @@ import properties
|
||||
class Lookuplet:
|
||||
"Handles the primary setup and operation of the lookuplet application."
|
||||
|
||||
# in theory these should be defined by GDK but seem not to be
|
||||
SELECTION_PRIMARY = 1;
|
||||
CURRENT_TIME = 0;
|
||||
|
||||
# our special key definitions
|
||||
PREV_HISTORY_KEY = GDK.Up
|
||||
NEXT_HISTORY_KEY = GDK.Down
|
||||
AUTO_COMPLETE_KEY = GDK.Tab
|
||||
PREV_HISTORY_KEY = gtk.keysyms.Up
|
||||
NEXT_HISTORY_KEY = gtk.keysyms.Down
|
||||
AUTO_COMPLETE_KEY = gtk.keysyms.Tab
|
||||
|
||||
# a reference to our key bindings
|
||||
bindings = None;
|
||||
@@ -67,16 +63,15 @@ class Lookuplet:
|
||||
def __init__ (self, xmlui, bindings, props, appletMode):
|
||||
window = xmlui.get_widget("lookuplet");
|
||||
self.about = xmlui.get_widget("about");
|
||||
self.string_atom = None;
|
||||
self.bindings = bindings;
|
||||
self.props = props;
|
||||
self.appletMode = appletMode;
|
||||
|
||||
# wire up our handlers
|
||||
nameFuncMap = {};
|
||||
for key in dir(self.__class__):
|
||||
nameFuncMap[key] = getattr(self, key);
|
||||
xmlui.signal_autoconnect(nameFuncMap);
|
||||
xmlui.signal_connect("on_query_key_press_event",
|
||||
self.on_query_key_press_event);
|
||||
xmlui.signal_connect("on_prefs_clicked", self.on_prefs_clicked);
|
||||
xmlui.signal_connect("exit_lookuplet", self.exit_lookuplet);
|
||||
|
||||
# create our query history
|
||||
self.history = history.History();
|
||||
@@ -97,23 +92,22 @@ class Lookuplet:
|
||||
applet.add(mainbox);
|
||||
# register our menu items
|
||||
applet.register_stock_callback(
|
||||
"properties", gnome.uiconsts.STOCK_MENU_PROP,
|
||||
"properties", gnome.ui.STOCK_MENU_PROP,
|
||||
"Properties...", self.on_props_selected, None);
|
||||
applet.register_stock_callback(
|
||||
"about", gnome.uiconsts.STOCK_MENU_ABOUT,
|
||||
"about", gnome.ui.STOCK_MENU_ABOUT,
|
||||
"About...", self.on_about_selected, None);
|
||||
applet.show();
|
||||
|
||||
else:
|
||||
window.show();
|
||||
|
||||
# request the selection
|
||||
if (self.string_atom == None):
|
||||
self.string_atom = gtk.atom_intern("STRING", gtk.FALSE);
|
||||
# obtain the primary selection and stuff that into our entry box
|
||||
# clip = gtk.clipboard_get(gtk.GDK_SELECTION_PRIMARY);
|
||||
# selection = gtk.clipboard_wait_for_text(clip);
|
||||
query = xmlui.get_widget("query");
|
||||
query.selection_convert(self.SELECTION_PRIMARY,
|
||||
self.string_atom,
|
||||
self.CURRENT_TIME);
|
||||
# self.display_selection(self, query, selection);
|
||||
# query.paste_clipboard();
|
||||
|
||||
# put the focus in the query box
|
||||
query.grab_focus();
|
||||
@@ -201,7 +195,7 @@ class Lookuplet:
|
||||
self.hisidx = -1;
|
||||
|
||||
# if they pressed return, map that to a special binding
|
||||
if (event.keyval == GDK.Return):
|
||||
if (event.keyval == gtk.keysyms.Return):
|
||||
binding = bindings.Binding("", bindings.Binding.URL, "", "%T");
|
||||
|
||||
else:
|
||||
@@ -242,14 +236,17 @@ class Lookuplet:
|
||||
# print "Selection retrieval failed.";
|
||||
return;
|
||||
|
||||
if (selection_data.type != GDK.SELECTION_TYPE_STRING):
|
||||
if (selection_data.type != gtk.keysyms.SELECTION_TYPE_STRING):
|
||||
print "Selection target not returned as a string.";
|
||||
return;
|
||||
|
||||
# print "Got selection '%s'." % selection_data.data;
|
||||
print "Got selection '%s'." % selection_data.data;
|
||||
display_selection(self, query, selection_data.data);
|
||||
return;
|
||||
|
||||
def display_selection (self, query, text):
|
||||
# prune spaces from the end of the text
|
||||
text = string.strip(selection_data.data);
|
||||
text = string.strip(text);
|
||||
# compress whitespace (and convert newlines to spaces)
|
||||
text = re.sub("[ \r\n]+", " ", text);
|
||||
|
||||
@@ -269,5 +266,7 @@ class Lookuplet:
|
||||
query.select_region(0, len(text));
|
||||
# print "Selected from %d to %d." % (0, len(text));
|
||||
|
||||
return;
|
||||
|
||||
def exit_lookuplet (self, button):
|
||||
gtk.mainquit();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# $Id: properties.py,v 1.2 2002/03/18 00:30:24 mdb Exp $
|
||||
# $Id: properties.py,v 1.3 2003/11/28 21:34:59 mdb Exp $
|
||||
#
|
||||
# lookuplet - a utility for quickly looking up information
|
||||
# Copyright (C) 2001-2002 Michael Bayne
|
||||
@@ -18,13 +18,14 @@
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
import gtk
|
||||
import GDK
|
||||
import gnome.ui
|
||||
import libglade
|
||||
import string
|
||||
import re
|
||||
|
||||
import gobject
|
||||
import gtk
|
||||
import gtk.gdk
|
||||
import gnome.ui
|
||||
|
||||
import edit_binding
|
||||
|
||||
class Properties:
|
||||
@@ -37,8 +38,8 @@ class Properties:
|
||||
# our binding editor
|
||||
bindEditor = None;
|
||||
|
||||
# the bindings list
|
||||
bindList = None;
|
||||
# the bindings model
|
||||
bindModel = None;
|
||||
|
||||
# the edit button
|
||||
editButton = None;
|
||||
@@ -47,43 +48,61 @@ class Properties:
|
||||
deleteButton = None;
|
||||
|
||||
# the selected binding index
|
||||
selection = -1;
|
||||
selection = None;
|
||||
|
||||
def __init__ (self, xmlui, bindings):
|
||||
# keep a handle on our bindings
|
||||
self.bindings = bindings;
|
||||
|
||||
# create our binding editor
|
||||
self.bindEditor = edit_binding.BindingEditor(xmlui, self, bindings);
|
||||
self.bindEditor = edit_binding.BindingEditor(xmlui, self);
|
||||
|
||||
# get a reference to some widgets
|
||||
self.propsPanel = xmlui.get_widget("properties");
|
||||
self.editButton = xmlui.get_widget("edit");
|
||||
self.deleteButton = xmlui.get_widget("delete");
|
||||
self.bindList = xmlui.get_widget("bindings");
|
||||
|
||||
# make our props panel not destroy itself on close
|
||||
self.propsPanel.close_hides(gtk.TRUE);
|
||||
|
||||
# wire up our handlers
|
||||
nameFuncMap = {};
|
||||
for key in dir(self.__class__):
|
||||
nameFuncMap[key] = getattr(self, key);
|
||||
xmlui.signal_autoconnect(nameFuncMap);
|
||||
xmlui.signal_connect("on_properties_apply", self.on_properties_apply);
|
||||
xmlui.signal_connect("on_add_clicked", self.on_add_clicked);
|
||||
xmlui.signal_connect("on_edit_clicked", self.on_edit_clicked);
|
||||
xmlui.signal_connect("on_delete_clicked", self.on_delete_clicked);
|
||||
|
||||
# set up our tree view
|
||||
bindList = xmlui.get_widget("bindings");
|
||||
renderer = gtk.CellRendererText();
|
||||
bindList.append_column(gtk.TreeViewColumn("Key", renderer, text=0));
|
||||
bindList.append_column(gtk.TreeViewColumn("Name", renderer, text=1));
|
||||
|
||||
# create a data model for our bindings list view
|
||||
self.bindModel = gtk.ListStore(gobject.TYPE_STRING,
|
||||
gobject.TYPE_STRING,
|
||||
gobject.TYPE_PYOBJECT);
|
||||
|
||||
# configure our properties panel with the loaded bindings
|
||||
for binding in bindings.bindings:
|
||||
self.bindList.append([binding.key, binding.name]);
|
||||
iter = self.bindModel.append()
|
||||
self.bindModel.set_value(iter, 0, binding.key);
|
||||
self.bindModel.set_value(iter, 1, binding.name);
|
||||
self.bindModel.set_value(iter, 2, binding);
|
||||
|
||||
bindList.set_model(self.bindModel);
|
||||
|
||||
# wire up our selection monitor
|
||||
selection = bindList.get_selection();
|
||||
selection.connect("changed", self.on_bindings_selection_changed);
|
||||
|
||||
def editProperties (self):
|
||||
self.propsPanel.show();
|
||||
return;
|
||||
|
||||
def updated (self, index):
|
||||
binding = self.bindings.bindings[index];
|
||||
def updated (self, iter, binding):
|
||||
# refresh the display for the specified index
|
||||
self.bindList.set_text(index, 0, binding.key);
|
||||
self.bindList.set_text(index, 1, binding.name);
|
||||
self.bindModel.set_value(iter, 0, binding.key);
|
||||
self.bindModel.set_value(iter, 1, binding.name);
|
||||
# and make a note that we've updated ourselves
|
||||
self.propsPanel.changed();
|
||||
|
||||
@@ -91,31 +110,35 @@ class Properties:
|
||||
# add the new binding to our list
|
||||
self.bindings.bindings.append(binding);
|
||||
# add it to the display
|
||||
self.bindList.append([binding.key, binding.name]);
|
||||
iter = self.bindModel.append()
|
||||
self.bindModel.set_value(iter, 0, binding.key);
|
||||
self.bindModel.set_value(iter, 1, binding.name);
|
||||
self.bindModel.set_value(iter, 2, binding);
|
||||
# and make a note that we've updated ourselves
|
||||
self.propsPanel.changed();
|
||||
|
||||
def on_bindings_selection_changed (self, selection):
|
||||
# make a note of the iterator for the selected binding
|
||||
model, self.selection = selection.get_selected();
|
||||
|
||||
# no ?: notation? egads!
|
||||
if (self.selection == None):
|
||||
sensitive = gtk.FALSE;
|
||||
else:
|
||||
sensitive = gtk.TRUE;
|
||||
|
||||
# enable our buttons
|
||||
self.editButton.set_sensitive(sensitive);
|
||||
self.deleteButton.set_sensitive(sensitive);
|
||||
|
||||
# make like they pressed the edit button on a double click
|
||||
# if (event.type == gtk.gdk._2BUTTON_PRESS):
|
||||
# self.on_edit_clicked(None);
|
||||
|
||||
def on_properties_apply (self, panel, page):
|
||||
if (page == 0):
|
||||
self.bindings.flush();
|
||||
|
||||
def on_bindings_select_row (self, clist, row, column, event):
|
||||
# enable our buttons
|
||||
self.editButton.set_sensitive(gtk.TRUE);
|
||||
self.deleteButton.set_sensitive(gtk.TRUE);
|
||||
|
||||
# make a note of the selected binding index
|
||||
self.selection = row;
|
||||
|
||||
# make like they pressed the edit button on a double click
|
||||
if (event.type == GDK._2BUTTON_PRESS):
|
||||
self.on_edit_clicked(None);
|
||||
|
||||
def on_bindings_unselect_row (self, clist, row, column, event):
|
||||
# disable our buttons
|
||||
self.editButton.set_sensitive(gtk.FALSE);
|
||||
self.deleteButton.set_sensitive(gtk.FALSE);
|
||||
|
||||
def on_add_clicked (self, button):
|
||||
# show the binding creation dialog
|
||||
self.bindEditor.createBinding();
|
||||
@@ -123,14 +146,15 @@ class Properties:
|
||||
|
||||
def on_edit_clicked (self, button):
|
||||
# tell the binding editor to edit this binding
|
||||
self.bindEditor.editBinding(self.selection);
|
||||
binding = self.bindModel.get_value(self.selection, 2);
|
||||
self.bindEditor.editBinding(self.selection, binding);
|
||||
return;
|
||||
|
||||
def on_delete_clicked (self, button):
|
||||
# remove the binding from the display and our bindings list
|
||||
binding = self.bindings.bindings[self.selection];
|
||||
self.bindList.remove(self.selection)
|
||||
binding = self.bindModel.get_value(self.selection, 2);
|
||||
self.bindModel.remove(self.selection)
|
||||
self.bindings.bindings.remove(binding);
|
||||
self.selection = -1;
|
||||
self.selection = None;
|
||||
self.propsPanel.changed();
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user