def _show_license(self, uri, license_apps): """ Show selected License to User. """ tmp_fd, tmp_path = None, None try: license_text = None # get the first repo with valid license text repos = set([x.get_details().channelname for \ x in license_apps]) if not repos: return with self._entropy.rwsem().reader(): for repo_id in repos: repo = self._entropy.open_repository(repo_id) license_text = repo.retrieveLicenseText(uri) if license_text is not None: break if license_text is not None: tmp_fd, tmp_path = const_mkstemp(suffix=".txt") try: license_text = const_convert_to_unicode( license_text, enctype=etpConst['conf_encoding']) except UnicodeDecodeError: license_text = const_convert_to_unicode( license_text) with entropy.tools.codecs_fdopen( tmp_fd, "w", etpConst['conf_encoding']) as tmp_f: tmp_f.write("License: %s\n" % ( uri,)) apps = self._licenses.get(uri, []) if apps: tmp_f.write("Applications:\n") for app in apps: tmp_f.write("\t%s\n" % (app.name,)) if apps: tmp_f.write("\n") tmp_f.write("-" * 79 + "\n") tmp_f.write(license_text) tmp_f.flush() else: const_debug_write( __name__, "LicensesNotificationBox._show_license: " "not available" ) finally: if tmp_fd is not None: try: os.close(tmp_fd) except OSError: pass # leaks, but xdg-open is async if tmp_path is not None: open_url(tmp_path)
def _on_image_clicked(self, widget, event): """ Image clicked event, load image in browser. """ url = self._image.document_url() if url is not None: open_url(url)
def _on_show_notice(self, view, notice): tmp_fd, tmp_path = None, None try: fname = notice.title().replace("/", "-") tmp_fd, tmp_path = tempfile.mkstemp(prefix=fname, suffix=".html") with entropy.tools.codecs_fdopen( tmp_fd, "w", etpConst['conf_encoding']) as tmp_f: tmp_f.write("<b>") tmp_f.write(notice.title()) tmp_f.write("</b>") tmp_f.write("\n<br/><i>") tmp_f.write(notice.date()) tmp_f.write("</i>, ") tmp_f.write(notice.repository()) tmp_f.write("\n\n<br/><br/><div style='max-width: 400px'>") tmp_f.write(notice.description()) tmp_f.write("</div>\n\n<br/>") tmp_f.write("<b>URL</b>: <a href=\"") tmp_f.write(notice.link()) tmp_f.write("\">") tmp_f.write(notice.link()) tmp_f.write("</a>") tmp_f.write("\n<br/><br/>") tmp_f.flush() finally: if tmp_fd is not None: try: os.close(tmp_fd) except OSError: pass # leaks, but xdg-open is async if tmp_path is not None: open_url(tmp_path)
def _show_license(self, uri, license_apps): """ Show selected License to User. """ tmp_fd, tmp_path = None, None try: license_text = None # get the first repo with valid license text repos = set([x.get_details().channelname for \ x in license_apps]) if not repos: return with self._entropy.rwsem().reader(): for repo_id in repos: repo = self._entropy.open_repository(repo_id) license_text = repo.retrieveLicenseText(uri) if license_text is not None: break if license_text is not None: tmp_fd, tmp_path = const_mkstemp(suffix=".txt") try: license_text = const_convert_to_unicode( license_text, enctype=etpConst['conf_encoding']) except UnicodeDecodeError: license_text = const_convert_to_unicode(license_text) with entropy.tools.codecs_fdopen( tmp_fd, "w", etpConst['conf_encoding']) as tmp_f: tmp_f.write("License: %s\n" % (uri, )) apps = self._licenses.get(uri, []) if apps: tmp_f.write("Applications:\n") for app in apps: tmp_f.write("\t%s\n" % (app.name, )) if apps: tmp_f.write("\n") tmp_f.write("-" * 79 + "\n") tmp_f.write(license_text) tmp_f.flush() else: const_debug_write( __name__, "LicensesNotificationBox._show_license: " "not available") finally: if tmp_fd is not None: try: os.close(tmp_fd) except OSError: pass # leaks, but xdg-open is async if tmp_path is not None: open_url(tmp_path)
def _register(self, button): """ Register button click event. """ open_url(build_register_url())
def _row_activated_callback(self, path, rowref): open_url(rowref.link())