예제 #1
0
    def __init__(self):
        Gtk.Window.__init__(self, title="SwDiag")
        self.set_border_width(10)
        self.set_default_size(600, 800)

        self.rake = HayRotaryRake()
        self.degrees_of_freedom = []
        self.outputs = {}
        self.inputs = {}

        self.box = Gtk.Box(spacing=6)
        self.add(self.box)

        self.drawing_area = Gtk.DrawingArea()
        self.drawing_area.set_size_request(800, 400)
        self.drawing_area.connect('draw', drawSimulation, self.inputs)

        try:
            self.conn = Connector("/dev/ttyACM{i}", 9600)
            self.conn.register_input_observer(self)
            self.conn.register_log_observer(self)
            self.conn.register_output_observer(self)

            integer_id = GObject.timeout_add(50, self.read)

            GObject.timeout_add(10000, self.activate)
        except Exception as e:
            print(e)

        #self.set_geometry_hints(self.scroll_txt_log,-1,-1)
        self.show_all()
예제 #2
0
    def __init__(self):
        Gtk.Window.__init__(self, title="SwDiag")
        self.set_border_width(10)
        self.set_default_size(600, 800)

        self.rake = HayRotaryRake()
        self.degrees_of_freedom = []
        self.outputs = {}
        self.inputs = {}

        self.box = Gtk.Box(spacing=6)
        self.add(self.box)

        self.drawing_area = Gtk.DrawingArea()
        self.drawing_area.set_size_request(800, 400)
        self.drawing_area.connect('draw', drawSimulation, self.inputs)

        try:
            self.conn = Connector("/dev/ttyACM{i}", 9600)
            self.conn.register_input_observer(self)
            self.conn.register_log_observer(self)
            self.conn.register_output_observer(self)

            integer_id = GObject.timeout_add(50, self.read)

            GObject.timeout_add(10000, self.activate)
        except Exception as e:
            print(e)

        #self.set_geometry_hints(self.scroll_txt_log,-1,-1)
        self.show_all()
예제 #3
0
    def __init__(self):
        # theme stuff
        self.root = Tk()
        self.root.title("SwDiag")

        self.style = ttk.Style()
        self.style.theme_use('clam')

        self.buildMainWindow()
        self.buildSimulateInput()

        self.conn = None
        #try:
        i = 0
        done = False
        while done == False and i < 15:
            try:
                port = '/dev/ttyACM' + str(i)
                self.conn = Connector(port, 9600)  #read from config
                done = True
                print("/dev/ttyACM" + str(i))
                self.log_txt.insert(
                    "1.0", "SUCCESS opening serial port: " + port + "\n")
            except:
                self.log_txt.insert(
                    "1.0", "Error opening serial port: " + port + "\n")
                i += 1

        self.conn.register_input_observer(self)
        self.conn.register_log_observer(self)
        self.conn.register_output_observer(self)

        self.conn.request_log_active(True)
        self.conn.request_input_listener_active(True)
        self.conn.request_output_listener_active(True)
        self.conn.request_all_input_values()
        self.conn.request_all_output_values()
        #except:
        #    self.log_txt.insert("1.0","Error opening serial port: "+'/dev/ttyACM0'+"\n")

        self.timer()
        self.root.mainloop()
def upload_to_gcs(serviceAccountFileName,file_path,bucket_name,make_blob_public=False,remove_local_file=True):
    
    
    storage_client = Connector().connect_to_gcs(serviceAccountFileName)
    bucket = storage_client.get_bucket(bucket_name)

    blob = bucket.blob(file_path.parts[-1])
    blob.upload_from_filename(str(file_path))
    print(str(file_path))
    if make_blob_public:
        blob.make_public()
    
    file_name=file_path.parts[-1]

    
    print('File {0} uploaded to google cloud storage bucket {1} \n'.format(file_name,bucket_name))
    
    if remove_local_file:
        from os import remove
        remove(str(file_path))
    
    return 'gs://'+bucket_name+'/'+file_name
예제 #5
0
    def __init__(self):
        # theme stuff
        self.root = Tk()
        self.root.title("SwDiag")

        self.style = ttk.Style()
        self.style.theme_use('clam')

        self.buildMainWindow()
        self.buildSimulateInput()

        self.conn = None
        #try:
        i = 0;
        done = False
        while done == False and i < 15:
            try:
                port = '/dev/ttyACM' + str(i)
                self.conn = Connector(port, 9600)  #read from config
                done = True
                print("/dev/ttyACM" + str(i))
                self.log_txt.insert("1.0", "SUCCESS opening serial port: " + port + "\n")
            except:
                self.log_txt.insert("1.0", "Error opening serial port: " + port + "\n")
                i += 1

        self.conn.register_input_observer(self)
        self.conn.register_log_observer(self)
        self.conn.register_output_observer(self)

        self.conn.request_log_active(True)
        self.conn.request_input_listener_active(True)
        self.conn.request_output_listener_active(True)
        self.conn.request_all_input_values()
        self.conn.request_all_output_values()
        #except:
        #    self.log_txt.insert("1.0","Error opening serial port: "+'/dev/ttyACM0'+"\n")

        self.timer()
        self.root.mainloop()
