def refresh(self): self.error_label.set_text("") if not self.account_setting.current_set_user: return if self.account_setting.current_set_user.get_real_name(): show_name = self.account_setting.current_set_user.get_real_name() else: show_name = self.account_setting.current_set_user.get_user_name() self.tips_label.set_text("<b>%s</b>" % _("Set <u>%s</u>'s picture") % tools.escape_markup_string(show_name)) self.history_icon = HistroyIcon(self.account_setting.current_set_user) self.history_icon.get_history() self.history_list_hbox.foreach(lambda w: w.destroy()) # the private history icon files history_dir = os.path.join(self.account_setting.current_set_user.get_home_directory(), ".config/deepin-system-settings/account/icons") if os.path.exists(history_dir): pic_list = os.listdir(history_dir) else: pic_list = [] pic_list.sort() private_icon_list = [] for pic in pic_list: try: icon_pixbuf = gtk.gdk.pixbuf_new_from_file( "%s/%s" %(history_dir, pic)).scale_simple(48, 48, gtk.gdk.INTERP_TILES) except: continue pic_file_path = "%s/%s" %(history_dir, pic) icon_bt = IconButton(icon_pixbuf, pic_file_path, has_frame=True, can_del=check_file_writable(pic_file_path)) icon_bt.connect("pressed", self.on_icon_bt_pressed_cb) private_icon_list.append(icon_bt) container_remove_all(self.icon_list_tabel) pic_list = self.public_icon_list + private_icon_list total_pic = len(pic_list) rows = (total_pic + 1) / 10 + 1 self.icon_list_tabel.resize(rows, 10) i = j = 0 for pic in pic_list: self.icon_list_tabel.attach(pic, i, i+1, j, j+1, 4) if pic.can_del: pic.row = j pic.col = i pic.connect("del-pressed", self.on_icon_bt_del_icon_file_cb) i += 1 if i >= 10: i = 0 j += 1 self.icon_list_tabel.attach(self.more_icon_button, i, i+1, j, j+1, 4) # history pic IconButton icon_button_list = pic_list i = 0 for pic in self.history_icon.history: if not os.path.exists(pic): continue icon_pixbuf = None for bt in icon_button_list: if pic == bt.get_image_path(): icon_pixbuf = bt.pixbuf break if not icon_pixbuf: try: icon_pixbuf = gtk.gdk.pixbuf_new_from_file(pic).scale_simple(48, 48, gtk.gdk.INTERP_TILES) except Exception, e: print e continue if i >= 10: break i += 1 icon_bt = IconButton(icon_pixbuf, pic, has_frame=True, can_del=True) icon_bt.connect("pressed", self.on_icon_bt_pressed_cb) icon_bt.connect("del-pressed", self.on_icon_bt_del_pressed_cb) self.history_list_hbox.pack_start(icon_bt, False, False)
def __init__(self, account_setting): super(IconSetPage, self).__init__(False) #self.set_spacing(BETWEEN_SPACING) self.account_setting = account_setting self.choose_menu_without_camera = Menu( [(None, _("Local picture"), self.choose_from_picture), (None, _("Take a screeshot"), self.choose_from_screenshot),], True) self.choose_menu_with_camera = Menu( [(None, _("Local picture"), self.choose_from_picture), (None, _("Take a screeshot"), self.choose_from_screenshot), (None, _("From camera"), self.choose_from_camera)], True) self.tips_label = Label("Set icon", label_width=460, enable_select=False, enable_double_click=False) self.error_label = Label("", wrap_width=560, enable_select=False, enable_double_click=False) set_page_sw = ScrolledWindow() self.pack_start(set_page_sw) main_vbox = gtk.VBox(False) set_page_sw.add_child(main_vbox) self.icon_list_tabel = gtk.Table() self.icon_list_tabel.set_row_spacings(4) self.icon_list_tabel.set_col_spacings(4) main_vbox.pack_start(tools.make_align(self.tips_label), False, False) main_vbox.pack_start(tools.make_align(height=20), False, False) self.history_list_hbox = gtk.HBox(False) self.history_list_hbox.set_size_request(-1, 56) self.history_list_hbox.set_spacing(4) main_vbox.pack_start(tools.make_align(Label(_("Choose a new picture for your account"), label_width=460, enable_select=False, enable_double_click=False), height=CONTAINNER_HEIGHT), False, False) main_vbox.pack_start(tools.make_align(self.icon_list_tabel), False, False) main_vbox.pack_start(tools.make_align(height=20), False, False) main_vbox.pack_start(tools.make_align(Label(_("Previously used pictures"), label_width=460, enable_select=False, enable_double_click=False), height=CONTAINNER_HEIGHT), False, False) main_vbox.pack_start(tools.make_align(self.history_list_hbox), False, False) main_vbox.pack_start(tools.make_align(height=20), False, False) main_vbox.pack_start(tools.make_align(self.error_label), False, False) # public picture list #face_dir = '/usr/share/pixmaps/faces' face_dir = '/var/lib/AccountsService/icons' if os.path.exists(face_dir): pic_list = os.listdir(face_dir) else: pic_list = [] pic_list.sort() self.public_icon_list = [] inital_list = ['001.jpg', '002.jpg', '003.jpg', '004.jpg', '005.jpg', '006.jpg', '007.jpg', '008.jpg', '009.jpg', '010.jpg', '011.jpg', '012.jpg', '013.jpg', '014.jpg', '015.jpg', '016.jpg', '017.jpg', '018.jpg', '019.jpg', '020.jpg'] for pic in pic_list: if pic not in inital_list: continue try: icon_pixbuf = gtk.gdk.pixbuf_new_from_file( "%s/%s" %(face_dir, pic)).scale_simple(48, 48, gtk.gdk.INTERP_TILES) except: continue icon_bt = IconButton(icon_pixbuf, "%s/%s" %(face_dir, pic), has_frame=True) icon_bt.connect("pressed", self.on_icon_bt_pressed_cb) self.public_icon_list.append(icon_bt) self.more_icon_button = IconButton(app_theme.get_pixbuf("%s/more.png" % MODULE_NAME).get_pixbuf(), has_frame=True) self.more_icon_button.connect("button-press-event", self.choose_more_picture) main_vbox.connect("expose-event", self.draw_white_background)
class IconSetPage(gtk.VBox): def __init__(self, account_setting): super(IconSetPage, self).__init__(False) #self.set_spacing(BETWEEN_SPACING) self.account_setting = account_setting self.choose_menu_without_camera = Menu( [(None, _("Local picture"), self.choose_from_picture), (None, _("Take a screeshot"), self.choose_from_screenshot),], True) self.choose_menu_with_camera = Menu( [(None, _("Local picture"), self.choose_from_picture), (None, _("Take a screeshot"), self.choose_from_screenshot), (None, _("From camera"), self.choose_from_camera)], True) self.tips_label = Label("Set icon", label_width=460, enable_select=False, enable_double_click=False) self.error_label = Label("", wrap_width=560, enable_select=False, enable_double_click=False) set_page_sw = ScrolledWindow() self.pack_start(set_page_sw) main_vbox = gtk.VBox(False) set_page_sw.add_child(main_vbox) self.icon_list_tabel = gtk.Table() self.icon_list_tabel.set_row_spacings(4) self.icon_list_tabel.set_col_spacings(4) main_vbox.pack_start(tools.make_align(self.tips_label), False, False) main_vbox.pack_start(tools.make_align(height=20), False, False) self.history_list_hbox = gtk.HBox(False) self.history_list_hbox.set_size_request(-1, 56) self.history_list_hbox.set_spacing(4) main_vbox.pack_start(tools.make_align(Label(_("Choose a new picture for your account"), label_width=460, enable_select=False, enable_double_click=False), height=CONTAINNER_HEIGHT), False, False) main_vbox.pack_start(tools.make_align(self.icon_list_tabel), False, False) main_vbox.pack_start(tools.make_align(height=20), False, False) main_vbox.pack_start(tools.make_align(Label(_("Previously used pictures"), label_width=460, enable_select=False, enable_double_click=False), height=CONTAINNER_HEIGHT), False, False) main_vbox.pack_start(tools.make_align(self.history_list_hbox), False, False) main_vbox.pack_start(tools.make_align(height=20), False, False) main_vbox.pack_start(tools.make_align(self.error_label), False, False) # public picture list #face_dir = '/usr/share/pixmaps/faces' face_dir = '/var/lib/AccountsService/icons' if os.path.exists(face_dir): pic_list = os.listdir(face_dir) else: pic_list = [] pic_list.sort() self.public_icon_list = [] inital_list = ['001.jpg', '002.jpg', '003.jpg', '004.jpg', '005.jpg', '006.jpg', '007.jpg', '008.jpg', '009.jpg', '010.jpg', '011.jpg', '012.jpg', '013.jpg', '014.jpg', '015.jpg', '016.jpg', '017.jpg', '018.jpg', '019.jpg', '020.jpg'] for pic in pic_list: if pic not in inital_list: continue try: icon_pixbuf = gtk.gdk.pixbuf_new_from_file( "%s/%s" %(face_dir, pic)).scale_simple(48, 48, gtk.gdk.INTERP_TILES) except: continue icon_bt = IconButton(icon_pixbuf, "%s/%s" %(face_dir, pic), has_frame=True) icon_bt.connect("pressed", self.on_icon_bt_pressed_cb) self.public_icon_list.append(icon_bt) self.more_icon_button = IconButton(app_theme.get_pixbuf("%s/more.png" % MODULE_NAME).get_pixbuf(), has_frame=True) self.more_icon_button.connect("button-press-event", self.choose_more_picture) main_vbox.connect("expose-event", self.draw_white_background) def refresh(self): self.error_label.set_text("") if not self.account_setting.current_set_user: return if self.account_setting.current_set_user.get_real_name(): show_name = self.account_setting.current_set_user.get_real_name() else: show_name = self.account_setting.current_set_user.get_user_name() self.tips_label.set_text("<b>%s</b>" % _("Set <u>%s</u>'s picture") % tools.escape_markup_string(show_name)) self.history_icon = HistroyIcon(self.account_setting.current_set_user) self.history_icon.get_history() self.history_list_hbox.foreach(lambda w: w.destroy()) # the private history icon files history_dir = os.path.join(self.account_setting.current_set_user.get_home_directory(), ".config/deepin-system-settings/account/icons") if os.path.exists(history_dir): pic_list = os.listdir(history_dir) else: pic_list = [] pic_list.sort() private_icon_list = [] for pic in pic_list: try: icon_pixbuf = gtk.gdk.pixbuf_new_from_file( "%s/%s" %(history_dir, pic)).scale_simple(48, 48, gtk.gdk.INTERP_TILES) except: continue pic_file_path = "%s/%s" %(history_dir, pic) icon_bt = IconButton(icon_pixbuf, pic_file_path, has_frame=True, can_del=check_file_writable(pic_file_path)) icon_bt.connect("pressed", self.on_icon_bt_pressed_cb) private_icon_list.append(icon_bt) container_remove_all(self.icon_list_tabel) pic_list = self.public_icon_list + private_icon_list total_pic = len(pic_list) rows = (total_pic + 1) / 10 + 1 self.icon_list_tabel.resize(rows, 10) i = j = 0 for pic in pic_list: self.icon_list_tabel.attach(pic, i, i+1, j, j+1, 4) if pic.can_del: pic.row = j pic.col = i pic.connect("del-pressed", self.on_icon_bt_del_icon_file_cb) i += 1 if i >= 10: i = 0 j += 1 self.icon_list_tabel.attach(self.more_icon_button, i, i+1, j, j+1, 4) # history pic IconButton icon_button_list = pic_list i = 0 for pic in self.history_icon.history: if not os.path.exists(pic): continue icon_pixbuf = None for bt in icon_button_list: if pic == bt.get_image_path(): icon_pixbuf = bt.pixbuf break if not icon_pixbuf: try: icon_pixbuf = gtk.gdk.pixbuf_new_from_file(pic).scale_simple(48, 48, gtk.gdk.INTERP_TILES) except Exception, e: print e continue if i >= 10: break i += 1 icon_bt = IconButton(icon_pixbuf, pic, has_frame=True, can_del=True) icon_bt.connect("pressed", self.on_icon_bt_pressed_cb) icon_bt.connect("del-pressed", self.on_icon_bt_del_pressed_cb) self.history_list_hbox.pack_start(icon_bt, False, False) self.history_list_hbox.show_all()
def refresh(self): self.error_label.set_text("") if not self.account_setting.current_set_user: return if self.account_setting.current_set_user.get_real_name(): show_name = self.account_setting.current_set_user.get_real_name() else: show_name = self.account_setting.current_set_user.get_user_name() self.tips_label.set_text("<b>%s</b>" % _("Set <u>%s</u>'s picture") % tools.escape_markup_string(show_name)) self.history_icon = HistroyIcon(self.account_setting.current_set_user) self.history_icon.get_history() self.history_list_hbox.foreach(lambda w: w.destroy()) # the private history icon files history_dir = os.path.join( self.account_setting.current_set_user.get_home_directory(), ".config/deepin-system-settings/account/icons") if os.path.exists(history_dir): pic_list = os.listdir(history_dir) else: pic_list = [] pic_list.sort() private_icon_list = [] for pic in pic_list: try: icon_pixbuf = gtk.gdk.pixbuf_new_from_file( "%s/%s" % (history_dir, pic)).scale_simple( 48, 48, gtk.gdk.INTERP_TILES) except: continue pic_file_path = "%s/%s" % (history_dir, pic) icon_bt = IconButton(icon_pixbuf, pic_file_path, has_frame=True, can_del=check_file_writable(pic_file_path)) icon_bt.connect("pressed", self.on_icon_bt_pressed_cb) private_icon_list.append(icon_bt) container_remove_all(self.icon_list_tabel) pic_list = self.public_icon_list + private_icon_list total_pic = len(pic_list) rows = (total_pic + 1) / 10 + 1 self.icon_list_tabel.resize(rows, 10) i = j = 0 for pic in pic_list: self.icon_list_tabel.attach(pic, i, i + 1, j, j + 1, 4) if pic.can_del: pic.row = j pic.col = i pic.connect("del-pressed", self.on_icon_bt_del_icon_file_cb) i += 1 if i >= 10: i = 0 j += 1 self.icon_list_tabel.attach(self.more_icon_button, i, i + 1, j, j + 1, 4) # history pic IconButton icon_button_list = pic_list i = 0 for pic in self.history_icon.history: if not os.path.exists(pic): continue icon_pixbuf = None for bt in icon_button_list: if pic == bt.get_image_path(): icon_pixbuf = bt.pixbuf break if not icon_pixbuf: try: icon_pixbuf = gtk.gdk.pixbuf_new_from_file( pic).scale_simple(48, 48, gtk.gdk.INTERP_TILES) except Exception, e: print e continue if i >= 10: break i += 1 icon_bt = IconButton(icon_pixbuf, pic, has_frame=True, can_del=True) icon_bt.connect("pressed", self.on_icon_bt_pressed_cb) icon_bt.connect("del-pressed", self.on_icon_bt_del_pressed_cb) self.history_list_hbox.pack_start(icon_bt, False, False)
def __init__(self, account_setting): super(IconSetPage, self).__init__(False) #self.set_spacing(BETWEEN_SPACING) self.account_setting = account_setting self.choose_menu_without_camera = Menu([ (None, _("Local picture"), self.choose_from_picture), (None, _("Take a screeshot"), self.choose_from_screenshot), ], True) self.choose_menu_with_camera = Menu( [(None, _("Local picture"), self.choose_from_picture), (None, _("Take a screeshot"), self.choose_from_screenshot), (None, _("From camera"), self.choose_from_camera)], True) self.tips_label = Label("Set icon", label_width=460, enable_select=False, enable_double_click=False) self.error_label = Label("", wrap_width=560, enable_select=False, enable_double_click=False) set_page_sw = ScrolledWindow() self.pack_start(set_page_sw) main_vbox = gtk.VBox(False) set_page_sw.add_child(main_vbox) self.icon_list_tabel = gtk.Table() self.icon_list_tabel.set_row_spacings(4) self.icon_list_tabel.set_col_spacings(4) main_vbox.pack_start(tools.make_align(self.tips_label), False, False) main_vbox.pack_start(tools.make_align(height=20), False, False) self.history_list_hbox = gtk.HBox(False) self.history_list_hbox.set_size_request(-1, 56) self.history_list_hbox.set_spacing(4) main_vbox.pack_start( tools.make_align(Label(_("Choose a new picture for your account"), label_width=460, enable_select=False, enable_double_click=False), height=CONTAINNER_HEIGHT), False, False) main_vbox.pack_start(tools.make_align(self.icon_list_tabel), False, False) main_vbox.pack_start(tools.make_align(height=20), False, False) main_vbox.pack_start( tools.make_align(Label(_("Previously used pictures"), label_width=460, enable_select=False, enable_double_click=False), height=CONTAINNER_HEIGHT), False, False) main_vbox.pack_start(tools.make_align(self.history_list_hbox), False, False) main_vbox.pack_start(tools.make_align(height=20), False, False) main_vbox.pack_start(tools.make_align(self.error_label), False, False) # public picture list #face_dir = '/usr/share/pixmaps/faces' face_dir = '/var/lib/AccountsService/icons' if os.path.exists(face_dir): pic_list = os.listdir(face_dir) else: pic_list = [] pic_list.sort() self.public_icon_list = [] inital_list = [ '001.jpg', '002.jpg', '003.jpg', '004.jpg', '005.jpg', '006.jpg', '007.jpg', '008.jpg', '009.jpg', '010.jpg', '011.jpg', '012.jpg', '013.jpg', '014.jpg', '015.jpg', '016.jpg', '017.jpg', '018.jpg', '019.jpg', '020.jpg' ] for pic in pic_list: if pic not in inital_list: continue try: icon_pixbuf = gtk.gdk.pixbuf_new_from_file( "%s/%s" % (face_dir, pic)).scale_simple( 48, 48, gtk.gdk.INTERP_TILES) except: continue icon_bt = IconButton(icon_pixbuf, "%s/%s" % (face_dir, pic), has_frame=True) icon_bt.connect("pressed", self.on_icon_bt_pressed_cb) self.public_icon_list.append(icon_bt) self.more_icon_button = IconButton(app_theme.get_pixbuf( "%s/more.png" % MODULE_NAME).get_pixbuf(), has_frame=True) self.more_icon_button.connect("button-press-event", self.choose_more_picture) main_vbox.connect("expose-event", self.draw_white_background)
class IconSetPage(gtk.VBox): def __init__(self, account_setting): super(IconSetPage, self).__init__(False) #self.set_spacing(BETWEEN_SPACING) self.account_setting = account_setting self.choose_menu_without_camera = Menu([ (None, _("Local picture"), self.choose_from_picture), (None, _("Take a screeshot"), self.choose_from_screenshot), ], True) self.choose_menu_with_camera = Menu( [(None, _("Local picture"), self.choose_from_picture), (None, _("Take a screeshot"), self.choose_from_screenshot), (None, _("From camera"), self.choose_from_camera)], True) self.tips_label = Label("Set icon", label_width=460, enable_select=False, enable_double_click=False) self.error_label = Label("", wrap_width=560, enable_select=False, enable_double_click=False) set_page_sw = ScrolledWindow() self.pack_start(set_page_sw) main_vbox = gtk.VBox(False) set_page_sw.add_child(main_vbox) self.icon_list_tabel = gtk.Table() self.icon_list_tabel.set_row_spacings(4) self.icon_list_tabel.set_col_spacings(4) main_vbox.pack_start(tools.make_align(self.tips_label), False, False) main_vbox.pack_start(tools.make_align(height=20), False, False) self.history_list_hbox = gtk.HBox(False) self.history_list_hbox.set_size_request(-1, 56) self.history_list_hbox.set_spacing(4) main_vbox.pack_start( tools.make_align(Label(_("Choose a new picture for your account"), label_width=460, enable_select=False, enable_double_click=False), height=CONTAINNER_HEIGHT), False, False) main_vbox.pack_start(tools.make_align(self.icon_list_tabel), False, False) main_vbox.pack_start(tools.make_align(height=20), False, False) main_vbox.pack_start( tools.make_align(Label(_("Previously used pictures"), label_width=460, enable_select=False, enable_double_click=False), height=CONTAINNER_HEIGHT), False, False) main_vbox.pack_start(tools.make_align(self.history_list_hbox), False, False) main_vbox.pack_start(tools.make_align(height=20), False, False) main_vbox.pack_start(tools.make_align(self.error_label), False, False) # public picture list #face_dir = '/usr/share/pixmaps/faces' face_dir = '/var/lib/AccountsService/icons' if os.path.exists(face_dir): pic_list = os.listdir(face_dir) else: pic_list = [] pic_list.sort() self.public_icon_list = [] inital_list = [ '001.jpg', '002.jpg', '003.jpg', '004.jpg', '005.jpg', '006.jpg', '007.jpg', '008.jpg', '009.jpg', '010.jpg', '011.jpg', '012.jpg', '013.jpg', '014.jpg', '015.jpg', '016.jpg', '017.jpg', '018.jpg', '019.jpg', '020.jpg' ] for pic in pic_list: if pic not in inital_list: continue try: icon_pixbuf = gtk.gdk.pixbuf_new_from_file( "%s/%s" % (face_dir, pic)).scale_simple( 48, 48, gtk.gdk.INTERP_TILES) except: continue icon_bt = IconButton(icon_pixbuf, "%s/%s" % (face_dir, pic), has_frame=True) icon_bt.connect("pressed", self.on_icon_bt_pressed_cb) self.public_icon_list.append(icon_bt) self.more_icon_button = IconButton(app_theme.get_pixbuf( "%s/more.png" % MODULE_NAME).get_pixbuf(), has_frame=True) self.more_icon_button.connect("button-press-event", self.choose_more_picture) main_vbox.connect("expose-event", self.draw_white_background) def refresh(self): self.error_label.set_text("") if not self.account_setting.current_set_user: return if self.account_setting.current_set_user.get_real_name(): show_name = self.account_setting.current_set_user.get_real_name() else: show_name = self.account_setting.current_set_user.get_user_name() self.tips_label.set_text("<b>%s</b>" % _("Set <u>%s</u>'s picture") % tools.escape_markup_string(show_name)) self.history_icon = HistroyIcon(self.account_setting.current_set_user) self.history_icon.get_history() self.history_list_hbox.foreach(lambda w: w.destroy()) # the private history icon files history_dir = os.path.join( self.account_setting.current_set_user.get_home_directory(), ".config/deepin-system-settings/account/icons") if os.path.exists(history_dir): pic_list = os.listdir(history_dir) else: pic_list = [] pic_list.sort() private_icon_list = [] for pic in pic_list: try: icon_pixbuf = gtk.gdk.pixbuf_new_from_file( "%s/%s" % (history_dir, pic)).scale_simple( 48, 48, gtk.gdk.INTERP_TILES) except: continue pic_file_path = "%s/%s" % (history_dir, pic) icon_bt = IconButton(icon_pixbuf, pic_file_path, has_frame=True, can_del=check_file_writable(pic_file_path)) icon_bt.connect("pressed", self.on_icon_bt_pressed_cb) private_icon_list.append(icon_bt) container_remove_all(self.icon_list_tabel) pic_list = self.public_icon_list + private_icon_list total_pic = len(pic_list) rows = (total_pic + 1) / 10 + 1 self.icon_list_tabel.resize(rows, 10) i = j = 0 for pic in pic_list: self.icon_list_tabel.attach(pic, i, i + 1, j, j + 1, 4) if pic.can_del: pic.row = j pic.col = i pic.connect("del-pressed", self.on_icon_bt_del_icon_file_cb) i += 1 if i >= 10: i = 0 j += 1 self.icon_list_tabel.attach(self.more_icon_button, i, i + 1, j, j + 1, 4) # history pic IconButton icon_button_list = pic_list i = 0 for pic in self.history_icon.history: if not os.path.exists(pic): continue icon_pixbuf = None for bt in icon_button_list: if pic == bt.get_image_path(): icon_pixbuf = bt.pixbuf break if not icon_pixbuf: try: icon_pixbuf = gtk.gdk.pixbuf_new_from_file( pic).scale_simple(48, 48, gtk.gdk.INTERP_TILES) except Exception, e: print e continue if i >= 10: break i += 1 icon_bt = IconButton(icon_pixbuf, pic, has_frame=True, can_del=True) icon_bt.connect("pressed", self.on_icon_bt_pressed_cb) icon_bt.connect("del-pressed", self.on_icon_bt_del_pressed_cb) self.history_list_hbox.pack_start(icon_bt, False, False) self.history_list_hbox.show_all()