def update_labels(self):
        ''' Function takes the RAM database and push it out to file.'''
        ''' All label widgets are updated on the screen. '''

        # Get the process time it takes to update the tags.
        self.start_time = time.clock()

        # Send all current tags to database to be saved.
        DataBase.refresh_tag_database()
        DataBase.set_value('h_datetime', time.strftime("%H:%M"))

        for each_widget in self.builder.get_objects():
            try:
                if type(each_widget) == Gtk.Label:
                    if (each_widget.get_name() in DataBase.tags):
                        tagname = str(each_widget.get_name())
                        value = DataBase.get_value(tagname)
                        each_widget.set_label(str(value))
                        # print(tagname + str(value))

            except:
                print(each_widget.get_name() + str(" not found durring window refresh."))

        # Update all Widget Labels on the HMI.
        # for each_tag in DataBase.tags:
        #     try:
        #         widget = self.builder.get_object(each_tag)
        #         tag = DataBase.get_value(str(each_tag))
        #         widget.set_label(str(tag))
        #     except:
                # pass


        # print(self.window_name + " Tags updated: {:.3f} ms.".format((time.clock() - self.start_time)*1000))
        return True
Beispiel #2
0
    def __init__(self, scale_number, address):
        if (address == 8):
            self.address = 0x08
        elif (address == 9):
            self.address = 0x09
        elif (address == 10):
            self.address = 0x10

        self.scale_number = str(scale_number)
        self.h_scale_address = 'h_scale_' + self.scale_number + '_address'
        DataBase.set_value(self.h_scale_address, address)

        self.h_scale_name = 'h_scale_' + self.scale_number + '_name'
        self.h_scale_style = 'h_scale_' + self.scale_number + '_style'
        self.h_scale_brewdate = 'h_scale_' + self.scale_number + '_brewdate'
        self.h_scale_brewstyle = 'h_scale_' + self.scale_number + '_brewstyle'
        self.h_scale_actual = 'h_scale_' + self.scale_number + '_actual'
        self.h_scale_raw_actual = 'h_scale_' + self.scale_number + '_raw_actual'
        self.h_scale_tare = 'h_scale_' + self.scale_number + '_tare'
        self.h_scale_raw_tare = 'h_scale_' + self.scale_number + '_raw_tare'
        self.h_scale_zero = 'h_scale_' + self.scale_number + '_zero'
        self.h_scale_raw_zero = 'h_scale_' + self.scale_number + '_raw_zero'
        self.h_scale_span = 'h_scale_' + self.scale_number + '_span'
        self.h_scale_raw_span = 'h_scale_' + self.scale_number + '_raw_span'
        self.h_scale_decimal = 'h_scale_' + self.scale_number + '_decimal'

        self.busy = False
        self.update_seconds = 1
        self.start_timers()

        print("Scale " + str(self.scale_number) + " created.")