def transfer_to_gbq(serviceAccountFileName,dataset_id,gs_uri,table_id,source_format,autodetect,partitioning_field_name):
    
    bigquery_client=Connector().connect_to_gbq(serviceAccountFileName)
    dataset_ref = bigquery_client.dataset(dataset_id)
    table_ref = dataset_ref.table(table_id)
    job_config = bigquery.LoadJobConfig()
    if autodetect:
        job_config.autodetect = autodetect
        num_rows_before=0
    else:
        table=bigquery_client.get_table(table_ref)
        num_rows_before=table.num_rows
        job_config.schema=table.schema
        if source_format=='CSV':
            job_config.skip_leading_rows=1
    if partitioning_field_name:
        job_config.time_partitioning = bigquery.TimePartitioning(
                type_=bigquery.TimePartitioningType.DAY,
                field=partitioning_field_name)  # name of column to use for partitioning)
    
    job_config.source_format = source_format
    uri = gs_uri
    
    load_job = bigquery_client.load_table_from_uri(
        uri,
        dataset_ref.table(table_id),
        location='EU',  # Location must match that of the destination dataset.
        job_config=job_config)  # API request
    
        
    print('Starting job {} .'.format(load_job.job_id))
    load_job.result()  # Waits for table load to complete.
    print('Job finished. ')
    destination_table = bigquery_client.get_table(dataset_ref.table(table_id))
    num_rows_after=destination_table.num_rows
    print('Loaded {} rows.\n'.format(num_rows_after-num_rows_before))
예제 #7
0
class FlowBoxWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="SwDiag")
        self.set_border_width(10)
        self.set_default_size(600, 800)

        self.rake = HayRotaryRake()
        self.degrees_of_freedom = []
        self.outputs = {}
        self.inputs = {}

        self.box = Gtk.Box(spacing=6)
        self.add(self.box)

        self.drawing_area = Gtk.DrawingArea()
        self.drawing_area.set_size_request(800, 400)
        self.drawing_area.connect('draw', drawSimulation, self.inputs)

        try:
            self.conn = Connector("/dev/ttyACM{i}", 9600)
            self.conn.register_input_observer(self)
            self.conn.register_log_observer(self)
            self.conn.register_output_observer(self)

            integer_id = GObject.timeout_add(50, self.read)

            GObject.timeout_add(10000, self.activate)
        except Exception as e:
            print(e)

        #self.set_geometry_hints(self.scroll_txt_log,-1,-1)
        self.show_all()

    def read(self):
        self.conn.read_frames()
        return True

    def activate(self):

        self.conn.request_log_active(True)
        self.conn.request_input_listener_active(True)
        self.conn.request_output_listener_active(True)

        self.conn.request_all_input_values()
        self.conn.request_simulate_manual_input_mode(True)
        self.conn.request_simulate_sensor_input_mode(True)
        self.conn.request_simulate_output_mode(True)

        self.conn.request_all_output_values()
        self.conn.request_all_input_values()

        integer_id = GObject.timeout_add(100, self.tick)
        return False

    def tick(self):

        self.conn.read_frames()
        simulated_active_sensors, self.degrees_of_freedom = self.rake.tick(
            self.outputs)
        for input_name, value in self.inputs.items():
            if input_name.startswith("SENS_"):
                if input_name in simulated_active_sensors and value == 0:
                    self.conn.simulate_sensor_input(
                        config.get_input_id(input_name), 1)
                elif input_name not in simulated_active_sensors and value == 1:
                    self.conn.simulate_sensor_input(
                        config.get_input_id(input_name), 0)
        time.sleep(0.05)
        self.conn.read_frames()

        # start redraw
        self.drawing_area.queue_draw()
        return True

    def on_output(self, output_id, value):
        name = config.get_output_name(output_id)
        self.outputs[name] = value
        print(
            str(time.time()) + ": <Output> " + name + " id: " +
            str(output_id) + " value: " + str(value))

    def on_input(self, input_id, value):
        name = config.get_input_name(input_id)
        self.inputs[name] = value
        print(
            str(time.time()) + ": <Input> " + name + " id: " + str(input_id) +
            " value: " + str(value))

    def on_log(self, input_type, input_id, value, additional_info):
        type_name = config.get_type_name(input_type)

        print(
            str(time.time()) + ": <Event> type: " + type_name + "(" +
            str(input_type) + ") id: " + str(input_id) + " value: " +
            str(value) + " additional_info: " + str(additional_info))
