Пример #1
0
    def __create_widgets(self):

        #box
        self.all_box = HIGVBox()
        self.input_box = HIGHBox()
        self.buttom_box = HIGHBox()
        self.check_btn_box = gtk.HButtonBox()

        #Add input
        self.title_text = HIGLabel(_("Locations"))
        self.longitude_text = HIGLabel(_("longitude:"))
        self.longitude_entry = HIGTextEntry()
        self.latitude_text = HIGLabel(_("latitude:"))
        self.latitude_entry = HIGTextEntry()

        #Add buttons
        self.get_event_btn = gtk.Button(_("Get Events"))
        self.refresh_btn = gtk.Button(_("Refresh"))

        #status bar
        self.statusbar = gtk.Statusbar()
        self.statusbar.push(0, 'Events in Database')

        self.listmodel = gtk.ListStore(str, str, str, str, str)

        # create the TreeView
        self.treeview = gtk.TreeView()

        # create the TreeViewColumns to display the data
        self.tvcolumn = [None] * len(self.column_names)
        cellpb = gtk.CellRendererText()

        self.tvcolumn[0] = gtk.TreeViewColumn(self.column_names[0], cellpb)
        self.tvcolumn[0].add_attribute(cellpb, 'text', 0)
        #cell = gtk.CellRendererText()
        #self.tvcolumn[0].set_cell_data_func(cell, self.test_type)
        self.treeview.append_column(self.tvcolumn[0])

        for n in range(1, len(self.column_names)):
            cell = gtk.CellRendererText()
            self.tvcolumn[n] = gtk.TreeViewColumn(self.column_names[n], cell)
            self.tvcolumn[n].add_attribute(cell, 'text', n)
            if n == 1:
                cell.set_property('xalign', 1.0)
            #self.tvcolumn[n].set_cell_data_func(cell, cell_data_funcs[n])
            self.treeview.append_column(self.tvcolumn[n])

        #self.treeview.connect('row-activated', self.open_file)
        self.scrolledwindow = gtk.ScrolledWindow()
        self.scrolledwindow.add(self.treeview)
        self.treeview.set_model(self.listmodel)
Пример #2
0
    def __create_widgets(self):
        
        #box
        self.all_box = HIGVBox()
        self.input_box = HIGHBox()
        self.buttom_box = HIGHBox()
        self.check_btn_box = gtk.HButtonBox()
        
        #Add input
        self.title_text = HIGLabel(_("Locations"))
        self.longitude_text = HIGLabel(_("longitude:"))
        self.longitude_entry = HIGTextEntry()
        self.latitude_text = HIGLabel(_("latitude:"))
        self.latitude_entry = HIGTextEntry()         
        
        #Add buttons
        self.get_event_btn = gtk.Button(_("Get Events"))
        self.refresh_btn = gtk.Button(_("Refresh"))
          
        #status bar
        self.statusbar = gtk.Statusbar()
        self.statusbar.push(0,'Events in Database')        
                                
        self.listmodel = gtk.ListStore(str, str, str, str, str)

        # create the TreeView
        self.treeview = gtk.TreeView()

        # create the TreeViewColumns to display the data
        self.tvcolumn = [None] * len(self.column_names)
        cellpb = gtk.CellRendererText()

        self.tvcolumn[0] = gtk.TreeViewColumn(self.column_names[0], cellpb)
        self.tvcolumn[0].add_attribute(cellpb, 'text', 0)
        #cell = gtk.CellRendererText()
        #self.tvcolumn[0].set_cell_data_func(cell, self.test_type)
        self.treeview.append_column(self.tvcolumn[0])

        for n in range(1, len(self.column_names)):
            cell = gtk.CellRendererText()
            self.tvcolumn[n] = gtk.TreeViewColumn(self.column_names[n], cell)
            self.tvcolumn[n].add_attribute(cell, 'text', n)
            if n == 1:
                cell.set_property('xalign', 1.0)
            #self.tvcolumn[n].set_cell_data_func(cell, cell_data_funcs[n])
            self.treeview.append_column(self.tvcolumn[n])

        #self.treeview.connect('row-activated', self.open_file)
        self.scrolledwindow = gtk.ScrolledWindow()
        self.scrolledwindow.add(self.treeview)
        self.treeview.set_model(self.listmodel)
    def _create_widgets(self):
        """"""
        self.web_listen_port_label = HIGLabel(_("Web Listen PORT"))
        self.web_listen_port_entry = HIGTextEntry()

        self.aggregator_ip_label = HIGLabel(_("Aggregator URL"))
        self.aggregator_ip_entry = HIGTextEntry()

        self.network_listen_port_label = HIGLabel(_("Peer Listen PORT"))
        self.network_listen_port_entry = HIGTextEntry()

        self.save_button = HIGButton(title="Save")
        self.close_button = HIGButton(title="Close")

        self.hbox = HIGHBox(False, 2)
        self.table = HIGTable(4, 2, False)
        self.table.set_row_spacings(5)
        self.table.set_col_spacings(10)
        self.action_area.set_homogeneous(False)
    def _create_widgets(self):
        """"""
        self.web_listen_port_label = HIGLabel(_("Web Listen PORT"))
        self.web_listen_port_entry = HIGTextEntry()

        self.aggregator_ip_label = HIGLabel(_("Aggregator URL"))
        self.aggregator_ip_entry = HIGTextEntry()

        self.network_listen_port_label = HIGLabel(_("Peer Listen PORT"))
        self.network_listen_port_entry = HIGTextEntry()

        self.save_button = HIGButton(title="Save")
        self.close_button = HIGButton(title="Close")

        self.hbox = HIGHBox(False, 2)
        self.table = HIGTable(4, 2, False)
        self.table.set_row_spacings(5)
        self.table.set_col_spacings(10)
        self.action_area.set_homogeneous(False)
