Forgot script was Re: A small example and GC-API



 Sorry forgot the python script


>>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<

On 5/22/00, 1:02:21 AM, Hassan Aurag <aurag@CRM.UMontreal.CA> wrote 
regarding A small example and GC-API:


>  Enclosed, you will find a small ill-written python script that wants
> to make a point.

>  The point is the following:

>  I have looked as a user at gnome equivalents of WinZip .... to no
> avail.

>  Gxtar et al. Are all particularly ugly and incredibly slow.

>  Indeed, these tools all use GtkTree, because it is easy even though
> on big archives it can become quite ugly.

>  Now try with script attached to this mail and you will notice a
> visual enhancement. This is not even an app, just a way to show Big
> Fat Archives in a better way.

>  Btw, nothing forbids you guys from actually unarchiving the tar.gz in
> some /tmp and have user manipulate it in a speedy way.

>  Now to the serious part of my post:

>  Again I will take an unexisting situation. For now at least.

>  I use GnomeZip and GnomeWord (please insert any names you like)

>  I open a tar.bz3(4,5,6) with GnomeZip.

>  Take my little script as example. Imagine I have actually enabled you
> the user to open files by clicking on them. It is easy with mime
> types. Now I open it with GnomeWord, change some lines, save and close 
it.

>  In Windows world, somehow Word or Winzip knows about it, and it will
> automagically update your archive accordingly.

>  If I want to implement this under Gnome, the only way I could think
> of is an inter-app callback mechanism for gnome compliant apps.

>  Example in python for simplicity's sake:

>   def double-click(file):
>    gnome_open_foreign_whatever_name_you_wish({"GnomeWord", "file",
> "open"},{"update", optional_data})


>  Of course I'd as GnomeZip creator implement update, but all gnome
> compliant apps would be able once done with "file" to do the same and
> launch
>  gnome_open_foreign({"GnomeZip", "file", "update"}, None)

>  None here is because GnomeWord doesn't want anything to do with that
> file anymore.


>  Am I babbling here or what?





> _______________________________________________
> gnome-devel-list mailing list
> gnome-devel-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gnome-devel-list

from gtk import *
from gnome.ui import *
import os, os.path, time, gnome.mime, string
from GtkExtra import *

bnode = {}


#GtkCTree List of files.
treelist = GtkCTree(cols=5, titles=["Name", "Size in Bytes", "Date", "Time", "Guessed Type"])
win = GtkScrolledWindow()

#Testing stuff
def tar_tzvf(what):
	res = {}
	for i in what:
		base = string.strip(i)
		full_path = string.split(base)[-1]
		res[full_path] = string.split(base)[:-1]
		
	return res

def build_nodes(what):
	global bnode
	#Sort keys
	mykeys = what.keys()
	mykeys.sort()
	#Build nodes
	for x in mykeys:
		tmp = string.split(x, "/")
		mytype = string.capwords(gnome.mime.type(x))
		if tmp[-1] == "":
			if len(tmp[:-1]) == 1:
				arg = None
			else: arg = bnode[string.join(tmp[:-2], "/") + "/"]
			bnode[x] = treelist.insert_node(arg, None, (tmp[-2],"", "", "", "Directory"), is_leaf=0, expanded=1)
		if tmp[-1] != "" and len(tmp) > 1:
			for i in range(len(tmp)):
				if i == 0:
					indice = tmp[0] + "/"
					if indice not in bnode.keys():
						bnode[indice] = treelist.insert_node(None, None, (tmp[-2],"", "", "", "Directory"), is_leaf=0, expanded=1)
				elif i < len(tmp) -1 and i > 0:
					indice = string.join(tmp[:-i], "/")+"/"
					parent = string.join(tmp[:-i-1],"/")+ "/"
					if indice not in bnode.keys():
						bnode[indice] =  treelist.insert_node(bnode[parent], None, (tmp[-1], what[x][2], what[x][3], what[x][4], "Directory"))
				else:
					if x not in bnode.keys():
						parent = string.join(tmp[:-1], "/") + "/"
						bnode[x] = treelist.insert_node(bnode[parent], None, (tmp[-1], what[x][2], what[x][3], what[x][4], mytype))


def open_arch(*what):
	global bnode
	bnode = {}
	for x in treelist.base_nodes():
		treelist.remove_node(x)
	myfile=file_sel_box()
	build_nodes(tar_tzvf(os.popen("tar -tzvf "+myfile).readlines()))
	treelist.columns_autosize()


treelist.column_titles_passive()
#Menus
file_menu = [UIINFO_MENU_EXIT_ITEM(cb=mainquit)]
menus = [UIINFO_SUBTREE("File", file_menu)]
toolbar = [
	UIINFO_ITEM_STOCK("Open", tip="Open An Archive", cb=open_arch, stock=STOCK_PIXMAP_OPEN)
	]
#GnomeApp
win.add(treelist)
app = GnomeApp("archivewiz", "Archive Wizard")
app.create_menus(menus)
app.create_toolbar(toolbar)
app.set_contents(win)
app.set_geometry_hints(treelist)


#We create a default view for CTree for testing purposes
#treelist.open_dir("/home/aurag/")
app.connect("destroy", mainquit)
app.set_default_size(2*screen_width()/3, 2*screen_height()/3)
app.show_all()
mainloop()




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