Example #1
0
    def _list_sdcard_results(self, l):
        # dismiss waiting dialog
        fl = {}
        for f in l:
            f = '/sd/{}'.format(f)
            if f.endswith('/'):
                fl[f[:-1]] = {'size': 0, 'isdir': True}
            else:
                fl[f] = {'size': 0, 'isdir': False}

        # get file to print
        f = FileDialog()
        f.open(title='SD File to print', file_list=fl, cb=self._start_sd_print)
Example #2
0
 def start_print(self):
     if self.is_printing:
         if not self.paused:
             self.paused = True
             self.app.comms.stream_pause(True)
             self.ids.print_but.text = 'Resume'
         else:
             self.paused = False
             self.app.comms.stream_pause(False)
             self.ids.print_but.text = 'Pause'
     else:
         # get file to print
         f = FileDialog(self._start_print)
         f.open(self.last_path)
Example #3
0
    def input_dialog(self, delete=False):
        dialog = QtWidgets.QDialog()
        dialog.setWindowTitle("Select file to modify")

        file_label = QtWidgets.QLabel("File: ")
        filepath = FileDialog() # select which file to change
        filepath.directory = os.path.join(filepath.directory, 'models')
        filepath.filter = ""
        file_layout = QtWidgets.QHBoxLayout()
        file_layout.addWidget(file_label)
        file_layout.addWidget(filepath)

        newname_frame = QtWidgets.QFrame()

        new_name_label = QtWidgets.QLabel("New name: ")
        new_name_input = QtWidgets.QLineEdit()
        new_name_input.setPlaceholderText("new name")
        new_name_layout = QtWidgets.QHBoxLayout()
        new_name_layout.addWidget(new_name_label)
        new_name_layout.addWidget(new_name_input)
        newname_frame.setLayout(new_name_layout)

        if delete:
            newname_frame.hide()

        # buttons
        cancel_btn = QtWidgets.QPushButton("Cancel")
        cancel_btn.clicked.connect(dialog.close)

        ok_btn = QtWidgets.QPushButton("OK")
        ok_btn.clicked.connect(dialog.close)

        ok_btn.clicked.connect(lambda: self.check_inputs(inputs=[filepath.filepath, new_name_input.text()], delete=delete))

        button_layout = QtWidgets.QHBoxLayout()
        button_layout.addWidget(cancel_btn)
        button_layout.addWidget(ok_btn)

        layout = QtWidgets.QVBoxLayout()
        layout.addLayout(file_layout)
        # layout.addLayout(new_name_layout)
        layout.addWidget(newname_frame)
        layout.addLayout(button_layout)
        dialog.setLayout(layout)

        dialog.exec_()
Example #4
0
    def _list_sdcard_results(self, l):
        # dismiss waiting dialog
        fl = {}
        for f in l:
            f = '/sd/{}'.format(f)
            # if f.endswith('/'):
            #     fl[f[:-1]] = {'size': 0, 'isdir': True}
            # else:
            #     fl[f] = {'size': 0, 'isdir': False}

            # as we can't handle subdirectories yet we do not list them
            if not f.endswith('/'):
                fl[f] = {'size': 0, 'isdir': False}

        # get file to print
        f = FileDialog()
        f.open(title='SD File to print', file_list=fl, cb=self._start_sd_print)
Example #5
0
 def startAnomalyDetector(self, rulefile):
     self.ui.runningRulefileLabel.setText('Running rulefile: ' + rulefile)
     if rulefile != 'None':
         dialog = FileDialog('load_file', self.ui, rulefile)
         self.deployAnomalyDetector()
     else:
         if 'falco' in self.threads.keys():
             self.threads['falco'].stop()
             self.threads['falco'].wait()
