def announce_remote(data, remote): import pgi pgi.install_as_gi() pgi.require_version('Notify', '0.7') from gi.repository import Notify Notify.init("Network Switcher") Hello = Notify.Notification.new( "Network change detected", "{} set to {}".format(data['target'], remote), "dialog-information") Hello.show()
def test_pep8(): """Run pep8 pyflakes tests""" import pgi pgi.install_as_gi() current_dir = os.path.join(os.path.dirname(__file__)) tests = discover(current_dir, "misc") tests = [unittest.makeSuite(t) for t in tests] run = unittest.TextTestRunner(verbosity=2).run(unittest.TestSuite(tests)) return len(run.failures) + len(run.errors)
def main(username, password): try: import gi except ImportError: import pgi pgi.install_as_gi() import gi gi.require_version('Notify', '0.7') from gi.repository import Notify tasks = get_delayed_tasks(username, password) if not tasks: return summary = "You have {n} tasks pending.".format(n=len(tasks)) body = "Some of them are:\n{sample}".format(sample=build_sample(tasks)) print(summary + "\n" + body) Notify.init('anyreport') notif = Notify.Notification(summary=summary, body=body) notif.show()
it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Flowblade Movie Editor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Flowblade Movie Editor. If not, see <http://www.gnu.org/licenses/>. """ try: import pgi pgi.install_as_gi() except ImportError: pass import gi gi.require_version('Gtk', '3.0') from gi.repository import GLib import locale import mlt import os import pickle import subprocess import sys import threading
def test(load_gi, backend=None, strict=False, filter_=None, failfast=False): """Run the test suite. load_gi -- run all tests in the pygobject suite with PyGObject backend -- "ctypes" or "cffi" strict -- fail on glib warnings filter_ -- filter for test names (class names) """ global _is_gi, _is_pypy, _has_cairo, _gi_version, GIOverflowError _is_gi = load_gi _is_pypy = platform.python_implementation() == "PyPy" _has_cairo = True if not load_gi: try: import cairocffi cairocffi.install_as_pycairo() except (ImportError, OSError): _has_cairo = False import pgi pgi.install_as_gi() try: pgi.set_backend(backend) except LookupError: print("Couldn't load backend: %r" % backend) return def headline(text): return (("### %s " % text) + "#" * 80)[:80] import gi TYPELIBS = { "Gtk": "3.0", "Gdk": "3.0", "Clutter": "1.0", "Regress": "1.0", "GIMarshallingTests": "1.0", "PangoCairo": "1.0" } for name, version in TYPELIBS.items(): try: gi.require_version(name, version) except ValueError: pass if load_gi: assert gi.__name__ == "gi" try: _gi_version = gi.version_info except AttributeError: _gi_version = gi._gobject.pygobject_version if _gi_version < (3, 10): GIOverflowError = ValueError else: GIOverflowError = OverflowError hl = headline("GI") else: assert gi.__name__ == "pgi" if backend: hl = headline("PGI (%s)" % backend) else: hl = headline("PGI") GIOverflowError = OverflowError print(hl[:80]) # gi uses logging logging.disable(logging.ERROR) if strict: # make glib warnings fatal from gi.repository import GLib GLib.log_set_always_fatal( GLib.LogLevelFlags.LEVEL_CRITICAL | GLib.LogLevelFlags.LEVEL_ERROR | GLib.LogLevelFlags.LEVEL_WARNING) current_dir = os.path.join(os.path.dirname(__file__)) tests = [] tests = discover(current_dir, "tests_pygobject") tests += discover(current_dir, "tests_mixed") if not load_gi: tests.extend(discover(current_dir, "tests_pgi")) if filter_ is not None: tests = filter(lambda t: filter_(t.__name__), tests) tests = [unittest.makeSuite(t) for t in tests] # only in case all get run, so filtered results don't get spammed if filter_ is None: # collected by the FIXME decorator print(headline("FIXME")) for item, desc in sorted(_fixme.items(), key=lambda x: repr(x)): print(" -> %s.%s" % (item.__module__, item.__name__), end="") if desc: print("(%s)" % desc) else: print() run = unittest.TextTestRunner( verbosity=2, failfast=failfast).run(unittest.TestSuite(tests)) return len(run.failures) + len(run.errors)
# Copyright 2013 Christoph Reiter # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. import os # Force disable translations for gi libraries. # For example descriptions of properties/signals are translated. os.environ["LANG"] = "en" import pgi pgi.install_as_gi() pgi.set_backend("ctypes,null")
def run(load_gi, backend=None): if not load_gi: import pgi pgi.install_as_gi() try: pgi.set_backend(backend) except LookupError: print("Couldn't load backend: %r" % backend) return import gi if load_gi: assert gi.__name__ == "gi" hl = "### GI " + "#" * 100 else: assert gi.__name__ == "pgi" if backend: hl = "### PGI (%s) " % backend + "#" * 100 else: hl = "### PGI " + "#" * 100 print(hl[:80]) t = time.time() from gi.repository import Gtk, GObject, GLib, Gio, Pango, Gdk GLib = GLib Gio = Gio Pango = Pango Gdk = Gdk t = time.time() - t print("%20s: %6.2f ms" % ("import", t * (10 ** 3))) def bench_func(n): times = [] for i in xrange(n): t = time.time() Gtk.get_current_event_time() Gtk.rc_get_theme_dir()[:] t = time.time() - t times.append(t) return times def bench_gvalue(n): times = [] b = Gtk.Button() for i in xrange(n): t = time.time() value = GObject.Value() value.init(GObject.TYPE_INT) value.set_int(42) value.get_int() value.unset() value = GObject.Value() value.init(GObject.TYPE_STRING) value.set_string("foobar") value.get_string() value.unset() value = GObject.Value() value.init(GObject.TYPE_OBJECT) value.set_object(b) value.get_object() value.unset() t = time.time() - t times.append(t) return times def bench_object(n): times = [] for i in xrange(n): t = time.time() w = Gtk.Window() w.props.title = "this" t = time.time() - t times.append(t) return times def bench_method(n): times = [] b = Gtk.Button() for i in xrange(n): t = time.time() b.set_name("foobar") b.get_name() b.set_relief(Gtk.ReliefStyle.NORMAL) b.get_relief() b.set_use_stock(True) b.get_use_stock() b.set_alignment(0.2, 0.4) b.get_alignment() t = time.time() - t times.append(t) return times def torture_signature_0(rounds): test = Regress.TestObj() func = test.torture_signature_0 times = [] for i in xrange(rounds): t0 = time.time() func(5000, "foobar", 12345) times.append(time.time() - t0) return times def torture_signature_1(rounds): test = Regress.TestObj() func = test.torture_signature_1 times = [] for i in xrange(rounds): t0 = time.time() func(5000, "foobar", 12344) times.append(time.time() - t0) return times def torture_signature_1e(rounds): test = Regress.TestObj() func = test.torture_signature_1 times = [] for i in xrange(rounds): t0 = time.time() try: func(5000, "foobar", 12345) except: pass times.append(time.time() - t0) return times def bench_arrays(rounds): times = [] for i in xrange(rounds): t0 = time.time() GIMarshallingTests.array_fixed_int_return() GIMarshallingTests.array_fixed_short_return() GIMarshallingTests.array_fixed_int_in([-1, 0, 1, 2]) GIMarshallingTests.array_fixed_out() GIMarshallingTests.array_fixed_inout([-1, 0, 1, 2]) GIMarshallingTests.array_return() GIMarshallingTests.array_return_etc(5, 9) GIMarshallingTests.array_string_in(['foo', 'bar']) times.append(time.time() - t0) return times bench = [ (bench_func, 100000), (bench_method, 100000), (bench_gvalue, 10000), (bench_object, 10000), ] try: from gi.repository import Regress except ImportError: pass else: bench.extend([ (torture_signature_0, 10000), (torture_signature_1, 10000), (torture_signature_1e, 10000), ]) try: from gi.repository import GIMarshallingTests except ImportError: pass else: bench.extend([ (bench_arrays, 10000), ]) for b, n in bench: min_time = min(b(n)) print("%20s: %6.2f µs" % (b.__name__, min_time * (10 ** 6)))
def test(load_gi, backend=None, strict=False, filter_=None, failfast=False): """Run the test suite. load_gi -- run all tests in the pygobject suite with PyGObject backend -- "ctypes" or "cffi" strict -- fail on glib warnings filter_ -- filter for test names (class names) """ global _is_gi, _is_pypy, _has_cairo, _gi_version, GIOverflowError _is_gi = load_gi _is_pypy = platform.python_implementation() == "PyPy" _has_cairo = True if not load_gi: try: import cairocffi cairocffi.install_as_pycairo() except (ImportError, OSError): _has_cairo = False import pgi pgi.install_as_gi() try: pgi.set_backend(backend) except LookupError: print("Couldn't load backend: %r" % backend) return def headline(text): return (("### %s " % text) + "#" * 80)[:80] import gi TYPELIBS = { "Gtk": "3.0", "Gdk": "3.0", "Clutter": "1.0", "Regress": "1.0", "GIMarshallingTests": "1.0", "PangoCairo": "1.0" } for name, version in TYPELIBS.items(): try: gi.require_version(name, version) except ValueError: pass if load_gi: assert gi.__name__ == "gi" try: _gi_version = gi.version_info except AttributeError: _gi_version = gi._gobject.pygobject_version if _gi_version < (3, 10): GIOverflowError = ValueError else: GIOverflowError = OverflowError hl = headline("GI") else: assert gi.__name__ == "pgi" if backend: hl = headline("PGI (%s)" % backend) else: hl = headline("PGI") GIOverflowError = OverflowError print(hl[:80]) # gi uses logging logging.disable(logging.ERROR) if strict: # make glib warnings fatal from gi.repository import GLib GLib.log_set_always_fatal(GLib.LogLevelFlags.LEVEL_CRITICAL | GLib.LogLevelFlags.LEVEL_ERROR | GLib.LogLevelFlags.LEVEL_WARNING) current_dir = os.path.join(os.path.dirname(__file__)) tests = [] tests = discover(current_dir, "tests_pygobject") tests += discover(current_dir, "tests_mixed") if not load_gi: tests.extend(discover(current_dir, "tests_pgi")) if filter_ is not None: tests = filter(lambda t: filter_(t.__name__), tests) tests = [unittest.makeSuite(t) for t in tests] # only in case all get run, so filtered results don't get spammed if filter_ is None: # collected by the FIXME decorator print(headline("FIXME")) for item, desc in sorted(_fixme.items(), key=lambda x: repr(x)): print(" -> %s.%s" % (item.__module__, item.__name__), end="") if desc: print("(%s)" % desc) else: print() run = unittest.TextTestRunner(verbosity=2, failfast=failfast).run( unittest.TestSuite(tests)) return len(run.failures) + len(run.errors)
import yaml import socket import signal import asyncio import logging.config from asyncio import StreamReader, StreamWriter from time import sleep once = True linux, windows = (None, ) * 2 try: import pgi as linux linux.install_as_gi() linux.require_version('Notify', '0.7') from pgi.repository import Notify Notify.init('Client Notifier') except ImportError: linux, Notify = (None, ) * 2 if not linux: try: import win10toast as windows except ImportError: windows = None if linux: def get_icon(state):