Пример #5
0
class EventWindow(HIGWindow):
    column_names = [
        'Event Type', 'Test Type', 'Time', 'Since Time', 'Locations'
    ]

    def __init__(self):
        HIGWindow.__init__(self, type=gtk.WINDOW_TOPLEVEL)

        self.location_user = Location()  #user location information
        self.location_user.longitude = 0.0
        self.location_user.latitude = 0.0

        self.set_title(_('Events List'))
        self.set_size_request(720, 580)
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)

        self.__create_widgets()
        self.__pack_widgets()
        self.__connect_widgets()

        self.__load_events()

    def __connect_widgets(self):

        self.get_event_btn.connect("clicked", lambda w: self._get_event())
        self.refresh_btn.connect("clicked", lambda w: self._refresh_list())

    def __create_widgets(self):

        #box
        self.all_box = HIGVBox()
        self.input_box = HIGHBox()
        self.buttom_box = HIGHBox()
        self.check_btn_box = gtk.HButtonBox()

        #Add input
        self.title_text = HIGLabel(_("Locations"))
        self.longitude_text = HIGLabel(_("longitude:"))
        self.longitude_entry = HIGTextEntry()
        self.latitude_text = HIGLabel(_("latitude:"))
        self.latitude_entry = HIGTextEntry()

        #Add buttons
        self.get_event_btn = gtk.Button(_("Get Events"))
        self.refresh_btn = gtk.Button(_("Refresh"))

        #status bar
        self.statusbar = gtk.Statusbar()
        self.statusbar.push(0, 'Events in Database')

        self.listmodel = gtk.ListStore(str, str, str, str, str)

        # create the TreeView
        self.treeview = gtk.TreeView()

        # create the TreeViewColumns to display the data
        self.tvcolumn = [None] * len(self.column_names)
        cellpb = gtk.CellRendererText()

        self.tvcolumn[0] = gtk.TreeViewColumn(self.column_names[0], cellpb)
        self.tvcolumn[0].add_attribute(cellpb, 'text', 0)
        #cell = gtk.CellRendererText()
        #self.tvcolumn[0].set_cell_data_func(cell, self.test_type)
        self.treeview.append_column(self.tvcolumn[0])

        for n in range(1, len(self.column_names)):
            cell = gtk.CellRendererText()
            self.tvcolumn[n] = gtk.TreeViewColumn(self.column_names[n], cell)
            self.tvcolumn[n].add_attribute(cell, 'text', n)
            if n == 1:
                cell.set_property('xalign', 1.0)
            #self.tvcolumn[n].set_cell_data_func(cell, cell_data_funcs[n])
            self.treeview.append_column(self.tvcolumn[n])

        #self.treeview.connect('row-activated', self.open_file)
        self.scrolledwindow = gtk.ScrolledWindow()
        self.scrolledwindow.add(self.treeview)
        self.treeview.set_model(self.listmodel)

    def __pack_widgets(self):

        self.all_box._pack_noexpand_nofill(self.input_box)
        self.all_box._pack_expand_fill(self.scrolledwindow)
        self.all_box._pack_noexpand_nofill(self.buttom_box)

        self.input_box.pack_start(self.title_text)
        self.input_box.pack_start(self.longitude_text)
        self.input_box.pack_start(self.longitude_entry)
        self.input_box.pack_start(self.latitude_text)
        self.input_box.pack_start(self.latitude_entry)

        self.buttom_box.pack_start(self.statusbar, True, True, 0)
        self.buttom_box.pack_end(self.check_btn_box, False, False, 0)

        self.check_btn_box.set_layout(gtk.BUTTONBOX_END)
        self.check_btn_box.set_spacing(8)
        self.check_btn_box.pack_start(self.get_event_btn)
        self.check_btn_box.pack_start(self.refresh_btn)

        self.add(self.all_box)

    def __load_events(self):
        for event_entry in theApp.event_manager.event_repository:
            if event_entry.EventType == 'CENSOR':
                pass
            elif event_entry.EventType == 'THROTTLING':
                pass
            elif event_entry.EventType == 'OFF_LINE':
                pass
            self.listmodel.append([
                event_entry.EventType, event_entry.TestType,
                time.strftime("%Y-%m-%d %H:%M:%S",
                              time.gmtime(event_entry.TimeUTC)),
                time.strftime("%Y-%m-%d %H:%M:%S",
                              time.gmtime(event_entry.SinceTimeUTC)),
                event_entry.Locations
            ])

    def _get_event(self):
        """
        get events from aggregator by using Aggregator API:get_events
        """
        longtitude = self.longitude_entry.get_text()
        latitude = self.latitude_entry.get_text()

        if longtitude != "" and latitude != "":
            self.location_user.longitude = float(longtitude)
            self.location_user.latitude = float(latitude)
        else:
            #There we should add user preference logitude
            self.location_user.longitude = 0.0
            self.location_user.latitude = 0.0

        defer_ = theApp.aggregator.get_events(self.location_user)
        defer_.addCallback(self.finish_get_events)
        defer_.addErrback(self.handler_error)

    def _refresh_list(self):
        """
        clear and load
        """
        self.listmodel.clear()
        self.__load_events()
        self.statusbar.push(0, _("Refresh the Events List!"))

    def handler_error(self, failure):
        g_logger.error("Error in get events %s" % str(failure))
        self.statusbar.push(0, _("Error in Get Events From Aggregator!"))

    def finish_get_events(self, message):
        if message is None:
            self.statusbar.push(0, _("No new Events from Aggregator!"))
            return

        self.statusbar.push(
            0, _("Get %d Events from Aggregator" % (len(message.events))))

    def test_type(self, column, cell, model, iter):
        #cell.set_property('text', model.get_value(iter, 0))
        return

    def event_type(self, column, cell, model, iter):
        #filename = os.path.join(self.dirname, model.get_value(iter, 0))
        #filestat = os.stat(filename)
        #cell.set_property('text', filestat.st_size)
        return

    def time(self, column, cell, model, iter):
        #filename = os.path.join(self.dirname, model.get_value(iter, 0))
        #filestat = os.stat(filename)
        #cell.set_property('text', oct(stat.S_IMODE(filestat.st_mode)))
        return

    def location(self, column, cell, model, iter):
        #filename = os.path.join(self.dirname, model.get_value(iter, 0))
        #filestat = os.stat(filename)
        #cell.set_property('text', time.ctime(filestat.st_mtime))
        return

    def report(self, column, cell, model, iter):
        return