Example #6
0
    def __init__(self, test, label):
        super(DataLoaderWidget, self).__init__()

        self.setWindowTitle("Select file to load data from")
        self.setFixedHeight(300)

        # initialize args to be used later
        self.x_fwd = ""
        self.x_rev = ""
        self.y = ""
        self.test = test
        self.label = label

        # create widgets
        text_label = QtWidgets.QLabel(
            "Supported file types: .csv, .txt, and .npy \
                                        \nGo to [url for github docs] for example file formats."
        )

        # radio buttons
        radio_btns_label = QtWidgets.QLabel("File extension")
        csv_txt_btn = QtWidgets.QRadioButton()
        csv_txt_btn.setChecked(True)
        csv_txt_btn.setText('.csv or .txt')
        npy_btn = QtWidgets.QRadioButton()
        npy_btn.setText('.npy')

        radio_btn_layout = QtWidgets.QHBoxLayout()
        radio_btn_layout.addWidget(radio_btns_label)
        radio_btn_layout.addWidget(csv_txt_btn)
        radio_btn_layout.addWidget(npy_btn)

        # filepath widget
        filepath_dialog = FileDialog()
        filepath_dialog.directory = os.path.join(filepath_dialog.directory,
                                                 'data')
        filepath_dialog.filter = "Text, CSV files (*.txt; *.csv);; Text files (*.txt);; CSV files (*.csv)"
        npy_filepaths_dialog = MultiFileDialog()
        npy_filepaths_dialog.directory = os.path.join(
            npy_filepaths_dialog.directory, 'data')
        npy_filepaths_dialog.filter = "Numpy files (*.npy)"
        npy_filepaths_dialog.setVisible(False)

        csv_txt_btn.toggled.connect(lambda: filepath_dialog.setVisible(True))
        csv_txt_btn.toggled.connect(
            lambda: npy_filepaths_dialog.setVisible(False))
        npy_btn.toggled.connect(lambda: filepath_dialog.setVisible(False))
        npy_btn.toggled.connect(lambda: npy_filepaths_dialog.setVisible(True))

        # buttons
        cancel_btn = QtWidgets.QPushButton("Cancel")
        # cancel_btn.clicked.connect(self.input_params.close)
        cancel_btn.clicked.connect(self.close)

        train_model_btn = QtWidgets.QPushButton(self.label)
        # train_model_btn.clicked.connect(self.input_params.close)
        train_model_btn.clicked.connect(self.close)

        train_model_btn.clicked.connect(lambda: self.process_selected_files(
            inputs=[filepath_dialog.filepath, npy_filepaths_dialog.filepaths],
            test=self.test))

        button_layout = QtWidgets.QHBoxLayout()
        button_layout.addWidget(cancel_btn)
        button_layout.addWidget(train_model_btn)

        # Create layout and add widgets
        layout = QtWidgets.QVBoxLayout()
        layout.addWidget(text_label)
        layout.addLayout(radio_btn_layout)
        layout.addWidget(filepath_dialog)
        layout.addWidget(npy_filepaths_dialog)
        layout.addLayout(button_layout)
        self.setLayout(layout)

        self.exec_()
Example #7
0
 def exportAnomalyRules(self):
     dialog = FileDialog('save_file', self.ui)
     self.data.saveScheduledRules()
     self.ruleConfigWidget.updateRules()
Example #8
0
 def loadAnomalyRules(self):
     dialog = FileDialog('load_file', self.ui)
Example #9
0
 def ButtonProcess_Click(self):
     FileDialog(self.file_loaded)
 def on_open_file(self, widget):
     self.file_dialog = FileDialog(self.window)
     file_path = self.file_dialog.choose_file()
     if(file_path):
         self.set_main_image(self.image_handler.read_main_image(file_path))
 def on_operand_file(self, widget):
     file_dialog = FileDialog(self.window)
     file_path = file_dialog.choose_file()
     if(file_path):
         self.set_secondary_image(self.image_handler.read_secondary_image(file_path))
class MainView:
    def __init__(self):
        self.builder = Gtk.Builder()
        self.builder.add_from_file('main_gui.glade')
        self.builder.connect_signals(self)

        self.box = self.builder.get_object('inner_box')
        self.window = self.builder.get_object('main_window')
        self.window.set_default_size(600, 400)

        self.image_handler = ImageHandler()

        self.main_canvas = FigureCanvas(self.image_handler.read_main_image('lena.jpg'))
        self.box.pack_start(self.main_canvas, True, True, 0)
        self.filtered_canvas = None
        self.secondary_canvas = None
        self.window.show_all()

    def set_main_image(self, figure):
        self.remove_current_images(all=True)
        self.main_canvas = FigureCanvas(figure)
        self.box.pack_start(self.main_canvas, True, True, 0)
        self.window.show_all()

    def set_resulted_image(self, figure, preserve_middle=False):
        self.remove_current_images(preserve_middle=preserve_middle)
        self.filtered_canvas = FigureCanvas(figure)
        self.box.pack_end(self.filtered_canvas, True, True, 0)
        self.window.show_all()

    def set_secondary_image(self, figure):
        self.remove_current_images()
        self.secondary_canvas = FigureCanvas(figure)
        self.box.pack_start(self.secondary_canvas, True, True, 0)
        self.window.show_all()

    def remove_current_images(self, all=False, preserve_middle=False):
        if not preserve_middle and self.secondary_canvas in self.box.get_children():
            self.box.remove(self.secondary_canvas)
        if self.filtered_canvas in self.box.get_children():
            self.box.remove(self.filtered_canvas)
        if all:
            self.box.remove(self.main_canvas)

