• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python tools._函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中syncthing_gtk.tools._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了_函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: error

	def error(self, page, title, message, display_bugreport_link):
		"""
		Called from pages on error. Removes everything from page and
		creates error message.
		"""
		for c in [] + page.get_children() :
			page.remove(c)
		# Title
		l_title = WrappedLabel("<b>%s</b>" % (title,))
		l_title.props.margin_bottom = 15
		page.attach(l_title,	0, 0, 2, 1)
		# Message
		l_message = WrappedLabel(message)
		l_message.props.margin_bottom = 15
		page.attach(l_message,	0, 1, 2, 1)
		# Bugreport link
		if display_bugreport_link:
			github_link = '<a href="https://github.com/syncthing/syncthing-gtk/issues">GitHub</a>'
			l_bugreport = WrappedLabel(
				_("Please, check error log and fill bug report on %s.") % (github_link,)
			)
			page.attach(l_bugreport, 0, 2, 2, 1)
			# 'Display error log' button
			button = Gtk.Button(_("Display error log"))
			button.props.margin_top = 25
			page.attach(button, 1, 3, 2, 1)
			button.connect("clicked", lambda *a : self.show_output())
		
		page.show_all()
		return page
开发者ID:TRV3NNORT4,项目名称:syncthing-gtk,代码行数:30,代码来源:wizard.py


示例2: _open_achive

	def _open_achive(self, archive_name):
		try:
			# Determine archive format
			archive = None
			if tarfile.is_tarfile(archive_name):
				# Open TAR
				archive = tarfile.open(archive_name, "r", bufsize=CHUNK_SIZE * 2)
			elif zipfile.is_zipfile(archive_name):
				# Open ZIP
				archive = ZipThatPretendsToBeTar(archive_name, "r")
			else:
				# Unrecognized format
				self.emit("error", None, _("Downloaded file is corrupted."))
			# Find binary inside
			for pathname in archive.getnames():
				filename = pathname.replace("\\", "/").split("/")[-1]
				if filename.startswith("syncthing"):
					# Last sanity check, then just open files
					# and start extracting
					tinfo = archive.getmember(pathname)
					if tinfo.isfile():
						compressed = archive.extractfile(pathname)
						try:
							os.makedirs(os.path.split(self.target)[0])
						except Exception: pass
						output = file(self.target, "wb")
						GLib.idle_add(self._extract, (archive, compressed, output, 0, tinfo.size))
						return
		except Exception, e:
			log.exception(e)
			self.emit("error", e,
				_("Failed to determine latest Syncthing version."))
			return
开发者ID:midyukov-anton,项目名称:syncthing-gtk,代码行数:33,代码来源:stdownloader.py


示例3: prepare

	def prepare(self):
		# Determine which Syncthing to use
		suffix, tag = StDownloader.determine_platform()
		# Report error on unsupported platforms
		if suffix is None or tag is None:
			pd = "%s %s %s" % (
				platform.uname()[0], platform.uname()[2],	# OS, version
				platform.uname()[4])						# architecture
			self.parent.error(self,
				_("Cannot download Syncthing daemon."),
				_("This platform (%s) is not supported") % (pd,),
				False)
			return
		# Determine target file & directory
		self.target = os.path.join(
			os.path.expanduser(StDownloader.get_target_folder()),
			"syncthing%s" % (suffix,)
			)
		# Create downloader and connect events
		self.sd = StDownloader(self.target, tag)
		self.sd.connect("error", self.on_download_error)
		self.sd.connect("version", self.on_version)
		self.sd.connect("download-progress", self.on_progress)
		self.sd.connect("download-finished", self.on_extract_start)
		self.sd.connect("extraction-progress", self.on_progress)
		self.sd.connect("extraction-finished", self.on_extract_finished)
		# Start downloading
		self.sd.get_version()
开发者ID:TRV3NNORT4,项目名称:syncthing-gtk,代码行数:28,代码来源:wizard.py


示例4: cb_process_exit

	def cb_process_exit(self, process, *a):
		""" Called after daemon binary outputs version and exits """
		from syncthing_gtk.app import MIN_ST_VERSION
		bin_path = process.get_commandline()[0]
		if compare_version(self.version_string, MIN_ST_VERSION):
			# Daemon binary exists, is executable and meets
			# version requirements. That's good, btw.
			self.parent.config["syncthing_binary"] = bin_path
			if not can_upgrade_binary(bin_path):
				# Don't try enable auto-update if binary is in
				# non-writable location (auto-update is enabled
				# by default on Windows only)
				self.parent.config["st_autoupdate"] = False
			self.parent.set_page_complete(self, True)
			self.label.set_markup(
					"<b>" + _("Syncthing daemon binary found.") + "</b>" +
					"\n\n" +
					_("Binary path:") + " " + bin_path + "\n" +
					_("Version:") + " " + self.version_string
				)
		else:
			# Found daemon binary too old to be ussable.
			# Just ignore it and try to find better one.
			log.info("Binary in %s is too old", bin_path)
			self.ignored_version = self.version_string
			GLib.idle_add(self.search)