Пример #6
0
class EventWindow(HIGWindow):
    column_names = ['Event Type',
                    'Test Type',
                    'Time',
                    'Since Time',
                    'Locations']

    def __init__(self):
        HIGWindow.__init__(self, type=gtk.WINDOW_TOPLEVEL)
        
        self.location_user = Location() #user location information
        self.location_user.longitude = 0.0
        self.location_user.latitude  = 0.0
         
        self.set_title(_('Events List'))
        self.set_size_request(720, 580)
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
        
        self.__create_widgets()
        self.__pack_widgets()
        self.__connect_widgets()
        
        self.__load_events()

    def __connect_widgets(self):
        
        self.get_event_btn.connect("clicked",lambda w:self._get_event())
        self.refresh_btn.connect("clicked",lambda w:self._refresh_list())
        
    def __create_widgets(self):
        
        #box
        self.all_box = HIGVBox()
        self.input_box = HIGHBox()
        self.buttom_box = HIGHBox()
        self.check_btn_box = gtk.HButtonBox()
        
        #Add input
        self.title_text = HIGLabel(_("Locations"))
        self.longitude_text = HIGLabel(_("longitude:"))
        self.longitude_entry = HIGTextEntry()
        self.latitude_text = HIGLabel(_("latitude:"))
        self.latitude_entry = HIGTextEntry()         
        
        #Add buttons
        self.get_event_btn = gtk.Button(_("Get Events"))
        self.refresh_btn = gtk.Button(_("Refresh"))
          
        #status bar
        self.statusbar = gtk.Statusbar()
        self.statusbar.push(0,'Events in Database')        
                                
        self.listmodel = gtk.ListStore(str, str, str, str, str)

        # create the TreeView
        self.treeview = gtk.TreeView()

        # create the TreeViewColumns to display the data
        self.tvcolumn = [None] * len(self.column_names)
        cellpb = gtk.CellRendererText()

        self.tvcolumn[0] = gtk.TreeViewColumn(self.column_names[0], cellpb)
        self.tvcolumn[0].add_attribute(cellpb, 'text', 0)
        #cell = gtk.CellRendererText()
        #self.tvcolumn[0].set_cell_data_func(cell, self.test_type)
        self.treeview.append_column(self.tvcolumn[0])

        for n in range(1, len(self.column_names)):
            cell = gtk.CellRendererText()
            self.tvcolumn[n] = gtk.TreeViewColumn(self.column_names[n], cell)
            self.tvcolumn[n].add_attribute(cell, 'text', n)
            if n == 1:
                cell.set_property('xalign', 1.0)
            #self.tvcolumn[n].set_cell_data_func(cell, cell_data_funcs[n])
            self.treeview.append_column(self.tvcolumn[n])

        #self.treeview.connect('row-activated', self.open_file)
        self.scrolledwindow = gtk.ScrolledWindow()
        self.scrolledwindow.add(self.treeview)
        self.treeview.set_model(self.listmodel)
        
    def __pack_widgets(self):
        
        self.all_box._pack_noexpand_nofill(self.input_box)
        self.all_box._pack_expand_fill(self.scrolledwindow) 
        self.all_box._pack_noexpand_nofill(self.buttom_box)  
                
        self.input_box.pack_start(self.title_text)
        self.input_box.pack_start(self.longitude_text)
        self.input_box.pack_start(self.longitude_entry)
        self.input_box.pack_start(self.latitude_text)
        self.input_box.pack_start(self.latitude_entry)
       
        self.buttom_box.pack_start(self.statusbar,True,True,0)
        self.buttom_box.pack_end(self.check_btn_box,False,False,0)
        
        self.check_btn_box.set_layout(gtk.BUTTONBOX_END)
        self.check_btn_box.set_spacing(8)       
        self.check_btn_box.pack_start(self.get_event_btn)
        self.check_btn_box.pack_start(self.refresh_btn)   
        
        self.add(self.all_box)
        
    def __load_events(self):
        for event_entry in theApp.event_manager.event_repository:
            if event_entry.EventType == 'CENSOR':
                pass
            elif event_entry.EventType == 'THROTTLING':
                pass
            elif event_entry.EventType == 'OFF_LINE':
                pass
            self.listmodel.append(
                [event_entry.EventType,
                 event_entry.TestType,
                 time.strftime("%Y-%m-%d %H:%M:%S",
                               time.gmtime(event_entry.TimeUTC)),
                 time.strftime("%Y-%m-%d %H:%M:%S",
                               time.gmtime(event_entry.SinceTimeUTC)),
                 event_entry.Locations])

    
    def _get_event(self):
        """
        get events from aggregator by using Aggregator API:get_events
        """
        longtitude = self.longitude_entry.get_text()
        latitude   = self.latitude_entry.get_text()
        
        if longtitude != "" and latitude != "":
            self.location_user.longitude = float(longtitude)
            self.location_user.latitude  = float(latitude)
        else:
            #There we should add user preference logitude
            self.location_user.longitude = 0.0
            self.location_user.latitude  = 0.0
        
        defer_ = theApp.aggregator.get_events(self.location_user)
        defer_.addCallback(self.finish_get_events)
        defer_.addErrback(self.handler_error)
    
    def _refresh_list(self):
        """
        clear and load
        """
        self.listmodel.clear()
        self.__load_events()
        self.statusbar.push(0,_("Refresh the Events List!"))  
     
    def handler_error(self,failure):
        g_logger.error("Error in get events %s"%str(failure))
        self.statusbar.push(0,_("Error in Get Events From Aggregator!"))         
            
    def finish_get_events(self,message):
        if message is None:
            self.statusbar.push(0,_("No new Events from Aggregator!"))  
            return
        
        self.statusbar.push(0,_("Get %d Events from Aggregator"%(len(message.events))))  
        

    def test_type(self, column, cell, model, iter):
        #cell.set_property('text', model.get_value(iter, 0))
        return

    def event_type(self, column, cell, model, iter):
        #filename = os.path.join(self.dirname, model.get_value(iter, 0))
        #filestat = os.stat(filename)
        #cell.set_property('text', filestat.st_size)
        return

    def time(self, column, cell, model, iter):
        #filename = os.path.join(self.dirname, model.get_value(iter, 0))
        #filestat = os.stat(filename)
        #cell.set_property('text', oct(stat.S_IMODE(filestat.st_mode)))
        return

    def location(self, column, cell, model, iter):
        #filename = os.path.join(self.dirname, model.get_value(iter, 0))
        #filestat = os.stat(filename)
        #cell.set_property('text', time.ctime(filestat.st_mtime))
        return

    def report(self, column, cell, model, iter):
        return
    def _create_widgets(self):
        """"""        
        #vbox
        self.all_box = HIGVBox()
        self.soft_update_info_box = HIGHBox()
        self.soft_update_list_box = HIGVBox()
        self.check_btn_box = gtk.HButtonBox()
        self.soft_update_detail_box = HIGVBox()
        self.bottom_btn_box = gtk.HButtonBox()
            
        #software update information title 
        self.update_icon = gtk.Image()
        self.update_icon.set_from_file(os.path.join(IMAGES_DIR,'software_update.ico'))
        self.version_information_label = HIGLabel(_("The newest open monitor in your computer!"))
        self.latest_time_information_label = HIGLabel(_(self.latest_update_time))
        self.soft_update_table = HIGTable()
             
        #software list
        self.column_names = ['Date','Version','Name']
        
        self.vbox_list = gtk.VBox(False,8)
        self.scroll_window_vbox = gtk.ScrolledWindow()
        self.scroll_window_vbox.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        self.scroll_window_vbox.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        self.vbox_list.pack_start(self.scroll_window_vbox,True,True,0)
        self.store = gtk.ListStore(str,str,str)
        self.treeview = gtk.TreeView()

        self.treeview.set_rules_hint(True)
        self.treeview.set_sensitive(False)
        self.vbox_list.set_size_request(100,100)
        self.scroll_window_vbox.add(self.treeview)
              
        self._create_colums()
        self.statusbar = gtk.Statusbar()
        self.statusbar.push(0,'No update!')
        
        self.vbox_list.pack_start(self.statusbar,False,False,0)
        
        self.progress_bar = gtk.ProgressBar()
        self.progress_bar.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
        self.progress_bar.set_fraction(0.0)
        
        self.vbox_list.pack_start(self.progress_bar,False,False,0)
        #button about the update
        self.check_btn = HIGButton(_("Check"))
        self.install_btn = HIGButton(_("Install"))
        self.install_btn.set_sensitive(False)
        
        #update details 
        self.detail_toggle_button = gtk.ToggleButton(_("Details"))
        self.detail_btn_box = gtk.HButtonBox()
        self.detail_btn_box.set_layout(gtk.BUTTONBOX_START)
        self.details_vbox = HIGVBox()
        self.details_scroll = gtk.ScrolledWindow()
        self.details_textview = gtk.TextView()
        self.details_textview.set_size_request(100,120)
        self.details_textview.set_editable(False)
        self.details_textview.set_buffer(self._set_details_content())
    
        #bottom button
        self.close_btn = HIGButton(_("Close"))
        self.settings_btn = HIGButton(_("Settings"))
