class BluetoothReplyDialog(DialogBox):
    DIALOG_MASK_SINGLE_PAGE = 0

    def __init__(self, message, default_width=300, default_height=140, is_succeed=True):
        DialogBox.__init__(self, "", default_width, default_height, self.DIALOG_MASK_SINGLE_PAGE)

        self.hbox = gtk.HBox()
        self.image_align = gtk.Alignment()
        self.image_align.set(0, 0, 0, 0)
        self.image_align.set_padding(0, 0, 20, 0)
        self.image_box = ImageBox(app_theme.get_pixbuf("bluetooth/succeed.png"))
        if not is_succeed:
            self.image_box = ImageBox(app_theme.get_pixbuf("bluetooth/failed.png"))
        self.image_align.add(self.image_box)
        self.message_align = gtk.Alignment()
        self.message_align.set(0, 0, 0, 0)
        self.message_align.set_padding(20, 0, 10, 0)
        if not is_succeed:
            self.message_align.set_padding(0, 0, 10, 0)
        self.message_label = Label(message, wrap_width = 200)
        self.message_align.add(self.message_label)
        self.hbox.pack_start(self.image_align)
        self.hbox.pack_start(self.message_align)
        self.confirm_align = gtk.Alignment()
        self.confirm_align.set(0, 0, 0, 0)
        self.confirm_align.set_padding(20, 0, 200, 0)
        self.confirm_button = Button(_("Ok"))
        self.confirm_button.set_size_request(70, WIDGET_HEIGHT)
        self.confirm_button.connect("clicked", lambda widget : self.destroy())
        self.confirm_align.add(self.confirm_button)

        self.body_box.pack_start(self.hbox, False, False)
        self.body_box.pack_start(self.confirm_align, False, False)
    def add_button(self, add_button):
        container_remove_all(self.buttons_align.get_children()[0])

        self.__setup_reset_button()
        button = Button(add_button)
        button.set_size_request(self.button_width, WIDGET_HEIGHT)
        button.connect("clicked", self.__add_button_clicked, add_button)
        self.buttons_list = []
        self.buttons_list.append(button)
        self.buttons_list.append(self.reset_button)
        self.buttons_align = self.__setup_buttons_align(self.buttons_list)
        self.right_box.pack_start(self.buttons_align)
    def add_button(self, add_button):
        container_remove_all(self.buttons_align.get_children()[0])

        self.__setup_reset_button()
        button = Button(add_button)
        button.set_size_request(self.button_width, WIDGET_HEIGHT)
        button.connect("clicked", self.__add_button_clicked, add_button)
        self.buttons_list = []
        self.buttons_list.append(button)
        self.buttons_list.append(self.reset_button)
        self.buttons_align = self.__setup_buttons_align(self.buttons_list)        
        self.right_box.pack_start(self.buttons_align)
class BluetoothProgressDialog(DialogBox):
    DIALOG_MASK_SINGLE_PAGE = 0

    def __init__(self, default_width=300, default_height=160, cancel_cb=None):
        DialogBox.__init__(self, "", default_width, default_height, self.DIALOG_MASK_SINGLE_PAGE)

        self.cancel_cb = cancel_cb

        self.message_align = gtk.Alignment()
        self.message_align.set(0, 0, 0, 0)
        self.message_align.set_padding(0, 0, 10, 0)
        self.message_label = Label("", label_width=300)
        self.message_align.add(self.message_label)
        self.progress_align = gtk.Alignment()
        self.progress_align.set(0, 0, 0, 0)
        self.progress_align.set_padding(20, 0, 10, 10)
        self.progress_bar = ProgressBar()
        self.progress_bar.set_size_request(default_width, -1)
        self.progress_align.add(self.progress_bar)
        self.percentage_align = gtk.Alignment()
        self.percentage_align.set(0, 0, 0, 0)
        self.percentage_align.set_padding(10, 0, 140, 0)
        self.percentage_label = Label("0%", label_width=300)
        self.percentage_label.set_size_request(default_width, -1)
        self.percentage_align.add(self.percentage_label)
        self.cancel_align = gtk.Alignment()
        self.cancel_align.set(0, 0, 0, 0)
        self.cancel_align.set_padding(20, 0, 200, 0)
        self.cancel_button = Button(_("Cancel"))
        self.cancel_button.set_size_request(70, WIDGET_HEIGHT)
        self.cancel_button.connect("clicked", self.__on_cancel_button_clicked)
        self.cancel_align.add(self.cancel_button)

        self.body_box.pack_start(self.message_align, False, False)
        self.body_box.pack_start(self.progress_align, False, False)
        self.body_box.pack_start(self.percentage_align, False, False)
        self.body_box.pack_start(self.cancel_align)

    def set_message(self, message):
        self.message_label.set_text(message)

    def set_progress(self, progress):
        self.progress_bar.set_progress(progress)
        self.percentage_label.set_text(_("Sent %d") % progress + "%")

    def __on_cancel_button_clicked(self, widget):
        if self.cancel_cb:
            self.cancel_cb()
            self.destroy()
Exemple #5
0
class Sections(gtk.Alignment):

    def __init__(self, connection, set_button, settings_obj=None):
        gtk.Alignment.__init__(self, 0, 0 ,0, 0)
        self.set_padding(35, 0, 20, 0)

        self.main_box = gtk.VBox()
        self.tab_name = "sfds"
        basic = SettingSection(_("Basic"))

        self.button = Button(_("Advanced"))
        self.button.set_size_request(50, 22)
        self.button.connect("clicked", self.show_more_options)
        self.broadband = SettingSection(_("Broadband"), always_show=True)
        self.ipv4 = SettingSection(_("IPv4 settings"), always_show=True)
        self.ppp = SettingSection(_("PPP"), always_show=True)
        align = gtk.Alignment(0, 0, 0, 0)
        align.set_padding(0, 0, 225, 0)
        align.add(self.button)
        
        self.broadband = Broadband(connection, set_button, settings_obj)
        basic.load([self.broadband, align])
        self.ipv4.load([IPV4Conf(connection, set_button, settings_obj=settings_obj)])
        self.ppp.load([PPPConf(connection, set_button, settings_obj)])

        self.space = gtk.HBox()
        self.space.set_size_request(-1 ,30)

        self.main_box.pack_start(basic, False, False)

        self.add(self.main_box)

    def show_more_options(self, widget):
        widget.destroy()
        #self.main_box.pack_start(self.space, False, False)
        self.main_box.pack_start(self.ipv4, False, False)
        self.main_box.pack_start(self.ppp, False, False, 15)
