Пример #1
0
 def load_gui(self):
     ## paste entry
     btn = gtk.Button()
     image = gtk.Image()
     pb = gtk.gdk.pixbuf_new_from_file(img_path+"/yt_icone.jpg")
     image.set_from_pixbuf(pb) 
     button = gtk.Button()
     button.set_image(image)
     button.connect("clicked", self.on_paste)
     button.set_tooltip_text(_('Paste youtube link'))
     self.gui.search_opt_box.pack_start(button,False,False,10)
     
     ## create orderby combobox
     cb = create_comboBox()
     self.orderbyOpt = {self.order_label:{_("Most relevant"):"relevance",
                                          _("Most recent"):"published",_("Most viewed"):"viewCount",
                                          _("Most rated"):"rating",
         },
     }
     self.orderby = create_comboBox(self.gui, self.orderbyOpt)
     
     ## create categories combobox
     self.category = ComboBox(cb)
     self.catlist = {self.category_label:{"":"",_("Sport"):"Sports",
                                          _("Films"):"Film",_("Cars"):"Autos",
                                          _("Music"):"Music",_("Technology"):"Tech",_("Animals"):"Animals",
                                          _("Travel"):"Travel",_("Games"):"Games",_("Comedy"):"Comedy",
                                          _("Peoples"):"People",_("News"):"News",
                                          _("Entertainement"):"Entertainment",_("Trailers"):"Trailers",
         },
     }
     self.category = create_comboBox(self.gui, self.catlist)
     self.orderby.setIndexFromString(_("Most relevant"))
     
     gobject.idle_add(self.gui.search_opt_box.show_all)
     
     ## vp8 check
     if not sys.platform == 'win32':
         out,err = Popen('/usr/bin/gst-inspect-0.10| grep vp8',shell=True,stdout=PIPE,stderr=STDOUT).communicate()
         if 'vp8' in str(out):
             self.vp8 = True
         else:
             out,err = Popen('/usr/bin/gst-inspect | grep vp8',shell=True,stdout=PIPE,stderr=STDOUT).communicate()
             if 'vp8' in str(out):
                 self.vp8 = True
     else:
         self.vp8 = True
