def __init_widget(self):
        self.manual_table = TableAsm()

        self.manual_radio = self.__row_check(
            _("Manual"), self.manual_table, None)
        self.http_entry, self.http_spin = self.__row_entry_spin(
            _("Http Proxy"), self.manual_table, "http")
        self.https_entry, self.https_spin = self.__row_entry_spin(
            _("Https Proxy"), self.manual_table, "https")
        self.ftp_entry, self.ftp_spin = self.__row_entry_spin(
            _("FTP Proxy"), self.manual_table, "ftp")
        self.socks_entry, self.socks_spin = self.__row_entry_spin(
            _("Socks Proxy"), self.manual_table, "socks")

        self.auto_table = TableAsm(
            left_width=STANDARD_LINE, right_width=self.ENTRY_WIDTH)
        self.auto_radio = self.__row_check(
            _("Automatic"), self.auto_table, self.manual_radio)
        self.conf_entry = self.auto_table.row_input_entry(
            _("Configuration url"))

        auto_align = gtk.Alignment(0, 0, 0, 0)
        auto_align.add(self.auto_table)

        table_box = gtk.VBox(spacing=15)
        table_box.pack_start(self.manual_table, False, False)
        table_box.pack_start(auto_align, False, False)

        align = gtk.Alignment(0, 0, 0, 0)
        align.set_padding(35, 0, 0, 0)
        align.add(table_box)
        self.pack_start(align)

        apply_button = Button(_("Apply"))
        apply_button.connect("clicked", self.save_changes)
        foot_box = FootBox()
        align.connect("expose-event", self.expose_line)
        foot_box.set_buttons([apply_button])
        self.pack_end(foot_box, False, False)
        #self.connect("expose-event", self.expose_event)

        self.manual_radio.connect("toggled", self.manual_radio_selected_cb)
        self.auto_radio.connect("toggled", self.auto_radio_selected_cb)
        self.manual_table.table_build()
        self.auto_table.table_build()
    def __init_widget(self):
        self.manual_table = TableAsm()

        self.manual_radio = self.__row_check(_("Manual"), self.manual_table,
                                             None)
        self.http_entry, self.http_spin = self.__row_entry_spin(
            _("Http Proxy"), self.manual_table, "http")
        self.https_entry, self.https_spin = self.__row_entry_spin(
            _("Https Proxy"), self.manual_table, "https")
        self.ftp_entry, self.ftp_spin = self.__row_entry_spin(
            _("FTP Proxy"), self.manual_table, "ftp")
        self.socks_entry, self.socks_spin = self.__row_entry_spin(
            _("Socks Proxy"), self.manual_table, "socks")

        self.auto_table = TableAsm(left_width=STANDARD_LINE,
                                   right_width=self.ENTRY_WIDTH)
        self.auto_radio = self.__row_check(_("Automatic"), self.auto_table,
                                           self.manual_radio)
        self.conf_entry = self.auto_table.row_input_entry(
            _("Configuration url"))

        auto_align = gtk.Alignment(0, 0, 0, 0)
        auto_align.add(self.auto_table)

        table_box = gtk.VBox(spacing=15)
        table_box.pack_start(self.manual_table, False, False)
        table_box.pack_start(auto_align, False, False)

        align = gtk.Alignment(0, 0, 0, 0)
        align.set_padding(35, 0, 0, 0)
        align.add(table_box)
        self.pack_start(align)

        apply_button = Button(_("Apply"))
        apply_button.connect("clicked", self.save_changes)
        foot_box = FootBox()
        align.connect("expose-event", self.expose_line)
        foot_box.set_buttons([apply_button])
        self.pack_end(foot_box, False, False)
        #self.connect("expose-event", self.expose_event)

        self.manual_radio.connect("toggled", self.manual_radio_selected_cb)
        self.auto_radio.connect("toggled", self.auto_radio_selected_cb)
        self.manual_table.table_build()
        self.auto_table.table_build()
    def __init__(self):
        gtk.VBox.__init__(self)
        self.open_dialog = False
        self.tmp_editing_session = None

        # UI style
        style.draw_background_color(self)
        self.tree = TreeView(
            [],
            enable_drag_drop=False,
            enable_hover=True,
            enable_multiple_select=False,
        )
        self.tree.set_expand_column(3)
        self.tree.set_column_titles(
            (_("Active"), _("Application"), _("Description"), _("Exec")), )

        self.tree.set_size_request(800, -1)
        self.tree.connect("right-press-items", self.right_press_item)

        self.tree.draw_mask = self.draw_mask
        self.tree.add_items(self.get_list())
        align = gtk.Alignment(0, 0, 0, 1)
        align.set_padding(15, 0, 20, 20)
        align.add(self.tree)
        align.connect("expose-event", self.expose_line)

        add_button = Button(_("New"))
        self.delete_button = Button(_("Delete"))
        add_button.connect("clicked", self.add_autostart)
        self.delete_button.connect("clicked", self.delete_autostart)
        self.delete_button.set_sensitive(False)

        foot_box = FootBox(adjustment=15)
        foot_box.set_buttons([add_button, self.delete_button])
        self.pack_start(align, True, True)

        self.pack_end(foot_box, False, False)
        #self.pack_end(self.new_box, False, False)

        self.show_all()

        self._init_monitor()
    def __init__(self):
        gtk.VBox.__init__(self)
        self.open_dialog = False
        self.tmp_editing_session = None
        
        # UI style
        style.draw_background_color(self)
        self.tree = TreeView([],enable_drag_drop=False,
                             enable_hover=True,
                             enable_multiple_select=False,
                             )
        self.tree.set_expand_column(3)
        self.tree.set_column_titles((_("Active"), _("Application"), _("Description"), _("Exec")),)

        self.tree.set_size_request(800, -1)
        self.tree.connect("right-press-items", self.right_press_item)

        self.tree.draw_mask = self.draw_mask
        self.tree.add_items(self.get_list())
        align = gtk.Alignment(0, 0, 0, 1)
        align.set_padding(15, 0, 20, 20)
        align.add(self.tree)
        align.connect("expose-event", self.expose_line)


        add_button = Button(_("New"))
        self.delete_button = Button(_("Delete"))
        add_button.connect("clicked", self.add_autostart)
        self.delete_button.connect("clicked", self.delete_autostart)
        self.delete_button.set_sensitive(False)
        
        foot_box = FootBox(adjustment=15)
        foot_box.set_buttons([add_button, self.delete_button])
        self.pack_start(align, True, True)
        
        self.pack_end(foot_box, False, False)
        #self.pack_end(self.new_box, False, False)

        self.show_all()

        self._init_monitor()