Exemple #6
0
class DetailPage(gtk.VBox):
    '''
    class docs
    '''
    def __init__(self):
        '''
        init docs
        '''
        gtk.VBox.__init__(self)

        self.__background_settings = deepin_gsettings.new(
            "com.deepin.dde.background")

        self.draw_title_background = self.draw_tab_title_background
        self.theme = None

        self.wallpaper_box = gtk.VBox()
        self.window_theme_box = gtk.VBox()
        self.wallpaper_view = WallpaperView(padding_x=30,
                                            padding_y=ITEM_PADDING_Y)
        self.wallpaper_view_sw = self.wallpaper_view.get_scrolled_window()
        self.wallpaper_view_sw.set_size_request(-1, 426)

        position_group, self.position_combobox = get_combo_group(
            _("Position"), DRAW_COMBO_ITEM, self.on_position_combox_selected)
        time_group, self.time_combobox = get_combo_group(
            _("Duration"), TIME_COMBO_ITEM, self.on_time_combox_selected)

        self.__is_random = True
        if self.__background_settings.get_int("background-duration") == 0:
            self.__is_random = False
        self.unorder_play, self.random_toggle = get_toggle_group(
            _("Random"), self.__on_random_toggled, self.__is_random)
        self.button_align = gtk.Alignment()
        self.button_box = gtk.HBox(spacing=5)
        self.select_all_button = Button(_("Select all"))
        self.select_all_button.set_size_request(80, WIDGET_HEIGHT)
        self.select_all_button.connect("clicked", self.__on_select_all)
        self.delete_button = Button(_("Delete"))
        self.delete_button.set_size_request(80, WIDGET_HEIGHT)
        self.delete_button.connect("clicked", self.__on_delete)
        self.button_box.pack_start(self.select_all_button, False, False)
        self.button_box.pack_start(self.delete_button, False, False)
        self.button_align.add(self.button_box)

        self.action_bar = gtk.HBox(spacing=26)
        self.action_bar.pack_start(position_group, False, False)
        self.action_bar.pack_start(time_group, False, False)
        self.action_bar.pack_start(self.unorder_play, False, False)
        self.action_bar.pack_end(self.button_align, False, False)
        action_bar_align = gtk.Alignment()
        action_bar_align.set_size_request(-1, STATUS_HEIGHT)
        action_bar_align.set_padding(5, 5, 50, 20)
        action_bar_align.add(self.action_bar)

        self.wallpaper_box.pack_start(self.wallpaper_view_sw, True, True)
        self.wallpaper_box.pack_start(action_bar_align, False, False)

        self.pack_start(self.wallpaper_box, False, False)

        event_manager.add_callback("select-wallpaper",
                                   self.on_wallpaper_select)
        event_manager.add_callback("apply-wallpaper",
                                   self.__on_wallpaper_apply)
        event_manager.add_callback("add-wallpapers", self.__on_add_wallpapers)

    def __random_enable(self):
        self.time_combobox.set_sensitive(True)
        self.unorder_play.set_child_visible(True)
        self.random_toggle.set_child_visible(True)
        self.random_toggle.set_active(self.theme.get_background_random_mode())

    def __random_disable(self):
        self.time_combobox.set_sensitive(False)
        self.unorder_play.set_child_visible(False)
        self.random_toggle.set_child_visible(False)
        self.random_toggle.set_active(self.theme.get_background_random_mode())

    def on_wallpaper_select(self, name, obj, select_item):
        if self.wallpaper_view.is_randomable():
            self.__random_enable()
        else:
            self.__random_disable()

        if self.wallpaper_view.is_select_all():
            self.select_all_button.set_label(_("Clear all"))
        else:
            self.select_all_button.set_label(_("Select all"))
        self.select_all_button.set_size_request(80, WIDGET_HEIGHT)

    def __on_wallpaper_apply(self, name, obj, select_item):
        self.__random_disable()

        if self.wallpaper_view.is_select_all():
            self.select_all_button.set_label(_("Clear all"))
        else:
            self.select_all_button.set_label(_("Select all"))
        self.select_all_button.set_size_request(80, WIDGET_HEIGHT)

    def __on_select_all(self, widget):
        self.wallpaper_view.select_all()
        if self.wallpaper_view.is_select_all():
            self.select_all_button.set_label(_("Clear all"))
        else:
            self.select_all_button.set_label(_("Select all"))
        self.select_all_button.set_size_request(80, WIDGET_HEIGHT)

        if self.wallpaper_view.is_randomable():
            self.__random_enable()
        else:
            self.__random_disable()

    def __on_delete(self, widget):
        event_manager.emit("switch-to-deletepage", self.theme)

    def __on_random_toggled(self, widget):
        self.theme.set_background_random_mode(widget.get_active())

    def draw_tab_title_background(self, cr, widget):
        rect = widget.allocation
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(0, 0, rect.width, rect.height - 1)
        cr.fill()

    def on_position_combox_selected(self, widget, label, data, index):
        self.theme.set_background_draw_mode(data)
        self.theme.save()

    def on_time_combox_selected(self, widget, label, data, index):
        self.theme.set_background_duration(data)
        self.theme.save()

    def __set_delete_button_visible(self):
        is_editable = self.wallpaper_view.is_editable()
        if is_editable:
            self.button_align.set_padding(0, 0, 113, 5)
        else:
            self.button_align.set_padding(0, 0, 204, 5)

        self.delete_button.set_child_visible(is_editable)

    def __on_add_wallpapers(self, name, obj, image_paths):
        if len(self.wallpaper_view.items) < 2:
            self.select_all_button.set_child_visible(False)
        else:
            self.select_all_button.set_child_visible(True)
            self.select_all_button.set_label(_("Select all"))

        self.__set_delete_button_visible()

    def set_theme(self, theme):
        self.theme = theme

        draw_mode = self.theme.get_background_draw_mode()
        item_index = 0
        for index, item in enumerate(DRAW_COMBO_ITEM):
            if draw_mode == item[-1]:
                item_index = index

        self.position_combobox.set_select_index(item_index)

        duration = self.theme.get_background_duration()
        item_index = 0
        for index, item in enumerate(TIME_COMBO_ITEM):
            if duration == item[-1]:
                item_index = index

        self.time_combobox.set_select_index(item_index)
        self.wallpaper_view.set_theme(theme)

        self.__set_delete_button_visible()

        if self.wallpaper_view.is_randomable():
            self.__random_enable()
        else:
            self.__random_disable()

        if len(self.wallpaper_view.items) < 2:
            self.select_all_button.set_child_visible(False)
        else:
            self.select_all_button.set_child_visible(True)

        if self.wallpaper_view.is_select_all():
            self.select_all_button.set_label(_("Clear all"))
            self.select_all_button.set_size_request(80, WIDGET_HEIGHT)

    def draw_mask(self, cr, x, y, w, h):
        '''
        Draw mask interface.
        
        @param cr: Cairo context.
        @param x: X coordiante of draw area.
        @param y: Y coordiante of draw area.
        @param w: Width of draw area.
        @param h: Height of draw area.
        '''
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(x, y, w, h)
        cr.fill()
class FaceRecordPage(gtk.VBox):
    def __init__(self, account_setting):
        gtk.VBox.__init__(self)
        self.account_setting = account_setting
        
        self.camera_pixbuf = app_theme.get_pixbuf("account/camera.png").get_pixbuf()
        self.error_pixbuf = app_theme.get_pixbuf("account/error.png").get_pixbuf()
        self.success_pixbuf = app_theme.get_pixbuf("account/success.png").get_pixbuf()

        self.camera_box_align = gtk.Alignment(0.5, 0, 0, 0)
        self.camera_box = gtk.VBox()
        self.camera_box.set_size_request(CAMERA_BOX_SIZE, CAMERA_BOX_SIZE)
        self.camera_box.connect("expose-event", self.__camera_box_expose)
        self.camera_box_align.add(self.camera_box)

        self.under_camera_box = gtk.VBox(spacing=10)
        self.under_camera_box_align = gtk.Alignment(0.5, 0, 0, 0)
        self.under_camera_box_align.set_padding(WIDGET_SPACING, 0, 0, 0)
        self.under_camera_box_align.add(self.under_camera_box)
        self.__init_widgets()
        if Webcam.has_device():
            self.under_camera_box.pack_start(self.start_record_button)
        else:
            self.under_camera_box.pack_start(self.no_device_warning)

        self.pack_start(self.camera_box_align, False, False)
        self.pack_start(self.under_camera_box_align, False, False)

    def __init_widgets(self):
        self.start_record_button = Button(_("Start"))
        self.start_record_button.set_size_request(CAMERA_BOX_SIZE, 25)
        self.start_record_button.connect("clicked", self.__start_record_clicked)
        
        self.no_device_warning = Label(_("Please plug in or enable your camera"), label_width=300, text_x_align=pango.ALIGN_CENTER)
        self.keep_few_minutes = Label(_("Please keep still for 5 seconds"), label_width=300, text_x_align=pango.ALIGN_CENTER)
        # self.success = Label(_("Your face has been successfully recorded"), label_width=300, text_x_align=pango.ALIGN_CENTER)
        self.fail = Label(_("Failed to record your face"), label_width=300, text_x_align=pango.ALIGN_CENTER)
        
        self.success = gtk.Alignment(0.5, 0.5, 0, 0)
        self.success.set_size_request(300, -1)
        self.success_img = gtk.Image()
        self.success_img.set_from_pixbuf(self.success_pixbuf)
        self.success_box = gtk.HBox()
        self.success_box.pack_start(self.success_img, False, False, 5)
        self.success_box.pack_start(Label(_("Your face has been successfully recorded")))
        self.success.add(self.success_box)

    def refresh(self):
        container_remove_all(self.camera_box)
        container_remove_all(self.under_camera_box)
        if Webcam.has_device():
            self.under_camera_box.pack_start(self.start_record_button)
        else:
            self.under_camera_box.pack_start(self.no_device_warning)        

    def __start_record_clicked(self, widget):
        container_remove_all(self.under_camera_box)
        self.under_camera_box.pack_start(self.keep_few_minutes)
        
        self.webcam_align = gtk.Alignment(0, 0.5, 0, 0)
        self.webcam_align.set_padding(5, 5, 5, 5)
        if not hasattr(self.account_setting, "record_webcam"):
            self.account_setting.record_webcam = Webcam()
            self.account_setting.record_webcam.set_size_request(WEBCAM_SIZE, min(WEBCAM_SIZE, 240))
            self.account_setting.record_webcam.create_video_pipeline(320, 240)
        self.webcam_align.add(self.account_setting.record_webcam)
        container_remove_all(self.camera_box)
        self.camera_box.add(self.webcam_align)
        self.account_setting.record_webcam.play()
        gobject.timeout_add(2000, self.__do_save_photo, 0)
        gobject.timeout_add(2500, self.__do_save_photo, 1)
        gobject.timeout_add(3000, self.__do_save_photo, 2)
        gobject.timeout_add(3500, self.__do_save_photo, 3)
        
        gobject.timeout_add(4000, self.__do_action)
        
    def __do_save_photo(self, num):
        pixbuf = self.account_setting.record_webcam.get_snapshot()
        path = "/tmp/face_recognition_%s.png" % num
        pixbuf.save(path, "png")
        
    # def __do_detection(self):
        
    #     def recognition_process(pixbuf):
    #         path = "/tmp/face_recognition_%s.png" % thread.get_ident()
    #         pixbuf.save(path, "png")
    #         result = facepp.detection.detect(img=File(path), mode="oneface")
    #         print result
    #         if result["face"]:
    #             try:
    #                 facepp.person.create(person_name=get_person_name())
    #             except:
    #                 pass
    #             facepp.person.add_face(person_name=get_person_name(), face_id=result["face"][0]["face_id"])
        
    #     pixbuf = self.account_setting.record_webcam.get_snapshot()
    #     # gtk.gdk.threads_enter()
    #     # Thread(target=recognition_process, args=[pixbuf]).start()
    #     # gtk.gdk.threads_leave()
    #     recognition_process(pixbuf)

    def __do_action(self):
        success = 0
        
        try:
            facepp.person.delete(person_name=get_person_name())
        except:
            pass
        
        try:
            facepp.person.create(person_name=get_person_name())
            
            for i in xrange(3):
                result = facepp.detection.detect(img=File("/tmp/face_recognition_%s.png" % i), 
                                                 mode="oneface")
                if result["face"]:
                    add_result = facepp.person.add_face(person_name=get_person_name(), 
                                                        face_id=result["face"][0]["face_id"])
                    print "add_result, ", add_result
                    success += 1
        except Exception, e:
            print e
        
        self.snapshot_pixbuf = self.account_setting.record_webcam.get_snapshot()
        self.account_setting.record_webcam.stop()
        self.webcam_align.remove(self.account_setting.record_webcam)

        self.scanning_box = ScanningBox(self.snapshot_pixbuf)
        self.scanning_box.set_size_request(WEBCAM_SIZE, WEBCAM_SIZE)
        self.webcam_align.add(self.scanning_box)
        self.webcam_align.show_all()
        
        def things_after_scanning():
            container_remove_all(self.under_camera_box)
            self.try_again_button = Button(_("Try Again"))
            self.try_again_button.set_size_request(CAMERA_BOX_SIZE, 25)
            self.try_again_button.connect("clicked", self.__start_record_clicked)
            start_record_button_align = gtk.Alignment(0.5, 0.5, 0, 0)
            start_record_button_align.add(self.try_again_button)
            if success > 0:
                facepp.train.verify(person_name=get_person_name())
                self.under_camera_box.pack_start(self.success)
            else:
                self.under_camera_box.pack_start(self.fail)
            self.under_camera_box.pack_start(start_record_button_align)
        gobject.timeout_add(2000, things_after_scanning)