Пример #2
0
    def __init__(self, gladexml, gstyle_obj):
        ## load buttons and attach signals
        self.gstyle_obj = gstyle_obj
        self.fullpack_dict = gstyle_obj.fullpack_dict
        self.gtk_dict = self.gstyle_obj.gtk_dict
        self.wallstat_dict = self.gstyle_obj.wallpapers_dict.get_dict_static_w(
        )
        self.walldyn_dict = self.gstyle_obj.wallpapers_dict.get_dict_dynamique_w(
        )
        self.icons_dict = self.gstyle_obj.icon_dict
        self.emerald_dict = self.gstyle_obj.emerald_dict
        self.mouse_dict = self.gstyle_obj.mouse_dict
        self.cubemodel_dict = self.gstyle_obj.cubemodels_dict
        self.metacity_dict = self.gstyle_obj.metacity_dict

        self.icon_obj = self.gstyle_obj.gtk_gui.icon_obj
        self.gtk_obj = self.gstyle_obj.gtk_gui.gtk_obj
        self.wallpaper_obj = self.gstyle_obj.gtk_gui.wallpaper_obj
        self.mouse_obj = self.gstyle_obj.gtk_gui.mouse_obj
        self.metacity_obj = self.gstyle_obj.gtk_gui.metacity_obj
        self.emerald_obj = self.gstyle_obj.gtk_gui.emerald_obj
        self.cubemodel_obj = self.gstyle_obj.gtk_gui.cubemodel_obj

        self.fpack_dic = {}
        self.fpack_dic_copy = {}

        self.fullpack_save_btn = gladexml.get_widget("fullpack_save_btn")
        self.fullpack_create_btn = gladexml.get_widget("fpack_create_btn")
        self.fullpack_manage_scroll = gladexml.get_widget(
            "fullpack_gest_viewer")
        self.fullpack_manage_info = gladexml.get_widget("fullpack_gest_label")
        self.fullpack_manage_info.set_text(_("Installed fullpack theme list"))
        ## fullpack notebook page image
        self.fullpack_page_img = gladexml.get_widget("fullpack_page_img")
        self.fullpack_page_img.set_from_file("%s/fullpack-icon.png" %
                                             config.img_path)
        ## fullpack top description
        self.fullpack_page_label = gladexml.get_widget("fullpack_page_label")
        self.fullpack_page_label.set_text(
            _("Fullpacks : \nOrganize, create or download fullpack themes...\n"
              ))

        self.fullpack_download_scroll = gladexml.get_widget(
            'fullpack_download_scroll')
        self.fullpack_download_info = gladexml.get_widget(
            'fullpack_download_info')
        self.fullpack_download_info.set_text(
            _("Click the refresh button to update the theme list"))

        ## progress
        self.progress_box = gladexml.get_widget("progress_box")
        self.progress_text = gladexml.get_widget("progress_box_text")
        self.main_progressbar = gladexml.get_widget("main_progressbar")

        self.statbar = gladexml.get_widget("statusbar")
        self.progress = gladexml.get_widget("fullpack_download_pbar")

        ## gui
        self.fullpack_name_scroll = gladexml.get_widget(
            "fullpack_gest_txtlist")
        self.fullpack_name_scroll.set_policy(gtk.POLICY_AUTOMATIC,
                                             gtk.POLICY_ALWAYS)
        self.model = gtk.ListStore(gtk.gdk.Pixbuf, str, str, str)
        self.fullpack_name_tree = gtk.TreeView()
        self.fullpack_name_tree.set_model(self.model)
        renderer = gtk.CellRendererText()
        img_renderer = gtk.CellRendererPixbuf()
        pixColumn = gtk.TreeViewColumn(_("Preview"), img_renderer)
        pixColumn.set_fixed_width(200)
        self.fullpack_name_tree.append_column(pixColumn)
        pixColumn.add_attribute(img_renderer, 'pixbuf', 0)
        titleColumn = gtk.TreeViewColumn(_("Fullpack name"), renderer, text=1)
        titleColumn.set_min_width(200)
        pathColumn = gtk.TreeViewColumn()
        iniColumn = gtk.TreeViewColumn()

        self.fullpack_name_tree.append_column(titleColumn)
        self.fullpack_name_tree.append_column(pathColumn)
        self.fullpack_name_tree.append_column(iniColumn)

        ## setup the scrollview
        self.name_list_columns = self.fullpack_name_tree.get_columns()
        self.name_list_columns[1].set_visible(0)
        self.name_list_columns[2].set_visible(0)
        self.name_list_columns[3].set_visible(0)
        self.fullpack_name_scroll.add_with_viewport(self.fullpack_name_tree)
        self.fullpack_name_scroll.show()

        self.fullpack_name_tree.connect('cursor-changed', self.get_model)
        self.fullpack_name_tree.connect('button-press-event',
                                        self.check_double_click)

        ## the fullpack editor
        self.fpack_gtk_selector = gladexml.get_widget('fpack_gtk_selector')
        self.fpack_gtk_selector.set_model(self.gtk_obj.model)
        self.fpack_icon_selector = gladexml.get_widget('fpack_icon_selector')
        self.fpack_icon_selector.set_model(self.icon_obj.model)
        self.fpack_metacity_selector = gladexml.get_widget(
            'fpack_metacity_selector')
        self.fpack_metacity_selector.set_model(self.metacity_obj.model)
        self.fpack_emerald_selector = gladexml.get_widget(
            'fpack_emerald_selector')
        self.fpack_emerald_selector.set_model(self.emerald_obj.model)
        self.fpack_wallstat_selector = gladexml.get_widget(
            'fpack_wallstat_selector')
        self.fpack_wallstat_selector.set_model(
            self.wallpaper_obj.wallstats_model)
        self.fpack_walldyn_selector = gladexml.get_widget(
            'fpack_walldyn_selector')
        self.fpack_walldyn_selector.set_model(
            self.wallpaper_obj.walldyns_model)
        self.fpack_mouse_selector = gladexml.get_widget('fpack_mouse_selector')
        self.fpack_mouse_selector.set_model(self.mouse_obj.model)
        self.fpack_cubemodel_selector = gladexml.get_widget(
            'fpack_cubemodel_selector')
        self.fpack_cubemodel_selector.set_model(self.cubemodel_obj.model)

        ## preview images
        self.fpack_gtk_img = gladexml.get_widget('fpack_gtk_img')
        self.fpack_gtk_preview = gladexml.get_widget('fpack_gtk_preview')
        self.fpack_icon_img = gladexml.get_widget('fpack_icon_img')
        self.metacity_previewbox = gladexml.get_widget('metacity_previewbox')
        self.fpack_emerald_img = gladexml.get_widget('fpack_emerald_img')
        self.fpack_wallstat_img = gladexml.get_widget('fpack_wallstat_img')
        self.fpack_walldyn_img = gladexml.get_widget('fpack_walldyn_img')
        self.fpack_mouse_img = gladexml.get_widget('fpack_mouse_img')
        self.fpack_cubemodel_img = gladexml.get_widget('fpack_cubemodel_img')

        ## entry
        self.fpack_name_entry = gladexml.get_widget('fpack_name_entry')
        self.fpack_author_entry = gladexml.get_widget('fpack_author_entry')
        self.fpack_licence_entry = gladexml.get_widget('fpack_licence_entry')
        self.fpack_website_entry = gladexml.get_widget('fpack_website_entry')

        ## create
        self.fpack_create_imgpath = gladexml.get_widget('fpack_create_imgpath')
        self.fpack_chooseimg_btn = gladexml.get_widget('fpack_chooseimg_btn')

        ############################################
        # download model
        ## gui
        self.fullpack_down_model = gtk.ListStore(gtk.gdk.Pixbuf, str, str)
        self.fullpack_down_iconview = gtk.IconView(
            model=self.fullpack_down_model)

        # Setup cubemodel iconview
        self.fullpack_down_iconview.set_pixbuf_column(0)
        self.fullpack_down_iconview.set_text_column(1)
        ## options
        self.fullpack_down_iconview.set_columns(0)
        self.fullpack_down_iconview.set_selection_mode('single')
        self.fullpack_down_iconview.set_reorderable(1)

        self.fullpack_down_iconview.connect('selection_changed',
                                            self.get_down_model)
        self.fullpack_download_scroll.add(self.fullpack_down_iconview)
        ## start listing
        self.fullpack_save_btn.set_sensitive(0)
        ## active comboboxes
        self.gtk_combo = ComboBox(self.fpack_gtk_selector)
        self.icons_combo = ComboBox(self.fpack_icon_selector)
        self.metacity_combo = ComboBox(self.fpack_metacity_selector)
        self.emerald_combo = ComboBox(self.fpack_emerald_selector)
        self.wallstat_combo = ComboBox(self.fpack_wallstat_selector)
        self.walldyn_combo = ComboBox(self.fpack_walldyn_selector)
        self.mouse_combo = ComboBox(self.fpack_mouse_selector)
        self.cubemodel_combo = ComboBox(self.fpack_cubemodel_selector)

        dic = {
            "on_fullpack_add_btn_clicked": self.action_add,
            "on_fullpack_apply_btn_clicked": self.action_apply,
            "on_fullpack_del_btn_clicked": self.action_del,
            "on_fullpack_refresh_btn_clicked": self.action_refresh,
            "on_fullpack_down_btn_clicked": self.action_download,
            "on_fullpack_save_btn_clicked": self.action_save,
            "on_fpack_gtk_selector_changed": self.on_select_gtk,
            "on_fpack_metacity_selector_changed": self.on_select_metacity,
            "on_fpack_icon_selector_changed": self.on_select_icon,
            "on_fpack_emerald_selector_changed": self.on_select_emerald,
            "on_fpack_wallstat_selector_changed": self.on_select_wallstat,
            "on_fpack_walldyn_selector_changed": self.on_select_walldyn,
            "on_fpack_mouse_selector_changed": self.on_select_mouse,
            "on_fpack_cubemodel_selector_changed": self.on_select_cubemodel,
            "on_fpack_create_btn_clicked": self.action_create,
            "on_fpack_chooseimg_btn_clicked": self.action_chooseimg,
            "on_fpack_gtk_reset_clicked": self.reset_combobox,
            "on_fpack_icons_reset_clicked": self.reset_combobox,
            "on_fpack_metacity_reset_clicked": self.reset_combobox,
            "on_fpack_wallstat_reset_clicked": self.reset_combobox,
            "on_fpack_walldyn_reset_clicked": self.reset_combobox,
            "on_fpack_mouse_reset_clicked": self.reset_combobox,
            "on_fpack_cubemodel_reset_clicked": self.reset_combobox,
            "on_fpack_emerald_reset_clicked": self.reset_combobox,
            "on_fpack_export_btn_clicked": self.export_fullpack,
        }
        gladexml.signal_autoconnect(dic)

        self.list_fullpack_themes()
