GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Oct 31, 2014 8:44 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: 【pygtk】treeview cannot display
PostPosted: Thu Jan 12, 2012 1:38 am 
Offline
Familiar Face

Joined: Sun Nov 09, 2008 7:29 am
Posts: 6
Hi,
My treeview cannot display, didn't know what to do with design and type of inheritance relationship, the code is as follows:
GUi class:
Code:
import gtk
import pygtk
class Ui(object):
    def __init__(self,glade_file = None):
        self.init(glade_file)

    #--init
    def init(self,glade_file):
        gtk.rc_parse_string('''style "default-font"\n{\nfont_name = "simsun 9"\n}\nwidget_class "*" style "default-font"\ngtk-font-name = "simsun 9"''')
        self.builder = gtk.Builder()
        self.ui_file = glade_file or 'itemSearcher.glade'
        try:
            self.gui = self.builder.add_from_file(self.ui_file)
        except Exception,e:
            print "Error:%s"%e

    def _get_widget(self,widget_name):
        return self.builder.get_object(widget_name)

pageUI class:
Code:
from Gui import Ui
import gtk
class pageUi(Ui):
    def __init__(self,entry_name,button_name,other):
        #self.base_class = gui.Gui()
        super(pageUi,self).__init__()
        if not (entry_name and button_name and other):
            raise TypeError,"miss argument or argument is None"
        self.entry = self._get_widget(entry_name)
        self.button = self._get_widget(button_name)
        self.other_widget = self._get_widget(other)
        self.other_widget.show_all()

    def build_model(self,titles):
        if not isinstance(titles,list):
            raise "[titles] must be a list"
        size = len(titles)
        opt = [str for i in range(size)]
        self.list_store = gtk.ListStore(*opt)
        self._set_model(self.list_store)
        self.make_header(titles)
        return True

    def _set_model(self,list_store):
        self.other_widget.set_model(list_store)
        return True

    def make_header(self,titles,tv = None):
        widget = tv or self.other_widget
        cols = widget.get_columns()
        print "tv is %s,widget is %s"%(tv,widget)
##        if not cols == None:
##            for col in cols:
##                widget.remove_column(col)
        index = 0
        for head in titles:  #####
            column = gtk.TreeViewColumn(head, gtk.CellRendererText(), text=index)
            column.set_sort_column_id(index)
            widget.append_column(column)
            index+=1
        return False

class itemPage(pageUi):
    def __init__(self,widget_names = None):
        widget_names = widget_names or ['cb_entry','bt_search','treeview']
        #--call parent init
        super(itemPage,self).__init__(*widget_names)
        #--auto entry
        self.entry_completion = gtk.EntryCompletion()
        self.LS_entry = self._get_widget('LS_entry')
        self.entry_completion.set_model(self.LS_entry)
        self.entry_completion.set_text_column(0)
        self.entry_completion.set_inline_completion(1)
        #--combox
        self.combox = self._get_widget('cb_item_type')
        cell = gtk.CellRendererText()
        self.combox.pack_start(cell, True)
        self.combox.add_attribute(cell, 'text', 0)
        #--history
        self._build_history()
        #--redefine entry
        self.entry = self.entry.child

    def _build_history(self):
        self._get_widget('hpaned').set_position(470)
        self.TV_history = self._get_widget('TV_history')
        self.LS_history = gtk.ListStore(str,str)
        self.TV_history.set_model(self.LS_history)
        self.make_header([u'name','ID'],self.TV_history )
        print "TV:history:",self.TV_history

class duanzaoPage(pageUi):
    def __init__(self,widget_names = None):
        widget_names = widget_names or ['en_duanzao','btn_duanzao_gen','TA_duanzao']
        super(duanzaoPage,self).__init__(*widget_names)
        self.btn_copy = self._get_widget('btn_duanzao_copy')
        self.TB_duanzao = self._get_widget('TB_duanzao')


mainWin.py:
Code:
#!/usr/bin/env python
from Gui import Ui
import gtk
import pageUi
class mainWin(Ui):
    def __init__(self):
        super(mainWin,self).__init__()
        self.win = self._get_widget('window')
        #--init item page
        self.item_page = pageUi.itemPage(['cb_entry','bt_search','treeview'])
        self.item_page.build_model([u'序号',u'物品ID',u'物品类型',u'物品名称',u'状态',])
        #--init drop page
        self.drop_page = pageUi.pageUi(*['cb_sentry','btn_drop_search','TV_drop'])
        self.drop_page.build_model([u'序号',u'物品ID',u'物品类型',u'物品名称',u'状态',])
        self.monster_page = pageUi.pageUi(*['en_monster','btn_monster_search','TV_monster'])
        self.monster_page.build_model([u'类型ID',u'名称',u'等级',u'模型ID',u'掉落ID'])
        self.duanzao_page = pageUi.duanzaoPage(['en_duanzao','btn_duanzao_gen','TA_duanzao'])
        #--show_all
        for page in (self.item_page,self.drop_page,self.monster_page,self.duanzao_page):pass
            #print page.other_widget.get_model()
            #self.win.add(self._get_widget('scrolledwindow'+str(i)))
        #menuItem
        self.MI_copy = self._get_widget('MI_copy')
        self.MI_gwsj = self._get_widget('MI_gwsj')
        self.MI_sjsj = self._get_widget('MI_sjsj')
        self.MI_gwsj.set_active(True)
        self.MI_rebuild_item_table = self._get_widget('MI_rebuild_item_table')
        self.MI_rebuild_drop_table = self._get_widget('MI_rebuild_drop_table')
        self.MI_rebuild_monster_table = self._get_widget('MI_rebuild_monster_table')
        self.MI_rebuild_duanzao_table = self._get_widget('MI_rebuild_duanzao_table')
        self.MI_testing= self._get_widget('MI_testing')
        self.MI_cehua = self._get_widget('MI_cehua')
        self.MI_testing.set_active(True)

        #----------------------------
        self.popup_menu= self._get_widget('popup_menu')
        self.PM_track = self._get_widget('PM_track')
        self.MI_track = self._get_widget('MI_track')
    def start(self):
        #self.win = self._get_widget('window')
        self.win.show_all()
        gtk.main()


please help me~Thanks


Top
 Profile  
 
 Post subject: Re: 【pygtk】treeview cannot display
PostPosted: Sun Jan 15, 2012 2:29 pm 
Offline
Familiar Face

Joined: Sun Nov 09, 2008 7:29 am
Posts: 6
anyone?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group