class DetailPage(gtk.VBox):
    """
    class docs
    """

    def __init__(self):
        """
        init docs
        """
        gtk.VBox.__init__(self)

        self.__background_settings = deepin_gsettings.new("com.deepin.dde.background")

        self.draw_title_background = self.draw_tab_title_background
        self.theme = None

        self.wallpaper_box = gtk.VBox()
        self.window_theme_box = gtk.VBox()
        self.wallpaper_view = WallpaperView(padding_x=30, padding_y=ITEM_PADDING_Y)
        self.wallpaper_view_sw = self.wallpaper_view.get_scrolled_window()
        self.wallpaper_view_sw.set_size_request(-1, 426)

        position_group, self.position_combobox = get_combo_group(
            _("Position"), DRAW_COMBO_ITEM, self.on_position_combox_selected
        )
        time_group, self.time_combobox = get_combo_group(_("Duration"), TIME_COMBO_ITEM, self.on_time_combox_selected)

        self.__is_random = True
        if self.__background_settings.get_int("background-duration") == 0:
            self.__is_random = False
        self.unorder_play, self.random_toggle = get_toggle_group(
            _("Random"), self.__on_random_toggled, self.__is_random
        )
        self.button_align = gtk.Alignment()
        self.button_box = gtk.HBox(spacing=5)
        self.select_all_button = Button(_("Select all"))
        self.select_all_button.set_size_request(80, WIDGET_HEIGHT)
        self.select_all_button.connect("clicked", self.__on_select_all)
        self.delete_button = Button(_("Delete"))
        self.delete_button.set_size_request(80, WIDGET_HEIGHT)
        self.delete_button.connect("clicked", self.__on_delete)
        self.button_box.pack_start(self.select_all_button, False, False)
        self.button_box.pack_start(self.delete_button, False, False)
        self.button_align.add(self.button_box)

        self.action_bar = gtk.HBox(spacing=26)
        self.action_bar.pack_start(position_group, False, False)
        self.action_bar.pack_start(time_group, False, False)
        self.action_bar.pack_start(self.unorder_play, False, False)
        self.action_bar.pack_end(self.button_align, False, False)
        action_bar_align = gtk.Alignment()
        action_bar_align.set_size_request(-1, STATUS_HEIGHT)
        action_bar_align.set_padding(5, 5, 50, 20)
        action_bar_align.add(self.action_bar)

        self.wallpaper_box.pack_start(self.wallpaper_view_sw, True, True)
        self.wallpaper_box.pack_start(action_bar_align, False, False)

        self.pack_start(self.wallpaper_box, False, False)

        event_manager.add_callback("select-wallpaper", self.on_wallpaper_select)
        event_manager.add_callback("apply-wallpaper", self.__on_wallpaper_apply)
        event_manager.add_callback("add-wallpapers", self.__on_add_wallpapers)

    def __random_enable(self):
        self.time_combobox.set_sensitive(True)
        self.unorder_play.set_child_visible(True)
        self.random_toggle.set_child_visible(True)
        self.random_toggle.set_active(self.theme.get_background_random_mode())

    def __random_disable(self):
        self.time_combobox.set_sensitive(False)
        self.unorder_play.set_child_visible(False)
        self.random_toggle.set_child_visible(False)
        self.random_toggle.set_active(self.theme.get_background_random_mode())

    def on_wallpaper_select(self, name, obj, select_item):
        if self.wallpaper_view.is_randomable():
            self.__random_enable()
        else:
            self.__random_disable()

        if self.wallpaper_view.is_select_all():
            self.select_all_button.set_label(_("Clear all"))
        else:
            self.select_all_button.set_label(_("Select all"))
        self.select_all_button.set_size_request(80, WIDGET_HEIGHT)

    def __on_wallpaper_apply(self, name, obj, select_item):
        self.__random_disable()

        if self.wallpaper_view.is_select_all():
            self.select_all_button.set_label(_("Clear all"))
        else:
            self.select_all_button.set_label(_("Select all"))
        self.select_all_button.set_size_request(80, WIDGET_HEIGHT)

    def __on_select_all(self, widget):
        self.wallpaper_view.select_all()
        if self.wallpaper_view.is_select_all():
            self.select_all_button.set_label(_("Clear all"))
        else:
            self.select_all_button.set_label(_("Select all"))
        self.select_all_button.set_size_request(80, WIDGET_HEIGHT)

        if self.wallpaper_view.is_randomable():
            self.__random_enable()
        else:
            self.__random_disable()

    def __on_delete(self, widget):
        event_manager.emit("switch-to-deletepage", self.theme)

    def __on_random_toggled(self, widget):
        self.theme.set_background_random_mode(widget.get_active())

    def draw_tab_title_background(self, cr, widget):
        rect = widget.allocation
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(0, 0, rect.width, rect.height - 1)
        cr.fill()

    def on_position_combox_selected(self, widget, label, data, index):
        self.theme.set_background_draw_mode(data)
        self.theme.save()

    def on_time_combox_selected(self, widget, label, data, index):
        self.theme.set_background_duration(data)
        self.theme.save()

    def __set_delete_button_visible(self):
        is_editable = self.wallpaper_view.is_editable()
        if is_editable:
            self.button_align.set_padding(0, 0, 113, 5)
        else:
            self.button_align.set_padding(0, 0, 204, 5)

        self.delete_button.set_child_visible(is_editable)

    def __on_add_wallpapers(self, name, obj, image_paths):
        if len(self.wallpaper_view.items) < 2:
            self.select_all_button.set_child_visible(False)
        else:
            self.select_all_button.set_child_visible(True)
            self.select_all_button.set_label(_("Select all"))

        self.__set_delete_button_visible()

    def set_theme(self, theme):
        self.theme = theme

        draw_mode = self.theme.get_background_draw_mode()
        item_index = 0
        for index, item in enumerate(DRAW_COMBO_ITEM):
            if draw_mode == item[-1]:
                item_index = index

        self.position_combobox.set_select_index(item_index)

        duration = self.theme.get_background_duration()
        item_index = 0
        for index, item in enumerate(TIME_COMBO_ITEM):
            if duration == item[-1]:
                item_index = index

        self.time_combobox.set_select_index(item_index)
        self.wallpaper_view.set_theme(theme)

        self.__set_delete_button_visible()

        if self.wallpaper_view.is_randomable():
            self.__random_enable()
        else:
            self.__random_disable()

        if len(self.wallpaper_view.items) < 2:
            self.select_all_button.set_child_visible(False)
        else:
            self.select_all_button.set_child_visible(True)

        if self.wallpaper_view.is_select_all():
            self.select_all_button.set_label(_("Clear all"))
            self.select_all_button.set_size_request(80, WIDGET_HEIGHT)

    def draw_mask(self, cr, x, y, w, h):
        """
        Draw mask interface.
        
        @param cr: Cairo context.
        @param x: X coordiante of draw area.
        @param y: Y coordiante of draw area.
        @param w: Width of draw area.
        @param h: Height of draw area.
        """
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(x, y, w, h)
        cr.fill()