class Region(gtk.Alignment):
    def __init__(self, connection=None):
        gtk.Alignment.__init__(self, 0, 0, 0, 0)

        #################
        self.provider_select = None
        self.connect('expose-event', self.expose_event)
        self.prop_dict = {}

        main_table = gtk.Table(2, 2, False)
        main_table.set_row_spacing(1, 10)
        main_table.set_col_spacings(4)
        self.add(main_table)

        self.country_tree = TreeView(
            enable_multiple_select=False,
            enable_drag_drop=False,
        )
        self.country_tree.set_expand_column(1)

        self.country_tree.set_size_request(365, 380)
        self.country_tree.draw_mask = self.draw_mask
        self.country_tree.connect("button-press-item", self.country_selected)
        left_box_align = gtk.Alignment(0, 0, 0, 0)
        left_box_align.set_padding(1, 1, 1, 1)
        left_box_align.add(self.country_tree)
        left_box_align.show_all()

        left_box = gtk.VBox()
        # wrap title
        country_title = TitleBar(
            app_theme.get_pixbuf("network/globe-green.png"),
            _("Country or Region:"),
            has_separator=False)
        left_box.pack_start(country_title, False, False)
        left_box.pack_start(left_box_align, False, False)

        self.provider_tree = TreeView(
            enable_multiple_select=False,
            enable_drag_drop=False,
        )
        self.provider_tree.set_expand_column(0)
        self.provider_tree.set_size_request(365, 380)
        self.provider_tree.draw_mask = self.draw_mask
        self.provider_tree.connect("button-press-item", self.provider_selected)
        right_box_align = gtk.Alignment(0, 0, 0, 0)
        right_box_align.set_padding(1, 1, 1, 1)
        right_box_align.add(self.provider_tree)
        right_box = gtk.VBox()
        # wrap title
        provider_title = TitleBar(app_theme.get_pixbuf("network/building.png"),
                                  _("Provider:"),
                                  has_separator=False)
        right_box.pack_start(provider_title, False, False)
        right_box.pack_start(right_box_align, False, False)

        main_left_align = gtk.Alignment(0, 0, 0, 0)
        main_left_align.set_padding(15, 0, 20, 0)
        main_left_align.add(left_box)
        main_table.attach(main_left_align, 0, 1, 0, 1)
        main_right_align = gtk.Alignment(0, 0, 0, 0)
        main_right_align.set_padding(15, 0, 0, 20)
        main_right_align.add(right_box)
        main_table.attach(main_right_align, 1, 2, 0, 1)

        hints = _(
            "Tips:This assistant helps you easily set up a mobile broadband connection to a cellular network."
        )

        left_box_align.connect("expose-event", self.expose_outline)
        right_box_align.connect("expose-event", self.expose_outline)

        next_button = Button("Next")
        next_button.connect("clicked", self.next_button_clicked)

        self.foot_box = FootBox()
        self.foot_box.set_buttons([next_button])
        self.foot_box.set_tip(hints)
        main_table.attach(self.foot_box, 0, 2, 1, 2)

        self.show_all()
        #self.init()

    def expose_outline(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            cr.set_source_rgb(*BORDER_COLOR)
            cr.rectangle(rect.x, rect.y, rect.width, rect.height)
            cr.stroke()

    def draw_mask(self, cr, x, y, w, h):
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(x, y, w, h)
        cr.fill()

    def expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(rect.x, rect.y, rect.width, rect.height)
        cr.fill()

    def expose_hint_background(self, widget, event):
        bg_color = color_hex_to_cairo(TREEVIEW_BG_COLOR)
        cr = widget.window.cairo_create()
        rect = widget.allocation
        cr.set_source_rgb(*bg_color)
        cr.rectangle(rect.x, rect.y, rect.width, rect.height)
        cr.fill()
        with cairo_disable_antialias(cr):
            cr.set_source_rgb(*BORDER_COLOR)
            cr.set_line_width(1)
            cr.rectangle(rect.x, rect.y, rect.width, rect.height - 1)
            cr.stroke()

    def next_button_clicked(self, widget):
        # 检查是否选择了运营商
        if not self.provider_select:
            print "provider has not selected"
            return
        try:
            self.plan_select
        except:
            self.plan_select = None

        def add_keys(settings):
            self.prop_dict = settings

        username = self.__sp.get_provider_username(self.code,
                                                   self.provider_select)
        password = self.__sp.get_provider_password(self.code,
                                                   self.provider_select)
        add_keys({
            "cdma": {
                "number": "#777",
                "username": username,
                "password": password
            }
        })
        provider_type = "cdma"
        if self.plan_select:
            self.prop_dict.pop("cdma")
            apn = self.plan_select
            index = self.__sp.get_provider_apns_name(
                self.code, self.provider_select).index(apn)
            (network_id, network_type) = self.__sp.get_provider_networks(
                self.code, self.provider_select)[index]
            add_keys({
                "gsm": {
                    "number": "*99#",
                    "username": username,
                    "password": password,
                    "apn": apn,
                    #"network_id": network_id,
                    "network_type": network_type
                }
            })
            provider_type = "gsm"

        #setting_page = nm_module.slider.get_page_by_name("setting")
        #broadband = setting_page.setting_group.get_broadband()
        if self.connection_type == None:
            new_connection = getattr(nm_module.nm_remote_settings,
                                     "new_%s_connection" % provider_type)()
            Dispatcher.emit("region-back", new_connection, self.prop_dict,
                            provider_type)

            #setting_page.sidebar.new_connection_list[provider_type].append(new_connection)
            #setting_page.init(setting_page.sidebar.new_connection_list)
            #setting_page.sidebar.set_active(new_connection)
            #broadband.set_new_values(self.prop_dict, provider_type)
        else:
            Dispatcher.emit("region-back", self.connection, self.prop_dict,
                            provider_type)

            #broadband.set_new_values(self.prop_dict, provider_type)

        nm_module.slider._slide_to_page("setting", "none")

    def init(self, connection):
        if connection == None:
            self.connection_type = None
        else:
            self.connection = connection
            mobile_type = connection.get_setting("connection").type
            self.connection_type = mobile_type
        Dispatcher.send_submodule_crumb(_("Region"), 2)

        from mm.provider import ServiceProviders
        self.__sp = ServiceProviders()
        self.country_list = self.__sp.get_country_name_list()
        self.country_tree.delete_all_items()
        self.country_tree.add_items(
            [CountryItem(_(country)) for country in self.country_list])
        # add a bottom line for last item

        code = self.__sp.get_country_from_timezone()

        self.country_codes = self.__sp.get_country_list()
        try:
            selected_country = self.country_tree.visible_items[
                self.country_codes.index(code)]
            self.country_tree.select_items([selected_country])
            self.auto_scroll_to()
            self.country_tree.emit("button-press-item", selected_country, 0, 1,
                                   1)
        except:
            pass

    def country_selected(self, widget, w, a, b, c):
        self.provider_tree.delete_all_items()
        self.code = self.country_codes[widget.select_rows[0]]
        if self.connection_type:
            self.provider_names = getattr(
                self.__sp, "get_country_%s_providers_name" %
                self.connection_type)(self.code)
        else:
            self.provider_names = self.__sp.get_country_providers_name(
                self.code)

        self.provider_select = None
        self.provider_tree.add_items(
            [Item(p, self.__sp, self.code) for p in self.provider_names])
        self.provider_tree.show_all()

    def provider_selected(self, widget, item, column, offset_x, offset_y):
        if type(item) is Item:
            self.provider_select = item.content
            self.plan_select = None
        else:
            self.plan_select = item.content

    def auto_scroll_to(self):
        vadjust = self.country_tree.scrolled_window.get_vadjustment()
        upper = vadjust.upper
        page_size = vadjust.page_size

        vadjust.set_value(
            min(upper - page_size,
                (self.country_tree.select_rows[0] - 4) * 30))
class Region(gtk.Alignment):
    def __init__(self, connection=None):
        gtk.Alignment.__init__(self, 0, 0, 0, 0)

        #################
        self.provider_select = None
        self.connect('expose-event', self.expose_event)
        self.prop_dict = {}

        main_table = gtk.Table(2, 2, False)
        main_table.set_row_spacing(1, 10)
        main_table.set_col_spacings(4)
        self.add(main_table)
        
        self.country_tree = TreeView(enable_multiple_select=False,
                                     enable_drag_drop=False,
                                     )
        self.country_tree.set_expand_column(1)

        self.country_tree.set_size_request(365, 380)
        self.country_tree.draw_mask = self.draw_mask
        self.country_tree.connect("button-press-item", self.country_selected)
        left_box_align = gtk.Alignment(0, 0, 0, 0)
        left_box_align.set_padding(1,1,1,1)
        left_box_align.add(self.country_tree)
        left_box_align.show_all()

        left_box = gtk.VBox()
        # wrap title
        country_title = TitleBar(app_theme.get_pixbuf("network/globe-green.png"),
                                 _("Country or Region:"),
                                 has_separator=False)
        left_box.pack_start(country_title, False, False)
        left_box.pack_start(left_box_align, False, False)

        self.provider_tree = TreeView(enable_multiple_select=False,
                                     enable_drag_drop=False,
                                      )
        self.provider_tree.set_expand_column(0)
        self.provider_tree.set_size_request(365, 380)
        self.provider_tree.draw_mask = self.draw_mask
        self.provider_tree.connect("button-press-item", self.provider_selected)
        right_box_align = gtk.Alignment(0, 0, 0, 0)
        right_box_align.set_padding(1,1,1,1)
        right_box_align.add(self.provider_tree)
        right_box = gtk.VBox()
        # wrap title
        provider_title = TitleBar(app_theme.get_pixbuf("network/building.png"),
                                  _("Provider:"),
                                  has_separator=False)
        right_box.pack_start(provider_title, False, False)
        right_box.pack_start(right_box_align, False, False)
        
        
        main_left_align = gtk.Alignment(0, 0, 0, 0)
        main_left_align.set_padding(15, 0, 20, 0)
        main_left_align.add(left_box)
        main_table.attach(main_left_align, 0, 1, 0, 1)
        main_right_align = gtk.Alignment(0, 0, 0, 0)
        main_right_align.set_padding(15, 0, 0, 20)
        main_right_align.add(right_box)
        main_table.attach(main_right_align, 1, 2, 0, 1)

        hints = _("Tips:This assistant helps you easily set up a mobile broadband connection to a cellular network.")
            
        left_box_align.connect("expose-event", self.expose_outline)
        right_box_align.connect("expose-event", self.expose_outline)

        next_button = Button("Next")
        next_button.connect("clicked", self.next_button_clicked)
        
        self.foot_box = FootBox()
        self.foot_box.set_buttons([next_button])
        self.foot_box.set_tip(hints)
        main_table.attach(self.foot_box, 0, 2, 1, 2)

        self.show_all()
        #self.init()

    def expose_outline(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        with cairo_disable_antialias(cr):
            cr.set_line_width(1)
            cr.set_source_rgb(*BORDER_COLOR)
            cr.rectangle(rect.x, rect.y, rect.width , rect.height )
            cr.stroke()

    def draw_mask(self, cr, x, y, w, h):
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(x, y, w, h)
        cr.fill()

    def expose_event(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        cr.set_source_rgb( 1, 1, 1) 
        cr.rectangle(rect.x, rect.y, rect.width, rect.height)
        cr.fill()

    def expose_hint_background(self, widget, event):
        bg_color = color_hex_to_cairo(TREEVIEW_BG_COLOR)
        cr = widget.window.cairo_create()
        rect = widget.allocation
        cr.set_source_rgb(*bg_color) 
        cr.rectangle(rect.x, rect.y, rect.width, rect.height)
        cr.fill()
        with cairo_disable_antialias(cr):
            cr.set_source_rgb(*BORDER_COLOR)
            cr.set_line_width(1)
            cr.rectangle(rect.x , rect.y, rect.width , rect.height -1)
            cr.stroke()


    def next_button_clicked(self, widget):
        # 检查是否选择了运营商
        if not self.provider_select:
            print "provider has not selected"
            return
        try:
            self.plan_select
        except:
            self.plan_select = None
        
        def add_keys(settings):
            self.prop_dict = settings
            
        username = self.__sp.get_provider_username(self.code, self.provider_select)
        password = self.__sp.get_provider_password(self.code, self.provider_select)
        add_keys({"cdma": {
                 "number": "#777",
                 "username": username,
                 "password": password}})
        provider_type = "cdma"
        if self.plan_select:
            self.prop_dict.pop("cdma")
            apn = self.plan_select
            index = self.__sp.get_provider_apns_name(self.code, self.provider_select).index(apn)
            (network_id, network_type) = self.__sp.get_provider_networks(self.code, self.provider_select)[index]
            add_keys({"gsm":{
                     "number": "*99#",
                     "username": username,
                     "password": password,
                     "apn": apn,
                     #"network_id": network_id,
                     "network_type": network_type}})
            provider_type = "gsm"

        #setting_page = nm_module.slider.get_page_by_name("setting")
        #broadband = setting_page.setting_group.get_broadband()
        if self.connection_type == None:
            new_connection = getattr(nm_module.nm_remote_settings, "new_%s_connection"%provider_type)()
            Dispatcher.emit("region-back", new_connection, self.prop_dict, provider_type)

            #setting_page.sidebar.new_connection_list[provider_type].append(new_connection)
            #setting_page.init(setting_page.sidebar.new_connection_list)
            #setting_page.sidebar.set_active(new_connection)
            #broadband.set_new_values(self.prop_dict, provider_type)
        else:
            Dispatcher.emit("region-back", self.connection, self.prop_dict, provider_type)

            #broadband.set_new_values(self.prop_dict, provider_type)

        nm_module.slider._slide_to_page("setting", "none")

    def init(self, connection):
        if connection == None:
            self.connection_type = None
        else:
            self.connection = connection
            mobile_type = connection.get_setting("connection").type
            self.connection_type = mobile_type
        Dispatcher.send_submodule_crumb(_("Region"), 2)

        from mm.provider import ServiceProviders
        self.__sp = ServiceProviders()
        self.country_list = self.__sp.get_country_name_list()
        self.country_tree.delete_all_items()
        self.country_tree.add_items([CountryItem(_(country)) for country in self.country_list])
        # add a bottom line for last item

        code = self.__sp.get_country_from_timezone()

        self.country_codes = self.__sp.get_country_list()
        try:
            selected_country = self.country_tree.visible_items[self.country_codes.index(code)]
            self.country_tree.select_items([selected_country])
            self.auto_scroll_to()
            self.country_tree.emit("button-press-item", selected_country, 0, 1, 1)
        except:
            pass

    def country_selected(self, widget, w, a, b, c):
        self.provider_tree.delete_all_items()
        self.code = self.country_codes[widget.select_rows[0]]
        if self.connection_type:
            self.provider_names = getattr(self.__sp, "get_country_%s_providers_name"%self.connection_type)(self.code)
        else:
            self.provider_names = self.__sp.get_country_providers_name(self.code)
        
        self.provider_select = None
        self.provider_tree.add_items([Item(p, self.__sp, self.code) for p in self.provider_names])
        self.provider_tree.show_all()

    def provider_selected(self, widget, item, column, offset_x, offset_y):
        if type(item) is Item:
            self.provider_select = item.content
            self.plan_select = None
        else:
            self.plan_select = item.content

    def auto_scroll_to(self):
        vadjust = self.country_tree.scrolled_window.get_vadjustment()
        upper = vadjust.upper
        page_size = vadjust.page_size

        vadjust.set_value(min(upper - page_size, (self.country_tree.select_rows[0]- 4)*30))