def test_get_from_name_load_icon_exception(self):
     """On exception `load_icon()` should be called again."""
     m_pixbuf = mock.Mock(spec=GdkPixbuf.Pixbuf,
                          get_height=lambda: DEFAULT_SIZE)
     with patch_load_icon(side_effect=[Exception, m_pixbuf]
                          ) as m_load_icon, patch_log() as m_log:
         m_load_icon.return_value.scale_simple.return_value = m_pixbuf
         pixbuf = get_from_name()
     self.assertEqual(
         m_load_icon.call_args_list,
         [mock.call("gtk-execute", 24, 0),
          mock.call("gtk-execute", 24, 0)])
     self.assertEqual(m_log.warning.call_count, 1)
     self.assertEqual(m_log.error.call_count, 0)
     self.assertEqual(pixbuf, m_pixbuf)
     # more than one exception would fallback to random alter icon loading
     with patch_load_icon(side_effect=[Exception, Exception, m_pixbuf]
                          ) as m_load_icon, patch_log() as m_log:
         m_load_icon.return_value.scale_simple.return_value = m_pixbuf
         pixbuf = get_from_name()
     self.assertEqual(m_load_icon.call_args_list, [
         mock.call("gtk-execute", 24, 0),
         mock.call("gtk-execute", 24, 0),
         mock.call(mock.ANY, 24, 0)
     ])
     self.assertEqual(m_log.warning.call_count, 1)
     self.assertEqual(m_log.error.call_count, 1)
     self.assertEqual(pixbuf, m_pixbuf)
 def helper_test_get_from_name_only_path(self, only_path, call_args_list):
     """Helper for checking if `lookup_icon()` is called or not based on `only_path` value."""
     with mock.patch("ubuntucleaner.utils.icon.Gtk.IconTheme.lookup_icon"
                     ) as m_lookup_icon:
         get_from_name(only_path=True)
     self.assertEqual(
         m_lookup_icon.call_args_list,
         [mock.call("gtk-execute", 24, Gtk.IconLookupFlags.USE_BUILTIN)])
 def helper_test_get_from_name_force_reload(self, force_reload,
                                            call_args_list):
     """Helper for checking if `get_default()` is called or not based on `force_reload` value."""
     with mock.patch("ubuntucleaner.utils.icon.Gtk.IconTheme.get_default"
                     ) as m_get_default:
         get_from_name(force_reload=force_reload)
     # resets `icontheme` global to unmocked version for subsequent tests
     get_from_name(force_reload=force_reload)
     self.assertEqual(m_get_default.call_args_list, call_args_list)
Example #4
0
    def update_model(self, a=None, b=None, expand=False):
        self.janitor_model.clear()
        self.result_model.clear()
        size_list = []

        loader = ModuleLoader('janitor')

        system_text = _('System')
        iter = self.janitor_model.append(
            None, (None, icon.get_from_name('distributor-logo'), system_text,
                   "<b><big>%s</big></b>" % system_text, None, None, None))

        for plugin in loader.get_modules_by_category('system'):
            size_list.append(
                Gtk.Label(
                    label=plugin.get_title()).get_layout().get_pixel_size()[0])
            self.janitor_model.append(
                iter, (False, None, plugin.get_title(), plugin.get_title(),
                       plugin(), None, None))

        personal_text = _('Personal')

        iter = self.janitor_model.append(
            None, (None, icon.get_from_name('system-users'), personal_text,
                   "<b><big>%s</big></b>" % personal_text, None, None, None))

        for plugin in loader.get_modules_by_category('personal'):
            size_list.append(
                Gtk.Label(
                    label=plugin.get_title()).get_layout().get_pixel_size()[0])
            self.janitor_model.append(
                iter, (False, None, plugin.get_title(), plugin.get_title(),
                       plugin(), None, None))

        app_text = _('Apps')

        iter = self.janitor_model.append(
            None, (None, icon.get_from_name('gnome-app-install'), app_text,
                   "<b><big>%s</big></b>" % app_text, None, None, None))

        for plugin in loader.get_modules_by_category('application'):
            size_list.append(
                Gtk.Label(
                    label=plugin.get_title()).get_layout().get_pixel_size()[0])
            self.janitor_model.append(
                iter, (False, None, plugin.get_title(), plugin.get_title(),
                       plugin(), None, None))
        if size_list:
            self.max_janitor_view_width = max(size_list) + 80

        if expand:
            self._expand_janitor_view()
    def on_scan_error(self, plugin, error, iters):
        plugin_iter, result_iter = iters

        self.janitor_model[plugin_iter][self.JANITOR_ICON] = icon.get_from_name('error', size=16)
        self.result_model[result_iter][self.RESULT_DISPLAY] = '<span color="red"><b>%s</b></span>' % _('Scan error for "%s", double-click to see details') % plugin.get_title()

        plugin.set_property('scan_finished', True)
        plugin.set_property('error', error)
Example #6
0
    def on_scan_error(self, plugin, error, iters):
        plugin_iter, result_iter = iters

        self.janitor_model[plugin_iter][self.JANITOR_ICON] = icon.get_from_name('error', size=16)
        self.result_model[result_iter][self.RESULT_DISPLAY] = '<span color="red"><b>%s</b></span>' % _('Scan error for "%s", double-click to see details') % plugin.get_title()

        plugin.set_property('scan_finished', True)
        plugin.set_property('error', error)