class DeletePage(gtk.VBox):
    '''
    class docs
    '''
    def __init__(self):
        '''
        init docs
        '''
        gtk.VBox.__init__(self)

        self.draw_title_background = self.draw_tab_title_background
        self.theme = None

        self.delete_view = DeleteView(padding_x=30, padding_y=ITEM_PADDING_Y)
        self.delete_view_sw = self.delete_view.get_scrolled_window()

        self.action_align = gtk.Alignment()
        self.action_align.set_padding(5, 5, 510, 5)
        self.action_box = gtk.HBox(spacing=10)
        self.back_button = Button(_("Back"))
        self.back_button.set_size_request(80, WIDGET_HEIGHT)
        self.back_button.connect("clicked", self.__on_back)
        self.select_all_button = Button(_("Select all"))
        self.select_all_button.set_size_request(80, WIDGET_HEIGHT)
        self.select_all_button.connect("clicked", self.__on_select_all)
        self.delete_button = Button(_("Delete"))
        self.delete_button.set_size_request(80, WIDGET_HEIGHT)
        self.delete_button.connect("clicked", self.__on_delete)
        self.action_box.pack_start(self.select_all_button, False, False)
        self.action_box.pack_start(self.delete_button, False, False)
        self.action_box.pack_start(self.back_button, False, False)
        self.action_align.add(self.action_box)

        self.pack_start(self.delete_view_sw, True, True)
        self.pack_start(self.action_align, False, False)

        event_manager.add_callback("select-delete-wallpaper",
                                   self.__on_select_delete_wallpaper)

    def __on_back(self, widget):
        event_manager.emit("back-to-detailpage", self.theme)

    def __on_select_delete_wallpaper(self, name, obj, select_item):
        if self.delete_view.is_select_all():
            self.select_all_button.set_label(_("Clear all"))
        else:
            self.select_all_button.set_label(_("Select all"))
        self.select_all_button.set_size_request(80, WIDGET_HEIGHT)

    def __on_select_all(self, widget):
        self.delete_view.select_all()
        if self.delete_view.is_select_all():
            self.select_all_button.set_label(_("Clear all"))
        else:
            self.select_all_button.set_label(_("Select all"))
        self.select_all_button.set_size_request(80, WIDGET_HEIGHT)

    def __delete_confirm(self):
        self.delete_view.delete_wallpaper()

    def __on_delete(self, widget):
        if self.delete_view.is_deletable():
            dlg = ConfirmDialog(_("Delete Wallpaper"),
                                _("Are you sure delete wallpaper?"), 300, 100,
                                lambda: self.__delete_confirm(), None, True,
                                CONTENT_FONT_SIZE)
            dlg.show_all()

    def draw_tab_title_background(self, cr, widget):
        rect = widget.allocation
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(0, 0, rect.width, rect.height - 1)
        cr.fill()

    def set_theme(self, theme):
        self.theme = theme
        self.delete_view.set_theme(self.theme)
        self.select_all_button.set_label(_("Select all"))
        self.select_all_button.set_size_request(80, WIDGET_HEIGHT)

    def draw_mask(self, cr, x, y, w, h):
        '''
        Draw mask interface.
        
        @param cr: Cairo context.
        @param x: X coordiante of draw area.
        @param y: Y coordiante of draw area.
        @param w: Width of draw area.
        @param h: Height of draw area.
        '''
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(x, y, w, h)
        cr.fill()
Exemple #10
0
class Login(Window):
    def __init__(self):
        Window.__init__(self, enable_resize=True)
        self.set_position(gtk.WIN_POS_CENTER)
        self.set_default_size(290, 512)
        titlebar = Titlebar(["min", "max", "close"], app_name="Baidu Hi for Linux")
        titlebar.min_button.connect("clicked", lambda w: self.min_window())
        titlebar.max_button.connect("clicked", lambda w: self.toggle_max_window())
        titlebar.close_button.connect("clicked", lambda w: gtk.main_quit())
        self.add_move_event(titlebar.drag_box)
        self.add_toggle_event(titlebar.drag_box)
        
        banner_image = gtk.image_new_from_file(get_banner_image())
        banner_box = set_widget_gravity(banner_image, (0,0,0,0), (10, 0, 0, 0))
        user_box, self.user_entry = self.create_combo_entry("帐号:")
        passwd_box, self.passwd_entry = self.create_combo_entry("密码:")
        self.remember_passwd = CheckButton("记住密码")
        self.automatic_login = CheckButton("自动登录")
        self.status_box, self.status_combo_box = self.create_combo_widget("状态:", 
                                                     [(key, None) for key in "在线 忙碌 离开 隐身".split()],
                                                     0)
        
        check_box = gtk.HBox(spacing=10)
        check_box.pack_start(self.remember_passwd, False, False)
        check_box.pack_start(self.automatic_login, False, False)
        
        body_table = gtk.Table(5, 1)
        body_table.set_row_spacings(10)
        body_table.attach(banner_box, 0, 1, 0, 1, xoptions=gtk.FILL, yoptions=gtk.FILL)
        body_table.attach(user_box, 0, 1, 1, 2, xoptions=gtk.FILL, yoptions=gtk.FILL, xpadding=8)
        body_table.attach(passwd_box, 0, 1, 2, 3, xoptions=gtk.FILL, yoptions=gtk.FILL, xpadding=8)
        # body_table.attach(self.status_box, 0, 1, 3, 4, xoptions=gtk.FILL, yoptions=gtk.FILL, xpadding=8)        
        body_table.attach(check_box, 0, 1, 4, 5, xoptions=gtk.FILL, yoptions=gtk.FILL)
        
        body_box_align = set_widget_gravity(set_widget_center(body_table), 
                                            (1, 1, 0.5, 0.5),
                                            (0, 0, 30, 30))
        
        self.login_button = Button("登录")
        self.login_button.set_size_request(95, 30)
        login_button_align = set_widget_gravity(set_widget_center(self.login_button),
                                                (1, 1, 0.5, 0.5),
                                                (30, 30, 0, 0))
        
        main_box = gtk.VBox()        
        main_box.connect("expose-event", self.draw_border_mask)
        main_box.pack_start(body_box_align, False, True)
        main_box.pack_start(login_button_align, False, True)
        
        self.window_frame.pack_start(titlebar, False, True)
        self.window_frame.pack_start(main_box)
        
        
    def create_combo_entry(self, label_content, entry_content=""):    
        vbox = gtk.VBox()
        vbox.set_spacing(5)
        label = Label(label_content)
        text_entry = TextEntry(entry_content)
        text_entry.set_size(198, 26)
        entry_box = set_widget_center(text_entry)
        vbox.pack_start(label, False, False)
        vbox.pack_start(entry_box, False, False)
        return vbox, text_entry
    
    def draw_border_mask(self, widget, event):    
        cr = widget.window.cairo_create()
        rect = widget.allocation
        draw_vlinear(cr, rect.x + 8, rect.y + 6, rect.width - 16, rect.height - 16,
                     app_theme.get_shadow_color("linearBackground").get_color_info(),
                     4)
        
    def create_combo_widget(self, label_content, items, select_index=0):
        label = Label(label_content)
        combo_box = ComboBox(items, select_index=select_index)
        hbox = gtk.HBox(spacing=5)
        hbox.pack_start(label, False, False)
        hbox.pack_start(combo_box, False, False)
        return hbox, combo_box