Пример #3
0
    def __init__(self,gladexml,icon_dict):
        #Load api icon
        self.icon_dict = icon_dict
        self.gclient = gconf.client_get_default()
        self.iconsTheme_save = gconf_get("/desktop/gnome/interface/icon_theme")
        ## load widget
        self.w_status_bar = gladexml.get_widget("statusbar")

        self.icons_page_img = gladexml.get_widget("icons_page_img")
        self.icons_page_img.set_from_file(config.img_path+"/iconspack.png")
        self.icons_page_label = gladexml.get_widget("icons_page_label")
        self.icons_page_label.set_text(_("Icons:\nManage and install your icons themes"))

        self.wl_icon_gest = gladexml.get_widget("icons_gest_label")
        self.wl_icon_gest.set_text(_("Available themes list"))

        self.progress_box = gladexml.get_widget("progress_box")
        self.progress_text = gladexml.get_widget("progress_box_text")

        self.main_progressbar = gladexml.get_widget("main_progressbar")

        self.statbar = gladexml.get_widget("statusbar")

        ## setup the iconview
        self.model = gtk.ListStore(str,gtk.gdk.Pixbuf, str, str, str, str, str, str)
        self.w_iconview = gtk.IconView(model=self.model)
        self.w_iconview.set_pixbuf_column(1)
        self.w_iconview.set_text_column(0)
        self.w_iconview.set_columns(0)
        self.w_iconview.set_item_width(150)
        self.w_iconview.set_selection_mode('single')
        self.w_iconview.set_reorderable(1)
        ## add the iconview
        self.w_viewer = gladexml.get_widget("icons_viewer")
        self.w_viewer.add(self.w_iconview)
        self.list_icon_themes()

        self.w_applybtn =  gladexml.get_widget("icons_gest_applybtn")


        #Mettre ça dans un objet fenétre principal
        self.decoration_page_img = gladexml.get_widget("decoration_page_img")
        self.decoration_page_desc = gladexml.get_widget("decoration_page_desc")
        img_path = os.path.join(config.exec_path,"/img/iconspack.png")
        if os.path.exists(img_path):
            self.decoration_page_img.set_from_file(img_path)
        self.decoration_page_desc.set_text(_("Icons:\nManage and install your icons themes..."))

        ## gconf and panel icons
        self.icon_panel_combobox = gladexml.get_widget("icon_panel_combobox")
        self.icon_panel_apply_btn = gladexml.get_widget("icon_panel_apply_btn")
        self.menuhaveicon_checkbox = gladexml.get_widget("icon_menuicons_select")
        self.btnhaveicon_checkbox = gladexml.get_widget("icon_btnicons_select")
        self.home_visible_checkbox = gladexml.get_widget("home_icon")
        self.computer_visible_checkbox = gladexml.get_widget("computer_icon")
        self.trash_visible_checkbox = gladexml.get_widget("trash_icon")
        self.network_visible_checkbox = gladexml.get_widget("network_icon")
        self.volumes_visible_checkbox = gladexml.get_widget("volumes_icon")
        ## initialize checkboxes
        self.check_gconf_options()

        ## panel icons
        self.panel_icon_dic = {}
        self.icon_panel_model = gtk.ListStore(str,gtk.gdk.Pixbuf,str)
        self.list_panel_icons()

        self.panelTree = gtk.TreeView()
        self.icon_panel_combobox.set_model(self.icon_panel_model)
        px = gtk.CellRendererPixbuf()
        text = gtk.CellRendererText()

        #Pack the cell renderer into the combobox.
        self.icon_panel_combobox.pack_start(px, False)
        self.icon_panel_combobox.pack_start(text, False)

        #Use the add_attribute method to specify which column in the model the
        self.icon_panel_combobox.add_attribute(px, "pixbuf", 1)
        #Do the same for CellRendererText()
        self.icon_panel_combobox.add_attribute(text, "text", 0)

        self.panel_icon_combo = ComboBox(self.icon_panel_combobox)
        self.get_active_panel_icon()

        ##load signal
        dic = {"on_icons_gest_addbtn_clicked" : self.action_add,
               "on_icons_gest_applybtn_clicked" : self.action_apply,
               "on_icons_gest_delbtn_clicked" : self.action_delete,
               "on_icon_panel_apply_btn_clicked" : self.apply_panel_icon,
               "on_icon_menuicons_select_toggled" : self.set_gconf_options,
               "on_icon_btnicons_select_toggled" : self.set_gconf_options,
               "on_panel_icon_addbtn_clicked" : self.add_panel_icon,
               "on_panel_icon_delbtn_clicked" : self.del_panel_icon,
               "on_computer_icon_toggled" : self.set_gconf_options,
               "on_home_icon_toggled" : self.set_gconf_options,
               "on_trash_icon_toggled" : self.set_gconf_options,
               "on_network_icon_toggled" : self.set_gconf_options,
               "on_volumes_icon_toggled" : self.set_gconf_options,
               }
        self.w_iconview.connect('selection_changed',self.action_get_model)
        self.w_iconview.connect('button-press-event',self.treeview_clicked)
        gladexml.signal_autoconnect(dic)
