Browse Source

added setup.py. it basically work, however, some features are missing

digital 7 years ago
parent
commit
c5a0f16b94

+ 10 - 0
MANIFEST

@@ -0,0 +1,10 @@
+# file GENERATED by distutils, do NOT edit
+setup.py
+beewatch/__init__.py
+beewatch/./config/commands.yaml
+beewatch/./config/controllers.yaml
+beewatch/./config/logging.yaml
+beewatch/./config/style.css
+beewatch/gui/__init__.py
+beewatch/pinapi/__init__.py
+beewatch/server/__init__.py

+ 12 - 2
beewatch/__init__.py

@@ -23,6 +23,7 @@ DOCSTRING
 import logging
 import logging.handlers
 import sys
+import os
 import time
 import traceback
 # Third party imports
@@ -38,15 +39,24 @@ log = logging.getLogger(__name__+"")
 _controllers = {}
 _commands = {}
 
+def get_example_config_path():
+    """
+    This function returns the absolute path to the example config directory. See also :doc:`/configure`
+    """
+    conf_path = os.path.abspath(__file__)
+    conf_path = conf_path.split(os.sep)
+    conf_path.pop()
+    conf_path.append("config")
+    conf_path = os.sep.join(conf_path)
+    return conf_path
 
 class Configure(object):
     """
-    Configure BeeWatch from a dict
+    Configure BeeWatch from a dict. See also :doc:/configure
 
     This class is inspired by logging.config
     (https://github.com/python/cpython/blob/3.6/Lib/logging/config.py)
 
-
     Parameters
     ----------
     config: dict

+ 80 - 0
beewatch/config/commands.yaml

@@ -0,0 +1,80 @@
+commands:
+    eturn:
+        controller: engines_ctrl
+        function: turn
+    estate:
+        controller: engines_ctrl
+        function: set_engine_state
+    espeed:
+        controller: engines_ctrl
+        function: set_engine_speed
+    led_1_on:
+        controller: led_test_1
+        function: "on"
+    led_1_off:
+        controller: led_test_1
+        function: "off"
+    led_2_on:
+        controller: led_test_2
+        function: "on"
+    led_2_off:
+        controller: led_test_2
+        function: "off"
+    dout:
+        controller: debug_ctrl
+        function: output
+    din:
+        controller: debug_ctrl
+        function: input
+    draise:
+        controller: debug_ctrl
+        function: raise_exc
+    daraise:
+        controller: debug_ctrl
+        function: araise_exc
+    set_status_ok:
+        controller: status_led
+        function: green
+    set_status_warn:
+        controller: status_led
+        function: red
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#

+ 46 - 0
beewatch/config/controllers.yaml

@@ -0,0 +1,46 @@
+controllers:
+    engines_ctrl:
+        target: digilib.pin.EnginesController
+        left: [4,17]
+        right: [27,22]
+    led_test_1:
+        target: digilib.pin.LED
+        pin: 5
+    led_test_2:
+        target: digilib.pin.LED
+        pin: 6
+    status_led:
+        target: digilib.pin.StatusLED
+        pin_red: 19
+        pin_green: 26
+    debug_ctrl:
+        target: digilib.pin.DebugPinController
+        pins: []
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#

+ 86 - 0
beewatch/config/logging.yaml

@@ -0,0 +1,86 @@
+version: 1
+disable_existing_loggers: False
+formatters:
+    formatter_console:
+        style: "{"
+        format: "({filename}:{lineno:<3}) {name} {levelname} - {message}"
+        # datefmt: "%Y-%m-%d %H:%M:%S"
+    formatter_file:
+        style: "{"
+        format: "{asctime} ({filename}:{lineno}) {name} {levelname} - {message}"
+        datefmt: "%Y-%m-%d %H:%M:%S"
+handlers:
+    chandler:
+        class: logging.StreamHandler
+        level: DEBUG
+        formatter: formatter_console
+        stream: ext://sys.stdout
+    fh_server_chat:
+        class: logging.FileHandler
+        level: DEBUG
+        formatter: formatter_file
+        filename: log/chat_server.log
+    fh_chat:
+        class: logging.FileHandler
+        level: DEBUG
+        formatter: formatter_file
+        filename: log/chat_client.log
+loggers:
+    __main__:
+        level: DEBUG
+        handlers: [chandler]
+        propagate: no
+    beewatch:
+        level: DEBUG
+        handlers: [chandler]
+        propagate: no
+    digilib:
+        level: DEBUG
+        handlers: [chandler]
+        propagate: no
+    digilib.network:
+        handlers: [chandler]
+        propagate: no
+    digilib.network.server.chat:
+        handlers: [chandler]
+        propagate: no
+        # handlers: [chandler,fh_client_chat]
+    digilib.network.client.chat:
+        handlers: [chandler]
+        propagate: no
+        # handlers: [chandler,fh_client_chat]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#

+ 78 - 0
beewatch/config/style.css

@@ -0,0 +1,78 @@
+frame {
+    /*border: 10px;*/
+    margin: 5px;
+    /*padding: 10px;*/
+}
+frame > box {
+    padding: 0 5px 0 5px;
+}
+frame > grid {
+    margin: 5px;
+}
+
+frame > grid {
+    /*background: cyan;*/
+}
+frame > grid > box > label {
+    /*background: red;*/
+}
+valuelabel {
+    /*background-color: yellow;*/
+    /*font-family: dejavu sans book;*/
+    /*font-family: lato light;*/
+    /*font-family: freemono;*/
+    font-family: dejavu serif;
+    /*font-weight: bolder;*/
+}
+#child_overview > frame > grid > label:nth-child(0n+1) {
+    /*background-color: red;*/
+    /*color: blue;*/
+    /*margin: 200px;*/
+    /*align: left;*/
+}
+
+#child_overview > frame > grid column {
+    background-color: yellow;
+
+    /*font-size: 5px;*/
+    /*background-color: red;*/
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/**/

+ 140 - 0
build/lib/beewatch/__init__.py

@@ -0,0 +1,140 @@
+#!/usr/bin/env python3.5
+# Copyright 2017 Digital
+#
+# This file is part of BeeWatch.
+#
+# BeeWatch is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# BeeWatch is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with BeeWatch.  If not, see <http://www.gnu.org/licenses/>.
+#
+"""
+DOCSTRING
+"""
+# Python imports
+import logging
+import logging.handlers
+import sys
+import time
+import traceback
+# Third party imports
+import blinker
+import curio
+
+import digilib.network
+
+# get the loggers
+log = logging.getLogger(__name__+"")
+
+# here are the configured commands and controllers stored
+_controllers = {}
+_commands = {}
+
+def get_example_config_path():
+    print(__file__)
+
+class Configure(object):
+    """
+    Configure BeeWatch from a dict
+
+    This class is inspired by logging.config
+    (https://github.com/python/cpython/blob/3.6/Lib/logging/config.py)
+
+
+    Parameters
+    ----------
+    config: dict
+        dictionary holding config information. for more information see :any:`/config/index`
+    """
+    warnings = True
+
+    def __init__(self,config):
+        super(Configure,self).__init__()
+        self.configure(config)
+
+    def configure(self,config):
+        retconf = {
+            "controllers":{},
+            "commands":{},
+        }
+        # Configure the Controllers first
+        for name,properties in config.get("controllers",{}).items():
+            log.debug("configuring {}".format(name))
+            target = properties.pop("target")
+            if not callable(target):
+                target = self.str_to_callable(target)
+            ctrl = target(**properties)
+            if name in _controllers.keys() and self.warnings:
+                log.warn("overwriting controller "+name)
+            _controllers[name] = ctrl
+            retconf["controllers"][name] = ctrl
+
+        # Next configure the commands
+        for name,properties in config.get("commands",{}).items():
+            log.debug("configuring {}".format(name))
+            function = properties.pop("function")
+            ctrl = properties.pop("controller")
+            if not callable(ctrl):
+                if ctrl not in _controllers.keys():
+                    raise ValueError("No controller found with name " + ctrl)
+            ctrl = _controllers[ctrl]
+            if not hasattr(ctrl,function):
+                raise ValueError(
+                    "{} doesn't have attribute {}".format(ctrl,function))
+            function = getattr(ctrl,function)
+            if name in _commands.keys() and self.warnings:
+                log.warn("overwriting command "+name)
+            _commands[name] = function
+            retconf["commands"][name] = function
+
+    def str_to_callable(self,dotted_str):
+        parts = dotted_str.split(".")
+        next_to_import = parts.pop(0)
+        converted = __import__(next_to_import)
+        for p in parts:
+            next_to_import += "." + p
+            if not hasattr(converted,p):
+                converted = __import__(next_to_import)
+            converted = getattr(converted,p)
+        return converted
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#

+ 80 - 0
build/lib/beewatch/config/commands.yaml

@@ -0,0 +1,80 @@
+commands:
+    eturn:
+        controller: engines_ctrl
+        function: turn
+    estate:
+        controller: engines_ctrl
+        function: set_engine_state
+    espeed:
+        controller: engines_ctrl
+        function: set_engine_speed
+    led_1_on:
+        controller: led_test_1
+        function: "on"
+    led_1_off:
+        controller: led_test_1
+        function: "off"
+    led_2_on:
+        controller: led_test_2
+        function: "on"
+    led_2_off:
+        controller: led_test_2
+        function: "off"
+    dout:
+        controller: debug_ctrl
+        function: output
+    din:
+        controller: debug_ctrl
+        function: input
+    draise:
+        controller: debug_ctrl
+        function: raise_exc
+    daraise:
+        controller: debug_ctrl
+        function: araise_exc
+    set_status_ok:
+        controller: status_led
+        function: green
+    set_status_warn:
+        controller: status_led
+        function: red
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#

+ 46 - 0
build/lib/beewatch/config/controllers.yaml

@@ -0,0 +1,46 @@
+controllers:
+    engines_ctrl:
+        target: digilib.pin.EnginesController
+        left: [4,17]
+        right: [27,22]
+    led_test_1:
+        target: digilib.pin.LED
+        pin: 5
+    led_test_2:
+        target: digilib.pin.LED
+        pin: 6
+    status_led:
+        target: digilib.pin.StatusLED
+        pin_red: 19
+        pin_green: 26
+    debug_ctrl:
+        target: digilib.pin.DebugPinController
+        pins: []
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#

+ 86 - 0
build/lib/beewatch/config/logging.yaml

@@ -0,0 +1,86 @@
+version: 1
+disable_existing_loggers: False
+formatters:
+    formatter_console:
+        style: "{"
+        format: "({filename}:{lineno:<3}) {name} {levelname} - {message}"
+        # datefmt: "%Y-%m-%d %H:%M:%S"
+    formatter_file:
+        style: "{"
+        format: "{asctime} ({filename}:{lineno}) {name} {levelname} - {message}"
+        datefmt: "%Y-%m-%d %H:%M:%S"
+handlers:
+    chandler:
+        class: logging.StreamHandler
+        level: DEBUG
+        formatter: formatter_console
+        stream: ext://sys.stdout
+    fh_server_chat:
+        class: logging.FileHandler
+        level: DEBUG
+        formatter: formatter_file
+        filename: log/chat_server.log
+    fh_chat:
+        class: logging.FileHandler
+        level: DEBUG
+        formatter: formatter_file
+        filename: log/chat_client.log
+loggers:
+    __main__:
+        level: DEBUG
+        handlers: [chandler]
+        propagate: no
+    beewatch:
+        level: DEBUG
+        handlers: [chandler]
+        propagate: no
+    digilib:
+        level: DEBUG
+        handlers: [chandler]
+        propagate: no
+    digilib.network:
+        handlers: [chandler]
+        propagate: no
+    digilib.network.server.chat:
+        handlers: [chandler]
+        propagate: no
+        # handlers: [chandler,fh_client_chat]
+    digilib.network.client.chat:
+        handlers: [chandler]
+        propagate: no
+        # handlers: [chandler,fh_client_chat]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#

+ 78 - 0
build/lib/beewatch/config/style.css

@@ -0,0 +1,78 @@
+frame {
+    /*border: 10px;*/
+    margin: 5px;
+    /*padding: 10px;*/
+}
+frame > box {
+    padding: 0 5px 0 5px;
+}
+frame > grid {
+    margin: 5px;
+}
+
+frame > grid {
+    /*background: cyan;*/
+}
+frame > grid > box > label {
+    /*background: red;*/
+}
+valuelabel {
+    /*background-color: yellow;*/
+    /*font-family: dejavu sans book;*/
+    /*font-family: lato light;*/
+    /*font-family: freemono;*/
+    font-family: dejavu serif;
+    /*font-weight: bolder;*/
+}
+#child_overview > frame > grid > label:nth-child(0n+1) {
+    /*background-color: red;*/
+    /*color: blue;*/
+    /*margin: 200px;*/
+    /*align: left;*/
+}
+
+#child_overview > frame > grid column {
+    background-color: yellow;
+
+    /*font-size: 5px;*/
+    /*background-color: red;*/
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/**/

+ 270 - 0
build/lib/beewatch/gui/__init__.py

@@ -0,0 +1,270 @@
+#!/usr/bin/env python3.5
+# Copyright 2017 Digital
+#
+# This file is part of BeeWatch.
+#
+# BeeWatch is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# BeeWatch is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with BeeWatch.  If not, see <http://www.gnu.org/licenses/>.
+
+import gi
+gi.require_version('Gtk', '3.0')
+from gi.repository import Gtk
+from gi.repository import Gdk
+import logging
+import logging.config
+import os
+import pprint
+import random
+import string
+import sys
+import time
+import yaml
+# My libraries
+import beewatch
+import beewatch.gui
+import digilib.misc
+import digilib.gui
+import digilib.network
+## Logging
+lgui = logging.getLogger(__name__+".gui")
+
+class ChildConsole(digilib.gui.ChildConsole):
+    def __init__(self,get_client=None):
+        super(ChildConsole,self).__init__(get_client)
+        self.text_buffer_log.set_text("program:HAIIII")
+        self.add_msg(digilib.misc.LOREM_IPSUM,"code")
+        self.add_msg(digilib.misc.LOREM_IPSUM,"code")
+        self.add_msg(digilib.misc.LOREM_IPSUM,"code")
+
+
+class ChildOverview(digilib.gui.ChildOverview):
+    def __init__(self):
+        super(ChildOverview,self).__init__()
+        self.prepare()
+    def prepare(self):
+        self.infobox1 = digilib.gui.InfoFrame()
+        self.infobox2 = digilib.gui.InfoFrame()
+        self.make_infobox_controller()
+        self.make_infobox_weight()
+        self.make_infobox_test(self.infobox1)
+        self.make_infobox_test(self.infobox2)
+        self.layout.attach(self.infobox_controller,0,0,1,1)
+        self.layout.attach(self.infobox_weight,    1,0,1,1)
+        self.layout.attach(self.infobox1,          0,1,1,1)
+        self.layout.attach(self.infobox2,          1,1,1,1)
+    def make_infobox_controller(self):
+        levelbar_cpu = Gtk.LevelBar()
+        levelbar_cpu.set_hexpand(True)
+        levelbar_mem = Gtk.LevelBar()
+        levelbar_mem.set_hexpand(True)
+        self.infobox_controller = digilib.gui.InfoFrame(label="Weight")
+        self.infobox_controller.add_line("uptime","Uptime:","99:59:592017-03-06 12:56")
+        self.infobox_controller.add_line("ip","IP:","30.47.10.O9",None)
+        self.infobox_controller.add_line("cpu","CPU:",30,"%",
+            levelbar_cpu,True)
+        self.infobox_controller.add_line("mem","Memory:",0.40,"%",
+            levelbar_mem,True)
+    def make_infobox_weight(self):
+        self.infobox_weight = digilib.gui.InfoFrame(label="Weight")
+        self.infobox_weight.add_line("total","Total:","50 kg")
+        self.infobox_weight.add_line("bees","Bees:","20 kg")
+        self.infobox_weight.add_line("honey","Honey:","42 kg")
+        self.infobox_weight.add_line("time","Time:","2017-03-06 12:56")
+    def make_infobox_test(self,infobox):
+        infobox.add_line("1","Label:","Value")
+        infobox.add_line("2","Baum:","Haus")
+        infobox.add_line("3","Weight:","40 kg")
+        infobox.add_line("4","Wiff","Woff")
+
+class ChildControl(digilib.gui.ChildControl):
+    def __init__(self):
+        super(ChildControl, self).__init__()
+        self.prepare()
+    def prepare(self):
+        pass
+
+class ChildSettings(digilib.gui.ChildSettings):
+    def __init__(self):
+        super(ChildSettings, self).__init__()
+        self.prepare()
+    def prepare(self):
+        pass
+
+class BeeWindow(digilib.gui.WindowBase):
+    def __init__(self,host,port,af_family):
+        super(BeeWindow,self).__init__(title="BeeWatch")
+        self.host = host
+        self.port = port
+        self.af_family = af_family
+        self.client = None
+        self.set_border_width(10)
+        self.tb = digilib.misc.Container()
+        self.prepare()
+        self.add_key_shortcut("Control_L q",self.quit)
+        self.add_key_shortcut("Control_L h e",lgui.info,["hello world"])
+        self.add_key_shortcut("Control_L h i",lgui.info,["hi world"])
+        # self.client = self.make_client()
+    def prepare(self):
+        self.child_console = ChildConsole(self.get_client)
+        self.child_overview = ChildOverview()
+        self.child_control = ChildControl()
+        self.child_settings = ChildSettings()
+        self.child_test = self.make_child_test()
+        self.child_label = self.make_child_label()
+        self.make_toolbar()
+        self.stack = Gtk.Stack()
+        self.stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
+        self.stack.set_transition_duration(750)
+        self.stack.add_titled(self.child_console, "child_console", "Console")
+        self.stack.add_titled(self.child_overview, "child_overview", "Overview")
+        self.stack.add_titled(self.child_control, "child_control", "Control")
+        self.stack.add_titled(self.child_settings, "child_settings", "Settings")
+        self.stack.add_titled(self.child_test, "check", "Check Button")
+        self.stack.add_titled(self.child_label, "label", "A label")
+        self.stack_switcher = Gtk.StackSwitcher()
+        self.stack_switcher.set_stack(self.stack)
+        self.scrolled_switcher = Gtk.ScrolledWindow()
+        self.scrolled_switcher.add(self.stack_switcher)
+        self.vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
+        self.vbox.add(self.tb.toolbar)
+        self.vbox.add(self.scrolled_switcher)
+        self.vbox.add(self.stack)
+        self.add(self.vbox)
+        # self.vbox.pack_start(self.stack_switcher, True, True, 0)
+        # self.vbox.pack_start(self.stack, True, True, 0)
+    def make_toolbar(self):
+        self.tb.toolbar = Gtk.Toolbar()
+        self.tb.img_connect = Gtk.Image(stock=Gtk.STOCK_CONNECT)
+        self.tb.img_connect.set_tooltip_text("Connect")
+        self.tb.bconnect = Gtk.ToolButton()
+        self.tb.bconnect.set_icon_widget(self.tb.img_connect)
+        self.tb.bconnect.connect("clicked",self.on_connect_request)
+        self.tb.img_disconnect = Gtk.Image(stock=Gtk.STOCK_DISCONNECT)
+        self.tb.img_disconnect.set_tooltip_text("Disconnect")
+        self.tb.bdisconnect = Gtk.ToolButton()
+        self.tb.bdisconnect.set_icon_widget(self.tb.img_disconnect)
+        self.tb.bdisconnect.connect("clicked",self.on_disconnect_request)
+        self.tb.img_auto_scroll = Gtk.Image(stock=Gtk.STOCK_GOTO_BOTTOM)
+        self.tb.img_auto_scroll.set_tooltip_text("Toggle auto scrolling")
+        self.tb.bauto_scroll = Gtk.ToolButton()
+        self.tb.bauto_scroll.set_icon_widget(self.tb.img_auto_scroll)
+        self.tb.bauto_scroll.connect(
+            "clicked",self.child_console.toggle_scroll)
+        self.tb.img_scroll_down = Gtk.Image(stock=Gtk.STOCK_GO_DOWN)
+        self.tb.img_scroll_down.set_tooltip_text("Toggle auto scrolling")
+        self.tb.bscroll_down = Gtk.ToolButton()
+        self.tb.bscroll_down.set_icon_widget(self.tb.img_scroll_down)
+        self.tb.bscroll_down.connect(
+            "clicked",self.child_console.scroll_down)
+        self.tb.iconnected = Gtk.ToolItem()
+        self.tb.img_connected = Gtk.Image(stock=Gtk.STOCK_YES)
+        self.tb.iconnected.set_visible_horizontal(False)
+        self.tb.iconnected.set_visible_vertical(False)
+        self.tb.img_connected.set_tooltip_text("Connection Status: Connected")
+        self.tb.idisconnected = Gtk.ToolItem()
+        self.tb.img_disconnected = Gtk.Image(stock=Gtk.STOCK_NO)
+        self.tb.img_disconnected.set_tooltip_text(
+            "Connection Status: Disconnected")
+        self.tb.iconnected.add(self.tb.img_connected)
+        self.tb.idisconnected.add(self.tb.img_disconnected)
+        self.tb.toolbar.add(self.tb.iconnected)
+        self.tb.toolbar.add(self.tb.idisconnected)
+        self.tb.toolbar.add(self.tb.bconnect)
+        self.tb.toolbar.add(self.tb.bdisconnect)
+        self.tb.toolbar.add(self.tb.bauto_scroll)
+        self.tb.toolbar.add(self.tb.bscroll_down)
+    def make_child_test(self):
+        box_test = Gtk.FlowBox()
+        for i in range(0,10):
+            checkbutton = Gtk.CheckButton("Click me!")
+            box_test.add(checkbutton)
+        return box_test
+    def make_child_label(self):
+        grid = Gtk.Grid()
+        label = Gtk.Label()
+        label.set_markup("<big>A fancy label</big>")
+        grid.add(label)
+        return grid
+    def make_client(self):
+        client = digilib.network.Client(
+            host=self.host,
+            port=self.port,
+            af_family=self.af_family,
+            handle_data_func=self.child_console.add_msg_threadsafe,
+        )
+        return client
+    def get_client(self):
+        return self.client
+    def quit(self,*args):
+        lgui.debug("quit")
+        if self.client:
+            self.client.stop()
+            # if self.client.is_connected:
+        Gtk.main_quit()
+    def start(self):
+        self.css_provider = Gtk.CssProvider()
+        self.css_provider.load_from_path("config/style.css")
+        screen = Gdk.Screen.get_default()
+        self.style_context = Gtk.StyleContext()
+        self.style_context.add_provider_for_screen(
+            screen,
+            self.css_provider,
+            Gtk.STYLE_PROVIDER_PRIORITY_USER,
+        )
+        self.show_all()
+        self.stack.set_visible_child(self.child_console)
+        Gdk.threads_init()
+        Gtk.main()
+    def on_connect_request(self,widget):
+        try:
+            lgui.debug("connect request")
+            if self.client == None:
+                self.client = self.make_client()
+            if not self.client.is_running():
+                self.client.start()
+            if not self.client.is_connected:
+                if self.client.connect():
+                    self.tb.iconnected.set_visible_horizontal(True)
+                    self.tb.iconnected.set_visible_vertical(True)
+                    self.tb.idisconnected.set_visible_horizontal(False)
+                    self.tb.idisconnected.set_visible_vertical(False)
+                    lgui.debug("client started")
+                else:
+                    lgui.debug(
+                        "client failed to connect, maybe it is connected")
+        except Exception as e:
+            lgui.error("error trying to connect",exc_info=e)
+    def on_disconnect_request(self,widget):
+        try:
+            lgui.debug("disconnect request")
+            if self.client != None:
+                if self.client.is_connected:
+                    self.client.disconnect()
+                    self.tb.iconnected.set_visible_horizontal(False)
+                    self.tb.iconnected.set_visible_vertical(False)
+                    self.tb.idisconnected.set_visible_horizontal(True)
+                    self.tb.idisconnected.set_visible_vertical(True)
+                    lgui.debug("client disconnected")
+                    return
+            lgui.debug(
+                "client failed to disconnect, maybe it wasn't connected")
+        except Exception as e:
+            lgui.error("error trying to disconnect",exc_info=e)
+    def on_scroll_down_request(self,widget):
+        self.child_console.scroll_down()
+    def on_toggle_scroll_request(self,widget):
+        self.child_console.scroll = not self.child_console.scroll
+    def on_exit_button_press(self,*args):
+        self.destroy()
+        Gtk.main_quit()
+        return True

+ 74 - 0
build/lib/beewatch/pinapi/__init__.py

@@ -0,0 +1,74 @@
+#!/usr/bin/env python3.5
+# Copyright 2017 Digital
+#
+# This file is part of BeeWatch.
+#
+# BeeWatch is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# BeeWatch is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with BeeWatch.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Python Libraries
+import curio
+import logging
+import threading
+import time
+import traceback
+# My Libraries
+import digilib.pin
+log = logging.getLogger(__name__+"")
+lpin = logging.getLogger(__name__+".pin")
+# log = logging.getLogger(__name__+"")
+
+print("*"*20)
+print("USE CURIO WHEN CODING THE PIN STUFF")
+print("this message is printed by {}".format(__file__))
+print("*"*20)
+
+class LoadCell(digilib.pin.PinControllerBase):
+    """interface for a single load cell"""
+    pass
+
+class BeeWeighingScale(digilib.pin.PinAPIBase):
+    """handles all load cells"""
+    pass
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#

+ 174 - 0
build/lib/beewatch/server/__init__.py

@@ -0,0 +1,174 @@
+#! /usr/bin/env python3.5
+# Copyright 2017 Digital
+#
+# This file is part of BeeWatch.
+#
+# BeeWatch is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# BeeWatch is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with BeeWatch.  If not, see <http://www.gnu.org/licenses/>.
+
+import curio
+import blinker
+import logging
+import logging.handlers
+import digilib.network
+import os
+import queue
+import select
+import socket
+import sys
+import threading
+import time
+import traceback
+
+import digilib.pin
+import digilib.network
+import beewatch
+# import beewatch.server
+import beewatch.pinapi
+
+log = logging.getLogger(__name__+"")
+# lapi = logging.getLogger(__name__+".api")
+# lschat = logging.getLogger(__name__+".schat")
+lch = logging.getLogger(__name__+".chandler")
+lserver = logging.getLogger(__name__+".server")
+
+
+class ConnHandlerBeeWatch(digilib.network.ConnHandler):
+    """
+    ConnHandlerBeeWatch is the connection handler for the BeeWatch server.
+
+    It parses commands to api calls.
+
+    Todo
+    ----
+        Implement a permission system
+    """
+    def __init__(self, socket, addr, server):
+        super(ConnHandlerBeeWatch, self).__init__(socket, addr, server)
+
+    async def handle(self, data):
+        """
+        The handle method parses commands and responds if a command was not
+        found. It executes synchronous and asynchronous methods correctly and
+        logs the traceback if an exception occured.
+        """
+        data = data.strip()
+        data = data.split(" ")
+        cmd,*args = data
+        func = beewatch._commands.get(cmd,False)
+        if not func:
+            await self.respond("Unknown command")
+            return
+        kwargs = {"args":args,"command":cmd,"respond":self.respond}
+        task = None
+        try:
+            coro = func(**kwargs)
+            if hasattr(coro,"__await__"):
+                task = await coro
+        except Exception as e:
+            lch.error("api_func raised an error:",exc_info=e)
+            tb = traceback.format_exc()
+            await self.respond(tb,log_msg="traceback of '{}'"
+                .format(e.__cause__))
+        finally:
+            pass
+        if task:
+            lch.debug("exec: "+task.exception.__cause__)
+        # task joins iself to suppress the "task not joined" warning
+        cur_task = await curio.current_task()
+        await curio.ignore_after(0,cur_task.wait)
+
+    async def respond(self,text,*args,log_msg=False):
+        """
+        this method is passed to apis so they can give feedback to the user
+        """
+        await self.send(text,log_msg)
+
+
+class BeeWatchServer(digilib.network.Server):
+    """
+    BeeWatchServer opens a secured connection to the outside world (or a file socket).
+
+    BeeWatchServer inherits from digilib.network.Server. It connects to the gpio control socket and adds protetction by requireing user authentification.
+
+    Warning
+    -------
+        as these features aren't implemented yet, the connection is *not* secure at all
+    Todo
+    ----
+        actually implement these features, right now BeeWatchServer does only debug stuff
+
+    Parameters are identical to `digilib.network.Server` if not specified in the following list:
+
+    Parameters
+    ----------
+        *args:
+            passed to :obj:`digilib.network.Server`
+        handler_class:
+            Same as in `digilib.network.Server` but defaults to :obj:`ConnHandlerBeeWatch`.
+        **kwargs:
+            passed to :obj:`digilib.network.Server`
+    """
+    def __init__(
+            self,
+            *args,
+            handler_class=ConnHandlerBeeWatch,
+            **kwargs
+        ):
+        super(BeeWatchServer, self).__init__(
+            *args,
+            handler_class=handler_class,
+            **kwargs,
+        )
+
+    def make_socket(self) -> socket.socket :
+        s = super(BeeWatchServer,self).make_socket()
+        # only for debugging because I'm impatient and don't want to wait
+        lch.warning("setting sokopt SO_REUSEADDR to 1. DEBUGGING ONLY")
+        s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+        return s
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#

+ 80 - 0
build/lib/config/commands.yaml

@@ -0,0 +1,80 @@
+commands:
+    eturn:
+        controller: engines_ctrl
+        function: turn
+    estate:
+        controller: engines_ctrl
+        function: set_engine_state
+    espeed:
+        controller: engines_ctrl
+        function: set_engine_speed
+    led_1_on:
+        controller: led_test_1
+        function: "on"
+    led_1_off:
+        controller: led_test_1
+        function: "off"
+    led_2_on:
+        controller: led_test_2
+        function: "on"
+    led_2_off:
+        controller: led_test_2
+        function: "off"
+    dout:
+        controller: debug_ctrl
+        function: output
+    din:
+        controller: debug_ctrl
+        function: input
+    draise:
+        controller: debug_ctrl
+        function: raise_exc
+    daraise:
+        controller: debug_ctrl
+        function: araise_exc
+    set_status_ok:
+        controller: status_led
+        function: green
+    set_status_warn:
+        controller: status_led
+        function: red
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#

+ 46 - 0
build/lib/config/controllers.yaml

@@ -0,0 +1,46 @@
+controllers:
+    engines_ctrl:
+        target: digilib.pin.EnginesController
+        left: [4,17]
+        right: [27,22]
+    led_test_1:
+        target: digilib.pin.LED
+        pin: 5
+    led_test_2:
+        target: digilib.pin.LED
+        pin: 6
+    status_led:
+        target: digilib.pin.StatusLED
+        pin_red: 19
+        pin_green: 26
+    debug_ctrl:
+        target: digilib.pin.DebugPinController
+        pins: []
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#

+ 86 - 0
build/lib/config/logging.yaml

@@ -0,0 +1,86 @@
+version: 1
+disable_existing_loggers: False
+formatters:
+    formatter_console:
+        style: "{"
+        format: "({filename}:{lineno:<3}) {name} {levelname} - {message}"
+        # datefmt: "%Y-%m-%d %H:%M:%S"
+    formatter_file:
+        style: "{"
+        format: "{asctime} ({filename}:{lineno}) {name} {levelname} - {message}"
+        datefmt: "%Y-%m-%d %H:%M:%S"
+handlers:
+    chandler:
+        class: logging.StreamHandler
+        level: DEBUG
+        formatter: formatter_console
+        stream: ext://sys.stdout
+    fh_server_chat:
+        class: logging.FileHandler
+        level: DEBUG
+        formatter: formatter_file
+        filename: log/chat_server.log
+    fh_chat:
+        class: logging.FileHandler
+        level: DEBUG
+        formatter: formatter_file
+        filename: log/chat_client.log
+loggers:
+    __main__:
+        level: DEBUG
+        handlers: [chandler]
+        propagate: no
+    beewatch:
+        level: DEBUG
+        handlers: [chandler]
+        propagate: no
+    digilib:
+        level: DEBUG
+        handlers: [chandler]
+        propagate: no
+    digilib.network:
+        handlers: [chandler]
+        propagate: no
+    digilib.network.server.chat:
+        handlers: [chandler]
+        propagate: no
+        # handlers: [chandler,fh_client_chat]
+    digilib.network.client.chat:
+        handlers: [chandler]
+        propagate: no
+        # handlers: [chandler,fh_client_chat]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#

+ 78 - 0
build/lib/config/style.css

@@ -0,0 +1,78 @@
+frame {
+    /*border: 10px;*/
+    margin: 5px;
+    /*padding: 10px;*/
+}
+frame > box {
+    padding: 0 5px 0 5px;
+}
+frame > grid {
+    margin: 5px;
+}
+
+frame > grid {
+    /*background: cyan;*/
+}
+frame > grid > box > label {
+    /*background: red;*/
+}
+valuelabel {
+    /*background-color: yellow;*/
+    /*font-family: dejavu sans book;*/
+    /*font-family: lato light;*/
+    /*font-family: freemono;*/
+    font-family: dejavu serif;
+    /*font-weight: bolder;*/
+}
+#child_overview > frame > grid > label:nth-child(0n+1) {
+    /*background-color: red;*/
+    /*color: blue;*/
+    /*margin: 200px;*/
+    /*align: left;*/
+}
+
+#child_overview > frame > grid column {
+    background-color: yellow;
+
+    /*font-size: 5px;*/
+    /*background-color: red;*/
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/**/

BIN
dist/BeeWatch-0.0.tar.gz


+ 55 - 0
sample/get_example_config_path.py

@@ -0,0 +1,55 @@
+#!/usr/bin/env python3.5
+# Copyright 2017 Digital
+#
+# This file is part of BeeWatch.
+#
+# BeeWatch is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# BeeWatch is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with BeeWatch.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+"""
+This example demonstrates how to get the path to the example config folder. It contains example configurations and is located in the top level of the module.
+"""
+
+# import the beewatch library
+import beewatch
+
+# get the config path and store it in `config_path`
+config_path = beewatch.get_example_config_path()
+
+# lets print the config path!
+print(config_path)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#

+ 81 - 0
setup.py

@@ -0,0 +1,81 @@
+#!/usr/bin/env python3.5
+# Copyright 2017 Digital
+#
+# This file is part of BeeWatch.
+#
+# BeeWatch is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# BeeWatch is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with BeeWatch.  If not, see <http://www.gnu.org/licenses/>.
+
+from distutils.core import setup
+import os
+
+
+# config_files = []
+# for f in os.listdir('config'):
+#     config_files.append('./config/'+f)
+
+setup_kwargs = {
+    'name':'BeeWatch',
+    'version': '0.0',
+    'description':'Beehive analyzer',
+    'author':'Digital',
+    'author_email':'[email protected]',
+    'url':'https://beewatch.readthedocs.io',
+    'packages':[
+        'beewatch',
+        'beewatch.gui',
+        'beewatch.pinapi',
+        'beewatch.server',
+    ],
+    # 'data_files': [
+    #     ('beewatch/config',config_files)
+    # ],
+    'package_data':{
+        'beewatch':['./config/*'],
+    },
+}
+
+setup(**setup_kwargs)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#