""" Various global hooks. """ import sys import threading import traceback from pisak import logger _LOG = logger.get_logger(__file__) _MESSAGES = { "unexpected_error": "Wystąpił nieoczekiwany błąd.\n" "Aplikacja zostanie zamknięta." } def _register_custom_excepthook(): """ Register custom function to be used as sys.excepthook for the current application. It will: handle any exception that has not been caught by the application itself; log the error as critical; if the application main loop is still alive then display some GUI message and then close the application, otherwise just do nothing and let the application close itself; only exceptions originating from the main thread are handled; call the default, built-in `sys.__excepthook__` function in the end. """ def excepthook(exctype, value, traceb): import pisak
import requests from pisak import logger from pisak.blog import exceptions, config _LOG = logger.get_logger(__name__) class Blog(object): """ Client of a blog that makes a JSON API avalaible. :param address: blog's site domain (string) or ID (integer). """ def __init__(self, address): self.max_posts = 100 # api's max self.max_comments = 100 # api's max self.address_base = "https://public-api.wordpress.com/rest/v1.1/sites/" self.address = self.address_base + str(address).replace("/", "%2F") def _get(self, resource): try: return requests.get(self.address + resource).json() except requests.exceptions.ConnectionError as exc: raise exceptions.BlogInternetError(exc) from exc except Exception as exc: raise exceptions.BlogMethodError(exc) from exc def get_all_posts(self): """ Get all posts from the blog.
""" Module with widgets specific to symboler application. """ import ezodf from gi.repository import Mx, Clutter, GObject from pisak import widgets, pager, layout, configurator, \ dirs, logger from pisak.res import colors _LOG = logger.get_logger(__name__) class Entry(layout.Box, widgets.TileContainer, configurator.Configurable): """ Entry window for typing symbols. """ __gtype_name__ = "PisakSymbolerEntry" __gproperties__ = { "tile_ratio_width": ( GObject.TYPE_FLOAT, None, None, 0, 1., 0, GObject.PARAM_READWRITE), "tile_ratio_height": ( GObject.TYPE_FLOAT, None, None, 0, 1., 0, GObject.PARAM_READWRITE), "tile_ratio_spacing": ( GObject.TYPE_FLOAT, None, None, 0, 1., 0, GObject.PARAM_READWRITE), "tile_preview_ratio_width": ( GObject.TYPE_FLOAT, None, None, 0, 1., 0,
""" Various global hooks. """ import sys import threading import traceback from pisak import logger _LOG = logger.get_logger(__file__) _MESSAGES = {"unexpected_error": "Wystąpił nieoczekiwany błąd.\n" "Aplikacja zostanie zamknięta."} def _register_custom_excepthook(): """ Register custom function to be used as sys.excepthook for the current application. It will: handle any exception that has not been caught by the application itself; log the error as critical; if the application main loop is still alive then display some GUI message and then close the application, otherwise just do nothing and let the application close itself; only exceptions originating from the main thread are handled; call the default, built-in `sys.__excepthook__` function in the end. """ def excepthook(exctype, value, traceb): import pisak
""" Websocket server and client implementations for PISAK eyetrackers. """ import asyncio import threading from ws4py.async_websocket import WebSocket from ws4py.server.tulipserver import WebSocketProtocol from ws4py.client.threadedclient import WebSocketClient from pisak import logger _LOG = logger.get_logger('tracker') SERVER_HOST = '127.0.0.1' SERVER_PORT = '28394' CLIENT_START_MSG = 'start' CLIENT_STOP_MSG = 'stop' class TrackerServer: """ Server for trackers. """ clients = set() class TrackerServerWebSocket(WebSocket): """ Handler web socket class for new coming connections.
import asyncio import threading from ws4py.async_websocket import WebSocket from ws4py.server.tulipserver import WebSocketProtocol from ws4py.client.threadedclient import WebSocketClient from pisak import logger _LOG = logger.get_logger('tracker') SERVER_HOST = '127.0.0.1' SERVER_PORT = '28394' CLIENT_START_MSG = 'start' CLIENT_STOP_MSG = 'stop' class TrackerServer(object): clients = set() class TrackerServerWebSocket(WebSocket): """ Handler web socket class for new coming connections. """ def __init__(self, *args, **kwargs): WebSocket.__init__(self, *args, **kwargs) self.active = False