Re: close an abiwidget

From: Daniel Carvalho <idnael_at_gmail.com>
Date: Mon Jan 05 2009 - 16:17:47 CET

hi!
I also tried with the destroy method.

The three examples included in pyabiword-0.6.1/examples only have one
canvas. The olpc example that Tomeu mentioned here in this list also
only uses one canvas in the program. Is there more example
applications available that use pyabiword?

The following is a small demonstration of an application with multiple
abiwidgets. The open button creates a new temporary txt file and opens
it. The close button closes the current pane.

If you do open, close, and open again, the application will crash. If
you comment the destroy() line it will not crash at this point but
will, later, if you open and close more files.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pygtk
pygtk.require('2.0')
import gtk

import abiword

import os.path
import tempfile
import shutil

import tempfile

class Tabes(gtk.Notebook):

    def __init__(self):

        gtk.Notebook.__init__(self)
        self.popup_enable()

        self.set_scrollable(True)
        self.set_show_border(False)

    def __map_editor_cb(self,widget,event,editor):
        pass
        #editor.invoke_cmd("com.abisource.abiword.loadbindings.fromURI","keybindings.xml",0,0)

    n=0
    def teste_open_cb(self,widget, data=None):

        path=tempfile.mkstemp(".txt","_teste"+str(self.n))[1]
        f=open(path,"w")
        f.write("ola "+str(self.n)+"\n"+path)
        f.close()

        print "Open "+path

        nome=os.path.basename(path)

        editor=abiword.Canvas()
        # nota: path tem que ser absoluto...
        editor.load_file("file:"+path,path)

        editor.set_show_margin(False) # sem efeito...

        editor.connect_after("map-event",self.__map_editor_cb,editor)

        editor.show()

        lab=gtk.Label(nome)

        index=self.append_page(editor,lab)
        self.set_current_page(index)

        self.n = (self.n+1 ) % 30

    def teste_close_cb(self,widget, data=None):
        if self.get_n_pages()==0:
            return

        print "Close..."
        pnum=self.get_current_page()
        editor=self.get_nth_page(pnum)

        self.remove_page(pnum)
        #editor.destroy()

if __name__ == "__main__":

    window=gtk.Window(gtk.WINDOW_TOPLEVEL)
    window.set_default_size(640, 480)

    box=gtk.VBox(False,5)
    box.show()
    window.add(box)

    tabes=Tabes()
    box.add(tabes)
    tabes.show()

    # buttons:

    b=gtk.Button("open")
    b.show()
    b.connect("clicked",tabes.teste_open_cb, None)
    box.pack_end(b,False,False)

    b=gtk.Button("close")
    b.show()
    b.connect("clicked",tabes.teste_close_cb, None)
    box.pack_end(b,False,False)

    window.show()

    gtk.main()
Received on Mon Jan 5 16:17:54 2009

This archive was generated by hypermail 2.1.8 : Mon Jan 05 2009 - 16:17:55 CET