class SoftwareUpdateDialog(HIGWindow):
    """"""
    def __init__(self):
        """Constructor"""
        HIGWindow.__init__(self, type=gtk.WINDOW_TOPLEVEL)
        self.set_title(_("Open Monitor Software Update Manager"))
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
        self.set_size_request(480,480)
        self.set_keep_above(True)
        self.set_border_width(10)
        
        self._create_record()
        self._create_widgets()
        self._pack_widgets()
        self._connect_widgets() 

    
    def _create_record(self):
        
        self.software_list_dict = {}
        self.software_details_dict ={
                                     "version":"",
                                     "news_date":"",
                                     "software_name":"",
                                     "description":"",
                                     "download_url":"",
                                     "is_update":"",
                                     "check_code":""
                                     } 
        self.current_record = {}
        #get history update information
        self.latest_update_time =  "The lastest update time is " + self._get_value_from_db("update_time")
        
    def _create_widgets(self):
        """"""        
        #vbox
        self.all_box = HIGVBox()
        self.soft_update_info_box = HIGHBox()
        self.soft_update_list_box = HIGVBox()
        self.check_btn_box = gtk.HButtonBox()
        self.soft_update_detail_box = HIGVBox()
        self.bottom_btn_box = gtk.HButtonBox()
            
        #software update information title 
        self.update_icon = gtk.Image()
        self.update_icon.set_from_file(os.path.join(IMAGES_DIR,'software_update.ico'))
        self.version_information_label = HIGLabel(_("The newest open monitor in your computer!"))
        self.latest_time_information_label = HIGLabel(_(self.latest_update_time))
        self.soft_update_table = HIGTable()
             
        #software list
        self.column_names = ['Date','Version','Name']
        
        self.vbox_list = gtk.VBox(False,8)
        self.scroll_window_vbox = gtk.ScrolledWindow()
        self.scroll_window_vbox.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        self.scroll_window_vbox.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        self.vbox_list.pack_start(self.scroll_window_vbox,True,True,0)
        self.store = gtk.ListStore(str,str,str)
        self.treeview = gtk.TreeView()

        self.treeview.set_rules_hint(True)
        self.treeview.set_sensitive(False)
        self.vbox_list.set_size_request(100,100)
        self.scroll_window_vbox.add(self.treeview)
              
        self._create_colums()
        self.statusbar = gtk.Statusbar()
        self.statusbar.push(0,'No update!')
        
        self.vbox_list.pack_start(self.statusbar,False,False,0)
        
        self.progress_bar = gtk.ProgressBar()
        self.progress_bar.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
        self.progress_bar.set_fraction(0.0)
        
        self.vbox_list.pack_start(self.progress_bar,False,False,0)
        #button about the update
        self.check_btn = HIGButton(_("Check"))
        self.install_btn = HIGButton(_("Install"))
        self.install_btn.set_sensitive(False)
        
        #update details 
        self.detail_toggle_button = gtk.ToggleButton(_("Details"))
        self.detail_btn_box = gtk.HButtonBox()
        self.detail_btn_box.set_layout(gtk.BUTTONBOX_START)
        self.details_vbox = HIGVBox()
        self.details_scroll = gtk.ScrolledWindow()
        self.details_textview = gtk.TextView()
        self.details_textview.set_size_request(100,120)
        self.details_textview.set_editable(False)
        self.details_textview.set_buffer(self._set_details_content())
    
        #bottom button
        self.close_btn = HIGButton(_("Close"))
        self.settings_btn = HIGButton(_("Settings"))
        
    def _pack_widgets(self):
        """"""
        self.all_box._pack_noexpand_nofill(self.soft_update_info_box)
        self.all_box._pack_expand_fill(self.soft_update_list_box)   
        self.all_box._pack_noexpand_nofill(self.check_btn_box)
        self.all_box._pack_noexpand_nofill(self.soft_update_detail_box)    
        self.all_box._pack_noexpand_nofill(self.bottom_btn_box)        
        
        self.soft_update_info_box._pack_noexpand_nofill(hig_box_space_holder())
        self.soft_update_info_box._pack_expand_fill(self.soft_update_table)      
        self.soft_update_list_box._pack_expand_fill(self.vbox_list)
                 
        self.soft_update_table.attach_label(self.update_icon,0,2,0,2,)
        self.soft_update_table.attach_label(self.version_information_label,2,4,0,1)
        self.soft_update_table.attach_label(self.latest_time_information_label,2,4,1,2)
        
        self.check_btn_box.set_layout(gtk.BUTTONBOX_END)
        self.check_btn_box.set_spacing(8)       
        self.check_btn_box.pack_start(self.check_btn)
        self.check_btn_box.pack_start(self.install_btn)

        self.detail_btn_box.set_spacing(8)       
        self.detail_btn_box.pack_start(self.detail_toggle_button)
                
        self.details_scroll.add(self.details_textview)
        self.details_vbox._pack_expand_fill(self.details_scroll)
        self.soft_update_detail_box._pack_expand_nofill(self.detail_btn_box) 
        self.soft_update_detail_box._pack_expand_fill(self.details_vbox)         
        
        self.bottom_btn_box.set_layout(gtk.BUTTONBOX_EDGE)
        self.bottom_btn_box.set_spacing(8)  
        self.bottom_btn_box.pack_start(self.settings_btn)         
        self.bottom_btn_box.pack_start(self.close_btn)
        
        self.add(self.all_box)
        
    def _connect_widgets(self):
        """"""
        self.check_btn.connect('clicked',lambda w:self._check_software())
        self.install_btn.connect('clicked',lambda w:self._install_software())
        self.close_btn.connect('clicked',lambda w:self._close()) 
        self.settings_btn.connect('clicked',lambda w:self._settings_windows()) 
        self.detail_toggle_button.connect('clicked',lambda w:self._show_details())
        self.treeview.connect('row-activated',self._on_activated)

    def _load_updates(self):
        """
        load the information from the DB
        """
        self.software_list_dict = {}
        cnt = 0
        #get details from the DB 
        rs = g_db_helper.select("select * from updates where is_update = %d" % no_updated)
        for record in rs:
            self.software_list_dict[cnt] = {}
            self.software_list_dict[cnt]["version"] = record[0]
            self.software_list_dict[cnt]["news_date"] = record[1]
            self.software_list_dict[cnt]["software_name"] = record[2]
            self.software_list_dict[cnt]["description"] = record[3]
            self.software_list_dict[cnt]["download_url"] = record[4] 
            self.software_list_dict[cnt]["is_update"] = record[5]
            self.software_list_dict[cnt]["check_code"] = record[6]
                                                                       
            cnt = cnt + 1    
        g_logger.info("Loaded %d updates from DB." % len(rs))       
        
        #output in the window
        if len(self.software_list_dict) == 0:
            self.install_btn.set_sensitive(False)
            g_logger.info("No new updates from UpdateMoule")
        else:
            self.treeview.set_sensitive(True)
            self.check_btn.set_sensitive(False)
            g_logger.debug("Show the records in the tree-view") 

            self.store.clear()           
            for line in self.software_list_dict.keys():
                self.store.append([self.software_list_dict[line]["news_date"],
                                   self.software_list_dict[line]["version"],
                                   self.software_list_dict[line]["software_name"]])
            
            self.treeview.set_model(self.store) #It must be after the store update
                
    #def create_model(self):
    #    store = gtk.ListStore(str,str,str)
    #    for act in stress:
    #        store.append([act[0],act[1],act[2]])
    #    return store
    
    def _get_value_from_db (self,key):
        """
        get value from the config in DB
        """
        rs = g_db_helper.select("select * from config where key = '%s'" % key)
        if rs == None or len(rs) != 1:
            g_logger.error("Wrong get the value from key:%s in config DB " % (key))   
            return 
        return str(rs[0][1])
    
    def _set_details_content(self,content=None):
        if content == None or content == "":
            content = str(_('Open Monitor Alpha is coming soon!\n Designed by UMIT'))
           
        buf = gtk.TextBuffer()
        buf.set_text(content)
        return buf
    
    def _show_details(self):
        """"""
        if (self.detail_toggle_button.get_active()):
            self.details_vbox.hide_all()
        else:
            self.details_vbox.show_all()
                 
    def _create_colums(self):
        """"""       
        for i in range(0,len(self.column_names)):
            rendererText = gtk.CellRendererText()
            column = gtk.TreeViewColumn(self.column_names[i],rendererText,text = i) #text attributes MUST!
            column.set_sort_column_id(i)
            self.treeview.append_column(column)
    
    def _on_activated(self,widget,row,col):
        """"""
        self.install_btn.set_sensitive(True)
        #choice
        selection = self.treeview.get_selection()
        (model,iter) = selection.get_selected()
        if iter == None:
            return
        else:
            cur_version = self.store.get_value(iter,1)
            #fill self.current_record
            rs = g_db_helper.select("select * from updates where version = '%s'" % cur_version)
            if len(rs) != 1:
                g_logger.error("Record is ERROR in DB!!!! The window will be closed!!!")
                self.destroy()
            self.current_record = {}
            
            self.current_record["version"] = rs[0][0]
            self.current_record["news_date"] = rs[0][1]
            self.current_record["software_name"] = rs[0][2]
            self.current_record["description"] = rs[0][3]
            self.current_record["download_url"] = rs[0][4] 
            self.current_record["is_update"] = rs[0][5]
            self.current_record["check_code"] = rs[0][6]            
              
            
            self.statusbar.push(0,_("You have selected the %s version" % \
                                self.current_record["version"])) 
           
            self.details_textview.set_buffer(self._set_details_content(_(self.current_record["description"] + "\n" + 
                                        "download:"+self.current_record["download_url"] + "\n" +
                                        "Designed by Umit!" 
                                        ))) 
            self.details_textview.show_all()
            g_logger.debug("Selected the item %s" % (self.current_record))              
    
    def _check_software(self):    
        """"""
        defer_ = theApp.aggregator.check_version()
        defer_.addCallback(self._handle_check_software)
        defer_.addErrback(self._handle_errback)
        
        return defer_
    
    def _handle_errback(self,failure):
        g_logger.error("auto check error:%s" % str(failure))          
    
    def _handle_check_software(self,message):
        if message == None:
            return
        
        g_logger.debug("Finish check the software update.")
        self.progress_bar.set_value(100)
        #self.progress_bar = gtk.ProgressBar(100)
        #show the record        
        self._load_updates()
        
    def _handle_errbdownloadURLack(self,failure):
        g_logger.error("Aggregator failure: %s" % str(failure))        
        
    def _check_software_test(self):
        """"""
        p = theApp.aggregator.check_version()
        print p
        self.progress_bar.set_value(100)
        
        #test: create some records
        result = {
                1:{"version":"0.9",
                   "news_date":"2012-1-1",
                   "software_name":"icm-agent",
                   "description":"test software update module icm-agent",
                   "download_url":"http://tianwei-wordpress.stor.sinaapp.com/uploads/2012/05/icm_agent_update.tar.gz",
                   "is_update":"1"},
                2:{"version":"1.1",
                   "news_date":"2012-5-21",
                   "software_name":"open monitor desktop",
                   "description":"test software update module open monitor 1.0",
                   "download_url":"http://tianwei-wordpress.stor.sinaapp.com/uploads/2012/05/icm_agent_update.tar.gz",
                   "is_update":"0"},
                3:{"version":"2.0",
                   "news_date":"2012-8-21",
                   "software_name":"open monitor desktop v2.0",
                   "description":"test software update module open monitor 2.0",
                   "download_url":"http://tianwei-wordpress.stor.sinaapp.com/uploads/2012/05/icm_agent_update.tar.gz",
                   "is_update":"0"},
                }
        #check the db and insert it
        if len(result) == 0:
            self.install_btn.set_sensitive(False)
            g_logger.info("No new updates from UpdateMoule")
            return            
        
        for key in result.keys():
            if not check_update_item_in_db(result[key]["version"]):
                insert_update_item_in_db(result[key])
        
        #show the record        
        self._load_updates()
        
    def _install_software(self):
        """"""
        self.progress_bar.set_value(0)
        if self.current_record == None or len(self.current_record) == 0:
            self.install_btn.set_sensitive(False)
            g_logger.info("No new updates to be installed")
            return

        print self.current_record 
        # download and install 
        if compare_version(self.current_record["version"],VERSION) == higher_version:
            g_logger.debug("The version is right for icm-agent")
            
            download_update(url=self.current_record["download_url"],
                            check_code = self.current_record["check_code"],
                            version=self.current_record["version"])
            self.install_btn.set_sensitive(False)
        else:
            g_logger.debug("The version is low than current icm-agent")
            self.statusbar.push(0,'The current is the lastest version!')
            self.install_btn.set_sensitive(False)
            self.check_btn.set_sensitive(True)
   
    def _close(self):
        """"""
        self.destroy()
    def _settings_windows(self):
        """"""
        theApp.gtk_main.show_preference()
        
    def _auto_update(self):
        """"""
        pass
    def _manually_update(self):
        """"""
        pass