예제 #8
0
class FlowBoxWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="SwDiag")
        self.set_border_width(10)
        self.set_default_size(600, 800)

        self.rake = HayRotaryRake()
        self.degrees_of_freedom = []
        self.outputs = {}
        self.inputs = {}

        self.box = Gtk.Box(spacing=6)
        self.add(self.box)

        self.drawing_area = Gtk.DrawingArea()
        self.drawing_area.set_size_request(800, 400)
        self.drawing_area.connect('draw', drawSimulation, self.inputs)

        try:
            self.conn = Connector("/dev/ttyACM{i}", 9600)
            self.conn.register_input_observer(self)
            self.conn.register_log_observer(self)
            self.conn.register_output_observer(self)

            integer_id = GObject.timeout_add(50, self.read)

            GObject.timeout_add(10000, self.activate)
        except Exception as e:
            print(e)

        #self.set_geometry_hints(self.scroll_txt_log,-1,-1)
        self.show_all()

    def read(self):
        self.conn.read_frames()
        return True

    def activate(self):

        self.conn.request_log_active(True)
        self.conn.request_input_listener_active(True)
        self.conn.request_output_listener_active(True)

        self.conn.request_all_input_values()
        self.conn.request_simulate_manual_input_mode(True)
        self.conn.request_simulate_sensor_input_mode(True)
        self.conn.request_simulate_output_mode(True)

        self.conn.request_all_output_values()
        self.conn.request_all_input_values()

        integer_id = GObject.timeout_add(100, self.tick)
        return False

    def tick(self):

        self.conn.read_frames()
        simulated_active_sensors, self.degrees_of_freedom = self.rake.tick(self.outputs)
        for input_name, value in self.inputs.items():
            if input_name.startswith("SENS_"):
                if input_name in simulated_active_sensors and value == 0:
                    self.conn.simulate_sensor_input(config.get_input_id(input_name), 1)
                elif input_name not in simulated_active_sensors and value == 1:
                    self.conn.simulate_sensor_input(config.get_input_id(input_name), 0)
        time.sleep(0.05)
        self.conn.read_frames()

        # start redraw
        self.drawing_area.queue_draw()
        return True

    def on_output(self, output_id, value):
        name = config.get_output_name(output_id)
        self.outputs[name] = value
        print(str(time.time())+": <Output> "+name+" id: " + str(output_id) + " value: " + str(value))

    def on_input(self, input_id, value):
        name = config.get_input_name(input_id)
        self.inputs[name] = value
        print(str(time.time())+": <Input> "+name+" id: " + str(input_id) + " value: " + str(value))

    def on_log(self, input_type, input_id, value, additional_info):
        type_name = config.get_type_name(input_type)

        print(str(time.time())+": <Event> type: "+type_name+"(" + str(input_type) + ") id: " + str(input_id) + " value: " + str(
            value) + " additional_info: " + str(additional_info))
예제 #9
0
파일: test.py 프로젝트: cbasix/GearRakeDiag
    def setUp(self):
        global connector
        if connector is None:
            connector = Connector()
            time.sleep(5)
            connector.request_simulate_manual_input_mode(True)
            connector.request_simulate_sensor_input_mode(True)
            connector.request_simulate_output_mode(True)
            time.sleep(3)
            connector.request_log_active(True)
            connector.request_input_listener_active(True)
            connector.request_output_listener_active(True)

        self.connector = connector  # Connector()

        self.connector.request_simulate_manual_input_mode(True)
        self.connector.request_simulate_sensor_input_mode(True)
        self.connector.request_simulate_output_mode(True)

        time.sleep(0.5)
        self.connector.clear()

        self.connector.register_input_observer(self)
        self.connector.register_output_observer(self)
        self.connector.register_log_observer(self)