Example #7
0
 def load_janitor(self):
     janitor_page = JanitorPage()
     self.feature_dict['janitor'] = self.notebook.append_page(
         janitor_page, Gtk.Label('janitor'))
     self.module_image.set_from_pixbuf(
         icon.get_from_name('computerjanitor', size=48))
     self.title_label.set_markup('<b><big>%s</big></b>' %
                                 _('Computer Janitor'))
     self.description_label.set_text(
         _("Clean up a system so it's more like a freshly installed one"))
 def test_get_from_name(self):
     """
     Calling with no parameters should return the pixbuf object through `load_icon()`
     and default parameters.
     """
     m_pixbuf = mock.Mock(spec=GdkPixbuf.Pixbuf,
                          get_height=lambda: DEFAULT_SIZE)
     with patch_load_icon() as m_load_icon:
         m_load_icon.return_value = m_pixbuf
         pixbuf = get_from_name()
     self.assertEqual(m_load_icon.call_args_list,
                      [mock.call("gtk-execute", 24, 0)])
     self.assertEqual(pixbuf, m_pixbuf)
 def get_icon(self):
     return icon.get_from_name('text-plain')
Example #10
0
 def load_janitor(self):
     janitor_page = JanitorPage()
     self.feature_dict['janitor'] = self.notebook.append_page(janitor_page, Gtk.Label('janitor'))
     self.module_image.set_from_pixbuf(icon.get_from_name('computerjanitor', size=48))
     self.title_label.set_markup('<b><big>%s</big></b>' % _('Computer Janitor'))
     self.description_label.set_text(_("Free up disk space and remove private information"))
Example #11
0
 def on_clean_error(self, plugin, error, plugin_iter):
     #TODO response to user?
     self.janitor_model[plugin_iter][
         self.JANITOR_ICON] = icon.get_from_name('error', size=16)
     self.clean_tasks = []
     plugin.set_property('clean_finished', True)
Example #12
0
 def get_icon(self):
     return icon.get_from_name('deb')
Example #13
0
 def load_janitor(self):
     janitor_page = JanitorPage()
     self.feature_dict['janitor'] = self.notebook.append_page(janitor_page, Gtk.Label('janitor'))
     self.module_image.set_from_pixbuf(icon.get_from_name('computerjanitor', size=48))
     self.title_label.set_markup('<b><big>%s</big></b>' % _('Computer Janitor'))
     self.description_label.set_text(_("Clean up a system so it's more like a freshly installed one"))
Example #14
0
    def update_model(self, a=None, b=None, expand=False):
        self.janitor_model.clear()
        self.result_model.clear()
        size_list = []

        loader = ModuleLoader('janitor')

        system_text = _('System')
        iter = self.janitor_model.append(None, (None,
                                                icon.get_from_name('distributor-logo'),
                                                system_text,
                                                "<b><big>%s</big></b>" % system_text,
                                                None,
                                                None,
                                                None))

        for plugin in loader.get_modules_by_category('system'):
            size_list.append(Gtk.Label(label=plugin.get_title()).get_layout().get_pixel_size()[0])
            self.janitor_model.append(iter, (False,
                                             None,
                                             plugin.get_title(),
                                             plugin.get_title(),
                                             plugin(),
                                             None,
                                             None))

        personal_text = _('Personal')

        iter = self.janitor_model.append(None, (None,
                                                icon.get_from_name('system-users'),
                                                personal_text,
                                                "<b><big>%s</big></b>" % personal_text,
                                                None,
                                                None,
                                                None))

        for plugin in loader.get_modules_by_category('personal'):
            size_list.append(Gtk.Label(label=plugin.get_title()).get_layout().get_pixel_size()[0])
            self.janitor_model.append(iter, (False,
                                             None,
                                             plugin.get_title(),
                                             plugin.get_title(),
                                             plugin(),
                                             None,
                                             None))

        app_text = _('Apps')

        iter = self.janitor_model.append(None, (None,
                                                icon.get_from_name('gnome-app-install'),
                                                app_text,
                                                "<b><big>%s</big></b>" % app_text,
                                                None,
                                                None,
                                                None))

        for plugin in loader.get_modules_by_category('application'):
            size_list.append(Gtk.Label(label=plugin.get_title()).get_layout().get_pixel_size()[0])
            self.janitor_model.append(iter, (False,
                                             None,
                                             plugin.get_title(),
                                             plugin.get_title(),
                                             plugin(),
                                             None,
                                             None))
        if size_list:
            self.max_janitor_view_width = max(size_list) + 80

        if expand:
            self._expand_janitor_view()
Example #15
0
 def on_clean_error(self, plugin, error, plugin_iter):
     #TODO response to user?
     self.janitor_model[plugin_iter][self.JANITOR_ICON] = icon.get_from_name('error', size=16)
     self.clean_tasks = []
     plugin.set_property('clean_finished', True)
Example #16
0
 def get_icon(self):
     return icon.get_from_name('deb')