Skip to content

Commit a3aa2df

Browse files
committed
Enhance formatting of README
1 parent e93d2e1 commit a3aa2df

File tree

1 file changed

+64
-64
lines changed

1 file changed

+64
-64
lines changed

README.md

+64-64
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,23 @@ API
5353

5454
An application using pyNotifier has to initialise the notifier,
5555
i.e. it has to choose which notifier implementation should be
56-
used. This is done by calling the 'init' function:
56+
used. This is done by calling the `init` function:
5757

58-
def init( type = GENERIC ):
58+
def init(type=GENERIC):
5959

60-
If no argument is given to the 'init' function the internal
60+
If no argument is given to the `init` function the internal
6161
implementation of pyNotifier is used. Other possible choices for the
62-
'type' argument are GTK, QT and WX (current support for wxWindows is
62+
`type` argument are GTK, QT and WX (current support for wxWindows is
6363
not up-to-date).
6464

6565
Some notifier implementations provide a set of options that control the
6666
behaviour of the notifier. The options are passed to the implementation
67-
as a keyword list through the 'init' function as shown in the following
67+
as a keyword list through the `init` function as shown in the following
6868
example:
6969

70-
def init( type = GTK, x11 = False )
70+
def init(type=GTK, x11=False)
7171

72-
This example uses the 'x11' option for the GTK notifier. If set
72+
This example uses the `x11` option for the GTK notifier. If set
7373
to False the notifier does not require gtk anymore and uses gobject
7474
instead.
7575

@@ -78,25 +78,25 @@ Sockets
7878

7979
To get notified when a specific event occurs the application has to
8080
register its interest for this event. For sockets and files this is
81-
done with the 'socket\_add' function':
81+
done with the `socket_add` function:
8282

83-
def socket_add( id, method, condition = IO_IN )
83+
def socket_add(id, method, condition=IO_IN)
8484

85-
The 'id' argument may be a socket or file object or a file descriptor
86-
that can be retrieved by calling the 'fileno()' member function of
87-
these objects. The second argument 'method' has to be a callable
85+
The `id` argument may be a socket or file object or a file descriptor
86+
that can be retrieved by calling the `fileno()` member function of
87+
these objects. The second argument `method` has to be a callable
8888
python object that is invoked by the notifier if the registered event
89-
has occured. The function is invoked with the 'id' as an
89+
has occured. The function is invoked with the `id` as an
9090
argument. Instead of a normal function the [Callback](#callbacks)
9191
object provided by pyNotifier may be useful at this point.
9292

9393
To remove a registered socket or file from the notifier the
94-
'socket\_remove' function has to be invoked. The 'id' is the socket or
95-
file object or the file descriptor given to 'socket\_add' and the
96-
optional argument 'condition' may be set to IO\_IN or IO\_OUT depending
94+
`socket_remove` function has to be invoked. The `id` is the socket or
95+
file object or the file descriptor given to `socket_add` and the
96+
optional argument `condition` may be set to `IO_IN` or `IO_OUT` depending
9797
on the previously registered event:
9898

99-
def socket_remove( id, condition = IO_IN )
99+
def socket_remove(id, condition=IO_IN)
100100

101101
Another way to achieve the removal of a socket or file object from the
102102
notifier is to return False in the callback function. If a callback
@@ -108,22 +108,22 @@ Timer
108108

109109
pyNotifier supports just one type of timer. If a timer is registered
110110
for a given interval of time the application is recurrently triggered
111-
when the timer expires. To register a timer the 'timer\_add' function
112-
has to be invoked. The first argument 'interval' must be specified in
113-
milliseconds. 'method' is the callback function that is invoked by the
111+
when the timer expires. To register a timer the `timer_add` function
112+
has to be invoked. The first argument `interval` must be specified in
113+
milliseconds. `method` is the callback function that is invoked by the
114114
notifier without any argument when the timer expires.
115115

116-
def timer_add( interval, method ) -> unique timer identifier
116+
def timer_add(interval, method) -> unique timer identifier
117117

118118
To implement a one-shot timer that is just triggered once and never
119119
again the application can use the return value of its callback
120120
function for this timer and return False or None. In this case the
121121
notifier automatically removes the timer. Another way to remove a
122-
timer is to call the method 'timer\_remove'.
122+
timer is to call the method `timer_remove`.
123123

124-
def timer_remove( id )
124+
def timer_remove(id)
125125

126-
The 'id' argument is the unique timer identifier returned by 'timer\_add'.
126+
The `id` argument is the unique timer identifier returned by `timer_add`.
127127

128128
Signals
129129
-------
@@ -149,32 +149,32 @@ context.
149149
import notifier.signals as signals
150150

151151
# global context
152-
signals.new( 'signal1' )
152+
signals.new('signal1')
153153

154-
class Test( signals.Provider ):
155-
def __init__( self ):
156-
signals.Provider.__init__( self )
157-
self.signal_new( 'signal1' )
154+
class Test(signals.Provider):
155+
def __init__(self):
156+
signals.Provider.__init__(self)
157+
self.signal_new('signal1')
158158

159159
To get informed when a signal is emitted a connection must be created as
160160
shown in the following code snippet.
161161

162162
# global context
163-
def _cb_signal( signal ):
163+
def _cb_signal(signal):
164164
pass
165165

166-
signals.connect( 'signal1', _cb_signal )
166+
signals.connect('signal1', _cb_signal)
167167

168168
# within the object
169-
class Test2( object ):
170-
def __init__( self, test ):
171-
test.signal_connect( 'signal1', self._cb_signal )
169+
class Test2(object):
170+
def __init__(self, test):
171+
test.signal_connect('signal1', self._cb_signal)
172172

173-
def _cb_signal( self, signal ):
173+
def _cb_signal(self, signal):
174174
pass
175175

176176
test = Test()
177-
test2 = Test2( test )
177+
test2 = Test2(test)
178178

179179
There is no restriction in how many connection to a signal may exist,
180180
but it should be noted, that to many connected instances may result an a
@@ -186,10 +186,10 @@ emit a signal its name and possibly optional arguments are passed to a
186186
function as shown in the following snippet.
187187

188188
# global context
189-
signals.emit( 'signal1', a, b )
189+
signals.emit('signal1', a, b)
190190

191191
# within an object
192-
test.signal_emit( 'signal1', a, b, c )
192+
test.signal_emit('signal1', a, b, c)
193193

194194
The signature of the callback function for a signal depends on the
195195
specific signal provider, e.g. each signal may provide as many arguments
@@ -210,49 +210,49 @@ pyNotifier provides the feature to add so called external
210210
dispatchers. These dispatchers are functions that will be invoked in
211211
each notifier step after all timers and sockets were checked. To add a
212212
dispatcher function to the notifier main loop the function
213-
'dispatcher\_add' is provided. The only argument to this function is the
213+
`dispatcher_add` is provided. The only argument to this function is the
214214
callback method that will be called.
215215

216-
def dispatcher_add( method )
216+
def dispatcher_add(method)
217217

218218
To remove such a dispatcher function from the notifier main loop
219-
'dispatcher\_remove' is used with the call back method as the only argument.
219+
`dispatcher_remove` is used with the call back method as the only argument.
220220

221-
def dispatcher_remove( method )
221+
def dispatcher_remove(method)
222222

223223
Callbacks
224224
---------
225225

226-
pyNotifier provides a class 'Callback' that can be used as a callback
227-
function that is passed to the 'socket\_add' and 'timer\_add'
226+
pyNotifier provides a class `Callback` that can be used as a callback
227+
function that is passed to the `socket_add` and `timer_add`
228228
function. This class provides the possibility to pass more than the
229229
specified arguments to the callback functions. For example the socket
230230
callback function is called with one single argument. To pass some
231-
state information to the callback function the 'Callback' object may
231+
state information to the callback function the `Callback` object may
232232
be used. A default callback function for a socket event would look
233-
like 'socket1'.
233+
like `socket1`.
234234

235235
import notifier
236236
...
237-
notifier.socket_add( fd, socket1 )
237+
notifier.socket_add(fd, socket1)
238238
...
239239

240-
def socket1( fd ):
241-
print 'data received on socket', fd
240+
def socket1(fd):
241+
print('data received on socket', fd)
242242
return True
243243

244-
'fd' is the 'id' given to 'socket\_add'. To pass some state information
244+
`fd` is the `id` given to `socket_add`. To pass some state information
245245
to the callback function it can be done as shown in the following
246246
example.
247247

248248
import notifier
249249
...
250-
notifier.socket_add( fd, notifier.Callback( socket1, arg1, arg2 ) )
250+
notifier.socket_add(fd, notifier.Callback(socket1, arg1, arg2))
251251
...
252252

253-
def socket1( fd, arg1, arg2 ):
254-
print 'data received on socket', fd
255-
print 'additional state information', arg1, arg2
253+
def socket1(fd, arg1, arg2):
254+
print('data received on socket', fd)
255+
print('additional state information', arg1, arg2)
256256

257257
The arguments given to the Callback object are appended to the
258258
original list of arguments for the callback function. The argument
@@ -270,26 +270,26 @@ pyNotifier in the examples sub-directory.
270270
import notifier
271271

272272
def another_minute():
273-
print "another minute is elapsed"
273+
print("another minute is elapsed")
274274
# callback should be invoked again
275275
return True
276276

277-
def first_10_secs( secs ):
278-
print "the first %d secs are elapsed" % secs
277+
def first_10_secs(secs):
278+
print("the first %d secs are elapsed" % secs)
279279
# this should be a one-shot timer
280280
return False
281281

282-
def standard_in( in ):
283-
print "someone entered some data on stdin"
284-
print in.read( 80 )
282+
def standard_in(in):
283+
print("someone entered some data on stdin")
284+
print(in.read(80))
285285
# still want to watch it
286286
return True
287287

288288
if __name__ == "__main__":
289-
notifier.init( notifier.GENERIC )
289+
notifier.init(notifier.GENERIC)
290290

291-
notifier.timer_add( 60000, another_minute )
292-
notifier.timer_add( 10000, notifier.Callback( first_10_secs, 10 ) )
293-
notifier.socket_add( sys.stdin, standard_in )
291+
notifier.timer_add(60000, another_minute)
292+
notifier.timer_add(10000, notifier.Callback(first_10_secs, 10))
293+
notifier.socket_add(sys.stdin, standard_in)
294294

295295
notifier.loop()

0 commit comments

Comments
 (0)