예제 #10
0
class Gui:
    def __init__(self):
        # theme stuff
        self.root = Tk()
        self.root.title("SwDiag")

        self.style = ttk.Style()
        self.style.theme_use('clam')

        self.buildMainWindow()
        self.buildSimulateInput()

        self.conn = None
        #try:
        i = 0
        done = False
        while done == False and i < 15:
            try:
                port = '/dev/ttyACM' + str(i)
                self.conn = Connector(port, 9600)  #read from config
                done = True
                print("/dev/ttyACM" + str(i))
                self.log_txt.insert(
                    "1.0", "SUCCESS opening serial port: " + port + "\n")
            except:
                self.log_txt.insert(
                    "1.0", "Error opening serial port: " + port + "\n")
                i += 1

        self.conn.register_input_observer(self)
        self.conn.register_log_observer(self)
        self.conn.register_output_observer(self)

        self.conn.request_log_active(True)
        self.conn.request_input_listener_active(True)
        self.conn.request_output_listener_active(True)
        self.conn.request_all_input_values()
        self.conn.request_all_output_values()
        #except:
        #    self.log_txt.insert("1.0","Error opening serial port: "+'/dev/ttyACM0'+"\n")

        self.timer()
        self.root.mainloop()

    def buildMainWindow(self):
        # init up-down panned window
        self.frameset_ud = ttk.PanedWindow(self.root)
        self.frameset_lr = ttk.PanedWindow(self.frameset_ud, orient=HORIZONTAL)

        self.in_out = Frame(self.frameset_ud, width=20)
        #self.in_out_scroll = ttk.Scrollbar( self.frameset_ud, orient=VERTICAL, command=self.in_out_list.yview)
        self.tabbed = ttk.Notebook(self.frameset_ud, height=600, width=800)

        #self.frm_log = ttk.Frame(self.frameset_ud)
        self.log_txt = Text(self.frameset_ud, height=10)
        #self.log_scroll = ttk.Scrollbar( self.frameset_ud, orient=VERTICAL, command=self.log_txt.yview)

        #adding them together
        self.frameset_ud.pack(fill=BOTH, expand=1)
        self.frameset_ud.add(self.frameset_lr, weight=100)
        self.frameset_ud.add(self.log_txt, weight=10)

        self.frameset_lr.add(self.tabbed, weight=100)
        self.frameset_lr.add(self.in_out, weight=10)
        #self.in_out_list. state["disabled"]

        #self.in_out_list['yscrollcommand'] = self.in_out_scroll.set
        #self.log_txt['yscrollcommand'] = self.log_scroll.set

        self.frm_inputs = ttk.Frame(
            self.tabbed, padding="3 3 12 12"
        )  # first page, which would get widgets gridded into it
        self.frm_settings = ttk.Frame(self.tabbed)  # second page
        self.frm_errors = ttk.Frame(self.tabbed)
        self.tabbed.add(self.frm_inputs,
                        text='Eingabesimulation',
                        sticky=N + E + S + W)
        self.tabbed.add(self.frm_settings, text='Einstellungen')
        self.tabbed.add(self.frm_errors, text='Fehler')

        self.log_txt.insert("1.0", "Hallo und Willkommen\n")
        self.log_txt.tag_configure('output', foreground="blue")
        self.log_txt.tag_configure('input', foreground="green")
        self.log_txt.tag_configure('log', foreground="grey")

        #self.hi_there = Button(self.frameset_ud, text="Hello")
        #self.frameset_ud.add(self.hi_there)

        #in_out bar on right side

        #listbox.configure(yscrollcommand=s.set)

        #self.frameset_ud.add(self.button)

        #in_out bar on right side
        #self.frameset_ud.add()

    def timer(self):
        self.readSerial()

        self.root.after(200, self.timer)

    def readSerial(self):
        if (self.conn):
            self.conn.read_frames()

    def on_output(self, output_id, value):
        self.log_txt.insert(
            "1.0",
            "<Output> id: " + str(output_id) + " value: " + str(value) + "\n",
            ('output'))

        existing_slaves = self.in_out.grid_slaves(row=output_id, column=0)
        if (len(existing_slaves) == 1):
            existing_slaves[0]["text"] = "OUT id: " + str(
                output_id) + " value: " + str(value)
        else:
            Label(self.in_out,
                  text="OUT id: " + str(output_id) + " value: " +
                  str(value)).grid(row=output_id, column=0)

    def on_input(self, input_id, value):
        self.log_txt.insert(
            "1.0",
            "<Input> id: " + str(input_id) + " value: " + str(value) + "\n",
            ('input'))

        existing_slaves = self.in_out.grid_slaves(row=input_id, column=1)
        if (len(existing_slaves) == 1):
            existing_slaves[0]["text"] = "IN id: " + str(
                input_id) + " value: " + str(value)
        else:
            Label(self.in_out,
                  text="IN id: " + str(input_id) + " value: " +
                  str(value)).grid(row=input_id, column=1)

    def on_log(self, input_type, input_id, value, additional_info):
        self.log_txt.insert(
            "1.0", " <Event> type: " + str(input_type) + " id: " +
            str(input_id) + " value: " + str(value) + " additional_info: " +
            str(additional_info) + "\n", ('log'))

    def buildSimulateInput(self):
        c = 5
        r = len(config["input"]) * 2 // 5

        cCol = 0
        cRow = 0
        for input_ in config["input"]:
            ttk.Button(self.frm_inputs,
                       text=input_["name"] + " ON",
                       command=lambda inid=input_["id"]: self.simulate_input(
                           inid, 1)).grid(column=cCol,
                                          row=cRow,
                                          ipady=3,
                                          ipadx=3,
                                          pady=3,
                                          padx=3,
                                          sticky=W + E)
            ttk.Button(self.frm_inputs,
                       text=input_["name"] + " OFF",
                       command=lambda inid=input_["id"]: self.simulate_input(
                           inid, 0)).grid(column=cCol,
                                          row=cRow + 1,
                                          ipady=3,
                                          ipadx=3,
                                          pady=3,
                                          padx=3,
                                          sticky=W + E)
            cCol += 1
            if cCol >= c:
                cCol = 0
                cRow += 2

    def simulate_input(self, input_id, value):
        self.conn.simulate_manual_input(input_id, value)