class Form(DialogBox):
    def __init__(self):
        DialogBox.__init__(
            self,
            _("Convert"),
            FORM_WIDTH,
            FORM_HEIGHT,
            mask_type=DIALOG_MASK_SINGLE_PAGE,
            close_callback=self.hide_all,
            modal=True,
            window_hint=gtk.gdk.WINDOW_TYPE_HINT_DIALOG,
            window_pos=gtk.WIN_POS_CENTER,
            # skip_taskbar_hint=False,
            resizable=False,
        )
        # Init value.
        self.init_value()
        # Init all widgets.
        self.InitializeComponent()

    def init_value(self):
        read_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                 "xml")
        self.read_xml = ReadXml(read_path)
        self.model_dict = {}

        # init brand EN list.
        self.brand_dict = {
            "intel": _("intel"),
            "zte": _("zte"),
            "hasee": _("hasee"),
            "apple": _("apple"),
            "nokia": _("nokia"),
            "alcatel": _("alcatel"),
            "google": _("google"),
            "asus": _("asus"),
            "hp": _("hp"),
            "sony": _("sony"),
            "hedy": _("hedy"),
            "archos": _("archos"),
            "boway": _("boway"),
            "bird": _("bird"),
            "vivo": _("vivo"),
            "great wall": _("great wall"),
            "changhong": _("changhong"),
            "skyworth": _("skyworth"),
            "dell": _("dell"),
            "philips": _("philips"),
            "toshiba": _("toshiba"),
            "amazon": _("amazon"),
            "sdo": _("sdo"),
            "disney": _("disney"),
            "haier": _("haier"),
            "fujitsu": _("fujitsu"),
            "acer": _("acer"),
            "lenovo": _("lenovo"),
            "gigabyte": _("gigabyte"),
            "xiaomi": _("xiaomi"),
            "huawei": _("huawei"),
            "blackberry": _("blackberry"),
            "motorola": _("motorola"),
            "sangsung": _("sangsung"),
            "meizu ": _("meizu "),
            "benq": _("benq"),
            "panasonic": _("panasonic"),
            "sony ericsson": _("sony ericsson"),
            "pioneer": _("pioneer"),
            "hyundai": _("hyundai"),
            "newman": _("newman"),
            "coolpad": _("coolpad"),
            "malata": _("malata"),
            "malata": _("malata"),
            "sharp": _("sharp"),
            "gionee": _("gionee"),
            "k-touch": _("k-touch"),
            "Pantech": _("Pantech"),
            "hisense": _("hisense"),
            "teclast": _("teclast"),
            "cube": _("cube"),
            "amoi": _("amoi"),
            "doov": _("doov"),
            "minte": _("minte"),
            "dopod": _("dopod"),
            "eton": _("eton"),
            "cherr": _("cherr"),
            "gaoxinqi": _("gaoxinqi"),
            "konka": _("konka"),
            "viewsonic": _("viewsonic"),
            "xibo": _("xibo"),
            "hosin": _("hosin"),
            "apanda": _("apanda"),
            "iocean": _("iocean"),
            "mastone": _("mastone")
        }

    def InitializeComponent(self):
        # Init form event.
        # self.connect("destroy", lambda w : self.destroy())
        self.connect("destroy", lambda w: self.hide_all())
        # Init widgets.
        self.brand_label = Label("%s: " % _("Phone brand"))
        self.format_label = Label("%s: " % _("Output format"))
        self.bit_rate_label = Label("%s: " % _("Audio encoder"))
        self.frame_rate_label = Label("%s: " % _("Video encoder"))
        self.path_label = Label("%s: " % _("Output directory"))
        self.model_label = Label("%s: " % _("Phone model"))
        self.ratio_label = Label('    %s: ' % _("Resolution"))

        self.path_entry = InputEntry()
        self.save_path_entry = InputEntry()
        fixed_width = 108
        self.brand_combo = NewComboBox(fixed_width)
        self.format_combo = NewComboBox(fixed_width)
        self.bit_rate_combo = NewComboBox(fixed_width)
        self.frame_rate_combo = NewComboBox(fixed_width)
        self.model_combo = NewComboBox(fixed_width)
        self.ratio_combo = NewComboBox(fixed_width)

        self.modify_chooser_btn = FileChooserButton(
            "选择")  # connect self.FileChooser
        self.save_chooser_btn = Button(_("Change"))
        self.start_btn = Button(_("Start"))
        self.close_btn = Button(_("Close"))
        self.higt_set_bool = False
        self.higt_set_btn = LabelButton()  #Button(_("Advanced"))

        self.show_and_hide_task_btn = Button(_("Task Manager"))

        self.higt_hbox = gtk.HBox()
        self.higt_hbox.pack_start(self.higt_set_btn)

        self.higt_align = gtk.Alignment()
        self.higt_align.add(self.higt_hbox)
        self.higt_align.set_padding(0, 0, 7, 0)
        self.higt_align.set(1, 0, 1, 0)

        self.left_button_box.set_buttons([self.higt_align])
        self.right_button_box.set_buttons([self.start_btn, self.close_btn])

        # ratio_combo.
        self.__ratio_list = [
            "176 x 220",
            "240 x 320",
            "320 x 240",
            "320 x 480",
            "400 x 240",
            "480 x 800",
            "540 x 960",
            "600 x 1024",
            "640 x 480",
            "720 x 1280",
            "800 x 480",
            "800 x 600",
            "1024 x 600",
            "1024 x 768",
            "1152 x 864",
        ]
        self.ratio_items = []
        for ratio in self.__ratio_list:
            self.ratio_combo.append_text(ratio)
            self.ratio_items.append((ratio, ratio))
        self.ratio_combo.set_active(5)
        # brand_combo.
        brand_items = []
        for brand in self.read_xml.brand_dict.keys():
            brand_po = brand
            if self.brand_dict.has_key(brand):
                brand_po = self.brand_dict[brand]
            brand_items.append((brand_po, brand))

        self.brand_combo.set_items(brand_items, 0)
        #self.brand_combo.add_items(brand_items, 0)

        self.brand_combo.prepend_text(_("No Presets"))
        self.brand_combo.connect("changed", self.brand_combo_item_selected)
        # model_combo.
        self.model_label.set_sensitive(False)
        self.model_combo.set_sensitive(False)
        self.model_combo.prepend_text(_("No Model"))
        self.model_combo.connect("changed", self.model_combo_item_selected)
        #
        self.save_chooser_btn.set_size_request(75, 21)
        self.save_chooser_btn.connect("clicked", self.save_chooser_btn_clicked)

        # path_entry.
        PATH_ENTRY_WIDTH = 240
        PATH_ENTRY_HEIGHT = 22
        self.save_path_entry.set_sensitive(False)
        self.save_path_entry.set_text(self.get_home_path())
        self.save_path_entry.set_size(PATH_ENTRY_WIDTH, PATH_ENTRY_HEIGHT)
        self.close_btn.connect("clicked", lambda w: self.hide_all())
        # higt_set_btn.
        self.higt_set_btn.connect("clicked", self.higt_set_btn_clicked)

        # form body box add main fixed.
        self.body_table_ali = gtk.Alignment()
        self.body_table_ali.set_padding(6, 0, 0, 0)
        self.body_table = gtk.Table(rows=6, columns=4, homogeneous=False)
        self.body_table_ali.add(self.body_table)

        self.brand_model_hbox = gtk.HBox()
        top, bottom = 5, 5
        brand_position = eval(_("('brand_position', 20)"))
        model_position = eval(_("('model_position', 20)"))
        self.brand_hbox_ali, self.brand_hbox = self.create_hbox(
            bottom, top, 15 + int(brand_position[1]), 0, self.brand_label,
            self.brand_combo)
        self.model_hbox_ali, self.model_hbox = self.create_hbox(
            bottom, top, 50 - int(model_position[1]), 0, self.model_label,
            self.model_combo)

        self.brand_model_hbox.pack_start(self.brand_hbox_ali, False, False)
        self.brand_model_hbox.pack_start(self.model_hbox_ali, False, False)
        format_position = eval(_("('format_position', 12)"))
        ratio_position = eval(_("('ratio_position', 18)"))
        self.format_hbox_ali, self.format_hbox = self.create_hbox(
            bottom, top, 15 + int(format_position[1]), 0, self.format_label,
            self.format_combo)
        self.ratio_hbox_ali, ratio_hbox = self.create_hbox(
            bottom, top, 50 - int(ratio_position[1]), 0, self.ratio_label,
            self.ratio_combo)

        self.format_ratio_hbox = gtk.HBox()
        self.format_ratio_hbox.pack_start(self.format_hbox_ali, False, False)
        self.format_ratio_hbox.pack_start(self.ratio_hbox_ali, False, False)

        frame_rate_position = eval(_("('frame_position', 13)"))
        bit_rate_position = eval(_("('bit_rate_position', 28)"))
        self.frame_rate_hbox_ali, self.frame_rate_hbox = self.create_hbox(
            bottom, top, 15 + int(frame_rate_position[1]), 0,
            self.frame_rate_label, self.frame_rate_combo)
        self.bit_rate_hbox_ali, self.bit_rate_hbox = self.create_hbox(
            bottom, top, 50 - int(bit_rate_position[1]), 0,
            self.bit_rate_label, self.bit_rate_combo)

        self.bit_frame_hbox = gtk.HBox()
        self.bit_frame_hbox.pack_start(self.frame_rate_hbox_ali, False, False)
        self.bit_frame_hbox.pack_start(self.bit_rate_hbox_ali, False, False)

        # self.path_label, self.save_path_entry, self.save_chooser_btn
        self.save_path_hbox_ali = gtk.Alignment()
        self.save_path_hbox = gtk.HBox()
        self.save_path_hbox_ali.set_padding(5, 5, 16, 0)
        self.save_path_hbox_ali.add(self.save_path_hbox)

        self.save_path_entry_ali = gtk.Alignment()
        self.save_path_entry_ali.set_padding(1, 0, 0, 0)
        self.save_path_entry_ali.add(self.save_path_entry)

        self.save_chooser_btn_ali = gtk.Alignment()
        self.save_chooser_btn_ali.set_padding(0, 0, 10, 0)
        self.save_chooser_btn_ali.add(self.save_chooser_btn)

        self.save_path_hbox.pack_start(self.path_label, False, False)
        self.save_path_hbox.pack_start(self.save_path_entry_ali, False, False)
        self.save_path_hbox.pack_start(self.save_chooser_btn_ali, False, False)

        # left right top, bottom.
        '''brand_model_hbox.'''
        # self.body_table.attach(self.brand_model_hbox, 0, 1, 0, 1, gtk.EXPAND, gtk.EXPAND)
        self.body_table.attach(self.brand_model_hbox, 0, 1, 0, 1, gtk.FILL,
                               gtk.FILL)
        # self.body_table.attach(self.model_hbox, 1, 2, 0, 1, gtk.EXPAND, gtk.EXPAND)
        # self.body_table.attach(self.model_hbox, 2, 3, 0, 1, gtk.EXPAND, gtk.EXPAND)
        # self.body_table.attach(self.model_hbox, 3, 4, 0, 1, gtk.EXPAND, gtk.EXPAND)
        '''format_ratio_hbox.'''
        # self.body_table.attach(self.format_ratio_hbox, 0, 1, 1, 2, gtk.EXPAND, gtk.EXPAND)
        self.body_table.attach(self.format_ratio_hbox, 0, 1, 1, 2, gtk.FILL,
                               gtk.FILL)
        # self.body_table.attach(self.format_combo, 1, 2, 1, 2, gtk.EXPAND, gtk.EXPAND)
        # self.body_table.attach(self.ratio_hbox, 2, 3, 1, 2, gtk.EXPAND, gtk.EXPAND)
        # self.body_table.attach(self.ratio_combo, 3, 4, 1, 2, gtk.EXPAND, gtk.EXPAND)
        '''bit_frame_hbox.'''
        # self.body_table.attach(self.bit_frame_hbox, 0, 1, 2, 3, gtk.EXPAND, gtk.EXPAND)
        self.body_table.attach(self.bit_frame_hbox, 0, 1, 2, 3, gtk.FILL,
                               gtk.FILL)
        '''save_path_hbox.'''
        # self.body_table.attach(self.save_path_hbox_ali, 0, 1, 3, 4, gtk.EXPAND, gtk.EXPAND)
        self.body_table.attach(self.save_path_hbox_ali, 0, 1, 3, 4, gtk.FILL,
                               gtk.FILL)

        self.body_box.pack_start(self.body_table_ali, True, True)
        self.hide_setting()

    def create_hbox(self, top, bottom, left, right, child1, child2):
        hbox_ali = gtk.Alignment()
        hbox_ali.set_padding(top, bottom, left, right)
        hbox = gtk.HBox()
        hbox_ali.add(hbox)
        hbox.pack_start(child1, False, False)
        hbox.pack_start(child2, False, False)
        return hbox_ali, hbox

    def get_home_path(self):
        return os.path.expanduser("~")

    def save_chooser_btn_clicked(self, widget):
        '''保存目录... ...'''
        self.show_open_dir_dialog_window()

    def show_open_dir_dialog_window(self):
        open_dialog = gtk.FileChooserDialog(
            _("Choose a directory"), None,
            gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
            (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN,
             gtk.RESPONSE_OK))
        # current floader set.
        open_dialog.set_current_folder(self.get_home_path())
        # run dir dialog window.
        res = open_dialog.run()

        if res == gtk.RESPONSE_OK:
            path_string = open_dialog.get_filename()
            if path_string:
                self.save_path_entry.set_text(path_string)
        # destroy dialog window.
        open_dialog.destroy()

    def brand_combo_item_selected(self, combo, item_content):
        self.model_combo.clear_items()
        self.ratio_combo.clear_items()
        #
        try:
            self.model_dict = self.read_xml.load(
                self.read_xml.brand_dict[item_content])
        except Exception, e:
            print "brand_combo_item_selected[error]:", e
            self.model_dict = {}
        #
        if item_content != _("No Presets") and self.model_dict != {}:
            model_items = []
            for model in self.model_dict:
                model_items.append((model, model))
            self.model_combo.set_items(model_items, 0)

            # self.model_combo.droplist.set_size_request(-1, self.model_combo.droplist_height)
            self.model_combo.set_active(0)
            self.model_combo.set_sensitive(True)
            self.model_label.set_sensitive(True)
        else:
            # clear model and ratio all text.
            self.model_combo.append_text(_("No Model"))
            self.model_combo.set_sensitive(False)
            self.model_label.set_sensitive(False)
            # add ratios.
            for ratio in self.ratio_items:
                self.ratio_combo.append_text(ratio[0])
            self.ratio_combo.set_active(5)