Пример #9
0
    def _create_widgets(self):
        """"""
        #vbox
        self.all_box = HIGVBox()
        self.soft_update_info_box = HIGHBox()
        self.soft_update_list_box = HIGVBox()
        self.check_btn_box = gtk.HButtonBox()
        self.soft_update_detail_box = HIGVBox()
        self.bottom_btn_box = gtk.HButtonBox()

        #software update information title
        self.update_icon = gtk.Image()
        self.update_icon.set_from_file(
            os.path.join(IMAGES_DIR, 'software_update.ico'))
        self.version_information_label = HIGLabel(
            _("The newest open monitor in your computer!"))
        self.latest_time_information_label = HIGLabel(
            _(self.latest_update_time))
        self.soft_update_table = HIGTable()

        #software list
        self.column_names = ['Date', 'Version', 'Name']

        self.vbox_list = gtk.VBox(False, 8)
        self.scroll_window_vbox = gtk.ScrolledWindow()
        self.scroll_window_vbox.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        self.scroll_window_vbox.set_policy(gtk.POLICY_AUTOMATIC,
                                           gtk.POLICY_AUTOMATIC)
        self.vbox_list.pack_start(self.scroll_window_vbox, True, True, 0)
        self.store = gtk.ListStore(str, str, str)
        self.treeview = gtk.TreeView()

        self.treeview.set_rules_hint(True)
        self.treeview.set_sensitive(False)
        self.vbox_list.set_size_request(100, 100)
        self.scroll_window_vbox.add(self.treeview)

        self._create_colums()
        self.statusbar = gtk.Statusbar()
        self.statusbar.push(0, 'No update!')

        self.vbox_list.pack_start(self.statusbar, False, False, 0)

        self.progress_bar = gtk.ProgressBar()
        self.progress_bar.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
        self.progress_bar.set_fraction(0.0)

        self.vbox_list.pack_start(self.progress_bar, False, False, 0)
        #button about the update
        self.check_btn = HIGButton(_("Check"))
        self.install_btn = HIGButton(_("Install"))
        self.install_btn.set_sensitive(False)

        #update details
        self.detail_toggle_button = gtk.ToggleButton(_("Details"))
        self.detail_btn_box = gtk.HButtonBox()
        self.detail_btn_box.set_layout(gtk.BUTTONBOX_START)
        self.details_vbox = HIGVBox()
        self.details_scroll = gtk.ScrolledWindow()
        self.details_textview = gtk.TextView()
        self.details_textview.set_size_request(100, 120)
        self.details_textview.set_editable(False)
        self.details_textview.set_buffer(self._set_details_content())

        #bottom button
        self.close_btn = HIGButton(_("Close"))
        self.settings_btn = HIGButton(_("Settings"))