开发者ID:TRV3NNORT4,项目名称:syncthing-gtk,代码行数:26,代码来源:wizard.py


示例5: display

		def display(self):
			if len(self.updated) == 1 and len(self.deleted) == 0:
				# One updated file
				f_path = list(self.updated)[0]
				filename = os.path.split(f_path)[-1]
				self.info(_("The file '%s' was updated on remote device.") % (filename,))
			elif len(self.updated) == 0 and len(self.deleted) == 1:
				# One deleted file
				f_path = list(self.deleted)[0]
				filename = os.path.split(f_path)[-1]
				self.info(_("The file '%s' was deleted on remote device.") % (filename,))
			elif len(self.deleted) == 0 and len(self.updated) > 0:
				# Multiple updated, nothing deleted
				self.info(_("%s files were updated on remote device.") % (len(self.updated),))
			elif len(self.updated) == 0 and len(self.deleted) > 0:
				# Multiple deleted, no updated
				self.info(_("%s files were deleted on remote device.") % (len(self.deleted),))
			elif len(self.deleted) > 0 and len(self.updated) > 0:
				 # Multiple deleted, multiple updated
				self.info(
					_("%(updated)s files were updated and %(deleted)s deleted on remote device.") % {
						'updated' : len(self.updated),
						'deleted' : len(self.deleted)
						}
					)
			self.updated = set([])
			self.deleted = set([])
开发者ID:acolomb,项目名称:syncthing-gtk,代码行数:27,代码来源:notifications.py


示例6: cb_format_value_kibps_or_no_limit

	def cb_format_value_kibps_or_no_limit(self, spinner):
		""" Formats spinner value """
		val = int(spinner.get_adjustment().get_value())
		if val < 1:
			spinner.get_buffer().set_text(_("no limit"), -1)
		else:
			spinner.get_buffer().set_text(_("%s KiB/s") % (val,), -1)
		return True
开发者ID:syncthing,项目名称:syncthing-gtk,代码行数:8,代码来源:editordialog.py


示例7: cb_format_value_s_or_disabed

	def cb_format_value_s_or_disabed(self, spinner):
		""" Formats spinner value """
		val = int(spinner.get_adjustment().get_value())
		if val < 1:
			spinner.get_buffer().set_text(_("disabled"), -1)
		else:
			spinner.get_buffer().set_text(_("%ss") % (val,), -1);
		return True
开发者ID:midyukov-anton,项目名称:syncthing-gtk,代码行数:8,代码来源:editordialog.py


示例8: init_page

	def init_page(self):
		""" Displayed while Syncthing binary is being searched for """
		self.label = WrappedLabel(
			"<b>%s</b>\n\n%s" % (
				_("Syncthing is generating RSA key and certificate."),
				_("This may take a while...")
			)
		)
		self.attach(self.label, 0, 0, 1, 1)
开发者ID:TRV3NNORT4,项目名称:syncthing-gtk,代码行数:9,代码来源:wizard.py


示例9: on_extract_finished

	def on_extract_finished(self, *a):
		""" Called after extraction is finished """
		# Everything done. Praise supernatural entities...
		self.label.set_markup("<b>" + _("Download finished.") + "</b>")
		self.parent.config["syncthing_binary"] = self.target
		self.version.set_markup(_("Binary path:") +
				" " + self.target)
		self.pb.set_visible(False)
		self.parent.set_page_complete(self, True)
开发者ID:TRV3NNORT4,项目名称:syncthing-gtk,代码行数:9,代码来源:wizard.py


示例10: cb_format_value_days

	def cb_format_value_days(self, spinner):
		""" Formats spinner value """
		v = int(spinner.get_adjustment().get_value())
		if v == 0:
			spinner.get_buffer().set_text(_("never delete"), -1)
		elif v == 1:
			spinner.get_buffer().set_text(_("%s day") % (v,), -1);
		else:
			spinner.get_buffer().set_text(_("%s days") % (v,), -1);
		return True
开发者ID:midyukov-anton,项目名称:syncthing-gtk,代码行数:10,代码来源:editordialog.py


