Source

asterator / Asterator / info.py


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

def mylbl(txt):
    lbl = gtk.Label(txt)
    lbl.set_alignment(0, 0)
    lbl.set_selectable(True)
    lbl.show()
    return lbl

class channel_info(gtk.Window):
    def __init__(self, chan):
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)

        self.chan = chan

        wvbox = gtk.VBox(homogeneous=False, spacing=0)
        self.add(wvbox)
        wvbox.show()
        
        self.set_title(chan.name)
        self.set_default_size(500, 250)
        self.set_position(gtk.WIN_POS_MOUSE)
        
        notebook = gtk.Notebook()
        notebook.set_tab_pos(gtk.POS_TOP)
        wvbox.pack_start(notebook)
        notebook.show()

        vbox = gtk.VBox(homogeneous=False, spacing=0)
        vbox.show()
        
        hbox = gtk.HBox(homogeneous=False, spacing=5)
        hbox.set_border_width(10)
        hbox.show()
        self.lbl_chan = gtk.Label()
        self.lbl_chan.set_markup('<span size="xx-large">' + self.chan.name + '</span>')
        hbox.pack_start(self.lbl_chan, False)
        self.lbl_chan.show()
        self.lbl_state = gtk.Label()
        self.lbl_state.set_markup('<span size="xx-large">' + self.chan.state + '</span>')
        hbox.pack_end(self.lbl_state, False)
        self.lbl_state.show()
        vbox.pack_start(hbox, False)

        sep = gtk.HSeparator()
        vbox.pack_start(sep, False)

        tbl = gtk.Table(7, 4, True)
        tbl.set_border_width(10)
        tbl.set_row_spacings(4)
        tbl.set_col_spacings(4)
        vbox.pack_start(tbl, True, True)
        tbl.show()

        tbl.attach(mylbl('Unique ID:'), 0, 1, 0, 1, gtk.FILL, gtk.FILL)
        tbl.attach(mylbl('Caller ID:'), 0, 1, 1, 2, gtk.FILL, gtk.FILL)
        tbl.attach(mylbl('DNID Digits:'), 0, 1, 2, 3, gtk.FILL, gtk.FILL)
        tbl.attach(mylbl('Rings:'), 0, 1, 3, 4, gtk.FILL, gtk.FILL)
        tbl.attach(mylbl('Native Format:'), 0, 1, 4, 5, gtk.FILL, gtk.FILL)
        tbl.attach(mylbl('Write Format:'), 0, 1, 5, 6, gtk.FILL, gtk.FILL)
        tbl.attach(mylbl('Read Format:'), 0, 1, 6, 7, gtk.FILL, gtk.FILL)
        tbl.attach(mylbl('Elapsed Time:'), 2, 3, 0, 1, gtk.FILL, gtk.FILL)
        tbl.attach(mylbl('Frames In:'), 2, 3, 1, 2, gtk.FILL, gtk.FILL)
        tbl.attach(mylbl('Frames Out:'), 2, 3, 2, 3, gtk.FILL, gtk.FILL)
        tbl.attach(mylbl('1st File Desc:'), 2, 3, 3, 4, gtk.FILL, gtk.FILL)
        tbl.attach(mylbl('Time to Hangup:'), 2, 3, 4, 5, gtk.FILL, gtk.FILL)
        tbl.attach(mylbl('Direct Bridge:'), 2, 3, 5, 6, gtk.FILL, gtk.FILL)
        tbl.attach(mylbl('Indirect Bridge:'), 2, 3, 6, 7, gtk.FILL, gtk.FILL)

        self.lbl_uniqueid = mylbl('Unknown')
        tbl.attach(self.lbl_uniqueid, 1, 2, 0, 1, gtk.FILL, gtk.FILL)
        self.lbl_callerid = mylbl('Unknown')
        tbl.attach(self.lbl_callerid, 1, 2, 1, 2, gtk.FILL, gtk.FILL)
        self.lbl_dniddigits = mylbl('Unknown')
        tbl.attach(self.lbl_dniddigits, 1, 2, 2, 3, gtk.FILL, gtk.FILL)
        self.lbl_rings = mylbl('Unknown')
        tbl.attach(self.lbl_rings, 1, 2, 3, 4, gtk.FILL, gtk.FILL)
        self.lbl_nativeformat = mylbl('Unknown')
        tbl.attach(self.lbl_nativeformat, 1, 2, 4, 5, gtk.FILL, gtk.FILL)
        self.lbl_writeformat = mylbl('Unknown')
        tbl.attach(self.lbl_writeformat, 1, 2, 5, 6, gtk.FILL, gtk.FILL)
        self.lbl_readformat = mylbl('Unknown')
        tbl.attach(self.lbl_readformat, 1, 2, 6, 7, gtk.FILL, gtk.FILL)
        self.lbl_elapsedtime = mylbl('Unknown')
        tbl.attach(self.lbl_elapsedtime, 3, 4, 0, 1, gtk.FILL, gtk.FILL)
        self.lbl_framesin = mylbl('Unknown')
        tbl.attach(self.lbl_framesin, 3, 4, 1, 2, gtk.FILL, gtk.FILL)
        self.lbl_framesout = mylbl('Unknown')
        tbl.attach(self.lbl_framesout, 3, 4, 2, 3, gtk.FILL, gtk.FILL)
        self.lbl_firstfd = mylbl('Unknown')
        tbl.attach(self.lbl_firstfd, 3, 4, 3, 4, gtk.FILL, gtk.FILL)
        self.lbl_timetohangup = mylbl('Unknown')
        tbl.attach(self.lbl_timetohangup, 3, 4, 4, 5, gtk.FILL, gtk.FILL)
        self.lbl_directbridge = mylbl('Unknown')
        tbl.attach(self.lbl_directbridge, 3, 4, 5, 6, gtk.FILL, gtk.FILL)
        self.lbl_indirectbridge = mylbl('Unknown')
        tbl.attach(self.lbl_indirectbridge, 3, 4, 6, 7, gtk.FILL, gtk.FILL)

        notebook.append_page(vbox, gtk.Label('Info'))

        bbox = gtk.HButtonBox()
        bbox.set_border_width(5)
        bbox.set_layout(gtk.BUTTONBOX_END)
        bbox.set_spacing(10)
        btn = gtk.Button(stock='gtk-refresh')
        btn.connect('clicked', self.action_refresh)
        bbox.pack_start(btn)
        btn.show()
        btn = gtk.Button(stock='gtk-close')
        btn.connect('clicked', self.action_close)
        bbox.pack_start(btn)
        btn.show()
        wvbox.pack_start(bbox, False)
        bbox.show()

        self.action_refresh()

    def on_info(self, info):
        gtk.threads_enter()

        if info == None:
            dlg = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT,
                                    gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
                                    "Error: " + frame['Message'])
            dlg.run()
            dlg.hide()
            gtk.threads_leave()
            return

        self.lbl_uniqueid.set_text(info['info']['UniqueID'])
        self.lbl_callerid.set_text(info['info']['Caller ID Name'] + ' <' + info['info']['Caller ID'] + '>')
        self.lbl_dniddigits.set_text(info['info']['DNID Digits'])
        self.lbl_rings.set_text(info['info']['Rings'])
        self.lbl_nativeformat.set_text(info['info']['NativeFormat'])
        self.lbl_writeformat.set_text(info['info']['WriteFormat'])
        self.lbl_readformat.set_text(info['info']['ReadFormat'])
        self.lbl_elapsedtime.set_text(info['info']['Elapsed Time'])
        self.lbl_framesin.set_text(info['info']['Frames in'])
        self.lbl_framesout.set_text(info['info']['Frames out'])
        self.lbl_firstfd.set_text(info['info']['1st File Descriptor'])
        self.lbl_timetohangup.set_text(info['info']['Time to Hangup'])
        self.lbl_directbridge.set_text(info['info']['Direct Bridge'])
        self.lbl_indirectbridge.set_text(info['info']['Indirect Bridge'])
        
        gtk.threads_leave()

    def action_refresh(self, widget=None, data=None):
        self.chan.getinfo(self.on_info)

    def action_close(self, widget=None, data=None):
        self.destroy()