Пример #10
0
class SoftwareUpdateDialog(HIGWindow):
    """"""
    def __init__(self):
        """Constructor"""
        HIGWindow.__init__(self, type=gtk.WINDOW_TOPLEVEL)
        self.set_title(_("Open Monitor Software Update Manager"))
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
        self.set_size_request(480, 480)
        self.set_keep_above(True)
        self.set_border_width(10)

        self._create_record()
        self._create_widgets()
        self._pack_widgets()
        self._connect_widgets()

    def _create_record(self):

        self.software_list_dict = {}
        self.software_details_dict = {
            "version": "",
            "news_date": "",
            "software_name": "",
            "description": "",
            "download_url": "",
            "is_update": "",
            "check_code": ""
        }
        self.current_record = {}
        #get history update information
        self.latest_update_time = "The lastest update time is " + self._get_value_from_db(
            "update_time")

    def _create_widgets(self):
        """"""
        #vbox
        self.all_box = HIGVBox()
        self.soft_update_info_box = HIGHBox()
        self.soft_update_list_box = HIGVBox()
        self.check_btn_box = gtk.HButtonBox()
        self.soft_update_detail_box = HIGVBox()
        self.bottom_btn_box = gtk.HButtonBox()

        #software update information title
        self.update_icon = gtk.Image()
        self.update_icon.set_from_file(
            os.path.join(IMAGES_DIR, 'software_update.ico'))
        self.version_information_label = HIGLabel(
            _("The newest open monitor in your computer!"))
        self.latest_time_information_label = HIGLabel(
            _(self.latest_update_time))
        self.soft_update_table = HIGTable()

        #software list
        self.column_names = ['Date', 'Version', 'Name']

        self.vbox_list = gtk.VBox(False, 8)
        self.scroll_window_vbox = gtk.ScrolledWindow()
        self.scroll_window_vbox.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        self.scroll_window_vbox.set_policy(gtk.POLICY_AUTOMATIC,
                                           gtk.POLICY_AUTOMATIC)
        self.vbox_list.pack_start(self.scroll_window_vbox, True, True, 0)
        self.store = gtk.ListStore(str, str, str)
        self.treeview = gtk.TreeView()

        self.treeview.set_rules_hint(True)
        self.treeview.set_sensitive(False)
        self.vbox_list.set_size_request(100, 100)
        self.scroll_window_vbox.add(self.treeview)

        self._create_colums()
        self.statusbar = gtk.Statusbar()
        self.statusbar.push(0, 'No update!')

        self.vbox_list.pack_start(self.statusbar, False, False, 0)

        self.progress_bar = gtk.ProgressBar()
        self.progress_bar.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
        self.progress_bar.set_fraction(0.0)

        self.vbox_list.pack_start(self.progress_bar, False, False, 0)
        #button about the update
        self.check_btn = HIGButton(_("Check"))
        self.install_btn = HIGButton(_("Install"))
        self.install_btn.set_sensitive(False)

        #update details
        self.detail_toggle_button = gtk.ToggleButton(_("Details"))
        self.detail_btn_box = gtk.HButtonBox()
        self.detail_btn_box.set_layout(gtk.BUTTONBOX_START)
        self.details_vbox = HIGVBox()
        self.details_scroll = gtk.ScrolledWindow()
        self.details_textview = gtk.TextView()
        self.details_textview.set_size_request(100, 120)
        self.details_textview.set_editable(False)
        self.details_textview.set_buffer(self._set_details_content())

        #bottom button
        self.close_btn = HIGButton(_("Close"))
        self.settings_btn = HIGButton(_("Settings"))

    def _pack_widgets(self):
        """"""
        self.all_box._pack_noexpand_nofill(self.soft_update_info_box)
        self.all_box._pack_expand_fill(self.soft_update_list_box)
        self.all_box._pack_noexpand_nofill(self.check_btn_box)
        self.all_box._pack_noexpand_nofill(self.soft_update_detail_box)
        self.all_box._pack_noexpand_nofill(self.bottom_btn_box)

        self.soft_update_info_box._pack_noexpand_nofill(hig_box_space_holder())
        self.soft_update_info_box._pack_expand_fill(self.soft_update_table)
        self.soft_update_list_box._pack_expand_fill(self.vbox_list)

        self.soft_update_table.attach_label(
            self.update_icon,
            0,
            2,
            0,
            2,
        )
        self.soft_update_table.attach_label(self.version_information_label, 2,
                                            4, 0, 1)
        self.soft_update_table.attach_label(self.latest_time_information_label,
                                            2, 4, 1, 2)

        self.check_btn_box.set_layout(gtk.BUTTONBOX_END)
        self.check_btn_box.set_spacing(8)
        self.check_btn_box.pack_start(self.check_btn)
        self.check_btn_box.pack_start(self.install_btn)

        self.detail_btn_box.set_spacing(8)
        self.detail_btn_box.pack_start(self.detail_toggle_button)

        self.details_scroll.add(self.details_textview)
        self.details_vbox._pack_expand_fill(self.details_scroll)
        self.soft_update_detail_box._pack_expand_nofill(self.detail_btn_box)
        self.soft_update_detail_box._pack_expand_fill(self.details_vbox)

        self.bottom_btn_box.set_layout(gtk.BUTTONBOX_EDGE)
        self.bottom_btn_box.set_spacing(8)
        self.bottom_btn_box.pack_start(self.settings_btn)
        self.bottom_btn_box.pack_start(self.close_btn)

        self.add(self.all_box)

    def _connect_widgets(self):
        """"""
        self.check_btn.connect('clicked', lambda w: self._check_software())
        self.install_btn.connect('clicked', lambda w: self._install_software())
        self.close_btn.connect('clicked', lambda w: self._close())
        self.settings_btn.connect('clicked',
                                  lambda w: self._settings_windows())
        self.detail_toggle_button.connect('clicked',
                                          lambda w: self._show_details())
        self.treeview.connect('row-activated', self._on_activated)

    def _load_updates(self):
        """
        load the information from the DB
        """
        self.software_list_dict = {}
        cnt = 0
        #get details from the DB
        rs = g_db_helper.select("select * from updates where is_update = %d" %
                                no_updated)
        for record in rs:
            self.software_list_dict[cnt] = {}
            self.software_list_dict[cnt]["version"] = record[0]
            self.software_list_dict[cnt]["news_date"] = record[1]
            self.software_list_dict[cnt]["software_name"] = record[2]
            self.software_list_dict[cnt]["description"] = record[3]
            self.software_list_dict[cnt]["download_url"] = record[4]
            self.software_list_dict[cnt]["is_update"] = record[5]
            self.software_list_dict[cnt]["check_code"] = record[6]

            cnt = cnt + 1
        g_logger.info("Loaded %d updates from DB." % len(rs))

        #output in the window
        if len(self.software_list_dict) == 0:
            self.install_btn.set_sensitive(False)
            g_logger.info("No new updates from UpdateMoule")
        else:
            self.treeview.set_sensitive(True)
            self.check_btn.set_sensitive(False)
            g_logger.debug("Show the records in the tree-view")

            self.store.clear()
            for line in self.software_list_dict.keys():
                self.store.append([
                    self.software_list_dict[line]["news_date"],
                    self.software_list_dict[line]["version"],
                    self.software_list_dict[line]["software_name"]
                ])

            self.treeview.set_model(
                self.store)  #It must be after the store update

    #def create_model(self):
    #    store = gtk.ListStore(str,str,str)
    #    for act in stress:
    #        store.append([act[0],act[1],act[2]])
    #    return store

    def _get_value_from_db(self, key):
        """
        get value from the config in DB
        """
        rs = g_db_helper.select("select * from config where key = '%s'" % key)
        if rs == None or len(rs) != 1:
            g_logger.error("Wrong get the value from key:%s in config DB " %
                           (key))
            return
        return str(rs[0][1])

    def _set_details_content(self, content=None):
        if content == None or content == "":
            content = str(
                _('Open Monitor Alpha is coming soon!\n Designed by UMIT'))

        buf = gtk.TextBuffer()
        buf.set_text(content)
        return buf

    def _show_details(self):
        """"""
        if (self.detail_toggle_button.get_active()):
            self.details_vbox.hide_all()
        else:
            self.details_vbox.show_all()

    def _create_colums(self):
        """"""
        for i in range(0, len(self.column_names)):
            rendererText = gtk.CellRendererText()
            column = gtk.TreeViewColumn(self.column_names[i],
                                        rendererText,
                                        text=i)  #text attributes MUST!
            column.set_sort_column_id(i)
            self.treeview.append_column(column)

    def _on_activated(self, widget, row, col):
        """"""
        self.install_btn.set_sensitive(True)
        #choice
        selection = self.treeview.get_selection()
        (model, iter) = selection.get_selected()
        if iter == None:
            return
        else:
            cur_version = self.store.get_value(iter, 1)
            #fill self.current_record
            rs = g_db_helper.select(
                "select * from updates where version = '%s'" % cur_version)
            if len(rs) != 1:
                g_logger.error(
                    "Record is ERROR in DB!!!! The window will be closed!!!")
                self.destroy()
            self.current_record = {}

            self.current_record["version"] = rs[0][0]
            self.current_record["news_date"] = rs[0][1]
            self.current_record["software_name"] = rs[0][2]
            self.current_record["description"] = rs[0][3]
            self.current_record["download_url"] = rs[0][4]
            self.current_record["is_update"] = rs[0][5]
            self.current_record["check_code"] = rs[0][6]


            self.statusbar.push(0,_("You have selected the %s version" % \
                                self.current_record["version"]))

            self.details_textview.set_buffer(
                self._set_details_content(
                    _(self.current_record["description"] + "\n" + "download:" +
                      self.current_record["download_url"] + "\n" +
                      "Designed by Umit!")))
            self.details_textview.show_all()
            g_logger.debug("Selected the item %s" % (self.current_record))

    def _check_software(self):
        """"""
        defer_ = theApp.aggregator.check_version()
        defer_.addCallback(self._handle_check_software)
        defer_.addErrback(self._handle_errback)

        return defer_

    def _handle_errback(self, failure):
        g_logger.error("auto check error:%s" % str(failure))

    def _handle_check_software(self, message):
        if message == None:
            return

        g_logger.debug("Finish check the software update.")
        self.progress_bar.set_value(100)
        #self.progress_bar = gtk.ProgressBar(100)
        #show the record
        self._load_updates()

    def _handle_errbdownloadURLack(self, failure):
        g_logger.error("Aggregator failure: %s" % str(failure))

    def _check_software_test(self):
        """"""
        p = theApp.aggregator.check_version()
        print p
        self.progress_bar.set_value(100)

        #test: create some records
        result = {
            1: {
                "version": "0.9",
                "news_date": "2012-1-1",
                "software_name": "icm-agent",
                "description": "test software update module icm-agent",
                "download_url":
                "http://tianwei-wordpress.stor.sinaapp.com/uploads/2012/05/icm_agent_update.tar.gz",
                "is_update": "1"
            },
            2: {
                "version": "1.1",
                "news_date": "2012-5-21",
                "software_name": "open monitor desktop",
                "description": "test software update module open monitor 1.0",
                "download_url":
                "http://tianwei-wordpress.stor.sinaapp.com/uploads/2012/05/icm_agent_update.tar.gz",
                "is_update": "0"
            },
            3: {
                "version": "2.0",
                "news_date": "2012-8-21",
                "software_name": "open monitor desktop v2.0",
                "description": "test software update module open monitor 2.0",
                "download_url":
                "http://tianwei-wordpress.stor.sinaapp.com/uploads/2012/05/icm_agent_update.tar.gz",
                "is_update": "0"
            },
        }
        #check the db and insert it
        if len(result) == 0:
            self.install_btn.set_sensitive(False)
            g_logger.info("No new updates from UpdateMoule")
            return

        for key in result.keys():
            if not check_update_item_in_db(result[key]["version"]):
                insert_update_item_in_db(result[key])

        #show the record
        self._load_updates()

    def _install_software(self):
        """"""
        self.progress_bar.set_value(0)
        if self.current_record == None or len(self.current_record) == 0:
            self.install_btn.set_sensitive(False)
            g_logger.info("No new updates to be installed")
            return

        print self.current_record
        # download and install
        if compare_version(self.current_record["version"],
                           VERSION) == higher_version:
            g_logger.debug("The version is right for icm-agent")

            download_update(url=self.current_record["download_url"],
                            check_code=self.current_record["check_code"],
                            version=self.current_record["version"])
            self.install_btn.set_sensitive(False)
        else:
            g_logger.debug("The version is low than current icm-agent")
            self.statusbar.push(0, 'The current is the lastest version!')
            self.install_btn.set_sensitive(False)
            self.check_btn.set_sensitive(True)

    def _close(self):
        """"""
        self.destroy()

    def _settings_windows(self):
        """"""
        theApp.gtk_main.show_preference()

    def _auto_update(self):
        """"""
        pass

    def _manually_update(self):
        """"""
        pass