예제 #11
0
    def setUp(self):
        global connector
        if connector is None:
            connector = Connector()
            time.sleep(5)
            connector.request_simulate_manual_input_mode(True)
            connector.request_simulate_sensor_input_mode(True)
            connector.request_simulate_output_mode(True)
            time.sleep(3)
            connector.request_log_active(True)
            connector.request_input_listener_active(True)
            connector.request_output_listener_active(True)

        self.connector = connector  # Connector()

        self.connector.request_simulate_manual_input_mode(True)
        self.connector.request_simulate_sensor_input_mode(True)
        self.connector.request_simulate_output_mode(True)

        time.sleep(0.5)
        self.connector.clear()

        self.connector.register_input_observer(self)
        self.connector.register_output_observer(self)
        self.connector.register_log_observer(self)
예제 #12
0
class FlowBoxWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="SwDiag")
        self.set_border_width(10)
        self.set_default_size(600, 800)
        self.inputs = [None for i in config["input"]]

        #self.grd_main = Gtk.Grid()
        #print(dir(self.grd_main))#.set_weight(1)
        #self.add(self.grd_main)

        notebook = Gtk.Notebook()
        self.add(notebook)
        # self.grd_main.attach(notebook, 0, 0, 18, 2)

        #header = Gtk.HeaderBar(title="Flow Box")
        #header.set_subtitle("Sample FlowBox app")
        #header.props.show_close_button = True

        #self.set_titlebar(header)

        # graphical views
        scroll_sensors = Gtk.ScrolledWindow()
        scroll_sensors.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        scroll_sensors.set_hexpand(True)
        scroll_sensors.set_vexpand(True)

        self.flow_sensors = Gtk.FlowBox()
        self.flow_sensors.set_valign(Gtk.Align.START)
        self.flow_sensors.set_max_children_per_line(2)
        self.flow_sensors.set_selection_mode(Gtk.SelectionMode.NONE)

        # draw top
        self.drawing_area = Gtk.DrawingArea()
        self.drawing_area.set_size_request(350, 350)
        self.drawing_area.connect('draw', drawTop, self.inputs)
        # button.connect("toggled", self.on_button_toggled, input_["id"])
        self.flow_sensors.add(self.drawing_area)

        #draw front
        self.drawing_area2 = Gtk.DrawingArea()
        self.drawing_area2.set_size_request(350, 350)
        self.drawing_area2.connect('draw', drawFront, self.inputs)
        # button.connect("toggled", self.on_button_toggled, input_["id"])
        self.flow_sensors.add(self.drawing_area2)

        #draw side
        self.drawing_area3 = Gtk.DrawingArea()
        self.drawing_area3.set_size_request(350, 350)
        self.drawing_area3.connect('draw', drawSide, self.inputs)
        # button.connect("toggled", self.on_button_toggled, input_["id"])
        self.flow_sensors.add(self.drawing_area3)

        # draw input
        self.drawing_area4 = Gtk.DrawingArea()
        self.drawing_area4.set_size_request(350, 350)
        self.drawing_area4.connect('draw', drawInput, self.inputs)
        # button.connect("toggled", self.on_button_toggled, input_["id"])
        self.flow_sensors.add(self.drawing_area4)


        scroll_sensors.add(self.flow_sensors)

        lbl_sim_input = Gtk.Label("Sensoren")
        notebook.append_page(scroll_sensors, lbl_sim_input)

        #Simulate input
        scroll_sim_input = Gtk.ScrolledWindow()
        scroll_sim_input.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        scroll_sim_input.set_hexpand(True)
        scroll_sim_input.set_vexpand(True)

        self.flow_sim_input = Gtk.FlowBox()
        self.flow_sim_input.set_valign(Gtk.Align.START)
        self.flow_sim_input.set_max_children_per_line(20)
        self.flow_sim_input.set_selection_mode(Gtk.SelectionMode.NONE)

        self.create_flow_sim_input(self.flow_sim_input)
        scroll_sim_input.add(self.flow_sim_input)

        #lbl_sim_input = Gtk.Label("Eingabesimulation")
        #notebook.append_page(scroll_sim_input, lbl_sim_input)

        self.create_txt_log()
        lbl_log = Gtk.Label("Log")
        notebook.append_page(self.scroll_txt_log, lbl_log)

        try:
            self.conn = Connector("/dev/ttyACM{i}", 9600)
            self.conn.register_input_observer(self)
            self.conn.register_log_observer(self)
            self.conn.register_output_observer(self)

            integer_id = GObject.timeout_add(200, self.read)
            GObject.timeout_add(10000, self.activate)
        except Exception as e:
            print(e)

        #self.set_geometry_hints(self.scroll_txt_log,-1,-1)
        self.show_all()

    def read(self):
        self.conn.read_frames()
        return True

    def activate(self):

        self.conn.request_log_active(True)
        self.conn.request_input_listener_active(True)
        self.conn.request_output_listener_active(True)

        self.conn.request_all_input_values()
        self.conn.request_simulate_manual_input_mode(False)
        self.conn.request_simulate_sensor_input_mode(False)
        self.conn.request_simulate_output_mode(False)

        self.conn.request_all_output_values()
        self.conn.request_all_input_values()

        return False

    def create_txt_log(self):
        self.scroll_txt_log = Gtk.ScrolledWindow()
        self.scroll_txt_log.set_hexpand(True)
        self.scroll_txt_log.set_vexpand(True)

        #self.scroll_txt_log.set_size_request(-1, 50)
        #self.grid.attach(scroll_txt_log, 0, 1, 3, 1)
        #parent.attach(self.scroll_txt_log, 0, 19, 25, 2)

        self.txt_log = Gtk.TextView()
        self.txt_log.set_editable(False)
        self.scroll_txt_log.add(self.txt_log)

        self.txt_log_buf = self.txt_log.get_buffer()
        self.txt_log_buf.set_text("Hallo und Wilkommen")


        self.tag_bold = self.txt_log_buf.create_tag("bold", weight=Pango.Weight.BOLD)
        self.tag_italic = self.txt_log_buf.create_tag("italic", style=Pango.Style.ITALIC)
        self.tag_underline = self.txt_log_buf.create_tag("underline", underline=Pango.Underline.SINGLE)
        self.tag_found = self.txt_log_buf.create_tag("found", background="yellow")

        self.tag_input = self.txt_log_buf.create_tag("input", foreground="green")
        self.tag_output = self.txt_log_buf.create_tag("output", foreground="blue")
        self.tag_error = self.txt_log_buf.create_tag("error", background="yellow")


    def txt_log_add(self, text, tag=None):
        begin_iter = self.txt_log_buf.get_start_iter()
        self.txt_log_buf.insert(begin_iter, text)
        end_iter = self.txt_log_buf.get_start_iter()
        self.txt_log_buf.apply_tag(tag, begin_iter, end_iter)


    def create_flow_sim_input(self, flowbox, manual=True):
        for input_ in config["input"]:
            if manual and input_["name"].startswith("IN_") or not manual and input_["name"].startswith("SENS_"):
                button = Gtk.ToggleButton(input_["description"])
                button.connect("toggled", self.on_button_toggled, input_["id"])

                flowbox.add(button)

    def on_button_toggled(self, button, input_id):
        if button.get_active():
            state = 1
        else:
            state = 0
        # manual and sensor inputs are using the same id set so it doesnt matter which simulate method is called
        self.conn.simulate_manual_input(input_id, state)
        print("Input (", input_id, ") was turned", state, "\n")

    def on_output(self, output_id, value):
        name = get_output_name(output_id)
        self.txt_log_add("<Output> "+name+" id: " + str(output_id) + " value: " + str(value) + "\n", self.tag_output)

        # existing_slaves = self.in_out.grid_slaves(row=output_id, column=0)
        # if(len(existing_slaves) ==  1):
        #     existing_slaves[0]["text"]="OUT id: " + str(output_id) + " value: " + str(value)
        # else:
        #     Label(self.in_out, text="OUT id: " + str(output_id) + " value: " + str(value)).grid(row=output_id, column=0)

    def on_input(self, input_id, value):
        self.inputs[input_id] = value
        self.flow_sensors.queue_draw()
        try:
            name = get_input_name(input_id)
        except Exception:
            name = "NoNameDefined"
        self.txt_log_add("<Input> "+name+" id: " + str(input_id) + " value: " + str(value) + "\n", self.tag_input)

        # existing_slaves = self.in_out.grid_slaves(row=input_id, column=1)
        # if(len(existing_slaves) ==  1):
        #     existing_slaves[0]["text"]="IN id: " + str(input_id) + " value: " + str(value)
        # else:
        #     Label(self.in_out, text="IN id: " + str(input_id) + " value: " + str(value)).grid(row=input_id, column=1)


    def on_log(self, input_type, input_id, value, additional_info):
        type_name = get_type_name(input_type)

        self.txt_log_add(" <Event> type: "+type_name+"(" + str(input_type) + ") id: " + str(input_id) + " value: " + str(
            value) + " additional_info: " + str(additional_info) + "\n", self.tag_italic)