Exemple #12
0
class FaceRecordPage(gtk.VBox):
    def __init__(self, account_setting):
        gtk.VBox.__init__(self)
        self.account_setting = account_setting

        self.camera_pixbuf = app_theme.get_pixbuf(
            "account/camera.png").get_pixbuf()
        self.error_pixbuf = app_theme.get_pixbuf(
            "account/error.png").get_pixbuf()
        self.success_pixbuf = app_theme.get_pixbuf(
            "account/success.png").get_pixbuf()

        self.camera_box_align = gtk.Alignment(0.5, 0, 0, 0)
        self.camera_box = gtk.VBox()
        self.camera_box.set_size_request(CAMERA_BOX_SIZE, CAMERA_BOX_SIZE)
        self.camera_box.connect("expose-event", self.__camera_box_expose)
        self.camera_box_align.add(self.camera_box)

        self.under_camera_box = gtk.VBox(spacing=10)
        self.under_camera_box_align = gtk.Alignment(0.5, 0, 0, 0)
        self.under_camera_box_align.set_padding(WIDGET_SPACING, 0, 0, 0)
        self.under_camera_box_align.add(self.under_camera_box)
        self.__init_widgets()
        if Webcam.has_device():
            self.under_camera_box.pack_start(self.start_record_button)
        else:
            self.under_camera_box.pack_start(self.no_device_warning)

        self.pack_start(self.camera_box_align, False, False)
        self.pack_start(self.under_camera_box_align, False, False)

    def __init_widgets(self):
        self.start_record_button = Button(_("Start"))
        self.start_record_button.set_size_request(CAMERA_BOX_SIZE, 25)
        self.start_record_button.connect("clicked",
                                         self.__start_record_clicked)

        self.no_device_warning = Label(
            _("Please plug in or enable your camera"),
            label_width=300,
            text_x_align=pango.ALIGN_CENTER)
        self.keep_few_minutes = Label(_("Please keep still for 5 seconds"),
                                      label_width=300,
                                      text_x_align=pango.ALIGN_CENTER)
        # self.success = Label(_("Your face has been successfully recorded"), label_width=300, text_x_align=pango.ALIGN_CENTER)
        self.fail = Label(_("Failed to record your face"),
                          label_width=300,
                          text_x_align=pango.ALIGN_CENTER)

        self.success = gtk.Alignment(0.5, 0.5, 0, 0)
        self.success.set_size_request(300, -1)
        self.success_img = gtk.Image()
        self.success_img.set_from_pixbuf(self.success_pixbuf)
        self.success_box = gtk.HBox()
        self.success_box.pack_start(self.success_img, False, False, 5)
        self.success_box.pack_start(
            Label(_("Your face has been successfully recorded")))
        self.success.add(self.success_box)

    def refresh(self):
        container_remove_all(self.camera_box)
        container_remove_all(self.under_camera_box)
        if Webcam.has_device():
            self.under_camera_box.pack_start(self.start_record_button)
        else:
            self.under_camera_box.pack_start(self.no_device_warning)

    def __start_record_clicked(self, widget):
        container_remove_all(self.under_camera_box)
        self.under_camera_box.pack_start(self.keep_few_minutes)

        self.webcam_align = gtk.Alignment(0, 0.5, 0, 0)
        self.webcam_align.set_padding(5, 5, 5, 5)
        if not hasattr(self.account_setting, "record_webcam"):
            self.account_setting.record_webcam = Webcam()
            self.account_setting.record_webcam.set_size_request(
                WEBCAM_SIZE, min(WEBCAM_SIZE, 240))
            self.account_setting.record_webcam.create_video_pipeline(320, 240)
        self.webcam_align.add(self.account_setting.record_webcam)
        container_remove_all(self.camera_box)
        self.camera_box.add(self.webcam_align)
        self.account_setting.record_webcam.play()
        gobject.timeout_add(2000, self.__do_save_photo, 0)
        gobject.timeout_add(2500, self.__do_save_photo, 1)
        gobject.timeout_add(3000, self.__do_save_photo, 2)
        gobject.timeout_add(3500, self.__do_save_photo, 3)

        gobject.timeout_add(4000, self.__do_action)

    def __do_save_photo(self, num):
        pixbuf = self.account_setting.record_webcam.get_snapshot()
        path = "/tmp/face_recognition_%s.png" % num
        pixbuf.save(path, "png")

    # def __do_detection(self):

    #     def recognition_process(pixbuf):
    #         path = "/tmp/face_recognition_%s.png" % thread.get_ident()
    #         pixbuf.save(path, "png")
    #         result = facepp.detection.detect(img=File(path), mode="oneface")
    #         print result
    #         if result["face"]:
    #             try:
    #                 facepp.person.create(person_name=get_person_name())
    #             except:
    #                 pass
    #             facepp.person.add_face(person_name=get_person_name(), face_id=result["face"][0]["face_id"])

    #     pixbuf = self.account_setting.record_webcam.get_snapshot()
    #     # gtk.gdk.threads_enter()
    #     # Thread(target=recognition_process, args=[pixbuf]).start()
    #     # gtk.gdk.threads_leave()
    #     recognition_process(pixbuf)

    def __do_action(self):
        success = 0

        try:
            facepp.person.delete(person_name=get_person_name())
        except:
            pass

        try:
            facepp.person.create(person_name=get_person_name())

            for i in xrange(3):
                result = facepp.detection.detect(img=File(
                    "/tmp/face_recognition_%s.png" % i),
                                                 mode="oneface")
                if result["face"]:
                    add_result = facepp.person.add_face(
                        person_name=get_person_name(),
                        face_id=result["face"][0]["face_id"])
                    print "add_result, ", add_result
                    success += 1
        except Exception, e:
            print e

        self.snapshot_pixbuf = self.account_setting.record_webcam.get_snapshot(
        )
        self.account_setting.record_webcam.stop()
        self.webcam_align.remove(self.account_setting.record_webcam)

        self.scanning_box = ScanningBox(self.snapshot_pixbuf)
        self.scanning_box.set_size_request(WEBCAM_SIZE, WEBCAM_SIZE)
        self.webcam_align.add(self.scanning_box)
        self.webcam_align.show_all()

        def things_after_scanning():
            container_remove_all(self.under_camera_box)
            self.try_again_button = Button(_("Try Again"))
            self.try_again_button.set_size_request(CAMERA_BOX_SIZE, 25)
            self.try_again_button.connect("clicked",
                                          self.__start_record_clicked)
            start_record_button_align = gtk.Alignment(0.5, 0.5, 0, 0)
            start_record_button_align.add(self.try_again_button)
            if success > 0:
                facepp.train.verify(person_name=get_person_name())
                self.under_camera_box.pack_start(self.success)
            else:
                self.under_camera_box.pack_start(self.fail)
            self.under_camera_box.pack_start(start_record_button_align)

        gobject.timeout_add(2000, things_after_scanning)
