All pastes #738577 Raw Edit

Someone

public text v1 · immutable
·published 2007-10-16 13:52 UTC
rendered paste body
#/usr/bin/env python
"""This module consists GUI related stuff, the whole GUI widget creation and destruction is done here"""


import pygtk
pygtk.require("2.0")
import gtk
from os import path
from backend.serailTest import get_file_name

def create_textbox():
    # Creata a text entry for the gtk window to enter the device information
    textbox = gtk.Entry()
    return textbox
    
def create_label():
    # Create a Label before the text entry
    label = gtk.Label()
    label.set_text("Device Information:   ")
    return label

def create_menu_items():
    """Method for creating Menu Items, and returns the menu bar items"""     
                   
    #create a File Menu
    file_menu = gtk.Menu()
    
    #create sub items under the file item
    run_tests_item = gtk.MenuItem("Run Tests")
    quit_item = gtk.MenuItem("Quit")
    
    #now create another menu called as Help
    help_menu = gtk.Menu()

    #create the about named menu item
    about_item = gtk.MenuItem("About")
    
    #add menu items to the Menu
    file_menu.append(run_tests_item)
    file_menu.append(quit_item)
    help_menu.append(about_item)
    
    #Attach the callback signal to the activate Item
    run_tests_item.connect("activate", menuitem_response, "Run Tests")
    quit_item.connect("activate", destroy, "Quit")
    about_item.connect("activate", menuitem_response, "About")

    #now we associate menu with file item
    file_item = gtk.MenuItem("File")
            
    #Now associate file menu items with file item, as their submenu's
    file_item.set_submenu(file_menu)
    help_item = gtk.MenuItem("Help")
            
    #now associate the same for help also
    help_item.set_submenu(help_menu)
    menu_bar = gtk.MenuBar()
    
    #now append the menu items to Menu bar
    menu_bar.append(file_item)
    menu_bar.append(help_item)
    
    return menu_bar

def create_treeview():
    """Method for creating a treeview, and return treeview with the columns"""
    
    # Now call the global treeview widget and set the model for it
    treestore = gtk.TreeStore(str)
         
    treeview = gtk.TreeView(treestore)   
    # create the TreeViewColumn to display the data
    tvcolumn = gtk.TreeViewColumn('Command')
    tvcolumn1 = gtk.TreeViewColumn('Output')
    
    #Now append the data to the model
    gsm_standards = ["07.07", "07.05"]
    for standard in gsm_standards:
        standard_expand = treestore.append(None, ["GSM %s" %standard])
            
    
    # create a CellRendererText to render the data
    cell = gtk.CellRendererText()

    # add the cell to the tvcolumn and allow it to expand
    tvcolumn.pack_start(cell, True)

    # Now add the tvcolumn to TreeView
    tvcolumn.add_attribute(cell, 'text', 0)

    # add tvcolumn to treeview
    treeview.append_column(tvcolumn)
    treeview.append_column(tvcolumn1)
    
    return treeview
    
def destroy(widget, event, data = None):
    """Returns only true when this method is called and this method will exit the application"""
    gtk.main_quit()
    print "Caught destroy signal, Exiting..."
    return True
    
def menuitem_response(widget, string):
    """Method prints the information of the object name on the console 
    when ever an event is generated on selecting or pressing"""
    print "%s" %string
    
class attestsuite:
    """The Class ATTestSuite creates the gui widgets and diplay information"""
       
    def __init__(self):
        """This Method initiates and creates the Vertical Box, and adds the items on top of it by calling individual methods"""
       
        # Create a new window
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        # Set a handler for the close event, that immediately closes the GTK window
        window.connect("delete_event", destroy)
        window.set_title("AT TEST SUITE")
        window.set_size_request(400, 400)
        
        #Create textbox
        self.textbox = create_textbox()        
             
        #Create a HBOX and pack the elements
        hbox = gtk.HBox(False, 0)
        
        # Call label method which creates the Label an example:
        label = create_label()
                       
        #Now pack the items into the Horizontal box
        hbox.pack_start(label, False, False, 0)
        hbox.pack_start(self.textbox, False, False, 0)
              
        #create a vetical box
        vbox = gtk.VBox(False, 0)
           
        # Call the MenuBar method and then add that to the vbox
        menu_bar = create_menu_items() 
        
        #create buttons Ok, and Cancel
        button_ok = gtk.Button("Ok")
        button_ok.connect("clicked", self.ok_button_pressed, self.textbox)
        button_cancel = gtk.Button("Cacel")
        button_cancel.connect("clicked", self.cancel_button_pressed, self.textbox)

        
        #Create Hbox2 to pack the buttons
        hbox2 = gtk.HBox(False, 0)
        hbox2.pack_start(button_ok, False, False, 0)
        hbox2.pack_start(button_cancel, False, False, 0)
                            
        #call the create_treeview method, which creates the treeview and returns the treeview
        treeview = create_treeview()
        
        vbox.pack_start(menu_bar, False, False, 0)
        vbox.pack_start(hbox, False, False, 0)
        vbox.pack_start(hbox2, False, False, 0)  
        vbox.pack_start(treeview, False, False, 0)         
        window.add(vbox)
        window.show_all()
           
    def main(self):
        """Main method"""
        gtk.main()
    
    def cancel_button_pressed(self, textbox, event):
        self.textbox.set_text("")
    
    def ok_button_pressed(self, textbox, event):
        text = self.textbox.get_text()
        if path.exists(text):
            global gsm_0707_data
            gsm_0707_data = get_file_name(text)
        else:
            print "No such file or directory"
     
             
if __name__=="__main__":
    gsm_0707_data = {}
    widget = attestsuite()
    widget.main()