예제 #13
0
    def __init__(self):
        Gtk.Window.__init__(self, title="SwDiag")
        self.set_border_width(10)
        self.set_default_size(600, 800)
        self.inputs = [None for i in config["input"]]

        #self.grd_main = Gtk.Grid()
        #print(dir(self.grd_main))#.set_weight(1)
        #self.add(self.grd_main)

        notebook = Gtk.Notebook()
        self.add(notebook)
        # self.grd_main.attach(notebook, 0, 0, 18, 2)

        #header = Gtk.HeaderBar(title="Flow Box")
        #header.set_subtitle("Sample FlowBox app")
        #header.props.show_close_button = True

        #self.set_titlebar(header)

        # graphical views
        scroll_sensors = Gtk.ScrolledWindow()
        scroll_sensors.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        scroll_sensors.set_hexpand(True)
        scroll_sensors.set_vexpand(True)

        self.flow_sensors = Gtk.FlowBox()
        self.flow_sensors.set_valign(Gtk.Align.START)
        self.flow_sensors.set_max_children_per_line(2)
        self.flow_sensors.set_selection_mode(Gtk.SelectionMode.NONE)

        # draw top
        self.drawing_area = Gtk.DrawingArea()
        self.drawing_area.set_size_request(350, 350)
        self.drawing_area.connect('draw', drawTop, self.inputs)
        # button.connect("toggled", self.on_button_toggled, input_["id"])
        self.flow_sensors.add(self.drawing_area)

        #draw front
        self.drawing_area2 = Gtk.DrawingArea()
        self.drawing_area2.set_size_request(350, 350)
        self.drawing_area2.connect('draw', drawFront, self.inputs)
        # button.connect("toggled", self.on_button_toggled, input_["id"])
        self.flow_sensors.add(self.drawing_area2)

        #draw side
        self.drawing_area3 = Gtk.DrawingArea()
        self.drawing_area3.set_size_request(350, 350)
        self.drawing_area3.connect('draw', drawSide, self.inputs)
        # button.connect("toggled", self.on_button_toggled, input_["id"])
        self.flow_sensors.add(self.drawing_area3)

        # draw input
        self.drawing_area4 = Gtk.DrawingArea()
        self.drawing_area4.set_size_request(350, 350)
        self.drawing_area4.connect('draw', drawInput, self.inputs)
        # button.connect("toggled", self.on_button_toggled, input_["id"])
        self.flow_sensors.add(self.drawing_area4)


        scroll_sensors.add(self.flow_sensors)

        lbl_sim_input = Gtk.Label("Sensoren")
        notebook.append_page(scroll_sensors, lbl_sim_input)

        #Simulate input
        scroll_sim_input = Gtk.ScrolledWindow()
        scroll_sim_input.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        scroll_sim_input.set_hexpand(True)
        scroll_sim_input.set_vexpand(True)

        self.flow_sim_input = Gtk.FlowBox()
        self.flow_sim_input.set_valign(Gtk.Align.START)
        self.flow_sim_input.set_max_children_per_line(20)
        self.flow_sim_input.set_selection_mode(Gtk.SelectionMode.NONE)

        self.create_flow_sim_input(self.flow_sim_input)
        scroll_sim_input.add(self.flow_sim_input)

        #lbl_sim_input = Gtk.Label("Eingabesimulation")
        #notebook.append_page(scroll_sim_input, lbl_sim_input)

        self.create_txt_log()
        lbl_log = Gtk.Label("Log")
        notebook.append_page(self.scroll_txt_log, lbl_log)

        try:
            self.conn = Connector("/dev/ttyACM{i}", 9600)
            self.conn.register_input_observer(self)
            self.conn.register_log_observer(self)
            self.conn.register_output_observer(self)

            integer_id = GObject.timeout_add(200, self.read)
            GObject.timeout_add(10000, self.activate)
        except Exception as e:
            print(e)

        #self.set_geometry_hints(self.scroll_txt_log,-1,-1)
        self.show_all()
