#!/usr/bin/python
# -*- coding: utf-8 -*-
# Glaview - A fast preview for your glade files.
# Copyright (C) 2010 Ba1T <byte-f@live.it>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# -------------------------------------------------------------------------------
from gtk import *
from pygtk import *
require ('2.0')
gf = ''
def boom (w, d=None):
w.destroy ()
def run_w (name):
global gf
if gf != '':
try:
bld = Builder ()
bld.add_from_file (gf)
w = bld.get_object (name)
try:
w.set_title (w.get_title () + ' [Glaview Preview]')
except:
w.set_title ('Glaview Preview of %s' % (name))
except:
print "%s:can't get widget %s.." % (gf, name)
w.connect ('destroy', boom)
w.show_all ()
del bld
del w
def click (w, row, col, d=None):
name = w.get_model ()[row][0].split (' [')[0]
run_w (name)
def parse (s, t):
l = t.get_model ()
w = '<?xml '
l.clear ()
while True:
try:
w = s.split (w)[1].split ('<object class="GtkWindow" id="')[1].split ('"')[0]
l.append ([w + ' [WINDOW]'])
print 'Found a window: ' + str (w)
except:
try:
w = s.split (w)[1].split ('Dialog" id="')[1].split ('"')[0]
l.append ([w + ' [DIALOG]'])
print 'Found a dialog: ' + str (w)
except:
break
def drag (tree, cntx, x, y, sel, i, tm):
global gf
data = sel.data
gf = data.split ('file://')[1].split ('\r\n')[0]
try:
f = file (gf, 'r')
r = f.read ()
f.close ()
except:
print "Can't open glade file."
return
parse (r, tree)
#window
win = Window (WINDOW_TOPLEVEL)
win.set_title ('Drag your glade file in the window')
win.set_size_request (350, 150);
win.connect ('destroy', main_quit)
#liststore
lst = ListStore (str)
#treeview
tree = TreeView (lst)
tree.enable_model_drag_source (gdk.BUTTON1_MASK, [('text/plain', 0, 0)],
gdk.ACTION_DEFAULT)
tree.enable_model_drag_dest ([('text/plain', 0, 0)], gdk.ACTION_DEFAULT)
col = TreeViewColumn ("Windows", CellRendererText (), text=0)
tree.append_column (col)
tree.connect ('drag-data-received', drag)
tree.connect ('row-activated', click)
win.add (tree)
#show all and start program
win.show_all ()
main ()