Example #1
0
def myTreField(name=("name","value"),
				call=None, data=['dati'],
				bord=1,
				font=['Luxi Mono 9', 'Sans 8'],
				size=[140, 180],
				widt=300, heig=400,
				shad=Gtk.SHADOW_ETCHED_IN, 
				poli=(Gtk.POLICY_AUTOMATIC, Gtk.POLICY_AUTOMATIC),
				nExp="Titolo"):
	""" crea una lista di campi da editare

		-> name lista campi
		-> call funzione da eseguire su evento
		-> data dati da passare alla funzione
		-> bord margine esterno dello scroolbar
		-> font font da usare per le celle
		-> cCol lista colore di fondo delle colonne
		-> iamg lista immagini
		-> widt ampiezza scrollbars
		-> heig altezza scrollbars
		-> shad tipo di cornice
			Gtk.SHADOW_NONE, Gtk.SHADOW_IN, Gtk.SHADOW_OUT, 
			Gtk.SHADOW_ETCHED_IN, Gtk.SHADOW_ETCHED_OUT
		-> poli politiche di visibilita delle barre di scorrimento
			(horizontal,vertical)
			POLICY_AUTOMATIC whether you need
			POLICY_ALWAYS leave the scrollbars
	"""

	# ridefinisco la callback        
	def row_activated(tree, path, colu, *data):
		# leggo record selezionato 
		#  dal doppio click o dal enter
		rec = getRecord(tree, path)
		# print rec, tree, path, colu

		# leggo il modello dei dati
		stor = tree.get_model()
		# leggo il riferimento della riga
		treeiter = stor.get_iter(path)
		if stor.iter_has_child(treeiter):
			# print "father"
			# collapse
			if tree.collapse_row(path):
				return
			# expand
			tree.expand_row(path,True)
		# else:
		# 	print "child"

#treeStore  
	mode = [GObject.TYPE_STRING,]* (len(name)*2)
	stor = Gtk.TreeStore(*mode)
#treeView
	tree = Gtk.TreeView(stor)
	tree.show()
#callback    
	# in assenza di callback usa quella di debug
	if call == None:
		call = row_activated
	# callback su doppio click o enter
	tree.connect('row-activated', call)
	# aggiungo evento tastiera per intercettare ctrl+Enter
	tree.set_events(Gdk.EventMask.KEY_PRESS_MASK)
	# # associamo la callback all'evento
	# tree.connect("key-press-event", ctlEnter, tree)	
	# active grid line
	tree.set_grid_lines(True)
	# hide column
	tree.set_headers_visible(False)

#cellRender + viewColumn
	# aggiungo le colonne e le celle
	colu = []
	cell = []
	head = []
	#First column's cell
	cel = Gtk.CellRendererText()
	cell.append(cel)
	cel.set_property('font', font[0])
	cel.set_property('background-set', True)
	# column 1
	col = Gtk.TreeViewColumn()
	colu.append(col)
	col.pack_start(cel, True)
	col.set_fixed_width(size[0])
	col.set_attributes(cel, text=0, background=2)
	tree.append_column(col)

	#Second column's cell
	cel = Gtk.CellRendererText()
	cell.append(cel)
	cel.set_property('font', font[1])
	cel.set_property('background-set', True)
	cel.set_property('editable', True )
	# column 2
	col = Gtk.TreeViewColumn()
	colu.append(col)
	col.pack_start(cel, True)
	col.set_fixed_width(size[1])
	col.set_attributes(cel, text=1, background=3)
	tree.append_column(col)

#myScrolled
	scro = myScrolled(obje=None, bord=bord, 
					  widt=widt, heig=heig, 
					  shad=shad, poli=poli)
	if 1:
		# titolo esterno allo scroll
		scro.add(tree)
	else:
		# titolo interno allo scroll
		scro.add_with_viewport(tree)

# myFather	
	# tree, scro=None, pare=None, colo=None, reco=[]
	pare = addField(tree=tree, colo=['#e0e0e0', '#e0e0e0'], reco=[nExp, ""] )

# <-
	# tree, [stor, colu, cell, scro, pare]
	return tree, [stor, colu, cell, scro, pare]