class DeletePage(gtk.VBox):
    '''
    class docs
    '''
	
    def __init__(self):
        '''
        init docs
        '''
        gtk.VBox.__init__(self)

        self.draw_title_background = self.draw_tab_title_background
        self.theme = None
        
        self.delete_view = DeleteView(padding_x=30, padding_y=ITEM_PADDING_Y)
        self.delete_view_sw = self.delete_view.get_scrolled_window()
        
        self.action_align = gtk.Alignment()
        self.action_align.set_padding(5, 5, 510, 5)
        self.action_box = gtk.HBox(spacing = 10)
        self.back_button = Button(_("Back"))
        self.back_button.set_size_request(80, WIDGET_HEIGHT)
        self.back_button.connect("clicked", self.__on_back)
        self.select_all_button = Button(_("Select all"))
        self.select_all_button.set_size_request(80, WIDGET_HEIGHT)
        self.select_all_button.connect("clicked", self.__on_select_all)
        self.delete_button = Button(_("Delete"))
        self.delete_button.set_size_request(80, WIDGET_HEIGHT)
        self.delete_button.connect("clicked", self.__on_delete)
        self.action_box.pack_start(self.select_all_button, False, False)
        self.action_box.pack_start(self.delete_button, False, False)
        self.action_box.pack_start(self.back_button, False, False)
        self.action_align.add(self.action_box)
        
        self.pack_start(self.delete_view_sw, True, True)
        self.pack_start(self.action_align, False, False)

        event_manager.add_callback("select-delete-wallpaper", self.__on_select_delete_wallpaper)

    def __on_back(self, widget):
        event_manager.emit("back-to-detailpage", self.theme)

    def __on_select_delete_wallpaper(self, name, obj, select_item):
        if self.delete_view.is_select_all():                                    
            self.select_all_button.set_label(_("Clear all"))                 
        else:                                                                   
            self.select_all_button.set_label(_("Select all"))
        self.select_all_button.set_size_request(80, WIDGET_HEIGHT)

    def __on_select_all(self, widget):
        self.delete_view.select_all()
        if self.delete_view.is_select_all():
            self.select_all_button.set_label(_("Clear all"))
        else:
            self.select_all_button.set_label(_("Select all"))
        self.select_all_button.set_size_request(80, WIDGET_HEIGHT)

    def __delete_confirm(self):
        self.delete_view.delete_wallpaper()

    def __on_delete(self, widget):
        if self.delete_view.is_deletable():
            dlg = ConfirmDialog(_("Delete Wallpaper"),                                  
                                _("Are you sure delete wallpaper?"), 
                                300,                                                
                                100,                                                
                                lambda : self.__delete_confirm(),                   
                                None,                                               
                                True, 
                                CONTENT_FONT_SIZE)                                               
            dlg.show_all()

    def draw_tab_title_background(self, cr, widget):
        rect = widget.allocation
        cr.set_source_rgb(1, 1, 1)    
        cr.rectangle(0, 0, rect.width, rect.height - 1)
        cr.fill()

    def set_theme(self, theme):
        self.theme = theme
        self.delete_view.set_theme(self.theme)
        self.select_all_button.set_label(_("Select all"))
        self.select_all_button.set_size_request(80, WIDGET_HEIGHT)
        
    def draw_mask(self, cr, x, y, w, h):
        '''
        Draw mask interface.
        
        @param cr: Cairo context.
        @param x: X coordiante of draw area.
        @param y: Y coordiante of draw area.
        @param w: Width of draw area.
        @param h: Height of draw area.
        '''
        cr.set_source_rgb(1, 1, 1)
        cr.rectangle(x, y, w, h)
        cr.fill()
