Ejemplo n.º 1
0
    def activate(self, leaf):
        leaf_text = kupferstring.tolocale(leaf.object)
        color = leaf_text[1:]
        result = "None"
        if len(color) == 3:
            r = color[0] + color[0]
            g = color[1] + color[1]
            b = color[2] + color[2]
        elif len(color) == 6:
            r = color[0:2]
            g = color[2:4]
            b = color[4:6]
        else:
            return TextLeaf("Unknown color format")

        color = colors.hex("#" + r + g + b)
        complement = colors.complementary(color)[4]
        r = int(complement.r * 255)
        g = int(complement.g * 255)
        b = int(complement.b * 255)

        r = '%02x' % r
        g = '%02x' % g
        b = '%02x' % b

        result = "#" + str(r) + str(g) + str(b)

        return TextLeaf(result)
Ejemplo n.º 2
0
	def write_items(self, items):
		our_ext = ".kfcom"

		def make_obj_filename(lname, id_):
			id_ = id_.replace("/", "_")
			return "%s (%s)%s" % (lname, id_, our_ext)

		written_now = set()
		for obj in items:
			obj = AppLeaf(obj)
			action = objects.Launch()
			composed = compose.ComposedLeaf(obj, action)
			lname = kupferstring.tolocale(unicode(obj))
			basename = make_obj_filename(lname, obj.get_id())
			filename = os.path.join(DOCKDIR, basename)
			written_now.add(basename)
			if os.path.exists(filename):
				#debug_log("exists:", filename)
				continue
			debug_log("creating:", filename)
			tmpname = "%s.%d" % (basename, os.getpid())
			execfile.save_to_file(composed, tmpname)
			execfile.update_icon(obj, tmpname)
			gio.File(tmpname).move(gio.File(filename),
			                       flags=gio.FILE_COPY_OVERWRITE)

		for fname in os.listdir(DOCKDIR):
			if fname.endswith(our_ext) and fname not in written_now:
				filepath = os.path.join(DOCKDIR, fname)
				if os.access(filepath, os.W_OK):
					debug_log("remove:", fname)
					gio.File(os.path.join(DOCKDIR, fname)).delete(None)
Ejemplo n.º 3
0
	def activate(self, leaf):
		leaf_text = kupferstring.tolocale(leaf.object)
		color = leaf_text[1:]
		result = "None"
		if len(color) == 3:
			r = color[0] + color[0]
			g = color[1] + color[1]
			b = color[2] + color[2]
		elif len(color) == 6:
			r = color[0:2]
			g = color[2:4]
			b = color[4:6]
		else:
			return TextLeaf("Unknown color format")


		color = colors.hex("#"+r+g+b)
		complement = colors.complementary(color)[4]
		r = int(complement.r*255)
		g = int(complement.g*255)
		b = int(complement.b*255)

		r = '%02x'%r
		g = '%02x'%g
		b = '%02x'%b

		result = "#" + str(r) + str(g) + str(b)

		return TextLeaf(result)
Ejemplo n.º 4
0
 def activate(self, leaf):
     text = leaf.object
     dict_id = __kupfer_settings__["dictionary"]
     dict_argv = list(dictionaries[dict_id])
     dict_argv[-1] = dict_argv[-1] + kupferstring.tolocale(text)
     try:
         utils.spawn_async_notify_as(dict_id + ".desktop", dict_argv)
     except utils.SpawnError as exc:
         raise OperationError(exc)
Ejemplo n.º 5
0
 def activate(self, leaf):
     text = leaf.object
     dict_id = __kupfer_settings__["dictionary"]
     dict_argv = list(dictionaries[dict_id])
     dict_argv[-1] = dict_argv[-1] + kupferstring.tolocale(text)
     try:
         utils.spawn_async_notify_as(dict_id + ".desktop", dict_argv)
     except utils.SpawnError as exc:
         raise OperationError(exc)
Ejemplo n.º 6
0
 def activate(self, leaf, iobj):
     outfile, outpath = utils.get_destfile_in_directory(iobj.object, _("Empty File"))
     try:
         l_text = kupferstring.tolocale(leaf.object)
         outfile.write(l_text)
         if not l_text.endswith("\n"):
             outfile.write("\n")
     finally:
         outfile.close()
     return FileLeaf(outpath)
Ejemplo n.º 7
0
 def activate(self, leaf, iobj):
     outfile, outpath = \
             utils.get_destfile_in_directory(iobj.object, _("Empty File"))
     try:
         l_text = kupferstring.tolocale(leaf.object)
         outfile.write(l_text)
         if not l_text.endswith(b"\n"):
             outfile.write(b"\n")
     finally:
         outfile.close()
     return FileLeaf(outpath)
Ejemplo n.º 8
0
 def get_items(self):
     package = kupferstring.tolocale(self.query)
     p = subprocess.run(['apt-cache', 'search', '--names-only', package],
                        capture_output=True)
     for line in kupferstring.fromlocale(p.stdout).splitlines():
         if not line.strip():
             continue
         if not " - " in line:
             self.output_error("apt-cache: ", line)
             continue
         package, desc = line.split(" - ", 1)
         yield Package(package, desc)
Ejemplo n.º 9
0
Archivo: plugin.py Proyecto: pbx/kupfer
    def activate(self, obj, iobj, ctx):
        ## accept with or without starting :
        lcmd = kupferstring.tolocale(iobj.object)
        if lcmd.startswith(":"):
            lcmd = lcmd[1:]

        def error_handler(exc):
            ctx.register_late_error(OperationError(exc))
        proxy_obj = get_plugin_service_obj(PLUGID)
        if proxy_obj:
            proxy_obj.SendEx(obj.serverid, lcmd,
                    reply_handler=_dummy_handler,
                    error_handler=error_handler)