Example #2
0
def myTreStore(name=["->", "Id", "->", "Name"], 
				call=None, data=['dati'],
				bord=1, 
				font=['Courier bold 9'] * 4, 
				cCol=['white','gray','white','gray'], 
				imag=[None,] * 4,
				widt=200, heig=100,
				shad=Gtk.SHADOW_ETCHED_IN, 
				poli=(Gtk.POLICY_AUTOMATIC, Gtk.POLICY_AUTOMATIC)):
	#item=, call=on_activated_makView):
	""" crea una TreeView

		-> name lista campi
		-> call funzione da eseguire su evento
		-> data dati da passare alla funzione
		-> bord margine esterno dello scroolbar
		-> font font da usare per le celle
		-> cCol lista colore di fondo delle colonne
		-> iamg lista immagini
		-> widt ampiezza
		-> heig altezza
		-> shad tipo di cornice
			Gtk.SHADOW_NONE, Gtk.SHADOW_IN, Gtk.SHADOW_OUT, 
			Gtk.SHADOW_ETCHED_IN, Gtk.SHADOW_ETCHED_OUT
		-> poli politiche di visibilita delle barre di scorrimento
			(horizontal,vertical)
			POLICY_AUTOMATIC whether you need
			POLICY_ALWAYS leave the scrollbars
	"""
	# ridefinisco la callback        
	def row_activated(tree, path, colu, *data):
		# print widg, path, colu

		# leggo record selezionato 
		#  dal doppio click o dal enter
		# rec = getRecord(widg, path)
		# print rec

		# leggo record selezionato 
		#  dal doppio click o dal enter
		rec = getRecord(tree, path)
		# print rec, tree, path, colu

		# leggo il modello dei dati
		stor = tree.get_model()
		# leggo il riferimento della riga
		treeiter = stor.get_iter(path)
		if stor.iter_has_child(treeiter):
			# print "father"
			# collapse
			if tree.collapse_row(path):
				return
			# expand
			tree.expand_row(path,True)
		# else:
		# 	print "child"
		
#treeStore  
	mode = [GObject.TYPE_STRING,]* (len(name))
	stor = Gtk.TreeStore(*mode)
#treeView
	tree = Gtk.TreeView(stor)
	tree.show()
#callback    
	# in assenza di callback usa quella di debug
	if call == None:
		call = row_activated
	# callback su doppio click o enter
	tree.connect('row-activated', call)
	# aggiungo evento tastiera per intercettare ctrl+Enter
	tree.set_events(Gdk.EventMask.KEY_PRESS_MASK)
	# # associamo la callback all'evento
	# tree.connect("key-press-event", ctlEnter, tree)
#cellRender + viewColumn
	# aggiungo le colonne e le celle
	colu = []
	cell = []
	head = []
	for ind, ele in enumerate(name):
		# qui bisognerebbe istanziare la cella
		#  in base al tipo!
	# istanzio cella di testo
		cel = Gtk.CellRendererText()
		# se non esistono colori 
		if cCol:
			# imposto i colori
			cel.set_property('cell-background', cCol[ind])
		if font:
			# imposto il font
			cel.set_property('font', font[ind])
	# istanzio colonna
		col = Gtk.TreeViewColumn(ele)
		head.append(col)
		# image ?
		if imag[ind]:
			# imposto immagine
			pix = Gtk.CellRendererPixbuf()
			pix.set_property(imag[ind], Gtk.STOCK_OPEN)
			# inserisco campo
			col.pack_start(pix, False)
			col.set_attributes(pix)
		# campo testo
		col.pack_start(cel, 1)
		col.set_attributes(cel, text=ind)
		# crea un contorno (sembra non funzionare)
		col.set_spacing(10)
	# aggiungo la colonna alla tree
		tree.append_column(col)
	# reference
		# salvo il riferimento di colonna
		colu.append(col)
		# salvo il riferimento della cella
		cell.append(cel)
			
#myScrolled
	scro = myScrolled(obje=None, bord=bord, 
					  widt=widt, heig=heig, 
					  shad=shad, poli=poli)
	if 1:
		# titolo esterno allo scroll
		scro.add(tree)
	else:
		# titolo interno allo scroll
		scro.add_with_viewport(tree)
		
