Beispiel #1
0
def sweep_get_content():
    sweep = SweepElement(key="sweep", title="Frequency sweep", default_datatype="src_data")

    cnt = Content()
    cnt.add(sweep, position=(0, 0))

    return cnt
Beispiel #2
0
def sweep_get_content():
    sweep = SweepElement(key="sweep",
                         title="Frequency sweep",
                         default_datatype="src_data")

    cnt = Content()
    cnt.add(sweep, position=(0, 0))

    return cnt
Beispiel #3
0
def dashboard_get_content():
    gain_slider = SliderElement(key="antenna_gain", title="Antenna gain",
                                width=1, range=(0, 50))
    freq_slider = SliderElement(key="center_freq", title="Center Frequency",
                                value=2.4, width=2, range=(2.38, 2.42), step=0.001)
    bin_slider = SliderElement(key="num_bins", title="Number of Bins", width=1, range=(100, 200))
    win_len_slider = SliderElement(key="window_length", title="Detection windows", width=1, range=(1, 200))
    vis1 = VisualisationElement(key="vis1", title="", default_type="fft", default_datatype="src_data")
    vis2 = VisualisationElement(key="vis2", title="", default_type="fft", default_datatype="rec_data")

    cnt = Content()
    cnt.add(gain_slider, position=(0, 0))
    cnt.add(freq_slider, position=(1, 0))
    cnt.add(bin_slider, position=(2, 0))
    cnt.add(win_len_slider, position=(3, 0))
    cnt.add(vis1, position=(0, 2))
    cnt.add(vis2, position=(1, 2))

    settings = ss.get_settings_object()

    return cnt
Beispiel #4
0
def dashboard_get_content():
    gain_slider = SliderElement(key="antenna_gain",
                                title="Antenna gain",
                                width=1,
                                range=(0, 50))
    freq_slider = SliderElement(key="center_freq",
                                title="Center Frequency",
                                value=2.4,
                                width=2,
                                range=(2.38, 2.42),
                                step=0.001)
    bin_slider = SliderElement(key="num_bins",
                               title="Number of Bins",
                               width=1,
                               range=(100, 200))
    win_len_slider = SliderElement(key="window_length",
                                   title="Detection windows",
                                   width=1,
                                   range=(1, 200))
    vis1 = VisualisationElement(key="vis1",
                                title="",
                                default_type="fft",
                                default_datatype="src_data")
    vis2 = VisualisationElement(key="vis2",
                                title="",
                                default_type="fft",
                                default_datatype="rec_data")

    cnt = Content()
    cnt.add(gain_slider, position=(0, 0))
    cnt.add(freq_slider, position=(1, 0))
    cnt.add(bin_slider, position=(2, 0))
    cnt.add(win_len_slider, position=(3, 0))
    cnt.add(vis1, position=(0, 2))
    cnt.add(vis2, position=(1, 2))

    settings = ss.get_settings_object()

    return cnt
Beispiel #5
0
class IPFSDrive(Tk):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.geometry("300x350")
        self.title("IPFS-Drive")

        mainframe = Frame(self)
        mainframe.pack(side="top", fill="both", expand=True)
        mainframe.grid_rowconfigure(0, weight=1)
        mainframe.grid_columnconfigure(0, weight=1)

        self.frames = {}

        for F in (Start, Main, Authentication, Registration):
            frame = F(parent=mainframe, controller=self)
            self.frames[F] = frame
            frame.grid(row=0, column=0, sticky="nsew")

        self.frames[Registration].next = Authentication
        self.frames[Start].next = Main
        self.frames[Main].prev = Start

        self.current_frame = None

        self.protocol("WM_DELETE_WINDOW", self.exit)

        self._working_dir_path = None
        self.init_working_dir()

        config = json.load(open("firebase.cfg"))
        self._firebase = Firebase(config)
        self._auth = self._firebase.auth()
        self._db = None
        self._ipfs = None
        self._root_dir_path = None
        self._encryption_password = None
        self._content = None
        self._event_observer = None
        self._sync = None

        self._logger = logging.getLogger()

        self._cipher = AESCipher()
        self._ipfs_client = IPFSClient(self._cipher, self._working_dir_path)
        self._ipfs_cluster = IPFSCluster()

        self.show_frame(Authentication)

    def show_frame(self, frame):
        self.current_frame = self.frames[frame]
        self.current_frame.tkraise()
        if isinstance(self.current_frame, Main):
            self.current_frame.on_raised()

    def get_frame(self, frame):
        return self.frames[frame]

    def get_auth(self):
        return self._firebase.auth()

    def get_content(self):
        return self._content

    def set_root_dir_path(self, root_dir_path):
        self._root_dir_path = root_dir_path.replace(os.sep, '/')

    def init_working_dir(self):
        self._working_dir_path = os.path.join(os.getcwd(), "working_dir")
        if not os.path.exists(self._working_dir_path):
            os.mkdir(self._working_dir_path)
            ctypes.windll.kernel32.SetFileAttributesW(self._working_dir_path, 2)

    def init_db(self, uid, token):
        self._db = Db(self._firebase.database(), uid, token)

    def init_content(self):
        self._content = Content(self._root_dir_path, self._db)

    def init_cipher_key(self, encryption_password):
        self._cipher.create_key(encryption_password)

    def init_ipfs(self):
        self._ipfs = IPFS()
        while not self._ipfs.is_ready():
            time.sleep(0.5)

    def init_sync(self):
        self._sync = Sync(self._root_dir_path, self._working_dir_path, self._content, self._db, self._ipfs_client,
                          self._cipher)

    def init_event_monitoring(self):
        event_handler = EventHandler(self._ipfs_client, self._ipfs_cluster, self._content, self._root_dir_path)
        self._event_observer = Observer()
        self._event_observer.schedule(event_handler, self._root_dir_path, recursive=True)
        self._event_observer.start()

    def synchronize(self):
        self._sync.start()

    def start_listening_for_changes(self):
        self._sync.start_listening()

    def add_root_dir(self, start_time):
        for path in os.listdir(self._root_dir_path):
            full_path = os.path.join(self._root_dir_path, path).replace(os.sep, '/')
            if os.path.getctime(full_path) >= start_time:
                continue
            if os.path.isfile(full_path):
                file = File(full_path)
                hash = self._ipfs_client.add_file(file)
                self._content.add(file.path, hash)
            elif os.path.isdir(full_path):
                content_list = self._ipfs_client.add_dir(Directory(full_path))
                self._content.add_list(content_list)
            self._ipfs_cluster.pin(self._content[full_path])

    def get_content_tree(self):
        db_content = self._db.get_content()

        root_dir = IPFSDirectory('.', None)

        if db_content is None:
            return root_dir

        for k, v in db_content.items():
            name = base64.b64decode(k).decode()
            if '.' in name:
                file = IPFSFile(name, v, root_dir)
                root_dir.add_file(file)
            else:
                dir = IPFSDirectory(name, v, root_dir)
                walk(dir)
                root_dir.add_dir(dir)

        return root_dir

    def attach(self, obj):
        self._content.attach(obj)
        self._logger.debug("Attached to content")
        if self._sync:
            self._sync.attach(obj)
            self._logger.debug("Attached to sync")

    def run(self):
        self.mainloop()

    def exit(self):
        if self.current_frame.close():
            if self._event_observer:
                self._event_observer.stop()
                self._event_observer.join()
            shutil.rmtree(self._working_dir_path)
            self.destroy()