예제 #14
0
class Gui:
    def __init__(self):
        # theme stuff
        self.root = Tk()
        self.root.title("SwDiag")

        self.style = ttk.Style()
        self.style.theme_use('clam')

        self.buildMainWindow()
        self.buildSimulateInput()

        self.conn = None
        #try:
        i = 0;
        done = False
        while done == False and i < 15:
            try:
                port = '/dev/ttyACM' + str(i)
                self.conn = Connector(port, 9600)  #read from config
                done = True
                print("/dev/ttyACM" + str(i))
                self.log_txt.insert("1.0", "SUCCESS opening serial port: " + port + "\n")
            except:
                self.log_txt.insert("1.0", "Error opening serial port: " + port + "\n")
                i += 1

        self.conn.register_input_observer(self)
        self.conn.register_log_observer(self)
        self.conn.register_output_observer(self)

        self.conn.request_log_active(True)
        self.conn.request_input_listener_active(True)
        self.conn.request_output_listener_active(True)
        self.conn.request_all_input_values()
        self.conn.request_all_output_values()
        #except:
        #    self.log_txt.insert("1.0","Error opening serial port: "+'/dev/ttyACM0'+"\n")

        self.timer()
        self.root.mainloop()

    def buildMainWindow(self):
        # init up-down panned window
        self.frameset_ud = ttk.PanedWindow(self.root)
        self.frameset_lr = ttk.PanedWindow(self.frameset_ud, orient=HORIZONTAL)

        self.in_out = Frame(self.frameset_ud, width=20)
        #self.in_out_scroll = ttk.Scrollbar( self.frameset_ud, orient=VERTICAL, command=self.in_out_list.yview)
        self.tabbed = ttk.Notebook(self.frameset_ud, height=600, width=800)

        #self.frm_log = ttk.Frame(self.frameset_ud)
        self.log_txt = Text(self.frameset_ud, height=10)
        #self.log_scroll = ttk.Scrollbar( self.frameset_ud, orient=VERTICAL, command=self.log_txt.yview)

        #adding them together
        self.frameset_ud.pack(fill=BOTH, expand=1)
        self.frameset_ud.add(self.frameset_lr, weight=100)
        self.frameset_ud.add(self.log_txt, weight=10)

        self.frameset_lr.add(self.tabbed, weight=100)
        self.frameset_lr.add(self.in_out, weight=10)
        #self.in_out_list. state["disabled"]


        #self.in_out_list['yscrollcommand'] = self.in_out_scroll.set
        #self.log_txt['yscrollcommand'] = self.log_scroll.set




        self.frm_inputs = ttk.Frame(self.tabbed,
                                    padding="3 3 12 12")  # first page, which would get widgets gridded into it
        self.frm_settings = ttk.Frame(self.tabbed)  # second page
        self.frm_errors = ttk.Frame(self.tabbed)
        self.tabbed.add(self.frm_inputs, text='Eingabesimulation', sticky=N+E+S+W)
        self.tabbed.add(self.frm_settings, text='Einstellungen')
        self.tabbed.add(self.frm_errors, text='Fehler')

        self.log_txt.insert("1.0", "Hallo und Willkommen\n")
        self.log_txt.tag_configure('output', foreground="blue")
        self.log_txt.tag_configure('input', foreground="green")
        self.log_txt.tag_configure('log', foreground="grey")

        #self.hi_there = Button(self.frameset_ud, text="Hello")
        #self.frameset_ud.add(self.hi_there)

        #in_out bar on right side

        #listbox.configure(yscrollcommand=s.set)

        #self.frameset_ud.add(self.button)


        #in_out bar on right side
        #self.frameset_ud.add()

    def timer(self):
        self.readSerial();

        self.root.after(200, self.timer)

    def readSerial(self):
        if (self.conn):
            self.conn.read_frames()


    def on_output(self, output_id, value):
        self.log_txt.insert("1.0", "<Output> id: " + str(output_id) + " value: " + str(value) + "\n", ('output'))

        existing_slaves = self.in_out.grid_slaves(row=output_id, column=0)
        if(len(existing_slaves) ==  1):
            existing_slaves[0]["text"]="OUT id: " + str(output_id) + " value: " + str(value)
        else:
            Label(self.in_out, text="OUT id: " + str(output_id) + " value: " + str(value)).grid(row=output_id, column=0)

    def on_input(self, input_id, value):
        self.log_txt.insert("1.0", "<Input> id: " + str(input_id) + " value: " + str(value) + "\n", ('input'))

        existing_slaves = self.in_out.grid_slaves(row=input_id, column=1)
        if(len(existing_slaves) ==  1):
            existing_slaves[0]["text"]="IN id: " + str(input_id) + " value: " + str(value)
        else:
            Label(self.in_out, text="IN id: " + str(input_id) + " value: " + str(value)).grid(row=input_id, column=1)


    def on_log(self, input_type, input_id, value, additional_info):
        self.log_txt.insert("1.0", " <Event> type: " + str(input_type) + " id: " + str(input_id) + " value: " + str(
            value) + " additional_info: " + str(additional_info) + "\n", ('log'))

    def buildSimulateInput(self):
        c = 5
        r = len(config["input"])*2 // 5

        cCol = 0
        cRow = 0
        for input_ in config["input"]:
            ttk.Button(self.frm_inputs, text=input_["name"]+" ON", command=lambda inid=input_["id"]: self.simulate_input(inid, 1)).grid(column=cCol,
                                                                                     row=cRow,
                                                                                     ipady=3,
                                                                                     ipadx=3,
                                                                                     pady=3,
                                                                                     padx=3,
                                                                                     sticky=W+E)
            ttk.Button(self.frm_inputs, text=input_["name"]+" OFF", command=lambda inid=input_["id"]: self.simulate_input(inid, 0)).grid(column=cCol,
                                                                                     row=cRow+1,
                                                                                     ipady=3,
                                                                                     ipadx=3,
                                                                                     pady=3,
                                                                                     padx=3,
                                                                                     sticky=W+E)
            cCol += 1
            if cCol >= c:
                cCol = 0
                cRow += 2

    def simulate_input(self, input_id, value):
        self.conn.simulate_manual_input(input_id, value)
예제 #15
0
# -*- coding: UTF-8 -*-

# 引入模組
from connect import Connector
from crawler import Crawler

# 輸入url進行連線
conn = Connector('https://class.ruten.com.tw/user/index00.php?s=hambergurs')

# 印出 title、img 清單
Crawler(conn.htmlStr)