def options_update(): g.timeout_remove(self.update_timeout) self.update_display(battery) # print str(int(self.ticks_till_update.int_value) * 100) print self.text_font self.set_size_request(self.applet_width.int_value, -1) self.update_timeout = g.timeout_add(int(self.ticks_till_update.int_value) * 100, self.update_display, battery)
def __init__(self): g.VBox.__init__(self) self.update_timeout = g.timeout_add(int(self.ticks_till_update.int_value) * 100, self.update_display, battery) def options_update(): g.timeout_remove(self.update_timeout) self.update_display(battery) # print str(int(self.ticks_till_update.int_value) * 100) print self.text_font self.set_size_request(self.applet_width.int_value, -1) self.update_timeout = g.timeout_add(int(self.ticks_till_update.int_value) * 100, self.update_display, battery) rox.app_options.add_notify(options_update) def destroyed(self): g.timeout_remove(self.update_timeout) rox.app_options.remove_notify(options_update) self.connect('destroy', destroyed) # pack_start(widget, expand, fill, padding) self.pack_start(self.percent_display, g.TRUE, g.TRUE, 0) self.pack_start(self.battery_display, g.FALSE, g.FALSE, 0) self.percent_display.set_size_request(-1,10) self.set_size_request(self.applet_width.int_value, -1) self.update_display(battery) self.battery_display.set_justify(g.JUSTIFY_CENTER) self.show()
def _test(): "Check that this module works." def show(): error = sys.exc_info()[1] print "(error reported was '%s')" % error def pipe_through_command(command, src, dst): PipeThroughCommand(command, src, dst).wait() print "Test _Tmp()..." test_file = _Tmp() test_file.write('Hello') print >>test_file, ' ', test_file.flush() os.write(test_file.fileno(), 'World') test_file.seek(0) assert test_file.read() == 'Hello World' print "Test pipe_through_command():" print "Try an invalid command..." try: pipe_through_command('bad_command_1234', None, None) assert 0 except ChildError: show() else: assert 0 print "Try a valid command..." pipe_through_command('exit 0', None, None) print "Writing to a non-fileno stream..." from cStringIO import StringIO a = StringIO() pipe_through_command('echo Hello', None, a) assert a.getvalue() == 'Hello\n' print "Try with args..." a = StringIO() pipe_through_command(('echo', 'Hello'), None, a) assert a.getvalue() == 'Hello\n' print "Reading from a stream to a StringIO..." test_file.seek(1) # (ignored) pipe_through_command('cat', test_file, a) assert a.getvalue() == 'Hello\nHello World' print "Writing to a fileno stream..." test_file.seek(0) test_file.truncate(0) pipe_through_command('echo Foo', None, test_file) test_file.seek(0) assert test_file.read() == 'Foo\n' print "Read and write fileno streams..." src = _Tmp() src.write('123') src.seek(0) test_file.seek(0) test_file.truncate(0) pipe_through_command('cat', src, test_file) test_file.seek(0) assert test_file.read() == '123' print "Detect non-zero exit value..." try: pipe_through_command('exit 1', None, None) except ChildError: show() else: assert 0 print "Detect writes to stderr..." try: pipe_through_command('echo one >&2; sleep 2; echo two >&2', None, None) except ChildError: show() else: assert 0 print "Check tmp file is deleted..." name = test_file.name assert os.path.exists(name) test_file = None assert not os.path.exists(name) print "Check we can kill a runaway proces..." ptc = PipeThroughCommand('sleep 100; exit 1', None, None) def stop(): ptc.kill() g.timeout_add(2000, stop) try: ptc.wait() assert 0 except ChildKilled: pass print "All tests passed!"
if handlers: return del _handlers[handler.watched_path] if gio: _gio_file_monitors.pop(handler.watched_path).cancel() elif gamin: _monitor.stop_watch(handler.watched_path) elif _fam: try: fam_request = _fam_requests.pop(watched_path) except KeyError: return fam_request.cancelMonitor() else: return def _watch(): if gamin: _monitor.handle_events() elif _fam: while _fam_conn.pending(): fam_event = _fam_conn.nextEvent() _event(fam_event.filename, fam_event.code, fam_event.userData) else: return False return True g.timeout_add(1000, _watch)
def __init__(self, timeout): """Trigger after 'timeout' seconds (may be a fraction).""" Blocker.__init__(self) rox.toplevel_ref() g.timeout_add(long(timeout * 1000), self._timeout)
def _test(): "Check that this module works." def show(): error = sys.exc_info()[1] print "(error reported was '%s')" % error def pipe_through_command(command, src, dst): PipeThroughCommand(command, src, dst).wait() print "Test _Tmp()..." file = _Tmp() file.write('Hello') print >> file, ' ', file.flush() os.write(file.fileno(), 'World') file.seek(0) assert file.read() == 'Hello World' print "Test pipe_through_command():" print "Try an invalid command..." try: pipe_through_command('bad_command_1234', None, None) assert 0 except ChildError: show() else: assert 0 print "Try a valid command..." pipe_through_command('exit 0', None, None) print "Writing to a non-fileno stream..." from cStringIO import StringIO a = StringIO() pipe_through_command('echo Hello', None, a) assert a.getvalue() == 'Hello\n' print "Try with args..." a = StringIO() pipe_through_command(('echo', 'Hello'), None, a) assert a.getvalue() == 'Hello\n' print "Reading from a stream to a StringIO..." file.seek(1) # (ignored) pipe_through_command('cat', file, a) assert a.getvalue() == 'Hello\nHello World' print "Writing to a fileno stream..." file.seek(0) file.truncate(0) pipe_through_command('echo Foo', None, file) file.seek(0) assert file.read() == 'Foo\n' print "Read and write fileno streams..." src = _Tmp() src.write('123') src.seek(0) file.seek(0) file.truncate(0) pipe_through_command('cat', src, file) file.seek(0) assert file.read() == '123' print "Detect non-zero exit value..." try: pipe_through_command('exit 1', None, None) except ChildError: show() else: assert 0 print "Detect writes to stderr..." try: pipe_through_command('echo one >&2; sleep 2; echo two >&2', None, None) except ChildError: show() else: assert 0 print "Check tmp file is deleted..." name = file.name assert os.path.exists(name) file = None assert not os.path.exists(name) print "Check we can kill a runaway proces..." ptc = PipeThroughCommand('sleep 100; exit 1', None, None) def stop(): ptc.kill() g.timeout_add(2000, stop) try: ptc.wait() assert 0 except ChildKilled: pass print "All tests passed!"