Ejemplo n.º 10
0
    def activate(self, obj, iobj, ctx):
        ## accept with or without starting :
        lcmd = kupferstring.tolocale(iobj.object)
        if lcmd.startswith(":"):
            lcmd = lcmd[1:]

        def error_handler(exc):
            ctx.register_late_error(OperationError(exc))

        proxy_obj = get_plugin_service_obj(PLUGID)
        if proxy_obj:
            proxy_obj.SendEx(obj.serverid,
                             lcmd,
                             reply_handler=_dummy_handler,
                             error_handler=error_handler)
Ejemplo n.º 11
0
Archivo: plugin.py Proyecto: pbx/kupfer
    def activate(self, obj, iobj, ctx):
        tmpf, tmpname = utils.get_safe_tempfile()
        tmpf.write(kupferstring.tolocale(obj.object))
        tmpf.close()
        vim_cmd = "r %s" % tmpname
        glib.timeout_add_seconds(10, os.unlink, tmpname)

        def error_handler(exc):
            ctx.register_late_error(OperationError(exc))

        proxy_obj = get_plugin_service_obj(PLUGID)
        if proxy_obj:
            proxy_obj.SendEx(iobj.serverid, vim_cmd,
                    reply_handler=_dummy_handler,
                    error_handler=error_handler)
Ejemplo n.º 12
0
	def get_items(self):
		package = kupferstring.tolocale(self.query)
		c_in, c_out_err = os.popen4(['apt-cache', 'search', '--names-only', package])
		try:
			c_in.close()
			acp_out = c_out_err.read()
			for line in kupferstring.fromlocale(acp_out).splitlines():
				if not line.strip():
					continue
				if not " - " in line:
					self.output_error("apt-cache: ", line)
					continue
				package, desc = line.split(" - ", 1)
				yield Package(package, desc)
		finally:
			c_out_err.close()
Ejemplo n.º 13
0
    def activate(self, obj, iobj, ctx):
        tmpf, tmpname = utils.get_safe_tempfile()
        tmpf.write(kupferstring.tolocale(obj.object))
        tmpf.close()
        vim_cmd = "r %s" % tmpname
        glib.timeout_add_seconds(10, os.unlink, tmpname)

        def error_handler(exc):
            ctx.register_late_error(OperationError(exc))

        proxy_obj = get_plugin_service_obj(PLUGID)
        if proxy_obj:
            proxy_obj.SendEx(iobj.serverid,
                             vim_cmd,
                             reply_handler=_dummy_handler,
                             error_handler=error_handler)
Ejemplo n.º 14
0
	def activate(self, leaf):
		leaf_text = kupferstring.tolocale(leaf.object)

		url = (__kupfer_settings__["receiver_url"])
		o = urlparse(url)
		host = o.netloc
		path = o.path

		# XXX This will fail with HTTPS, right?
		params = urllib.urlencode({'content': leaf_text})
		headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
		conn = httplib.HTTPConnection(host)
		conn.request("POST", path, params, headers)
		response = conn.getresponse()

		data = response.read()
		conn.close()
Ejemplo n.º 15
0
 def get_items(self):
     package = kupferstring.tolocale(self.query)
     c_in, c_out_err = os.popen4(
         ['apt-cache', 'search', '--names-only', package])
     try:
         c_in.close()
         acp_out = c_out_err.read()
         for line in kupferstring.fromlocale(acp_out).splitlines():
             if not line.strip():
                 continue
             if not " - " in line:
                 self.output_error("apt-cache: ", line)
                 continue
             package, desc = line.split(" - ", 1)
             yield Package(package, desc)
     finally:
         c_out_err.close()
Ejemplo n.º 16
0
def _argv_to_locale(argv):
	"encode unicode strings in @argv according to the locale encoding"
	return [kupferstring.tolocale(A) if isinstance(A, unicode) else A
			for A in argv]
Ejemplo n.º 17
0
def _argv_to_locale(argv):
    "encode unicode strings in @argv according to the locale encoding"
    return [
        kupferstring.tolocale(A) if isinstance(A, unicode) else A for A in argv
    ]
Ejemplo n.º 18
0
def locale_encode_argv(argv):
    for x in argv:
        if isinstance(x, unicode):
            yield kupferstring.tolocale(x)
        else:
            yield x
Ejemplo n.º 19
0
 def activate(self, obj, iobj):
     filepath = kupferstring.tolocale(iobj.object)
     execfile.save_to_file(obj, filepath)
     execfile.update_icon(obj, iobj.object)
     return FileLeaf(os.path.abspath(filepath))
Ejemplo n.º 20
0
def locale_encode_argv(argv):
	for x in argv:
		if isinstance(x, unicode):
			yield kupferstring.tolocale(x)
		else:
			yield x
Ejemplo n.º 21
0
 def activate(self, obj, iobj):
     filepath = kupferstring.tolocale(iobj.object)
     execfile.save_to_file(obj, filepath)
     execfile.update_icon(obj, iobj.object)
     return FileLeaf(os.path.abspath(filepath))
Ejemplo n.º 22
0
 def activate(self, leaf, iobj):
     l_text = kupferstring.tolocale(leaf.object)
     with open(iobj.object, "ab") as outfile:
         outfile.write(l_text)
         outfile.write("\n")
Ejemplo n.º 23
0
	def activate(self, leaf, iobj):
		l_text = kupferstring.tolocale(leaf.object)
		with open(iobj.object, "ab") as outfile:
			outfile.write(l_text)
			outfile.write("\n")