def check_version(self): gtk.gdk.threads_enter() version = TweakSettings.get_version() if version > VERSION: dialog = QuestionDialog( _( "A newer version: %s is available online.\nWould you like to update?\n\nNote: if you prefer to update from the source code, you can disable this feature in Preferences." ) % version, title=_("Software Update"), ) update = False if dialog.run() == gtk.RESPONSE_YES: update = True dialog.destroy() if update: dialog = UpdateDialog(parent=self.get_toplevel()) dialog.run() dialog.destroy() gtk.gdk.threads_leave()
def clean_selected_ppa(self): self.set_busy() # name_list is to display the name of PPA # url_list is to identify the ppa name_list = [] url_list = [] for id in self.get_list(): #TODO try: name_list.append(SOURCE_PARSER.get_name(int(id))) url_list.append(SOURCE_PARSER.get_url(int(id))) except: name_list.append(ppa.get_short_name(id)) url_list.append(id) package_view = DowngradeView() package_view.update_model(url_list) sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) select_pkgs = package_view.get_downgrade_packages() sw.add(package_view) #TODO the logic is a little ugly, need to improve the BaseMessageDialog if not select_pkgs: message = _("It's safe to purge the PPA, no packages need to be downgraded.") sw.hide() else: message = _("To safely purge the PPA, the following packages must be downgraded.") sw.show_all() sw.set_size_request(500, 100) dialog = QuestionDialog(message, title=_("You're going to purge: %s") % ', '.join(name_list)) dialog.set_resizable(True) dialog.vbox.pack_start(sw, True, True, 0) dialog.show() response = dialog.run() dialog.destroy() # Workflow # 1. Downgrade all the PPA packages to offical packages #TODO Maybe not official? Because anther ppa which is enabled may have newer packages then offical # 2. If succeed, disable PPA, or keep it if response == gtk.RESPONSE_YES: self.set_busy() log.debug("The select pkgs is: %s", str(select_pkgs)) dialog = CleanPpaDialog(self.get_toplevel(), select_pkgs, url_list) dialog.run() dialog.destroy() if dialog.error == False: self.show_success_dialog() else: self.show_failed_dialog() self.update_ppa_model() self.unset_busy() else: self.update_ppa_model() # TODO refresh source? self.__check_list = [] self.emit('cleaned') self.unset_busy()
def on_have_update(self, client, id, entry, data): if entry.get_value().get_bool(): dialog = QuestionDialog(_('New application data available, would you like to update?')) response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_YES: dialog = FetchingDialog(get_app_data_url(), self.get_toplevel()) dialog.connect('destroy', self.on_app_data_downloaded) dialog.run() dialog.destroy()
def on_have_update(self, client, id, entry, data): if entry.get_value().get_bool(): if self.check_update(): dialog = QuestionDialog(_("New source data available, would you like to update?")) response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_YES: dialog = FetchingDialog(get_source_data_url(), self.get_toplevel()) dialog.connect("destroy", self.on_source_data_downloaded) dialog.run() dialog.destroy()
def on_idle_check(self): gtk.gdk.threads_enter() if self.check_update(): dialog = QuestionDialog(_('New application data available, would you like to update?')) response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_YES: dialog = FetchingDialog(APP_URL, self.get_toplevel()) dialog.connect('destroy', self.on_app_data_downloaded) dialog.run() dialog.destroy() gtk.gdk.threads_leave()
def on_reset_button_clicked(self, widget): iter = self.backup_combobox.get_active_iter() model = self.backup_combobox.get_model() dir = self.dir_label.get_text() if dir.count("/") == 2: message = _("Would you like to reset settings for: <b>%s</b>?") % dir else: message = _("Would you like to reset all settings under: <b>%s</b>?") % dir addon_message = _("<b>NOTES</b>: Whilst resetting, your desktop may be unresponsive for a moment.") dialog = QuestionDialog(message + "\n\n" + addon_message) response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_YES: if dir.count("/") == 1: for line in open(path): stdout, stderr = do_reset_task(line.strip()) else: stdout, stderr = do_reset_task(dir) if stderr: log.error(stderr) # TODO raise error or others return InfoDialog(_("Reset Successful!\nYou may need to restart your desktop for changes to take effect")).launch()
def on_recover_button_clicked(self, widget): iter = self.backup_combobox.get_active_iter() model = self.backup_combobox.get_model() dir = self.dir_label.get_text() path = model.get_value(iter, 1) if dir.count("/") == 2: message = _("Would you like to recover the backup: <b>%s/%s</b>?") % (dir, os.path.basename(path)[:-4]) else: message = _("Would you like to recover the backup of all <b>%s</b> settings named <b>%s</b>?") % ( dir, os.path.basename(path)[:-4], ) addon_message = _("<b>NOTES</b>: While recovering, your desktop may be unresponsive for a moment.") dialog = QuestionDialog(message + "\n\n" + addon_message) response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_YES: if dir.count("/") == 1: for line in open(path): stdout, stderr = do_recover_task(line.strip()) else: stdout, stderr = do_recover_task(path) if stderr: log.error(stderr) # TODO raise error or others return InfoDialog( _("Recovery Successful!\nYou may need to restart your desktop for changes to take effect") ).launch()
def on_restore_directory(self, widget): model, iter = self.get_selection().get_selected() userdir = model.get_value(iter, COLUMN_DIR) dialog = QuestionDialog( _( "Ubuntu Tweak will restore the selected " "directory to it's default location.\n" "However, you must move your files back into place manually.\n" "Do you wish to continue?" ) ) if dialog.run() == gtk.RESPONSE_YES: newdir = os.path.join(os.getenv("HOME"), self.uf.get_restorename(userdir)) self.uf.set_userdir(userdir, newdir) model.set_value(iter, COLUMN_PATH, newdir) if not os.path.exists(newdir): os.mkdir(newdir) elif os.path.isfile(newdir): os.remove(newdir) os.mkdir(newdir) dialog.destroy()
def show_changes(self): dialog = QuestionDialog("Install ?") res = dialog.run() dialog.hide() if res == gtk.RESPONSE_YES: return True else: return False
def on_change_icon_clicked(self, widget): dialog = gtk.FileChooserDialog(_('Choose a new logo image'), action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_REVERT_TO_SAVED, gtk.RESPONSE_DELETE_EVENT, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_ACCEPT)) filter = gtk.FileFilter() filter.set_name(_("PNG image (*.png)")) filter.add_mime_type("image/png") dialog.set_current_folder(os.path.expanduser('~')) dialog.add_filter(filter) if module_check.get_codename() == 'karmic': dest = os.path.expanduser('~/.icons/%s/places/24/start-here.png' % self.__setting.get_icon_theme()) else: dest = os.path.expanduser('~/.icons/%s/apps/24/start-here.png' % self.__setting.get_icon_theme()) revert_button = dialog.action_area.get_children()[-1] if not os.path.exists(dest): revert_button.set_sensitive(False) filename = '' response = dialog.run() if response == gtk.RESPONSE_ACCEPT: filename = dialog.get_filename() dialog.destroy() if filename: pixbuf = gtk.gdk.pixbuf_new_from_file(filename) w, h = pixbuf.get_width(), pixbuf.get_height() if w != 24 or h != 24: ErrorDialog(_("This image size isn't suitable for the panel.\nIt should be 24x24.")).launch() return else: os.system('mkdir -p %s' % os.path.dirname(dest)) os.system('cp %s %s' % (filename, dest)) image = gtk.image_new_from_file(dest) widget.set_image(image) elif response == gtk.RESPONSE_DELETE_EVENT: dialog.destroy() os.remove(dest) image = gtk.image_new_from_pixbuf(icon.get_from_name('start-here', size=24, force_reload=True)) widget.set_image(image) else: dialog.destroy() return dialog = QuestionDialog(_('Do you want your changes to take effect immediately?')) if dialog.run() == gtk.RESPONSE_YES: os.system('killall gnome-panel') dialog.destroy()
def on_clean_thumbnails_clicked(self, widget): question = QuestionDialog(_('The thumbnail cache will be deleted. Do you wish to continue?'), title = _('Warning')) if question.run() == gtk.RESPONSE_YES: question.destroy() dialog = CleanDialog(widget.get_toplevel()) dialog.run() InfoDialog(_('Clean up Successful!')).launch() self.set_clean_button_label(widget) else: question.destroy()
def upgrade_sources(self): dialog = QuestionDialog(_('After a successful distribution upgrade, ' 'any third-party sources you use will be disabled by default.\n' 'Would you like to re-enable any sources disabled by Update Manager?'), title=_('Upgrade Third Party Sources')) response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_YES: proxy.upgrade_sources(self.__get_disable_string(), UPGRADE_DICT) if not self.check_source_upgradable(): InfoDialog(_('Upgrade Successful!')).launch() else: ErrorDialog(_('Upgrade Failed!')).launch() self.emit('call', 'ubuntutweak.modules.sourceeditor', 'update_source_combo', {}) self.update_thirdparty()
def on_hostname_button_clicked(self, widget, label): dialog = QuestionDialog(_('Please enter your new hostname. Blank characters should not be used.'), title = _('New hostname')) vbox = dialog.vbox entry = gtk.Entry() vbox.pack_start(entry, False, False, 0) vbox.show_all() res = dialog.run() dialog.destroy() if res == gtk.RESPONSE_YES: new_name = entry.get_text() proxy.exec_command('hostname %s' % new_name) if os.popen('hostname').read().strip() == new_name: label.set_label(new_name)
def on_delete_button_clicked(self, widget): def try_remove_record_in_root_backup(dir, path): rootpath = build_backup_prefix("/".join(dir.split("/")[:2])) + os.path.basename(path) if os.path.exists(rootpath): lines = open(rootpath).read().split() lines.remove(path) if len(lines) == 0: os.remove(rootpath) else: new = open(rootpath, "w") new.write("\n".join(lines)) new.close() def try_remove_all_subback(path): for line in open(path): os.remove(line.strip()) iter = self.backup_combobox.get_active_iter() model = self.backup_combobox.get_model() dir = self.dir_label.get_text() path = model.get_value(iter, 1) if dir.count("/") == 2: dialog = QuestionDialog( _("Would you like to delete the backup: <b>%s/%s</b>?") % (dir, os.path.basename(path)[:-4]) ) else: dialog = QuestionDialog( _("Would you like to delete the backup of all <b>%s</b> settings named <b>%s</b>?") % (dir, os.path.basename(path)[:-4]) ) response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_YES: if dir.count("/") == 2: try_remove_record_in_root_backup(dir, path) else: try_remove_all_subback(path) os.remove(path) self.update_backup_model(dir)
def on_reset_button_clicked(self, widget): iter = self.backup_combobox.get_active_iter() model = self.backup_combobox.get_model() dir = self.dir_label.get_text() if dir.count('/') == 2: message = _('Would you like to reset settings for: <b>%s</b>?') % dir else: message = _('Would you like to reset all settings under: <b>%s</b>?') % dir addon_message = _('<b>NOTES</b>: Whilst resetting, your desktop may be unresponsive for a moment.') dialog = QuestionDialog(message + '\n\n' + addon_message) response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_YES: stdout, stderr = do_reset_task(dir) if stderr: log.error(stderr) #TODO raise error or others return self.__show_successful_with_logout_button(_('Reset Successful!\nYou may need to restart your desktop for changes to take effect'))
def on_enable_toggled(self, cell, path): model = self.get_model() iter = model.get_iter((int(path),)) id = model.get_value(iter, self.COLUMN_ID) name = model.get_value(iter, self.COLUMN_NAME) enabled = model.get_value(iter, self.COLUMN_ENABLED) conflicts = SOURCE_PARSER.get_conflicts(id) dependencies = SOURCE_PARSER.get_dependencies(id) #Convert to real model, because will involke the set method if type(model) == gtk.TreeModelFilter: iter = model.convert_iter_to_child_iter(iter) model = model.get_model() if not enabled and conflicts: conflict_list = [] conflict_name_list = [] for conflict_id in conflicts: if self.get_source_enabled(conflict_id): conflict_list.append(conflict_id) name_list = [r[self.COLUMN_NAME] for r in model if r[self.COLUMN_ID] == conflict_id] if name_list: conflict_name_list.extend(name_list) if conflict_list and conflict_name_list: full_name = ', '.join(conflict_name_list) ErrorDialog(_('You can\'t enable this Source because' '<b>"%(SOURCE)s"</b> conflicts with it.\nTo ' 'continue you need to disable <b>"%(SOURCE)s"</b>' \ 'first.') % {'SOURCE': full_name}).launch() model.set(iter, self.COLUMN_ENABLED, enabled) return if enabled is False and dependencies: depend_list = [] depend_name_list = [] for depend_id in dependencies: if self.get_source_enabled(depend_id) is False: depend_list.append(depend_id) name_list = [r[self.COLUMN_NAME] for r in model if r[self.COLUMN_ID] == depend_id] if name_list: depend_name_list.extend(name_list) if depend_list and depend_name_list: full_name = ', '.join(depend_name_list) dialog = QuestionDialog(\ _('To enable this Source, You need to enable <b>"%s"</b> at first.\nDo you wish to continue?') \ % full_name, title=_('Dependency Notice')) if dialog.run() == gtk.RESPONSE_YES: for depend_id in depend_list: self.set_source_enabled(depend_id) self.set_source_enabled(id) else: model.set(iter, self.COLUMN_ENABLED, enabled) dialog.destroy() return if enabled and SOURCE_PARSER.has_reverse_depends(id): depend_list = [] depend_name_list = [] for depend_id in SOURCE_PARSER.get_reverse_depends(id): if self.get_source_enabled(depend_id): depend_list.append(depend_id) name_list = [r[self.COLUMN_NAME] for r in model if r[self.COLUMN_ID] == depend_id] if name_list: depend_name_list.extend(name_list) if depend_list and depend_name_list: full_name = ', '.join(depend_name_list) ErrorDialog(_('You can\'t disable this Source because ' '<b>"%(SOURCE)s"</b> depends on it.\nTo continue ' 'you need to disable <b>"%(SOURCE)s"</b> first.') \ % {'SOURCE': full_name}).launch() model.set(iter, self.COLUMN_ENABLED, enabled) return self.do_source_enable(iter, not enabled)
def on_change_icon_clicked(self, widget): dialog = gtk.FileChooserDialog(_('Choose a new logo image'), action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_REVERT_TO_SAVED, gtk.RESPONSE_DELETE_EVENT, gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_ACCEPT)) filter = gtk.FileFilter() filter.set_name(_("PNG images with 24x24 size or SVG images")) filter.add_pattern('*.png') filter.add_pattern('*.svg') dialog.set_current_folder(os.path.expanduser('~')) dialog.add_filter(filter) if module_check.get_codename() == 'karmic': dest = os.path.expanduser('~/.icons/%s/places/24/start-here' % self.__setting.get_icon_theme()) else: dest = os.path.expanduser('~/.icons/%s/apps/24/start-here' % self.__setting.get_icon_theme()) revert_button = dialog.action_area.get_children()[-1] HAVE_ICON = os.path.exists(dest + '.png') or os.path.exists(dest + '.svg') if not HAVE_ICON: revert_button.set_sensitive(False) filename = '' response = dialog.run() if response == gtk.RESPONSE_ACCEPT: filename = dialog.get_filename() dialog.destroy() if filename: ext = os.path.splitext(filename)[1] log.debug('The select file name is: %s' % ext) pixbuf = gtk.gdk.pixbuf_new_from_file(filename) w, h = pixbuf.get_width(), pixbuf.get_height() dest = dest + ext if ext == '.png' and (w != 24 or h != 24): ErrorDialog(_("This image size isn't suitable for the panel.\nIt should measure 24x24.")).launch() return else: os.system('mkdir -p %s' % os.path.dirname(dest)) os.system('cp %s %s' % (filename, dest)) if ext == '.svg': pixbuf = pixbuf.scale_simple(24, 24, gtk.gdk.INTERP_BILINEAR) image = gtk.image_new_from_pixbuf(pixbuf) widget.set_image(image) elif response == gtk.RESPONSE_DELETE_EVENT: dialog.destroy() for dest in glob.glob(dest + '*'): os.remove(dest) image = gtk.image_new_from_pixbuf(icon.get_from_name('start-here', force_reload=True)) widget.set_image(image) else: dialog.destroy() return dialog = QuestionDialog(_('Do you want your changes to take effect immediately?')) if dialog.run() == gtk.RESPONSE_YES: os.system('killall gnome-panel') dialog.destroy()