Пример #4
0
class IconGui(object):
    def __init__(self,gladexml,icon_dict):
        #Load api icon
        self.icon_dict = icon_dict
        self.gclient = gconf.client_get_default()
        self.iconsTheme_save = gconf_get("/desktop/gnome/interface/icon_theme")
        ## load widget
        self.w_status_bar = gladexml.get_widget("statusbar")

        self.icons_page_img = gladexml.get_widget("icons_page_img")
        self.icons_page_img.set_from_file(config.img_path+"/iconspack.png")
        self.icons_page_label = gladexml.get_widget("icons_page_label")
        self.icons_page_label.set_text(_("Icons:\nManage and install your icons themes"))

        self.wl_icon_gest = gladexml.get_widget("icons_gest_label")
        self.wl_icon_gest.set_text(_("Available themes list"))

        self.progress_box = gladexml.get_widget("progress_box")
        self.progress_text = gladexml.get_widget("progress_box_text")

        self.main_progressbar = gladexml.get_widget("main_progressbar")

        self.statbar = gladexml.get_widget("statusbar")

        ## setup the iconview
        self.model = gtk.ListStore(str,gtk.gdk.Pixbuf, str, str, str, str, str, str)
        self.w_iconview = gtk.IconView(model=self.model)
        self.w_iconview.set_pixbuf_column(1)
        self.w_iconview.set_text_column(0)
        self.w_iconview.set_columns(0)
        self.w_iconview.set_item_width(150)
        self.w_iconview.set_selection_mode('single')
        self.w_iconview.set_reorderable(1)
        ## add the iconview
        self.w_viewer = gladexml.get_widget("icons_viewer")
        self.w_viewer.add(self.w_iconview)
        self.list_icon_themes()

        self.w_applybtn =  gladexml.get_widget("icons_gest_applybtn")


        #Mettre ça dans un objet fenétre principal
        self.decoration_page_img = gladexml.get_widget("decoration_page_img")
        self.decoration_page_desc = gladexml.get_widget("decoration_page_desc")
        img_path = os.path.join(config.exec_path,"/img/iconspack.png")
        if os.path.exists(img_path):
            self.decoration_page_img.set_from_file(img_path)
        self.decoration_page_desc.set_text(_("Icons:\nManage and install your icons themes..."))

        ## gconf and panel icons
        self.icon_panel_combobox = gladexml.get_widget("icon_panel_combobox")
        self.icon_panel_apply_btn = gladexml.get_widget("icon_panel_apply_btn")
        self.menuhaveicon_checkbox = gladexml.get_widget("icon_menuicons_select")
        self.btnhaveicon_checkbox = gladexml.get_widget("icon_btnicons_select")
        self.home_visible_checkbox = gladexml.get_widget("home_icon")
        self.computer_visible_checkbox = gladexml.get_widget("computer_icon")
        self.trash_visible_checkbox = gladexml.get_widget("trash_icon")
        self.network_visible_checkbox = gladexml.get_widget("network_icon")
        self.volumes_visible_checkbox = gladexml.get_widget("volumes_icon")
        ## initialize checkboxes
        self.check_gconf_options()

        ## panel icons
        self.panel_icon_dic = {}
        self.icon_panel_model = gtk.ListStore(str,gtk.gdk.Pixbuf,str)
        self.list_panel_icons()

        self.panelTree = gtk.TreeView()
        self.icon_panel_combobox.set_model(self.icon_panel_model)
        px = gtk.CellRendererPixbuf()
        text = gtk.CellRendererText()

        #Pack the cell renderer into the combobox.
        self.icon_panel_combobox.pack_start(px, False)
        self.icon_panel_combobox.pack_start(text, False)

        #Use the add_attribute method to specify which column in the model the
        self.icon_panel_combobox.add_attribute(px, "pixbuf", 1)
        #Do the same for CellRendererText()
        self.icon_panel_combobox.add_attribute(text, "text", 0)

        self.panel_icon_combo = ComboBox(self.icon_panel_combobox)
        self.get_active_panel_icon()

        ##load signal
        dic = {"on_icons_gest_addbtn_clicked" : self.action_add,
               "on_icons_gest_applybtn_clicked" : self.action_apply,
               "on_icons_gest_delbtn_clicked" : self.action_delete,
               "on_icon_panel_apply_btn_clicked" : self.apply_panel_icon,
               "on_icon_menuicons_select_toggled" : self.set_gconf_options,
               "on_icon_btnicons_select_toggled" : self.set_gconf_options,
               "on_panel_icon_addbtn_clicked" : self.add_panel_icon,
               "on_panel_icon_delbtn_clicked" : self.del_panel_icon,
               "on_computer_icon_toggled" : self.set_gconf_options,
               "on_home_icon_toggled" : self.set_gconf_options,
               "on_trash_icon_toggled" : self.set_gconf_options,
               "on_network_icon_toggled" : self.set_gconf_options,
               "on_volumes_icon_toggled" : self.set_gconf_options,
               }
        self.w_iconview.connect('selection_changed',self.action_get_model)
        self.w_iconview.connect('button-press-event',self.treeview_clicked)
        gladexml.signal_autoconnect(dic)

    def add_panel_icon(self,widget):
        filterlist = ["*.png","*.svg"]
        dialog = create_filechooser_open((_("Choose an icon image")),filterlist)
        result = dialog.run()
        if result != gtk.RESPONSE_OK:
            dialog.destroy()
            return
        ## if ok
        icon = dialog.get_filename()
        dialog.destroy()
        if icon:
            self.icon_dict.add_panelicon_todic(icon)
            name = os.path.basename(os.path.splitext(icon)[0])
            self.add_panel_model(name,icon)
            self.panel_icon_combo.setIndexFromString(name)
            self.apply_panel_icon()

    def get_active_panel_icon(self):
        parser = ConfigParser.RawConfigParser()
        parser.readfp(open(gstyle_conf_file))
        name = parser.get('panel-icon', 'name')
        if name:
            self.panel_icon_combo.setIndexFromString(name)

    def del_panel_icon(self,widget):
        name = self.panel_icon_combo.getSelected()
        img = self.panel_icon_dic[name]
        imgname = os.path.basename(img)
        self.icon_panel_model.clear()
        os.unlink(img)
        del self.panel_icon_dic[name]
        self.list_panel_icons()
        self.panel_icon_combo.select(0)

    def apply_panel_icon(self,widget=None):
        name = self.panel_icon_combo.getSelected()
        img = self.panel_icon_dic[name]
        imgname = os.path.basename(img)
        ext = os.path.splitext(imgname)[-1]
        ## get the path for active icon theme
        theme = self.icon_dict.get_active_item()
        if theme:
            path = theme.path
            mainpath = None
            if os.path.exists(path+'/24x24/places'):
                mainpath = path+'/24x24/places'
                if ext == '.png':
                    os.system('convert -resize 24x24! %s %s' % (img, img))
            elif os.path.exists(path+'/places/24'):
                mainpath = path+'/places/24'
                if ext == '.png':
                    os.system('convert -resize 24x24! %s %s' % (img, img))
            elif os.path.exists(path+'/places'):
                mainpath = path+'/places'
                if ext == '.png':
                    os.system('convert -resize 24x24! %s %s' % (img, img))
            elif os.path.exists(path+'/scalable/places'):
                mainpath = path+'/scalable/places'
                if ext == '.png':
                    os.system('convert -resize 128x128! %s %s' % (img, img))
            else:
                mainpath = path+'/scalable/places'
                if ext == '.png':
                    os.system('convert -resize 128x128! %s %s' % (img, img))

            target = mainpath+'/start-here'+ext
            if not os.path.islink(path) and ('/usr' in path):
                if not os.path.exists(mainpath):
                    run_as_root('mkdir -p %s' % mainpath, msg)
                for i in glob(mainpath+'/start-here*'):
                    run_as_root('rm %s' % i, msg)
                run_as_root("cp -f %s %s" % (img, target), msg)
            else:
                if not os.path.exists(mainpath):
                    os.makedirs(mainpath, 0755)
                for i in glob(mainpath+'/start-here*'):
                    os.system('rm %s' % i)
                copyfile(img, target)
            os.system('killall -9 gnome-panel')
            ## update gstyle .ini
            parser = ConfigParser.RawConfigParser()
            parser.readfp(open(gstyle_conf_file))
            parser.set('panel-icon', 'name', name)
            parser.set('panel-icon', 'path', img)
            with open(gstyle_conf_file, 'w+') as configfile:
                parser.write(configfile)

    def run_sudo(self, cmd, msg):
        gksu_context = gksu2.Context()
        gksu_context.set_message(msg)
        gksu2.run(cmd)

    def list_panel_icons(self):
        for file in glob(panel_icon_dir+'/*'):
            name = os.path.basename(os.path.splitext(file)[0])
            self.add_panel_model(name,file)

    def check_gconf_options(self):
        menuicon = gconf_get("/desktop/gnome/interface/menus_have_icons")
        btnicon = gconf_get("/desktop/gnome/interface/buttons_have_icons")
        homeicon = gconf_get("/apps/nautilus/desktop/home_icon_visible")
        compicon = gconf_get("/apps/nautilus/desktop/computer_icon_visible")
        trashicon = gconf_get("/apps/nautilus/desktop/trash_icon_visible")
        neticon = gconf_get("/apps/nautilus/desktop/network_icon_visible")
        volicon = gconf_get("/apps/nautilus/desktop/volumes_visible")
        if menuicon:
            self.menuhaveicon_checkbox.set_active(1)
        if btnicon:
            self.btnhaveicon_checkbox.set_active(1)
        if homeicon:
            self.home_visible_checkbox.set_active(1)
        if trashicon:
            self.trash_visible_checkbox.set_active(1)
        if neticon:
            self.network_visible_checkbox.set_active(1)
        if volicon:
            self.volumes_visible_checkbox.set_active(1)
        if compicon:
            self.computer_visible_checkbox.set_active(1)

    def set_gconf_options(self,widget):
        self.icon_dict.set_gconf_options(widget)

    def list_icon_themes(self):
        for item in self.icon_dict.values():
            self.add_model(item)

    def add_model(self,item):
        picture_path = item.picture
        extension = os.path.splitext(picture_path)[1]
        if extension == '.svg':
            img = gtk.gdk.pixbuf_new_from_file_at_size(picture_path, 60, 60)
        elif extension == '.png':
            gtk.ACCEL_LOCKED
            img = gtk.gdk.pixbuf_new_from_file_at_size(picture_path, 60, 60 )
        else:
            return
        self.iter = self.model.append()
        self.model.set(self.iter,
        0, item.dirname,
        1, img,
        2, item.path,
        3, item.description,
        4, item.name,
        )

    def add_panel_model(self,name,path):
        extension = os.path.splitext(path)[-1]
        img = None

        if extension == '.svg':
            img = gtk.gdk.pixbuf_new_from_file_at_scale(path, 24, 24, 1)
        elif extension == '.png':
            gtk.ACCEL_LOCKED
            img = gtk.gdk.pixbuf_new_from_file_at_scale(path, 24, 24, 1)
        else:
            return
        iter = self.icon_panel_model.append()
        self.icon_panel_model.set(iter,
        0, name,
        1, img,
        2, path,
        )
        self.panel_icon_dic[name] = path

    #Action
    def action_add(self,widget):
        filterlist = ["*.gz","*.bz2","*.tar","*.zip","*.rar"]
        dialog = create_filechooser_open((_("Choose a tar.gz/bz2 file")),filterlist)
        result = dialog.run()
        if result != gtk.RESPONSE_OK:
            dialog.destroy()
            return
        ## if ok
        icons_archive = dialog.get_filename()
        dirname = ""
        dialog.destroy()
        if not os.path.exists(icons_archive):
            print "Icon theme non-existent or corrupt \n"
            return
        theme_list = self.icon_dict.add_item_archive(icons_archive)
        if theme_list and theme_list.has_key('icons'):
            return self.action_add_todic(theme_list)
        else:
            print "no icons themes in this file... %s " % icons_archive
            return

    def action_add_todic(self,theme_list):
        icons_theme_list = theme_list['icons']
        for destination in icons_theme_list.values():
            if destination:
                item = self.icon_dict.add_item_system(destination)
                if item:
                    dirname = item.dirname
                    self.add_model(item)
        if item:
            path = self.model[-1].path
            self.w_iconview.select_path(path)
            self.w_iconview.set_cursor(path)
            self.icon_dict.set_active_item(dirname)

    def action_apply(self,widget=None,dirname=None):
        if dirname:
            self.item_dirname = dirname
            self.item_name = dirname
        self.icon_dict.set_active_item(self.item_dirname)
        self.w_status_bar.push(1,(_("Icons theme  %s successfully activated") % self.item_name))

    def action_delete(self,widget):
        confirm = yesno((_("Remove icons themes")),\
                (_("Are you sure you want to delete the icons Theme \n %s ?") % self.item_name))
        if confirm == "No":
            return
        ## remove the theme
        self.icon_dict.del_item(self.item_dirname)
        self.model.remove(self.iter)
        self.statbar.push(1,(_("Icons themes %s removed successfully") % self.item_name))

    def action_get_model(self,widget=None):
        selected = self.w_iconview.get_selected_items()
        ## check if path exist (or problems when clicking between rows..)
        try:
            row_index = selected[0]
        except:
             return
        self.iter = self.model.get_iter(row_index)
        self.item_name = self.model.get_value(self.iter,4)
        self.item_path = self.model.get_value(self.iter,2)
        self.item_description = self.model.get_value(self.iter,3)
        self.item_dirname = self.model.get_value(self.iter,0)
        self.wl_icon_gest.set_text(_("Description : %s") % self.item_description)
        self.w_status_bar.push(1,_("Selected icons theme : %s") % self.item_name)

    def treeview_clicked(self, widget, event):
        if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS:
            self.action_get_model()
            self.action_apply()
