<commit_before>#!/usr/bin/env python

import gi.repository.GObject as gobject

import dbus
import dbus.service
import dbus.mainloop.glib

class HeadlessKeyboardServer(dbus.service.Object):

    # methods

    @dbus.service.method("ch.abertschi.keyboard.headless.Server", in_signature='s', out_signature='')
    def send_text(self, text):
        print("keyboardlayout: send_text is called")
        self.receive_text(text) # text.decode('utf-8', 'ignore')

    @dbus.service.method("ch.abertschi.keyboard.headless.Server", in_signature='', out_signature='')
    def exit(self):
        mainloop.quit()
        pass

    @dbus.service.method("ch.abertschi.keyboard.headless.Server", in_signature='', out_signature='')
    def send_key_return(self):
        self.receive_key_return()

    @dbus.service.method("ch.abertschi.keyboard.headless.Server", in_signature='', out_signature='')
    def send_key_del(self):
        self.receive_key_del()

    @dbus.service.method("ch.abertschi.keyboard.headless.Server", in_signature='s', out_signature='')
    def send_key_arrow(self, direction):
        allowed = ['up', 'down', 'right', 'left']
        if not direction in allowed:
            print ("Unknown arrow direction %s" % (direction))
            return
        self.receive_key_arrow(direction)

    @dbus.service.method("ch.abertschi.keyboard.headless.Server", in_signature='b', out_signature='')
    def send_enable_debug(self, enable):
        self.receive_enable_debug(enable)


    # todo: new service for keyboard layout
    @dbus.service.method("ch.abertschi.keyboard.headless.Server", in_signature='s', out_signature='')
    def send_clipboard_set(self, content):
        self.receive_clipboard_changed(content)

    # signals

    @dbus.service.signal("ch.abertschi.keyboard.headless.Server")
    def receive_text(self, text):
        print("keyboardlayout: receive_text")
        pass

    @dbus.service.signal("ch.abertschi.keyboard.headless.Server")
    def receive_key_return(self):
        pass

    @dbus.service.signal("ch.abertschi.keyboard.headless.Server")
    def receive_key_del(self):
        pass

    @dbus.service.signal("ch.abertschi.keyboard.headless.Server")
    def receive_key_arrow(self, direction):
        pass

    @dbus.service.signal("ch.abertschi.keyboard.headless.Server")
    def receive_enable_debug(self, enable):
        pass

    @dbus.service.signal("ch.abertschi.keyboard.headless.Server")
    def receive_clipboard_changed(self, content):
        pass


if __name__ == '__main__':
    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
    session_bus = dbus.SessionBus()

    print("launching dbus service ch.abertschi.keyboard.headless")
    name = dbus.service.BusName("ch.abertschi.keyboard.headless", session_bus)
    server = HeadlessKeyboardServer(session_bus, '/')

    print("headless keyboard layout is ready for mainLoop")
    mainloop = gobject.MainLoop()
    mainloop.run()
    pass<commit_msg>clean up<commit_after>#!/usr/bin/env python

import gi.repository.GObject as gobject

import dbus
import dbus.service
import dbus.mainloop.glib

class HeadlessKeyboardServer(dbus.service.Object):

    # methods

    @dbus.service.method("ch.abertschi.keyboard.headless.Server", in_signature='s', out_signature='')
    def send_text(self, text):
        print("keyboardlayout: send_text is called")
        self.receive_text(text) # text.decode('utf-8', 'ignore')

    @dbus.service.method("ch.abertschi.keyboard.headless.Server", in_signature='', out_signature='')
    def exit(self):
        mainloop.quit()
        pass

    @dbus.service.method("ch.abertschi.keyboard.headless.Server", in_signature='', out_signature='')
    def send_key_return(self):
        self.receive_key_return()

    @dbus.service.method("ch.abertschi.keyboard.headless.Server", in_signature='', out_signature='')
    def send_key_del(self):
        self.receive_key_del()

    @dbus.service.method("ch.abertschi.keyboard.headless.Server", in_signature='s', out_signature='')
    def send_key_arrow(self, direction):
        allowed = ['up', 'down', 'right', 'left']
        if not direction in allowed:
            print ("Unknown arrow direction %s" % (direction))
            return
        self.receive_key_arrow(direction)

    @dbus.service.method("ch.abertschi.keyboard.headless.Server", in_signature='b', out_signature='')
    def send_enable_debug(self, enable):
        self.receive_enable_debug(enable)


    # todo: new service for keyboard layout
    @dbus.service.method("ch.abertschi.keyboard.headless.Server", in_signature='s', out_signature='')
    def send_clipboard_set(self, content):
        self.receive_clipboard_changed(content)

    # signals

    @dbus.service.signal("ch.abertschi.keyboard.headless.Server")
    def receive_text(self, text):
        print("keyboardlayout: receive_text")
        pass

    @dbus.service.signal("ch.abertschi.keyboard.headless.Server")
    def receive_key_return(self):
        pass

    @dbus.service.signal("ch.abertschi.keyboard.headless.Server")
    def receive_key_del(self):
        pass

    @dbus.service.signal("ch.abertschi.keyboard.headless.Server")
    def receive_key_arrow(self, direction):
        pass

    @dbus.service.signal("ch.abertschi.keyboard.headless.Server")
    def receive_enable_debug(self, enable):
        pass

    @dbus.service.signal("ch.abertschi.keyboard.headless.Server")
    def receive_clipboard_changed(self, content):
        pass

if __name__ == '__main__':
    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
    session_bus = dbus.SessionBus()

    print("launching dbus service ch.abertschi.keyboard.headless")
    name = dbus.service.BusName("ch.abertschi.keyboard.headless", session_bus)
    server = HeadlessKeyboardServer(session_bus, '/')

    print("headless keyboard layout is ready for mainLoop")
    mainloop = gobject.MainLoop()
    mainloop.run()
    pass
{'fraction_non_alphanumeric': 0.12956698240866035, 'fraction_numerical': 0.00033829499323410016, 'mean_word_length': 3.8112286411716845, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4970167', 'n_tokens_mistral': 1973, 'n_tokens_neox': 1921, 'n_words': 296}