def new_window(window):

    window_name = window
    path = os.path.join(VIEWS_DIR, 'glade')
    # self.gladefile = self.path + '/' + self.window_name + '.glade'
    gladefile = path + '/' + 'overview.glade'

    # Create a GTK Window Object
    builder = Gtk.Builder()

    # Link all the GTK objects to a glade file.
    builder.add_from_file(gladefile)

    # Create a database of all the glade widgets.
    DataBase.create_widget_database(builder.get_objects())

    # Link window to the windows handler
    builder.connect_signals(eval('OverviewHandler()'))

    # Add css styling from my custom file.
    css = Gtk.CssProvider()
    css.load_from_path(VIEWS_DIR + '/glade/css/custom.css')

    context = Gtk.StyleContext()
    context.add_provider_for_screen(Gdk.Screen.get_default(), css,
                                    Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

    # Get the GTKWindow ID from the glade file and show window.
    window = builder.get_object(window_name)

    window.show_all()
Beispiel #4
0
    def _update_weight(self):
        x = self._get_command(10)

        if (x == False):
            pass

        else:
            DataBase.set_value(self.h_scale_raw_actual, str(x))
            ymin = float(DataBase.get_value(self.h_scale_zero))
            ymax = float(DataBase.get_value(self.h_scale_span))
            xmin = float(DataBase.get_value(self.h_scale_raw_zero))
            xmax = float(DataBase.get_value(self.h_scale_raw_span))

            try:
                m = (ymax - ymin) / (xmax - xmin)

            except:
                m = 0.0

            b = ymin - (m * xmin)
            y = (m * x) + b

            decimal = DataBase.get_value(self.h_scale_decimal)
            result = str(y / pow(10, int(decimal)))
            truncated_result = result[0:(result.find('.') + 1 + int(decimal))]
            DataBase.set_value(self.h_scale_actual, truncated_result)

        if (self.read_scale_timer.get_status() == False):
            print('Scale ' + self.scale_number +
                  ' has timed out, manually reconnect.')
Beispiel #5
0
    def read_switch(self):
        self.busy = True
        try:
            self.pin_state = GPIO.input(self.pin_number)
            #print(GPIO.input(self.pin_number))
        except:
            self.pin_state = 1

        if (self.pin_state == 0):
            DataBase.set_value(self.door_switch_temp, 'open')
        else:
            DataBase.set_value(self.door_switch_temp, 'closed')

        self.busy = False
    def run_compressor(self):
        if self.error_state == False:
            self.busy = True
            temp = DataBase.get_value('h_temperature')

            if (temp == 'Error'):
                DataBase.set_value('h_door_switch', 'STOPPED')
                GPIO.output(self.pin_number, 0)

            else:
                temp = float(temp)

                #try:
                if (temp > 4.0):
                    DataBase.set_value('h_door_switch', 'RUNNING')
                    GPIO.output(self.pin_number, 1)

                elif (temp < 2.0):
                    DataBase.set_value('h_door_switch', 'STOPPED')
                    GPIO.output(self.pin_number, 0)

                else:
                    pass
        else:
            print("Compressor is in error state.")

        self.busy = False
    def read_sensor(self):
        self.busy = True

        try:
            sensor = W1ThermSensor()
            self.new_input = sensor.get_temperature()
            #print(self.new_input)
            self.filtered = (
                (1.0 - self.filter_k) *
                self.filtered_previous) + (self.filter_k * self.new_input)
            self.filtered_previous = self.filtered
            temp = '{0:.1f}'.format(self.filtered)
            DataBase.set_value(self.h_temperature, temp)

        except Exception as e:
            self.read_sensor_timer.error()
            print("Temperature Sensor reading failed. " + str(e) + '.')
            DataBase.set_value(self.h_temperature, 'Error')

        self.busy = False
    def push_letter(self, *args):
        letter = str(self.get_name())

        if letter == "apostorphe":
            letter = "'"
        elif letter == "period":
            letter = "."

        if (DataBase.get_local_value('keyboard_shift_pointer')) == 1:
            letter = letter.capitalize()
            DataBase.set_local_value('keyboard_shift_pointer', 0)
        value = DataBase.get_local_value('keyboard_buffer') + letter
        DataBase.set_local_value('keyboard_buffer', value)

        if letter == "space":
            print('space')
            DataBase.set_local_value('keyboard_shift_pointer', 1)
        buffer_label.set_label(DataBase.get_local_value('keyboard_buffer'))
    def __init__(self, name, handler):
        self.window_name = str(name)
        path = os.path.join(VIEWS_DIR, 'glade')
        gladefile = path + '/' + self.window_name + '.glade'

        # Create a GTK Window Object
        self.builder = Gtk.Builder()

        # Link all the GTK objects to a glade file.
        self.builder.add_from_file(gladefile)

        # Add tags from the current window to the RAM database
        DataBase.create_tag_database(self.builder.get_objects(), self.window_name)

        # Link window to the windows handler.  Requires a function name only.
        # Note that the handler is not fucntion call!
        self.builder.connect_signals(handler)

        # Add css styling from my custom file.
        css = Gtk.CssProvider()
        css.load_from_path(VIEWS_DIR + '/glade/css/custom.css')

        context = Gtk.StyleContext()
        context.add_provider_for_screen(
            Gdk.Screen.get_default(),
            css,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

        # Get the GTKWindow ID from the glade file and show window.
        self.window = self.builder.get_object(self.window_name)

        # Immediatly updates all the labels from the Tag Database.
        self.update_labels()

        # Add a Label Update using the built in GObject Thread.
        GObject.timeout_add(1000, self.update_labels)

        # Show the window.make
        self.window.show_all()
    def __init__(self, tagname):
        print("Creating Keyboard Window...")
        Window.__init__(self, 'keyboard', KeyboardHandler)

        # Create a global variable...not sure handlers can't inherit builder.
        global buffer_label
        buffer_label = self.builder.get_object('l_buffer')

        # Create the local buffer but, leave it blank.
        DataBase.set_local_value('keyboard_buffer', '')

        # Set the label to show the current tag value.
        buffer_label.set_label(DataBase.get_value(tagname.get_name()))

        DataBase.set_local_value('keyboard_shift_pointer', 1)
        DataBase.set_local_value('keyboard_variable', tagname.get_name())
 def push_space(self, *args):
     value = DataBase.get_local_value('keyboard_buffer') + " "
     DataBase.set_local_value('keyboard_buffer', value)
     DataBase.set_local_value('keyboard_shift_pointer', 1)
     buffer_label.set_label(DataBase.get_local_value('keyboard_buffer'))
 def enable_shift(self, *args):
     DataBase.set_local_value('keyboard_shift_pointer', 1)
 def push_enter(self, *args):
     DataBase.set_value(DataBase.get_local_value('keyboard_variable'),
         DataBase.get_local_value('keyboard_buffer'))
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib
from views.admin import RunViewServer
from database.admin import DataBase
from hardware.admin import Hardware

if __name__ == '__main__':
    DataBase()
    hardware = Hardware()
    RunViewServer()
    hardware.stop_services()
 def push_clear(self, *args):
     DataBase.set_local_value('keyboard_buffer', "")
     DataBase.set_local_value('keyboard_shift_pointer', 1)
     buffer_label.set_label(DataBase.get_local_value('keyboard_buffer'))
 def delete_letter(self, *args):
     value = DataBase.get_local_value('keyboard_buffer')
     if len(value) >= 1:
         value = value[:-1]
         DataBase.set_local_value('keyboard_buffer', value)
     buffer_label.set_label(DataBase.get_local_value('keyboard_buffer'))
def create_window():
    new_window('overview')
    DataBase.create_tag_database()
    Gtk.main()