Embedding FileDiff in another application



Hi,

I was trying to embed the FileDiff widget into another application to
show the diff between two files. I was using the following simple
script to achieve this:

---
#!/usr/bin/python

import sys

import pygtk
import gtk

import gettext
gettext.install('meld')

# Adding meld's stuff to the path
sys.path += [ '/usr/lib/meld' ]

import filediff
import prefs

class DummyPreferences(prefs.Preferences):
   defaults = {
       "window_size_x": prefs.Value(prefs.INT, 600),
       "window_size_y": prefs.Value(prefs.INT, 600),
       "use_custom_font": prefs.Value(prefs.BOOL,0),
       "custom_font": prefs.Value(prefs.STRING,"monospace, 14"),
       "tab_size": prefs.Value(prefs.INT, 4),
       "show_line_numbers": prefs.Value(prefs.BOOL, 0),
       "use_syntax_highlighting": prefs.Value(prefs.BOOL, 0),
       "edit_wrap_lines" : prefs.Value(prefs.INT, 0),
       "edit_command_type" : prefs.Value(prefs.STRING, "internal"),
#internal, gnome, custom
       "edit_command_custom" : prefs.Value(prefs.STRING, "gedit"),
       "supply_newline": prefs.Value(prefs.BOOL,1),
       "text_codecs": prefs.Value(prefs.STRING, "utf8 latin1"),
       "save_encoding": prefs.Value(prefs.INT, 0),
       "draw_style": prefs.Value(prefs.INT,2),
       "toolbar_style": prefs.Value(prefs.INT,0),
       "ignore_symlinks": prefs.Value(prefs.BOOL,0),
       "cvs_quiet": prefs.Value(prefs.BOOL, 1),
       "cvs_compression": prefs.Value(prefs.BOOL, 1),
       "cvs_compression_value": prefs.Value(prefs.INT, 3),
       "cvs_ignore_cvsrc": prefs.Value(prefs.BOOL, 0),
       "cvs_binary": prefs.Value(prefs.STRING, "/usr/bin/cvs"),
       "cvs_create_missing": prefs.Value(prefs.BOOL, 1),
       "cvs_prune_empty": prefs.Value(prefs.BOOL, 1),
       "vc_console_visible": prefs.Value(prefs.BOOL, 0),
       "color_delete_bg" : prefs.Value(prefs.STRING, "DarkSeaGreen1"),
       "color_delete_fg" : prefs.Value(prefs.STRING, "Red"),
       "color_replace_bg" : prefs.Value(prefs.STRING, "#ddeeff"),
       "color_replace_fg" : prefs.Value(prefs.STRING, "Black"),
       "color_conflict_bg" : prefs.Value(prefs.STRING, "Pink"),
       "color_conflict_fg" : prefs.Value(prefs.STRING, "Black"),
       "color_inline_bg" : prefs.Value(prefs.STRING, "LightSteelBlue2"),
       "color_inline_fg" : prefs.Value(prefs.STRING, "Red"),
       "color_edited_bg" : prefs.Value(prefs.STRING, "gray90"),
       "color_edited_fg" : prefs.Value(prefs.STRING, "Black"),
       "filters" : prefs.Value(prefs.STRING,
           #TRANSLATORS: translate this string ONLY to the first
"\t", leave it and the following parts intact
           _("Backups\t1\t#*# .#* ~* *~ *.{orig,bak,swp}\n") + \
           #TRANSLATORS: translate this string ONLY to the first
"\t", leave it and the following parts intact
           _("Version Control\t1\tCVS .svn MT [{]arch[}] .arch-ids
.arch-inventory\n") + \
           #TRANSLATORS: translate this string ONLY to the first
"\t", leave it and the following parts intact
           _("Binaries\t1\t*.{pyc,a,obj,o,so,la,lib,dll}\n") + \
           #TRANSLATORS: translate this string ONLY to the first
"\t", leave it and the following parts intact
           _("Media\t0\t*.{jpg,gif,png,wav,mp3,ogg,xcf,xpm}")),
           #TRANSLATORS: translate this string ONLY to the first
"\t", leave it and the following parts intact
           "regexes" : prefs.Value(prefs.STRING, _("CVS
keywords\t0\t\$\\w+(:[^\\n$]+)?\$\n") + \
           #TRANSLATORS: translate this string ONLY to the first
"\t", leave it and the following parts intact
           _("C++ comment\t0\t//.*\n") + \
           #TRANSLATORS: translate this string ONLY to the first
"\t", leave it and the following parts intact
           _("C comment\t0\t/\*.*?\*/\n") + \
           #TRANSLATORS: translate this string ONLY to the first
"\t", leave it and the following parts intact
           _("All whitespace\t0\t[ \\t\\r\\f\\v]*\n") + \
           #TRANSLATORS: translate this string ONLY to the first
"\t", leave it and the following parts intact
           _("Leading whitespace\t0\t^[ \\t\\r\\f\\v]*\n") + \
           #TRANSLATORS: translate this string ONLY to the first
"\t", leave it and the following parts intact
           _("Script comment\t0\t#.*")),
       "ignore_blank_lines" : prefs.Value(prefs.BOOL, 1)
   }

   def __init__(self):
       prefs.Preferences.__init__(self, "/apps/meld", self.defaults)

   def get_cvs_command(self, op=None):
       cmd = [self.cvs_binary]
       if self.cvs_quiet:
           cmd.append("-q")
       if self.cvs_compression:
           cmd.append("-z%i" % self.cvs_compression_value)
       if self.cvs_ignore_cvsrc:
           cmd.append("-f")
       if op:
           cmd.append(op)
           if op == "update":
               if self.cvs_create_missing:
                   cmd.append("-d")
               if self.cvs_prune_empty:
                   cmd.append("-P")
       return cmd
   def get_current_font(self):
       if self.use_custom_font:
           return self.custom_font
       else:
           return
self._gconf.get_string('/desktop/gnome/interface/monospace_font_name')
or "Monospace 10"


preferences = DummyPreferences()
files = [ 'old.txt', 'new.txt' ]

window = gtk.Window()
doc = filediff.FileDiff(preferences, len(files))
doc.set_files(files)

window.add(doc.widget)
window.connect('delete-event', gtk.main_quit)
window.show_all()

gtk.main()
---

Running this script gives several gconf-related warnings, but there is
something more interesting in the output:

/usr/lib/meld/filediff.py:165: GtkDeprecationWarning: gtk.idle_add is
deprecated, use gobject.idle_add instead
 gtk.idle_add( lambda *args: self.load_font()) # hack around Bug 316730
Traceback (most recent call last):
 File "/usr/lib/meld/filediff.py", line 1187, in on_linkmap_expose_event
   pix_start[which+1] = self.textview[which+1].get_visible_rect().y
IndexError: list assignment index out of range
Traceback (most recent call last):
 File "/usr/lib/meld/filediff.py", line 1187, in on_linkmap_expose_event
   pix_start[which+1] = self.textview[which+1].get_visible_rect().y
IndexError: list assignment index out of range

(Installed meld from svn.gnome.org trunk)

There is also no text appearing in the TextViews (and there are 3 of
them instead of 2).

I hope someone could help me with this issue, or just point me to
another simple integration of meld's infrastructure into an
application.

Cheers,
Szilveszter / phanatic



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]