示例11: rejected

		def rejected(self):
			label_fb = self.label or self.id
			actions = [
				(self.ACT_DEFAULT, _('Accept device "%s"') % label_fb, self.cb_accept, None),
				(self.ACT_ACCEPT,  _('Accept device "%s"') % label_fb, self.cb_accept, None),
				(self.ACT_IGNORE,  _('Ignore device "%s"') % label_fb, self.cb_ignore, None),
			]
			summary = _("Unknown Device")
			body = _('Device "%s" is trying to connect to syncthing daemon.' % self.label)
			self.push(summary, body, actions=actions, urg=Notify.Urgency.CRITICAL)
开发者ID:syncthing,项目名称:syncthing-gtk,代码行数:10,代码来源:notifications.py


示例12: cb_daemon_exit

	def cb_daemon_exit(self, dproc, exit_code):
		""" Called when Syncthing finishes """
		if exit_code == 0:
			# Finished without problem, advance to next page
			self.parent.set_page_complete(self, True)
			self.parent.next_page()
		else:
			self.parent.error(self,
				_("Failed to generate keys"),
				_("Syncthing daemon failed to generate RSA key or certificate."),
				True)
开发者ID:TRV3NNORT4,项目名称:syncthing-gtk,代码行数:11,代码来源:wizard.py


示例13: sync_conflict

		def sync_conflict(self, path):
			path_full = os.path.join(self.app.folders[self.id]["norm_path"], path)

			summary = _('Conflicting file in "%s"') % (self.label or self.id)
			text = _('Conflict in path "%s" detected.') % path_full

			n = Notify.Notification.new(summary, text, ICON_ERR)
			n.set_urgency(Notify.Urgency.CRITICAL)
			n.add_action(self.ACT_DEFAULT, _("Open Conflicting file in filemanager"), self.cb_open_conflict, path_full)
			n.connect("closed", self.cb_sync_conflict_closed),
			self.conflict.add(n)

			self.show(n)
开发者ID:syncthing,项目名称:syncthing-gtk,代码行数:13,代码来源:notifications.py


示例14: __init__

	def __init__(self, app, title, icon):
		# Variables
		self.app = app
		self.child = None
		self.header = None
		self.str_title = None
		self.str_status = None
		self.header_inverted = False
		self.values = {}
		self.icons = {}
		self.value_widgets = {}
		self.hilight = False
		self.hilight_factor = 0.0
		self.timer_enabled = False
		self.icon = icon
		self.color = (1, 0, 1, 1)		# rgba
		self.background = (1, 1, 1, 1)	# rgba
		self.dark_color  = None			# Overrides background if set
		self.text_color = (0, 0, 0, 1)	# rgba (text color)
		self.real_color = self.color	# set color + hilight
		self.border_width = 2
		self.children = [self.header, self.child]
		# Initialization
		Gtk.Container.__init__(self)
		self.init_header()
		self.init_grid()
		# Settings
		self.set_title(title)
		self.set_status(_("Disconnected"))
开发者ID:muelli,项目名称:syncthing-gtk,代码行数:29,代码来源:infobox.py


示例15: _cb_read_latest

	def _cb_read_latest(self, f, result, buffer, *a):
		# Extract release version from response
		from syncthing_gtk.app import MIN_ST_VERSION
		latest_ver = None
		try:
			success, data, etag = f.load_contents_finish(result)
			if not success: raise Exception("Gio download failed")
			# Go over all available versions until compatibile one
			# is found
			data = json.loads(data)
			for release in data:
				version = release["tag_name"]
				if latest_ver is None:
					latest_ver = version
				if compare_version(self.latest_compat, version) and (self.forced or compare_version(version, MIN_ST_VERSION)):
					# Compatibile
					log.verbose("STDownloader: Found compatibile Syncthing version: %s", version)
					self.version = version
					for asset in release["assets"]:
						if self.platform in asset["name"]:
							self.dll_url = asset["browser_download_url"]
							self.dll_size = int(asset["size"])
							log.debug("STDownloader: URL: %s", self.dll_url)
							break
					break
				else:
					log.verbose("STDownloader: Ignoring too new Syncthing version: %s", version)
			del f
			if self.dll_url is None:
				raise Exception("No release to download")
		except Exception, e:
			log.exception(e)
			self.emit("error", e,
				_("Failed to determine latest Syncthing version."))
			return
开发者ID:TRV3NNORT4,项目名称:syncthing-gtk,代码行数:35,代码来源:stdownloader.py