class Form(DialogBox):
    def __init__(self):
        DialogBox.__init__(
            self,
            _("Convert"),
            FORM_WIDTH,
            FORM_HEIGHT,
            mask_type=DIALOG_MASK_SINGLE_PAGE,
            close_callback=self.hide_all,
            modal=True,
            window_hint=gtk.gdk.WINDOW_TYPE_HINT_DIALOG,
            window_pos=gtk.WIN_POS_CENTER,
            # skip_taskbar_hint=False,
            resizable=False,
        )
        # Init value.
        self.init_value()
        # Init all widgets.
        self.InitializeComponent()

    def init_value(self):
        read_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "xml")
        self.read_xml = ReadXml(read_path)
        self.model_dict = {}

        # init brand EN list.
        self.brand_dict = {
            "intel": _("intel"),
            "zte": _("zte"),
            "hasee": _("hasee"),
            "apple": _("apple"),
            "nokia": _("nokia"),
            "alcatel": _("alcatel"),
            "google": _("google"),
            "asus": _("asus"),
            "hp": _("hp"),
            "sony": _("sony"),
            "hedy": _("hedy"),
            "archos": _("archos"),
            "boway": _("boway"),
            "bird": _("bird"),
            "vivo": _("vivo"),
            "great wall": _("great wall"),
            "changhong": _("changhong"),
            "skyworth": _("skyworth"),
            "dell": _("dell"),
            "philips": _("philips"),
            "toshiba": _("toshiba"),
            "amazon": _("amazon"),
            "sdo": _("sdo"),
            "disney": _("disney"),
            "haier": _("haier"),
            "fujitsu": _("fujitsu"),
            "acer": _("acer"),
            "lenovo": _("lenovo"),
            "gigabyte": _("gigabyte"),
            "xiaomi": _("xiaomi"),
            "huawei": _("huawei"),
            "blackberry": _("blackberry"),
            "motorola": _("motorola"),
            "sangsung": _("sangsung"),
            "meizu ": _("meizu "),
            "benq": _("benq"),
            "panasonic": _("panasonic"),
            "sony ericsson": _("sony ericsson"),
            "pioneer": _("pioneer"),
            "hyundai": _("hyundai"),
            "newman": _("newman"),
            "coolpad": _("coolpad"),
            "malata": _("malata"),
            "malata": _("malata"),
            "sharp": _("sharp"),
            "gionee": _("gionee"),
            "k-touch": _("k-touch"),
            "Pantech": _("Pantech"),
            "hisense": _("hisense"),
            "teclast": _("teclast"),
            "cube": _("cube"),
            "amoi": _("amoi"),
            "doov": _("doov"),
            "minte": _("minte"),
            "dopod": _("dopod"),
            "eton": _("eton"),
            "cherr": _("cherr"),
            "gaoxinqi": _("gaoxinqi"),
            "konka": _("konka"),
            "viewsonic": _("viewsonic"),
            "xibo": _("xibo"),
            "hosin": _("hosin"),
            "apanda": _("apanda"),
            "iocean": _("iocean"),
            "mastone": _("mastone"),
        }

    def InitializeComponent(self):
        # Init form event.
        # self.connect("destroy", lambda w : self.destroy())
        self.connect("destroy", lambda w: self.hide_all())
        # Init widgets.
        self.brand_label = Label("%s: " % _("Phone brand"))
        self.format_label = Label("%s: " % _("Output format"))
        self.bit_rate_label = Label("%s: " % _("Audio encoder"))
        self.frame_rate_label = Label("%s: " % _("Video encoder"))
        self.path_label = Label("%s: " % _("Output directory"))
        self.model_label = Label("%s: " % _("Phone model"))
        self.ratio_label = Label("    %s: " % _("Resolution"))

        self.path_entry = InputEntry()
        self.save_path_entry = InputEntry()
        fixed_width = 108
        self.brand_combo = NewComboBox(fixed_width)
        self.format_combo = NewComboBox(fixed_width)
        self.bit_rate_combo = NewComboBox(fixed_width)
        self.frame_rate_combo = NewComboBox(fixed_width)
        self.model_combo = NewComboBox(fixed_width)
        self.ratio_combo = NewComboBox(fixed_width)

        self.modify_chooser_btn = FileChooserButton("选择")  # connect self.FileChooser
        self.save_chooser_btn = Button(_("Change"))
        self.start_btn = Button(_("Start"))
        self.close_btn = Button(_("Close"))
        self.higt_set_bool = False
        self.higt_set_btn = LabelButton()  # Button(_("Advanced"))

        self.show_and_hide_task_btn = Button(_("Task Manager"))

        self.higt_hbox = gtk.HBox()
        self.higt_hbox.pack_start(self.higt_set_btn)

        self.higt_align = gtk.Alignment()
        self.higt_align.add(self.higt_hbox)
        self.higt_align.set_padding(0, 0, 7, 0)
        self.higt_align.set(1, 0, 1, 0)

        self.left_button_box.set_buttons([self.higt_align])
        self.right_button_box.set_buttons([self.start_btn, self.close_btn])

        # ratio_combo.
        self.__ratio_list = [
            "176 x 220",
            "240 x 320",
            "320 x 240",
            "320 x 480",
            "400 x 240",
            "480 x 800",
            "540 x 960",
            "600 x 1024",
            "640 x 480",
            "720 x 1280",
            "800 x 480",
            "800 x 600",
            "1024 x 600",
            "1024 x 768",
            "1152 x 864",
        ]
        self.ratio_items = []
        for ratio in self.__ratio_list:
            self.ratio_combo.append_text(ratio)
            self.ratio_items.append((ratio, ratio))
        self.ratio_combo.set_active(5)
        # brand_combo.
        brand_items = []
        for brand in self.read_xml.brand_dict.keys():
            brand_po = brand
            if self.brand_dict.has_key(brand):
                brand_po = self.brand_dict[brand]
            brand_items.append((brand_po, brand))

        self.brand_combo.set_items(brand_items, 0)
        # self.brand_combo.add_items(brand_items, 0)

        self.brand_combo.prepend_text(_("No Presets"))
        self.brand_combo.connect("changed", self.brand_combo_item_selected)
        # model_combo.
        self.model_label.set_sensitive(False)
        self.model_combo.set_sensitive(False)
        self.model_combo.prepend_text(_("No Model"))
        self.model_combo.connect("changed", self.model_combo_item_selected)
        #
        self.save_chooser_btn.set_size_request(75, 21)
        self.save_chooser_btn.connect("clicked", self.save_chooser_btn_clicked)

        # path_entry.
        PATH_ENTRY_WIDTH = 240
        PATH_ENTRY_HEIGHT = 22
        self.save_path_entry.set_sensitive(False)
        self.save_path_entry.set_text(self.get_home_path())
        self.save_path_entry.set_size(PATH_ENTRY_WIDTH, PATH_ENTRY_HEIGHT)
        self.close_btn.connect("clicked", lambda w: self.hide_all())
        # higt_set_btn.
        self.higt_set_btn.connect("clicked", self.higt_set_btn_clicked)

        # form body box add main fixed.
        self.body_table_ali = gtk.Alignment()
        self.body_table_ali.set_padding(6, 0, 0, 0)
        self.body_table = gtk.Table(rows=6, columns=4, homogeneous=False)
        self.body_table_ali.add(self.body_table)

        self.brand_model_hbox = gtk.HBox()
        top, bottom = 5, 5
        brand_position = eval(_("('brand_position', 20)"))
        model_position = eval(_("('model_position', 20)"))
        self.brand_hbox_ali, self.brand_hbox = self.create_hbox(
            bottom, top, 15 + int(brand_position[1]), 0, self.brand_label, self.brand_combo
        )
        self.model_hbox_ali, self.model_hbox = self.create_hbox(
            bottom, top, 50 - int(model_position[1]), 0, self.model_label, self.model_combo
        )

        self.brand_model_hbox.pack_start(self.brand_hbox_ali, False, False)
        self.brand_model_hbox.pack_start(self.model_hbox_ali, False, False)
        format_position = eval(_("('format_position', 12)"))
        ratio_position = eval(_("('ratio_position', 18)"))
        self.format_hbox_ali, self.format_hbox = self.create_hbox(
            bottom, top, 15 + int(format_position[1]), 0, self.format_label, self.format_combo
        )
        self.ratio_hbox_ali, ratio_hbox = self.create_hbox(
            bottom, top, 50 - int(ratio_position[1]), 0, self.ratio_label, self.ratio_combo
        )

        self.format_ratio_hbox = gtk.HBox()
        self.format_ratio_hbox.pack_start(self.format_hbox_ali, False, False)
        self.format_ratio_hbox.pack_start(self.ratio_hbox_ali, False, False)

        frame_rate_position = eval(_("('frame_position', 13)"))
        bit_rate_position = eval(_("('bit_rate_position', 28)"))
        self.frame_rate_hbox_ali, self.frame_rate_hbox = self.create_hbox(
            bottom, top, 15 + int(frame_rate_position[1]), 0, self.frame_rate_label, self.frame_rate_combo
        )
        self.bit_rate_hbox_ali, self.bit_rate_hbox = self.create_hbox(
            bottom, top, 50 - int(bit_rate_position[1]), 0, self.bit_rate_label, self.bit_rate_combo
        )

        self.bit_frame_hbox = gtk.HBox()
        self.bit_frame_hbox.pack_start(self.frame_rate_hbox_ali, False, False)
        self.bit_frame_hbox.pack_start(self.bit_rate_hbox_ali, False, False)

        # self.path_label, self.save_path_entry, self.save_chooser_btn
        self.save_path_hbox_ali = gtk.Alignment()
        self.save_path_hbox = gtk.HBox()
        self.save_path_hbox_ali.set_padding(5, 5, 16, 0)
        self.save_path_hbox_ali.add(self.save_path_hbox)

        self.save_path_entry_ali = gtk.Alignment()
        self.save_path_entry_ali.set_padding(1, 0, 0, 0)
        self.save_path_entry_ali.add(self.save_path_entry)

        self.save_chooser_btn_ali = gtk.Alignment()
        self.save_chooser_btn_ali.set_padding(0, 0, 10, 0)
        self.save_chooser_btn_ali.add(self.save_chooser_btn)

        self.save_path_hbox.pack_start(self.path_label, False, False)
        self.save_path_hbox.pack_start(self.save_path_entry_ali, False, False)
        self.save_path_hbox.pack_start(self.save_chooser_btn_ali, False, False)

        # left right top, bottom.
        """brand_model_hbox."""
        # self.body_table.attach(self.brand_model_hbox, 0, 1, 0, 1, gtk.EXPAND, gtk.EXPAND)
        self.body_table.attach(self.brand_model_hbox, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
        # self.body_table.attach(self.model_hbox, 1, 2, 0, 1, gtk.EXPAND, gtk.EXPAND)
        # self.body_table.attach(self.model_hbox, 2, 3, 0, 1, gtk.EXPAND, gtk.EXPAND)
        # self.body_table.attach(self.model_hbox, 3, 4, 0, 1, gtk.EXPAND, gtk.EXPAND)
        """format_ratio_hbox."""
        # self.body_table.attach(self.format_ratio_hbox, 0, 1, 1, 2, gtk.EXPAND, gtk.EXPAND)
        self.body_table.attach(self.format_ratio_hbox, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
        # self.body_table.attach(self.format_combo, 1, 2, 1, 2, gtk.EXPAND, gtk.EXPAND)
        # self.body_table.attach(self.ratio_hbox, 2, 3, 1, 2, gtk.EXPAND, gtk.EXPAND)
        # self.body_table.attach(self.ratio_combo, 3, 4, 1, 2, gtk.EXPAND, gtk.EXPAND)
        """bit_frame_hbox."""
        # self.body_table.attach(self.bit_frame_hbox, 0, 1, 2, 3, gtk.EXPAND, gtk.EXPAND)
        self.body_table.attach(self.bit_frame_hbox, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
        """save_path_hbox."""
        # self.body_table.attach(self.save_path_hbox_ali, 0, 1, 3, 4, gtk.EXPAND, gtk.EXPAND)
        self.body_table.attach(self.save_path_hbox_ali, 0, 1, 3, 4, gtk.FILL, gtk.FILL)

        self.body_box.pack_start(self.body_table_ali, True, True)
        self.hide_setting()

    def create_hbox(self, top, bottom, left, right, child1, child2):
        hbox_ali = gtk.Alignment()
        hbox_ali.set_padding(top, bottom, left, right)
        hbox = gtk.HBox()
        hbox_ali.add(hbox)
        hbox.pack_start(child1, False, False)
        hbox.pack_start(child2, False, False)
        return hbox_ali, hbox

    def get_home_path(self):
        return os.path.expanduser("~")

    def save_chooser_btn_clicked(self, widget):
        """保存目录... ..."""
        self.show_open_dir_dialog_window()

    def show_open_dir_dialog_window(self):
        open_dialog = gtk.FileChooserDialog(
            _("Choose a directory"),
            None,
            gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
            (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK),
        )
        # current floader set.
        open_dialog.set_current_folder(self.get_home_path())
        # run dir dialog window.
        res = open_dialog.run()

        if res == gtk.RESPONSE_OK:
            path_string = open_dialog.get_filename()
            if path_string:
                self.save_path_entry.set_text(path_string)
        # destroy dialog window.
        open_dialog.destroy()

    def brand_combo_item_selected(self, combo, item_content):
        self.model_combo.clear_items()
        self.ratio_combo.clear_items()
        #
        try:
            self.model_dict = self.read_xml.load(self.read_xml.brand_dict[item_content])
        except Exception, e:
            print "brand_combo_item_selected[error]:", e
            self.model_dict = {}
        #
        if item_content != _("No Presets") and self.model_dict != {}:
            model_items = []
            for model in self.model_dict:
                model_items.append((model, model))
            self.model_combo.set_items(model_items, 0)

            # self.model_combo.droplist.set_size_request(-1, self.model_combo.droplist_height)
            self.model_combo.set_active(0)
            self.model_combo.set_sensitive(True)
            self.model_label.set_sensitive(True)
        else:
            # clear model and ratio all text.
            self.model_combo.append_text(_("No Model"))
            self.model_combo.set_sensitive(False)
            self.model_label.set_sensitive(False)
            # add ratios.
            for ratio in self.ratio_items:
                self.ratio_combo.append_text(ratio[0])
            self.ratio_combo.set_active(5)