#################################################################
#                   Signal Handlers                             #
    def on_delete_window(self, *args):
        Gtk.main_quit(*args)

    def on_open_file(self, widget):
        self.file_dialog = FileDialog(self.window)
        file_path = self.file_dialog.choose_file()
        if(file_path):
            self.set_main_image(self.image_handler.read_main_image(file_path))

    def on_salt_and_pepper(self, widget):
        resulted_figure = self.image_handler.salt_and_pepper()
        self.set_resulted_image(resulted_figure)

    def on_gray_scale(self, widget):
        resulted_figure = self.image_handler.convert_current_to_gray()
        self.set_resulted_image(resulted_figure)

    def on_replace(self, widget):
        self.set_main_image(self.image_handler.replace_current_img())

    def on_recover(self, widget):
        self.set_main_image(self.image_handler.recover_original_img())

    def on_thresholding(self, widget):
        self.threshold_dialog = ThresholdDialog(self.window)
        threshold_value, is_adaptive = self.threshold_dialog.open_dialog()
        if(threshold_value != None):
            resulted_figure = self.image_handler.threshold(threshold_value, is_adaptive)
            self.set_resulted_image(resulted_figure)

    def on_average(self, widget):
        self.mask_dialog = MaskDialog(self.window)
        mask_value = self.mask_dialog.open_dialog()
        if(mask_value != None):
            resulted_figure = self.image_handler.average(mask_value)
            self.set_resulted_image(resulted_figure)

    def on_median(self, widget):
        self.mask_dialog = MaskDialog(self.window)
        mask_value = self.mask_dialog.open_dialog()
        if(mask_value != None):
            resulted_figure = self.image_handler.median(mask_value)
            self.set_resulted_image(resulted_figure)

    def on_high_pass(self, widget):
        resulted_figure = self.image_handler.high_pass()
        self.set_resulted_image(resulted_figure)

    def on_horizontal(self, widget):
        resulted_figure = self.image_handler.horizontal()
        self.set_resulted_image(resulted_figure)

    def on_vertical(self, widget):
        resulted_figure = self.image_handler.vertical()
        self.set_resulted_image(resulted_figure)

    def on_plus_45(self, widget):
        resulted_figure = self.image_handler.plus_45()
        self.set_resulted_image(resulted_figure)

    def on_minus_45(self, widget):
        resulted_figure = self.image_handler.minus_45()
        self.set_resulted_image(resulted_figure)

    def on_sobel(self, widget):
        resulted_figure = self.image_handler.sobel()
        self.set_resulted_image(resulted_figure)

    def on_prewitt(self, widget):
        resulted_figure = self.image_handler.prewitt()
        self.set_resulted_image(resulted_figure)

    def on_roberts(self, widget):
        resulted_figure = self.image_handler.roberts()
        self.set_resulted_image(resulted_figure)

    def on_hough_line(self, widget):
        self.config_dialog = ConfigDialog(self.window)
        config_value = self.config_dialog.open_dialog('Nivel de Aceitacao', 255)
        if(config_value != None):
            resulted_figure = self.image_handler.hough_line(config_value)
            self.set_resulted_image(resulted_figure)

    def on_seam_carving(self, widget):
        self.config_dialog = ConfigDialog(self.window)
        amount_value = self.config_dialog.open_dialog('Linhas a Retirar', self.image_handler.get_current_img_width())
        if(amount_value != None):
            resulted_figure = self.image_handler.apply_seam_carving(amount_value)
            self.set_resulted_image(resulted_figure)

    def on_color_extract(self, widget):
        self.colorDialog = ColorDialog(self.window)
        color = self.colorDialog.select()
        if color != None:
            self.config_dialog = ConfigDialog(self.window)
            config_value = self.config_dialog.open_dialog('Taxa de Tolerancia', 255)
            if(config_value != None):
                resulted_figure = self.image_handler.color_extract(color, config_value)
                self.set_resulted_image(resulted_figure)

    def on_operand_file(self, widget):
        file_dialog = FileDialog(self.window)
        file_path = file_dialog.choose_file()
        if(file_path):
            self.set_secondary_image(self.image_handler.read_secondary_image(file_path))

    def on_union(self, widget):
        resulted_figure = self.image_handler.union()
        self.set_resulted_image(resulted_figure, preserve_middle=True)

    def on_intersection(self, widget):
        resulted_figure = self.image_handler.intersection()
        self.set_resulted_image(resulted_figure, preserve_middle=True)

    def on_subtraction(self, widget):
        resulted_figure = self.image_handler.subtraction()
        self.set_resulted_image(resulted_figure, preserve_middle=True)

    def on_complement(self, widget):
        resulted_figure = self.image_handler.complement()
        self.set_resulted_image(resulted_figure)