# <-
	#           0,    1,    2,    3    4    
	# tree, [stor, colu, cell, scro, head]
	return tree, [stor, colu, cell, scro, head]
Example #3
0
def myTreView(name=["->", "Id", "->", "Name"], 
				call=None, data=['dati'],
				bord=1, font='Courier bold 9', 
				cCol=['white','gray','white','gray'], 
				widt=200, heig=100,
				shad=Gtk.SHADOW_ETCHED_IN, 
				poli=(Gtk.POLICY_AUTOMATIC, Gtk.POLICY_AUTOMATIC)):
	#item=, call=on_activated_makView):
	""" crea una TreeView

		-> name lista campi
		-> call funzione da eseguire su evento
		-> data dati da passare alla funzione
		-> bord margine esterno dello scroolbar
		-> font font da usare per le celle
		-> cCol lista colore di fondo delle colonne (name * N)
		-> widt ampiezza
		-> heig altezza
		-> shad tipo di cornice
			Gtk.SHADOW_NONE, Gtk.SHADOW_IN, Gtk.SHADOW_OUT, 
			Gtk.SHADOW_ETCHED_IN, Gtk.SHADOW_ETCHED_OUT
		-> poli politiche di visibilita delle barre di scorrimento
			(horizontal,vertical)
			POLICY_AUTOMATIC whether you need
			POLICY_ALWAYS leave the scrollbars
	"""
	#callback debug    
	def row_activated(widg, path, colu, *data):
		pass
		# leggo record selezionato 
		#  dal doppio click o dal enter
		# rec = getRecord(widg,path)
		
#listStore  
	if 0:  
		# costruisco il comando per l'istanza
		#  stor = Gtk.ListStore(gobject.TYPE_STRING, other..)
		cmd = "stor = Gtk.ListStore("
		for ele in name:
			# aggiungo il tipo
			cmd += str(type(ele))[7:10]+','
		cmd += ")"
		# istanzio
		exec(cmd)
	else:
		mode = [GObject.TYPE_STRING,]* (len(name))
		stor = Gtk.ListStore(*mode)
#treeView
	tree = Gtk.TreeView(stor)
	tree.show()
#callback    
	# in assenza di callback usa quella di debug
	if call == None:
		call = row_activated
	# callback su doppio click o enter
	tree.connect('row-activated', call)
	# aggiungo evento tastiera per intercettare ctrl+Enter
	tree.set_events(Gdk.EventMask.KEY_PRESS_MASK)
	# # associamo la callback all'evento
	# tree.connect("key-press-event", ctlEnter, tree)
#cellRender + viewColumn
	# aggiungo le colonne e le celle
	colu = []
	cell = []
	for ind, ele in enumerate(name):
		# qui bisognerebbe istanziare la cella
		#  in base al tipo!
	# istanzio cella di testo
		cel = Gtk.CellRendererText()
		# se non esistono colori 
		if cCol:
			# imposto i colori
			cel.set_property('cell-background', cCol[ind])
		if font:
			# imposto il font
			cel.set_property('font', font)
	# istanzio colonna
		col = Gtk.TreeViewColumn(ele, cel, text=ind)
		# crea un contorno (sembra non funzionare)
		col.set_spacing(10)
	# aggiungo la colonna alla tree
		tree.append_column(col)
	# reference
		# salvo il riferimento di colonna
		colu.append(col)
		# salvo il riferimento della cella
		cell.append(cel)
			
#myScrolled
	if shad != None:
		scro = myScrolled(obje=None, bord=bord, 
						  widt=widt, heig=heig, 
						  shad=shad, poli=poli)
		if 1:
			# titolo esterno allo scroll
			scro.add(tree)
		else:
			# titolo interno allo scroll
			scro.add_with_viewport(tree)
	else:
		scro = None
		
# <-
	#           0,    1,    2,    3        
	# tree, [stor, colu, cell, scro]
	return tree, [stor, colu, cell, scro]