class SettingsDialog(HIGDialog):
    """"""
    def __init__(self, title=_('Settings')):
        """Constructor"""
        HIGDialog.__init__(self, title=title, flags=gtk.DIALOG_MODAL)

        self.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
        self.set_default_response(gtk.RESPONSE_ACCEPT)
        self.set_keep_above(True)
        self.set_size_request(480, 100)
        self.set_border_width(2)

        self._create_widgets()
        self._pack_widgets()
        self._connect_widgets()
        self._load_settings()

    def _load_settings(self):
        """"""
        aggregator_url = g_config.get('network', 'aggregator_url')
        self.aggregator_ip_entry.set_text(aggregator_url)

    def _create_widgets(self):
        """"""
        self.web_listen_port_label = HIGLabel(_("Web Listen PORT"))
        self.web_listen_port_entry = HIGTextEntry()

        self.aggregator_ip_label = HIGLabel(_("Aggregator URL"))
        self.aggregator_ip_entry = HIGTextEntry()

        self.network_listen_port_label = HIGLabel(_("Peer Listen PORT"))
        self.network_listen_port_entry = HIGTextEntry()

        self.save_button = HIGButton(title="Save")
        self.close_button = HIGButton(title="Close")

        self.hbox = HIGHBox(False, 2)
        self.table = HIGTable(4, 2, False)
        self.table.set_row_spacings(5)
        self.table.set_col_spacings(10)
        self.action_area.set_homogeneous(False)

    def _pack_widgets(self):
        """"""
        self.hbox.set_border_width(8)
        self.table.attach(self.aggregator_ip_label, 0, 1, 0, 1, gtk.FILL,
                          gtk.FILL, 0, 0)
        self.table.attach(self.aggregator_ip_entry, 1, 4, 0, 1,
                          gtk.FILL | gtk.EXPAND, gtk.FILL | gtk.EXPAND, 0, 0)

        self.hbox._pack_expand_fill(self.table)
        self.vbox.pack_start(self.hbox, False, False)

        self.action_area.pack_end(self.save_button)
        self.action_area.reorder_child(self.save_button, 0)
        self.action_area.pack_end(self.close_button)
        self.action_area.reorder_child(self.close_button, 1)

    def _connect_widgets(self):
        """"""
        self.save_button.connect("clicked", lambda w: self._save_settings())
        self.close_button.connect("clicked", lambda w: self._close_settings())

    def _save_settings(self):
        """"""
        aggregator_url = self.aggregator_ip_entry.get_text()
        #print aggregator_url
        if aggregator_url != None and aggregator_url != "":
            #http address check
            if 'http://' not in aggregator_url:
                aggregator_url = "http://" + aggregator_url
            aggregator_url = aggregator_url.rstrip('/')
            theApp.aggregator.base_url = aggregator_url
            g_config.set('network', 'aggregator_url', aggregator_url)
            g_db_helper.set_value('config', 'aggregator_url', aggregator_url)

        self.destroy()

    def _close_settings(self):
        """"""
        self.destroy()