Пример #5
0
class Youtube(object):
    def __init__(self,gui):
        self.gui = gui
        self.current_page = 1
        self.main_start_page = 1
        self.engine_type = "video"
        self.num_start = 1
        self.results_by_page = 25
        self.name="Youtube"
        self.client = yt_service.YouTubeService()
        self.youtube_max_res = "320x240"
        self.media_codec = None
        self.thread_stop= False
        self.has_browser_mode = False
        self.vp8 = False
        ## the gui box to show custom filters/options
        self.opt_box = self.gui.gladeGui.get_widget("search_options_box")
        ## options labels
        self.order_label = _("Order by: ")
        self.category_label = _("Category: ")
        ## video quality combobox
        self.youtube_quality_box = self.gui.gladeGui.get_widget("quality_box")
        
        self.youtube_quality_model = gtk.ListStore(str)
        self.youtube_video_rate = gtk.ComboBox(self.youtube_quality_model)
        cell = gtk.CellRendererText()
        self.youtube_video_rate.pack_start(cell, True)
        self.youtube_video_rate.add_attribute(cell, 'text', 0)
        self.youtube_quality_box.add(self.youtube_video_rate)
        new_iter = self.youtube_quality_model.append()
        self.youtube_quality_model.set(new_iter,
                                0, _("Quality"),
                                )
        self.youtube_video_rate.connect('changed', self.on_youtube_video_rate_changed)

        ## youtube video quality choices
        self.res320 = self.gui.gladeGui.get_widget("res1")
        self.res640 = self.gui.gladeGui.get_widget("res2")
        self.res854 = self.gui.gladeGui.get_widget("res3")
        self.res1280 = self.gui.gladeGui.get_widget("res4")
        self.res1920 = self.gui.gladeGui.get_widget("res5")

        ## SIGNALS
        dic = {
        "on_res1_toggled" : self.set_max_youtube_res,
        "on_res2_toggled" : self.set_max_youtube_res,
        "on_res3_toggled" : self.set_max_youtube_res,
        "on_res4_toggled" : self.set_max_youtube_res,
        "on_res5_toggled" : self.set_max_youtube_res,
         }
        self.gui.gladeGui.signal_autoconnect(dic)
        ## start
        self.start_engine()

    def print_info(self,msg):
        gobject.idle_add(self.gui.info_label.set_text,msg)

    def start_engine(self):
        self.gui.engine_list[self.name] = ''
        ## get default max_res for youtube videos
        try:
            self.youtube_max_res = self.gui.conf["youtube_max_res"]
        except:
            self.gui.conf["youtube_max_res"] = self.youtube_max_res

        if self.youtube_max_res == "320x240":
            self.res320.set_active(1)
        elif self.youtube_max_res == "640x360":
            self.res640.set_active(1)
        elif self.youtube_max_res == "854x480":
            self.res854.set_active(1)
        elif self.youtube_max_res == "1280x720":
            self.res1280.set_active(1)
        elif self.youtube_max_res == "1920x1080":
            self.res1920.set_active(1)

        gobject.idle_add(self.youtube_video_rate.hide)
        gobject.idle_add(self.youtube_video_rate.set_active,0)

    
    
    
    def load_gui(self):
        ## paste entry
        btn = gtk.Button()
        image = gtk.Image()
        pb = gtk.gdk.pixbuf_new_from_file(img_path+"/yt_icone.jpg")
        image.set_from_pixbuf(pb) 
        button = gtk.Button()
        button.set_image(image)
        button.connect("clicked", self.on_paste)
        button.set_tooltip_text(_('Paste youtube link'))
        self.gui.search_opt_box.pack_start(button,False,False,10)
        
        ## create orderby combobox
        cb = create_comboBox()
        self.orderbyOpt = {self.order_label:{_("Most relevant"):"relevance",
                                             _("Most recent"):"published",_("Most viewed"):"viewCount",
                                             _("Most rated"):"rating",
            },
        }
        self.orderby = create_comboBox(self.gui, self.orderbyOpt)
        
        ## create categories combobox
        self.category = ComboBox(cb)
        self.catlist = {self.category_label:{"":"",_("Sport"):"Sports",
                                             _("Films"):"Film",_("Cars"):"Autos",
                                             _("Music"):"Music",_("Technology"):"Tech",_("Animals"):"Animals",
                                             _("Travel"):"Travel",_("Games"):"Games",_("Comedy"):"Comedy",
                                             _("Peoples"):"People",_("News"):"News",
                                             _("Entertainement"):"Entertainment",_("Trailers"):"Trailers",
            },
        }
        self.category = create_comboBox(self.gui, self.catlist)
        self.orderby.setIndexFromString(_("Most relevant"))
        
        gobject.idle_add(self.gui.search_opt_box.show_all)
        
        ## vp8 check
        if not sys.platform == 'win32':
            out,err = Popen('/usr/bin/gst-inspect-0.10| grep vp8',shell=True,stdout=PIPE,stderr=STDOUT).communicate()
            if 'vp8' in str(out):
                self.vp8 = True
            else:
                out,err = Popen('/usr/bin/gst-inspect | grep vp8',shell=True,stdout=PIPE,stderr=STDOUT).communicate()
                if 'vp8' in str(out):
                    self.vp8 = True
        else:
            self.vp8 = True
        
    def on_paste(self,widget=None,url=None):
        text = ''
        if not url:
            clipboard = gtk.Clipboard(gtk.gdk.display_get_default(), "CLIPBOARD")
            data = clipboard.wait_for_contents('UTF8_STRING')
            try:
                text = data.get_text()
            except:
                error_dialog(_("There's no link to paste..."))
                return
        else:
            text = url
        if text != '':
            vid=None
            try:
                vid = re.search('watch\?v=(.*?)&(.*)',text).group(1)
            except:
                try:
                    vid = re.search('watch\?v=(.*)',text).group(1)
                except:
                    error_dialog(_('Your link:\n\n%s\n\nis not a valid youtube link...' % text))
                    return
            yt = yt_service.YouTubeService()
            entry = yt.GetYouTubeVideoEntry(video_id='%s' % vid)
            self.filter(entry, '', 1)
        else:
            return

    def set_max_youtube_res(self, widget):
        if widget.get_active():
            self.youtube_max_res = widget.get_child().get_label()
            self.gui.conf["youtube_max_res"] = self.youtube_max_res
            ## return a dic as conf
            try:
                self.gui.conf.write()
            except:
                print "Can't write to the %s config file..." % self.gui.conf_file

    def get_search_url(self,user_search,page):
        return self.search(user_search,page)
    
    def search(self,user_search,page):
        self.thread_stop=False
        nlist = []
        link_list = []
        next_page = 0
        ## prepare query
        query = yt_service.YouTubeVideoQuery()
        query.vq = user_search # the term(s) that you are searching for
        query.max_results = '25'
        #query.lr = 'fr'
        orderby = self.orderby.getSelected()
        query.orderby = self.orderbyOpt[self.order_label][orderby]
        cat = self.category.getSelected()
        if self.category.getSelectedIndex() != 0:
            query.categories.append('/%s' % self.catlist[self.category_label][cat])

        if self.current_page == 1:
            self.num_start = 1
        query.start_index = self.num_start
        vquery = self.client.YouTubeQuery(query)
        return vquery

    def filter(self,vquery,user_search,direct_link=None):
        if not vquery :
            self.num_start = 1
            self.current_page = 1
            self.print_info(_("%s: No results for %s ...") % (self.name,user_search))
            time.sleep(5)
            self.thread_stop=True

        if direct_link:
            gobject.idle_add(self.gui.model.clear)
            return self.make_youtube_entry(vquery, True)
        
        if len(vquery.entry) == 0:
            self.print_info(_("%s: No results for %s ...") % (self.name,user_search))
            time.sleep(5)
            self.thread_stop=True

        for entry in vquery.entry:
            if not self.thread_stop:
                self.make_youtube_entry(entry)
            else:
                return
        self.thread_stop=True

    def play(self,link):
        gobject.idle_add(self.gui.quality_box.show)
        self.load_youtube_res(link)
        self.gui.media_link=link
        active = self.youtube_video_rate.get_active()
        try:
            self.media_codec = self.quality_list[active].split('|')[1]
            self.gui.start_play(self.media_link[active])
        except:
            self.gui.start_play('')

    def make_youtube_entry(self,video,read=None):
        duration = video.media.duration.seconds
        calc = divmod(int(duration),60)
        seconds = int(calc[1])
        if seconds < 10:
            seconds = "0%d" % seconds
        duration = "%d:%s" % (calc[0],seconds)
        url = video.link[1].href
        thumb = video.media.thumbnail[-1].url
        count = 0
        try:
            count = video.statistics.view_count
        except:
            pass
        vid_id = os.path.basename(os.path.dirname(url))
        try:
            vid_pic = download_photo(thumb)
        except:
            return
        title = video.title.text
        if not count:
            count = 0

        
        values = {'name': title, 'count': count, 'duration': duration}
        markup = _("\n<small><b>view:</b> %(count)s        <b>Duration:</b> %(duration)s</small>") % values
        if not title or not url or not vid_pic:
            return
        gobject.idle_add(self.gui.add_sound,title, vid_id, vid_pic,None,self.name,markup)
                

    def get_codec(self, num):
        codec=None
        if re.match('5',num):
            codec = "flv"
        elif re.match('18|22|38|37|34|35',num):
            codec= "mp4"
        elif re.match('43|44|45',num):
            codec= "webm"
        elif re.match('17',num):
            codec= "3gp"
        return codec
    
    def load_youtube_res(self,link):
        gobject.idle_add(self.youtube_quality_model.clear)
        self.media_link = None
        self.quality_list = None
        try:
            self.media_link,self.quality_list = self.get_quality_list(link)
        except:
            return
        if not self.quality_list:
            return
        for rate in self.quality_list:
            new_iter = self.youtube_quality_model.append()
            self.youtube_quality_model.set(new_iter,
                            0, rate,
                            )
        self.set_default_youtube_video_rate()
        gobject.idle_add(self.youtube_video_rate.show)

    def set_default_youtube_video_rate(self,widget=None):
        active = self.youtube_video_rate.get_active()
        qn = 0
        ## if there s only one quality available, read it...
        if active == -1:
            if len(self.quality_list) == 1:
                gobject.idle_add(self.youtube_video_rate.set_active,0)
            for frate in self.quality_list:
                rate = frate.split('|')[0]
                codec = frate.split('|')[1]
                h = int(rate.split('x')[0])
                dh = int(self.youtube_max_res.split('x')[0])
                if h > dh:
                    qn += 1
                    continue
                else:
                    if codec == 'mp4' and '%s|webm' % rate in str(self.quality_list):
                        continue
                    self.youtube_video_rate.set_active(qn)
            active = gobject.idle_add(self.youtube_video_rate.get_active)
        else:
            if self.quality_list:
                active = self.youtube_video_rate.get_active()

    def on_youtube_video_rate_changed(self,widget):
        active = self.youtube_video_rate.get_active()
        if self.gui.is_playing:
            self.gui.stop_play()
            try:
                self.media_codec = self.quality_list[active].split('|')[1]
                self.gui.start_play(self.media_link[active])
            except:
                pass

    
    def get_quality_list(self,vid_id):
        links_arr = []
        quality_arr = []
        try:
            req = urllib2.Request("http://www.youtube.com/get_video_info?video_id=" + urllib2.quote('%s' % vid_id))
            stream = urllib2.urlopen(req)
            contents = urllib.unquote(stream.read())
            if re.search('status=fail',contents):
                req = urllib2.Request("http://www.youtube.com/watch?v=" + urllib2.quote('%s' % vid_id))
                stream = urllib2.urlopen(req)
                contents = urllib.unquote(stream.read())
            ## links list
            try:
                matches = re.search("url_encoded_fmt_stream_map=(.*?)fmt_list",contents).group(1)
            except:
                try:
                    matches = re.search("url_encoded_fmt_stream_map=(.*?)\">",contents).group(1)
                except:
                    matches = re.search("url_encoded_fmt_stream_map=(.*)",contents).group(1)
            fmt_arr = urllib.unquote(matches).split(',')
            ## quality_list
            regexp1 = re.compile("fmt_list=([^&]+)&")
            matches = regexp1.search(contents).group(1)
            quality_list = urllib.unquote(matches).split(',')
            stream.close()
            ##
            link_list = []
            for link in fmt_arr:
                try:
                    res = re.search('url=(.*?)&type', link).group(1)
                    link_list.append(urllib.unquote(res))
                except:
                    continue
            ## remove flv links...
            i = 0
            if quality_list[0] == quality_list[1]:
                quality_list.remove(quality_list[0])
                fmt_arr.remove(fmt_arr[0])
            for quality in quality_list:
                #print quality
                codec = self.get_codec(quality)
                if codec == 'webm' and not self.vp8:
                    i+=1
                    continue
                if codec == "flv" and quality.split("/")[1] == "320x240" and re.search("18/320x240",str(quality_list)):
                    i+=1
                    continue
                elif codec == "flv" and quality.split("/")[1] != "320x240":
                    i+=1
                    continue
                elif quality == '18/640x360/9/0/115' and re.search("34/640x360/9/0/115",str(quality_list)):
                    i+=1
                    continue
                else:
                    links_arr.append(link_list[i])
                    q = quality.split("/")[1] + "|%s" % codec
                    quality_arr.append(quality.split("/")[1] + "|%s" % codec)
                    i+=1
        except:
            return
        return links_arr, quality_arr