Example #4
0
def myTreField(name=("name", "value"),
               call=None,
               data=['dati'],
               bord=1,
               font=['Luxi Mono 9', 'Sans 8'],
               size=[140, 180],
               widt=300,
               heig=400,
               shad=Gtk.SHADOW_ETCHED_IN,
               poli=(Gtk.POLICY_AUTOMATIC, Gtk.POLICY_AUTOMATIC),
               nExp="Titolo"):
    """ crea una lista di campi da editare

		-> name lista campi
		-> call funzione da eseguire su evento
		-> data dati da passare alla funzione
		-> bord margine esterno dello scroolbar
		-> font font da usare per le celle
		-> cCol lista colore di fondo delle colonne
		-> iamg lista immagini
		-> widt ampiezza scrollbars
		-> heig altezza scrollbars
		-> shad tipo di cornice
			Gtk.SHADOW_NONE, Gtk.SHADOW_IN, Gtk.SHADOW_OUT, 
			Gtk.SHADOW_ETCHED_IN, Gtk.SHADOW_ETCHED_OUT
		-> poli politiche di visibilita delle barre di scorrimento
			(horizontal,vertical)
			POLICY_AUTOMATIC whether you need
			POLICY_ALWAYS leave the scrollbars
	"""

    # ridefinisco la callback
    def row_activated(tree, path, colu, *data):
        # leggo record selezionato
        #  dal doppio click o dal enter
        rec = getRecord(tree, path)
        # print rec, tree, path, colu

        # leggo il modello dei dati
        stor = tree.get_model()
        # leggo il riferimento della riga
        treeiter = stor.get_iter(path)
        if stor.iter_has_child(treeiter):
            # print "father"
            # collapse
            if tree.collapse_row(path):
                return
            # expand
            tree.expand_row(path, True)
        # else:
        # 	print "child"

#treeStore

    mode = [
        GObject.TYPE_STRING,
    ] * (len(name) * 2)
    stor = Gtk.TreeStore(*mode)
    #treeView
    tree = Gtk.TreeView(stor)
    tree.show()
    #callback
    # in assenza di callback usa quella di debug
    if call == None:
        call = row_activated
    # callback su doppio click o enter
    tree.connect('row-activated', call)
    # aggiungo evento tastiera per intercettare ctrl+Enter
    tree.set_events(Gdk.EventMask.KEY_PRESS_MASK)
    # # associamo la callback all'evento
    # tree.connect("key-press-event", ctlEnter, tree)
    # active grid line
    tree.set_grid_lines(True)
    # hide column
    tree.set_headers_visible(False)

    #cellRender + viewColumn
    # aggiungo le colonne e le celle
    colu = []
    cell = []
    head = []
    #First column's cell
    cel = Gtk.CellRendererText()
    cell.append(cel)
    cel.set_property('font', font[0])
    cel.set_property('background-set', True)
    # column 1
    col = Gtk.TreeViewColumn()
    colu.append(col)
    col.pack_start(cel, True)
    col.set_fixed_width(size[0])
    col.set_attributes(cel, text=0, background=2)
    tree.append_column(col)

    #Second column's cell
    cel = Gtk.CellRendererText()
    cell.append(cel)
    cel.set_property('font', font[1])
    cel.set_property('background-set', True)
    cel.set_property('editable', True)
    # column 2
    col = Gtk.TreeViewColumn()
    colu.append(col)
    col.pack_start(cel, True)
    col.set_fixed_width(size[1])
    col.set_attributes(cel, text=1, background=3)
    tree.append_column(col)

    #myScrolled
    scro = myScrolled(obje=None,
                      bord=bord,
                      widt=widt,
                      heig=heig,
                      shad=shad,
                      poli=poli)
    if 1:
        # titolo esterno allo scroll
        scro.add(tree)
    else:
        # titolo interno allo scroll
        scro.add_with_viewport(tree)

# myFather
# tree, scro=None, pare=None, colo=None, reco=[]
    pare = addField(tree=tree, colo=['#e0e0e0', '#e0e0e0'], reco=[nExp, ""])

    # <-
    # tree, [stor, colu, cell, scro, pare]
    return tree, [stor, colu, cell, scro, pare]
Example #5
0
def myTreStore(name=["->", "Id", "->", "Name"],
               call=None,
               data=['dati'],
               bord=1,
               font=['Courier bold 9'] * 4,
               cCol=['white', 'gray', 'white', 'gray'],
               imag=[
                   None,
               ] * 4,
               widt=200,
               heig=100,
               shad=Gtk.SHADOW_ETCHED_IN,
               poli=(Gtk.POLICY_AUTOMATIC, Gtk.POLICY_AUTOMATIC)):
    #item=, call=on_activated_makView):
    """ crea una TreeView

		-> name lista campi
		-> call funzione da eseguire su evento
		-> data dati da passare alla funzione
		-> bord margine esterno dello scroolbar
		-> font font da usare per le celle
		-> cCol lista colore di fondo delle colonne
		-> iamg lista immagini
		-> widt ampiezza
		-> heig altezza
		-> shad tipo di cornice
			Gtk.SHADOW_NONE, Gtk.SHADOW_IN, Gtk.SHADOW_OUT, 
			Gtk.SHADOW_ETCHED_IN, Gtk.SHADOW_ETCHED_OUT
		-> poli politiche di visibilita delle barre di scorrimento
			(horizontal,vertical)
			POLICY_AUTOMATIC whether you need
			POLICY_ALWAYS leave the scrollbars
	"""

    # ridefinisco la callback
    def row_activated(tree, path, colu, *data):
        # print widg, path, colu

        # leggo record selezionato
        #  dal doppio click o dal enter
        # rec = getRecord(widg, path)
        # print rec

        # leggo record selezionato
        #  dal doppio click o dal enter
        rec = getRecord(tree, path)
        # print rec, tree, path, colu

        # leggo il modello dei dati
        stor = tree.get_model()
        # leggo il riferimento della riga
        treeiter = stor.get_iter(path)
        if stor.iter_has_child(treeiter):
            # print "father"
            # collapse
            if tree.collapse_row(path):
                return
            # expand
            tree.expand_row(path, True)
        # else:
        # 	print "child"

#treeStore

    mode = [
        GObject.TYPE_STRING,
    ] * (len(name))
    stor = Gtk.TreeStore(*mode)
    #treeView
    tree = Gtk.TreeView(stor)
    tree.show()
    #callback
    # in assenza di callback usa quella di debug
    if call == None:
        call = row_activated
    # callback su doppio click o enter
    tree.connect('row-activated', call)
    # aggiungo evento tastiera per intercettare ctrl+Enter
    tree.set_events(Gdk.EventMask.KEY_PRESS_MASK)
    # # associamo la callback all'evento
    # tree.connect("key-press-event", ctlEnter, tree)
    #cellRender + viewColumn
    # aggiungo le colonne e le celle
    colu = []
    cell = []
    head = []
    for ind, ele in enumerate(name):
        # qui bisognerebbe istanziare la cella
        #  in base al tipo!
        # istanzio cella di testo
        cel = Gtk.CellRendererText()
        # se non esistono colori
        if cCol:
            # imposto i colori
            cel.set_property('cell-background', cCol[ind])
        if font:
            # imposto il font
            cel.set_property('font', font[ind])
    # istanzio colonna
        col = Gtk.TreeViewColumn(ele)
        head.append(col)
        # image ?
        if imag[ind]:
            # imposto immagine
            pix = Gtk.CellRendererPixbuf()
            pix.set_property(imag[ind], Gtk.STOCK_OPEN)
            # inserisco campo
            col.pack_start(pix, False)
            col.set_attributes(pix)
        # campo testo
        col.pack_start(cel, 1)
        col.set_attributes(cel, text=ind)
        # crea un contorno (sembra non funzionare)
        col.set_spacing(10)
        # aggiungo la colonna alla tree
        tree.append_column(col)
        # reference
        # salvo il riferimento di colonna
        colu.append(col)
        # salvo il riferimento della cella
        cell.append(cel)

#myScrolled
    scro = myScrolled(obje=None,
                      bord=bord,
                      widt=widt,
                      heig=heig,
                      shad=shad,
                      poli=poli)
    if 1:
        # titolo esterno allo scroll
        scro.add(tree)
    else:
        # titolo interno allo scroll
        scro.add_with_viewport(tree)

# <-
#           0,    1,    2,    3    4
# tree, [stor, colu, cell, scro, head]
    return tree, [stor, colu, cell, scro, head]
Example #6
0
def myTreView(name=["->", "Id", "->", "Name"],
              call=None,
              data=['dati'],
              bord=1,
              font='Courier bold 9',
              cCol=['white', 'gray', 'white', 'gray'],
              widt=200,
              heig=100,
              shad=Gtk.SHADOW_ETCHED_IN,
              poli=(Gtk.POLICY_AUTOMATIC, Gtk.POLICY_AUTOMATIC)):
    #item=, call=on_activated_makView):
    """ crea una TreeView

		-> name lista campi
		-> call funzione da eseguire su evento
		-> data dati da passare alla funzione
		-> bord margine esterno dello scroolbar
		-> font font da usare per le celle
		-> cCol lista colore di fondo delle colonne (name * N)
		-> widt ampiezza
		-> heig altezza
		-> shad tipo di cornice
			Gtk.SHADOW_NONE, Gtk.SHADOW_IN, Gtk.SHADOW_OUT, 
			Gtk.SHADOW_ETCHED_IN, Gtk.SHADOW_ETCHED_OUT
		-> poli politiche di visibilita delle barre di scorrimento
			(horizontal,vertical)
			POLICY_AUTOMATIC whether you need
			POLICY_ALWAYS leave the scrollbars
	"""

    #callback debug
    def row_activated(widg, path, colu, *data):
        pass
        # leggo record selezionato
        #  dal doppio click o dal enter
        # rec = getRecord(widg,path)

#listStore

    if 0:
        # costruisco il comando per l'istanza
        #  stor = Gtk.ListStore(gobject.TYPE_STRING, other..)
        cmd = "stor = Gtk.ListStore("
        for ele in name:
            # aggiungo il tipo
            cmd += str(type(ele))[7:10] + ','
        cmd += ")"
        # istanzio
        exec(cmd)
    else:
        mode = [
            GObject.TYPE_STRING,
        ] * (len(name))
        stor = Gtk.ListStore(*mode)
#treeView
    tree = Gtk.TreeView(stor)
    tree.show()
    #callback
    # in assenza di callback usa quella di debug
    if call == None:
        call = row_activated
    # callback su doppio click o enter
    tree.connect('row-activated', call)
    # aggiungo evento tastiera per intercettare ctrl+Enter
    tree.set_events(Gdk.EventMask.KEY_PRESS_MASK)
    # # associamo la callback all'evento
    # tree.connect("key-press-event", ctlEnter, tree)
    #cellRender + viewColumn
    # aggiungo le colonne e le celle
    colu = []
    cell = []
    for ind, ele in enumerate(name):
        # qui bisognerebbe istanziare la cella
        #  in base al tipo!
        # istanzio cella di testo
        cel = Gtk.CellRendererText()
        # se non esistono colori
        if cCol:
            # imposto i colori
            cel.set_property('cell-background', cCol[ind])
        if font:
            # imposto il font
            cel.set_property('font', font)
    # istanzio colonna
        col = Gtk.TreeViewColumn(ele, cel, text=ind)
        # crea un contorno (sembra non funzionare)
        col.set_spacing(10)
        # aggiungo la colonna alla tree
        tree.append_column(col)
        # reference
        # salvo il riferimento di colonna
        colu.append(col)
        # salvo il riferimento della cella
        cell.append(cel)

#myScrolled
    if shad != None:
        scro = myScrolled(obje=None,
                          bord=bord,
                          widt=widt,
                          heig=heig,
                          shad=shad,
                          poli=poli)
        if 1:
            # titolo esterno allo scroll
            scro.add(tree)
        else:
            # titolo interno allo scroll
            scro.add_with_viewport(tree)
    else:
        scro = None

# <-
#           0,    1,    2,    3
# tree, [stor, colu, cell, scro]
    return tree, [stor, colu, cell, scro]