Пример #12
0
class SettingsDialog(HIGDialog):
    """"""
    def __init__(self,title=_('Settings')):
        """Constructor"""
        HIGDialog.__init__(self, title=title, flags=gtk.DIALOG_MODAL)
        
        self.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
        self.set_default_response(gtk.RESPONSE_ACCEPT)
        self.set_keep_above(True)
        self.set_size_request(480,100)
        self.set_border_width(2)
        
        self._create_widgets()
        self._pack_widgets()
        self._connect_widgets() 
        self._load_settings()
    
    def _load_settings(self):
        """"""
        aggregator_url = g_config.get('network', 'aggregator_url')
        self.aggregator_ip_entry.set_text(aggregator_url)
          
    def _create_widgets(self):
        """"""
        self.web_listen_port_label = HIGLabel(_("Web Listen PORT"))
        self.web_listen_port_entry = HIGTextEntry()
        
        self.aggregator_ip_label = HIGLabel(_("Aggregator URL"))
        self.aggregator_ip_entry = HIGTextEntry()
        
        
        self.network_listen_port_label = HIGLabel(_("Peer Listen PORT"))
        self.network_listen_port_entry = HIGTextEntry()   
        
        self.save_button =  HIGButton(title = "Save")
        self.close_button = HIGButton(title = "Close")   
        
        self.hbox = HIGHBox(False,2)
        self.table = HIGTable(4,2,False)
        self.table.set_row_spacings(5)
        self.table.set_col_spacings(10)
        self.action_area.set_homogeneous(False)
        
    def _pack_widgets(self):
        """"""
        self.hbox.set_border_width(8)
        self.table.attach(self.aggregator_ip_label,0,1,0,1,gtk.FILL,gtk.FILL,0,0)
        self.table.attach(self.aggregator_ip_entry,1,4,0,1,gtk.FILL|gtk.EXPAND,gtk.FILL|gtk.EXPAND,0,0)
                     
        self.hbox._pack_expand_fill(self.table)
        self.vbox.pack_start(self.hbox, False, False) 
        
        self.action_area.pack_end(self.save_button)    
        self.action_area.reorder_child(self.save_button,0)                             
        self.action_area.pack_end(self.close_button)    
        self.action_area.reorder_child(self.close_button,1) 
        
    def _connect_widgets(self):
        """"""
        self.save_button.connect("clicked",lambda w: self._save_settings())
        self.close_button.connect("clicked",lambda w: self._close_settings())

    def _save_settings(self):
        """"""
        aggregator_url = self.aggregator_ip_entry.get_text()
        #print aggregator_url
        if aggregator_url != None and aggregator_url != "":
            #http address check
            if 'http://' not in aggregator_url:
                aggregator_url = "http://"+ aggregator_url
            aggregator_url = aggregator_url.rstrip('/')
            theApp.aggregator.base_url = aggregator_url
            g_config.set('network', 'aggregator_url', aggregator_url)
            g_db_helper.set_value('config','aggregator_url', aggregator_url)
            
        self.destroy()
    def _close_settings(self):
        """"""
        self.destroy()