garfield.barcode_scanner Package

This package contains the barcode scanner client network back-end and GUI front-ends.

garfield.barcode_scanner.client Module

This module contains the barcode scanner client network class.

class garfield.barcode_scanner.client.BarcodeScannerClient(host, port, identifier, on_connect=None, on_received_barcode=None, on_owner_changed=None, on_disconnect=None, on_connect_error=None, on_acquire_failed=None, on_release_failed=None, on_grab_failed=None, on_async_connect=None, on_completed_handshake=None)

Bases: object

Represents a network client connection with a barcode server daemon.

Wraps the barcode server protocol with an event-based interface, allowing a user of the instance to query the current state and listen for barcodes announced by the server.

To receive barcodes you need to acquire the scanner (acquire_scanner()) first. Only one client can own the scanner at a time. In case another client holds the scanner, you may call grab_scanner() to take the scanner away from it.

PROTO_VER = 1
acquire_scanner()

Informs the barcode scanner daemon, that this client wishes to acquire the scanner.

close()

Close the connection to the server.

Invalidates the fd returned by fileno().

connect()

Creates a socket and connects to the barcode scanner daemon. When the underlying network connection has started,`on_connect` is called. As soon as the protocol handshake has completed, on_completed_handshake is called.

If the connect call would block, on_async_connect is signalled and it is expected that on_connect_complete will be called as soon as the connection has completed.

fileno()

Returns the socket file-descriptor. The fd is only valid until close() is called.

grab_scanner()

Makes the barcode scanner daemon re-assign the barcode scanner to this client, even though it is currently owned by a different client.

is_connected()

Return True in case the client is fully connected to and registered with the server.

on_activity()

Should be called as soon as the associated socket has data available for reading.

on_connect_complete()

Needs to be called iff on_async_connect was signalled and the connect has completed/failed in the meanwhile.

owns_scanner()

Returns True in case this client is the current owner of the scanner.

release_scanner()

Informs the barcode scanner daemon, that this client whishes to release the (previously acquired) scanner.

report_connect_error(msg=None, code=None, exc=None)

Helper to report connection errors.

scanner_owner

Is the identifier of the client that currently holds the scanner or None in case the scanner is currently free.

send_line(line)

Helper function that sends a line to the server.

Should only be used by the internal state classes.

server_identifier

Is the identifier of the server to which the client is connected.

set_internal_state(new_state)

Sets the new internal state instance.

Should only be used by the internal state classes.

exception garfield.barcode_scanner.client.ProtocolError

Bases: exceptions.Exception

Raised in case there was a problem during communication with the server, for example: Unexpected responses and protocol version mismatches.

exception garfield.barcode_scanner.client.StateError

Bases: exceptions.Exception

Raised when a method is called that may not be called for the current connection state. For example, make sure that the client is properly connected by waiting for the appropriate signal.

garfield.barcode_scanner.manager Module

This module manages the connection to (potentially) several barcode scanner daemons and provides hooks to update connected UIs.

class garfield.barcode_scanner.manager.BarcodeScannerClientManager

Bases: PyQt4.QtCore.QObject

Manages multiple client connections to barcode scanners. Multiplexes and demultiplexes the client access and notifications. Integrates the native Python clients with Qt’s signals and Qt’s network sockets.

Supports the concept of a preferred client connection.

Is configured using :meth:load.

CFG_LIST_SECTION = 'barcode_scanner_servers'
CFG_SECTION = 'barcode_scanner'
client_connected
client_connection_error
client_disconnected
client_owner_changed
client_released
load(cfg)

Loads the list and details of the barcode scanner servers from the configuration object cfg.

Example:

[barcode_scanner_servers] sample_server1 = server1.example.org:1234 sample_server2 = server1.example.org:1234

[barcode_scanner] preferred_server = sample_server2

received_barcode
try_connect()
exception garfield.barcode_scanner.manager.ConfigurationError

Bases: exceptions.Exception

garfield.barcode_scanner.manager.setup_env(config, _db_sess, _db_meta, environment_sess)