示例16: on_btBrowse_clicked

	def on_btBrowse_clicked(self, *a):
		"""
		Display folder browser dialog to browse for folder... folder.
		Oh god, this new terminology sucks...
		"""
		if not self.is_new: return
		# Prepare dialog
		d = Gtk.FileChooserDialog(
			_("Select Folder for new Folder"),	# fuck me...
			self["editor"],
			Gtk.FileChooserAction.SELECT_FOLDER,
			(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
			Gtk.STOCK_OK, Gtk.ResponseType.OK))
		# Set default path to home directory
		d.set_current_folder(os.path.expanduser("~"))
		# Get response
		if d.run() == Gtk.ResponseType.OK:
			self["vpath"].set_text(d.get_filename())
			if len(self["vid"].get_text().strip()) == 0:
				# ID is empty, fill it with last path element
				try:
					lpl = os.path.split(d.get_filename())[-1]
					id = RE_GEN_ID.search(lpl).group(0).lower()
					self["vid"].set_text(id)
				except AttributeError:
					# Can't regexp anything
					pass
		d.destroy()
开发者ID:acolomb,项目名称:syncthing-gtk,代码行数:28,代码来源:foldereditor.py


示例17: add_page

	def add_page(self, page):
		""" Adds page derived from custom Page class """
		index = self.append_page(page)
		page.parent = self
		self.set_page_type(page, page.TYPE)
		self.set_page_title(page, _(page.TITLE) + "  ")
		return index
开发者ID:TRV3NNORT4,项目名称:syncthing-gtk,代码行数:7,代码来源:wizard.py


示例18: _extract

	def _extract(self, data):
		(archive, compressed, output, extracted, ex_size) = data
		try:
			buffer = compressed.read(CHUNK_SIZE)
			read_size = len(buffer)
			if read_size == CHUNK_SIZE:
				# Need some more
				output.write(buffer)
				extracted += read_size
				GLib.idle_add(self._extract, (archive, compressed, output, extracted, ex_size))
				self.emit("extraction-progress", float(extracted) / float(ex_size))
			else:
				# End of file
				# Write rest, if any
				if read_size > 0:
					output.write(buffer)
				# Change file mode to 0755
				if hasattr(os, "fchmod"):
					# ... on Unix
					os.fchmod(output.fileno(), 0o755)
				output.close()
				archive.close()
				compressed.close()
				self.emit("extraction-progress", 1.0)
				self.emit("extraction-finished")
		except Exception as e:
			log.exception(e)
			self.emit("error", e,
				_("Failed to determine latest Syncthing version."))
			return
		return False
开发者ID:syncthing,项目名称:syncthing-gtk,代码行数:31,代码来源:stdownloader.py


示例19: _cb_download

	def _cb_download(self, stream, result, data):
		(tmpfile, downloaded) = data
		try:
			# Get response from async call
			response = stream.read_bytes_finish(result)
			if response == None:
				raise Exception("No data received")
			# 0b of data read indicates end of file
			if response.get_size() > 0:
				# Not EOF. Write buffer to disk and download some more
				downloaded += response.get_size()
				tmpfile.write(response.get_data())
				stream.read_bytes_async(CHUNK_SIZE, GLib.PRIORITY_DEFAULT, None,
						self._cb_download, (tmpfile, downloaded))
				self.emit("download-progress", float(downloaded) / float(self.dll_size))
			else:
				# EOF. Re-open tmpfile as tar and prepare to extract
				# binary
				self.emit("download-finished")
				stream.close(None)
				tmpfile.close()
				GLib.idle_add(self._open_archive, tmpfile.name)
		except Exception as e:
			log.exception(e)
			self.emit("error", e, _("Download failed."))
			return
开发者ID:syncthing,项目名称:syncthing-gtk,代码行数:26,代码来源:stdownloader.py


示例20: syncthing_cb_post_error

	def syncthing_cb_post_error(self, exception, *a):
		# TODO: Unified error message
		if isinstance(exception, ConnectionRestarted):
			# Should be ok, this restart is triggered
			# by App handler for 'config-saved' event.
			return self.syncthing_cb_post_config()
		message = "%s\n%s" % (
			_("Failed to save configuration."),
			str(exception)
		)
		
		if hasattr(exception, "full_response"):
			try:
				fr = unicode(exception.full_response)[0:1024]
			except UnicodeError:
				# ... localized error strings on windows are usually
				# in anything but unicode :(
				fr = str(repr(exception.full_response))[0:1024]
			message += "\n\n" + fr
		
		d = Gtk.MessageDialog(
			self["editor"],
			Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
			Gtk.MessageType.INFO, Gtk.ButtonsType.CLOSE,
			message
			)
		d.run()
		d.hide()
		d.destroy()
		self["editor"].set_sensitive(True)
开发者ID:syncthing,项目名称:syncthing-gtk,代码行数:30,代码来源:editordialog.py



注:本文中的syncthing_gtk.tools._函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python lib.dryrun_msg函数代码示例发布时间:2022-05-27
下一篇:
Python editordialog.EditorDialog类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap