ich habe mir eine kleine Anwendung gestrickt, im wesentlichen geht es darum das es eine Tabelle ist und in der ersten Spalte sind Bilder und in der zweiten ein text dazu, so eine art twitter client.
Da ich jetzt allerdings von Linux auf osx umgestiegen bin, ist pygtk nicht mehr die 1. Wahl sondern eher wxpython. Hier habe ich allerdings riesen probleme ein bild in eine listctrl einzufügen.
hier einfach mal mein bisheriger Versuch:
Code: Alles auswählen
# -*- coding: latin1 -*-
import wx, os, sys
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,title="test")
##Creating the list image.
print "we are creating the image list"
li=wx.ImageList(120,120,True)
##Creating the bitmap
print "Creating the bitmap"
bitmap=wx.Bitmap("test.jpg")
##populating image list
print "populating image list"
li.Add(bitmap)
lo=li.GetImageCount()
print "Lenght of image list:", lo
##Size of l'image
ta=li.GetSize(0)
print "Size of image is:", ta
##Creating list control
print "creating list control"
self.list=wx.ListCtrl(self,-1,style=wx.LC_REPORT)
self.list.InsertColumn(0, 'Bild')
index=self.list.InsertStringItem(0, 'test')
self.list.SetStringItem(0, 0, 'test')
##Assign list image
print "Assign list image"
self.list.AssignImageList(li,wx.IMAGE_LIST_NORMAL)
#img_list=self.lc.SetImageList(il, wx.IMAGE_LIST_SMALL)
self.list.SetItemImage(index,0)
##Populating list control
print "Populating list control"
self.list.InsertStringItem(0,"premier")
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()
hier mein alter pygtk code:
Code: Alles auswählen
(
COLUMN_BILD,
COLUMN_TEXT,
) = range(2)
class buschfunkwindow(gtk.Window):
def __init__(self, parent=None):
# create window, etc
gtk.Window.__init__(self)
try:
self.set_screen(parent.get_screen())
except AttributeError:
self.connect('destroy', lambda *w: gtk.main_quit())
self.set_title(self.__class__.__name__)
self.set_border_width(8)
self.set_default_size(300, 250)
#self.set_resizable(False)
vbox = gtk.VBox(False, 8)
self.add(vbox)
label = gtk.Label('These are the Buschfunk entries')
vbox.pack_start(label, False, False)
sw = gtk.ScrolledWindow()
sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
vbox.pack_start(sw)
# create tree view
liststore = gtk.ListStore(gtk.gdk.Pixbuf, str)
treeview = gtk.TreeView(liststore)
# Just text rendering for the columns
textrenderer = gtk.CellRendererText() #.set_wrap_mode(gtk.WRAP_WORD)
img_cell = gtk.CellRendererPixbuf()
img_column = gtk.TreeViewColumn('Bild', img_cell)
img_column.set_sort_column_id(COLUMN_TEXT)
img_column.add_attribute(img_cell, "pixbuf",0)
treeview.append_column(img_column)
column = gtk.TreeViewColumn('Text', textrenderer, text=COLUMN_TEXT)
column.set_sort_column_id(COLUMN_TEXT)
# column.set_wrap_mode(gtk.WRAP_WORD)
treeview.append_column(column)
# Add the items to the liststore
buschfunk = SvzBrowser('xxx', 'xxx').getStatusUpdates()
i = 0
while i < len(buschfunk):
picture_page = buschfunk[i]['foto']
image = ".studicache/" + picture_page[-24:]
if not os.path.exists(image):
opener1 = urllib2.build_opener()
page1 = opener1.open(picture_page)
my_picture = page1.read()
fout = open(image, "wb")
fout.write(my_picture)
fout.close()
image=gtk.gdk.pixbuf_new_from_file(image)
liststore.append([image, buschfunk[i]['name'] + " schreibt:\n" + buschfunk[i]['text']])# + buschfunk[i]['time']])
i = i + 1
sw.add(treeview)
#self.update()
self.show_all()
def main():
buschfunkwindow()
gtk.main()
if __name__ == '__main__':
main()