コード例 #1
0
    def updateDataFile(self, data_file: DataFileExtended, new_database: bool) -> None:
        self.data_file = data_file
        self.config = data_file.getOptionAccess()

        self.undo = undo(self.data_file.db, ["mask"])
        self.undo.activate()
        self.undo.refresh = self.updateState
コード例 #2
0
    def updateDataFile(self, data_file: DataFileExtended,
                       new_database: bool) -> None:
        self.data_file = data_file
        self.config = data_file.getOptionAccess()

        self.ToggleInterfaceEvent(hidden=self.config.contrast_interface_hidden)
        self.schedule_update = True
コード例 #3
0
ファイル: MaskHandler.py プロジェクト: morefigs/clickpoints
    def updateDataFile(self, data_file: DataFileExtended, new_database: bool) -> None:
        self.data_file = data_file
        self.config = data_file.getOptionAccess()

        self.mask_file = MaskFile(data_file)

        # if a new database is created take mask types from config
        if new_database:
            for type_id, type_def in enumerate(self.config.draw_types):
                if len(type_def) >= 3:
                    name = type_def[2]
                else:
                    name = "Color%d" % type_id
                self.mask_file.set_type(type_id, name, type_def[1], type_def[0])

        # update mask interface buttons
        self.maskTypeChooser.updateButtons(self.mask_file)

        # get config options
        self.changeOpacity(self.config.mask_opacity - self.mask_opacity)
        self.changeCursorSize(self.config.mask_brush_size - self.DrawCursorSize)
        self.ToggleInterfaceEvent(hidden=self.config.mask_interface_hidden)
        if self.config.selected_draw_type >= 0:
            self.maskTypeChooser.setActiveDrawType(self.config.selected_draw_type)

        # place tick marks for already present masks
        # but lets take care that there are masks ...
        try:
            frames = np.array(self.mask_file.get_mask_frames().tuples())[:, 0]
            BroadCastEvent(self.modules, "MarkerPointsAddedList", frames)
        except IndexError:
            pass
コード例 #4
0
    def updateDataFile(self, data_file: DataFileExtended,
                       new_database: bool) -> None:
        self.data_file = data_file
        self.config = data_file.getOptionAccess()

        if self.config.info_hud_string != "":
            self.setVisible(True)
            self.hidden = False
            self.ToggleInterfaceEvent(self.hidden)
コード例 #5
0
    def updateDataFile(self, data_file: DataFileExtended, new_database: bool) -> None:
        self.data_file = data_file
        self.config = data_file.getOptionAccess()
        self.scripts = self.loadScripts()

        for script in self.data_file.getOption("scripts"):
            self.activateScript(script, silent=True)

        self.updateScripts()
コード例 #6
0
def addList(data_file: DataFileExtended, path: str,
            list_filename: list) -> None:
    with open(os.path.join(path, list_filename)) as fp:
        paths = {}
        data = []
        while True:
            start_time = time.time()
            for line in fp:  # continue with the iteration over the file iterator where we stopped last time
                timestamp = None
                external_id = None
                annotation_id = None
                try:
                    line, timestamp, external_id, annotation_id = line.strip(
                    ).split()
                except:
                    line = line.strip().split()[0]

                file_path, file_name = os.path.split(line)
                if file_path not in paths.keys():
                    paths[file_path] = data_file.table_path(path=file_path)
                    paths[file_path].save()

                if timestamp:
                    timestamp = datetime.strptime(timestamp, '%Y%m%d-%H%M%S')
                    # TODO implement getting time stamps from file for file lists
                else:
                    data_file.getTimeStamp(file_name)

                # extract the extension and frame number
                extension = os.path.splitext(file_name)[1]
                frames = getFrameNumber(line, extension)
                # add the file to the database
                data_new = data_file.add_image(file_name,
                                               extension,
                                               external_id,
                                               frames,
                                               path=paths[file_path],
                                               full_path=os.path.join(
                                                   file_path, file_name),
                                               timestamp=timestamp,
                                               commit=False)
                data.extend(data_new)

                if time.time() - start_time > 0.1:
                    break
            else:  # break if we have reached the end of the file
                break
            data_file.add_bulk(data)
            data = []
        data_file.add_bulk(data)

    BroadCastEvent2("ImagesAdded")
コード例 #7
0
 def updateDataFile(self, data_file: DataFileExtended,
                    new_database: bool) -> None:
     self.data_file = data_file
     self.config = data_file.getOptionAccess()
コード例 #8
0
def addPath(data_file: DataFileExtended,
            path: str,
            file_filter: str = "",
            layer_entry: "Layer" = None,
            subdirectories: bool = False,
            use_natsort: bool = False,
            select_file: str = None,
            window: "ClickPointsWindow" = None):
    # if we should add subdirectories, add them or create a list with only one path
    if subdirectories:
        path_list = iter(sorted(GetSubdirectories(path)))
    else:
        path_list = iter([path])

    if layer_entry is None:
        # get a layer for the paths
        layer_entry = data_file.getLayer("default", create=True)

    # with data_file.db.atomic():
    data = []
    while True:
        # iterate over all folders
        for path in path_list:
            # use glob if a filter is active or just get all the files
            if file_filter != "":
                file_list = glob.glob(os.path.join(path, file_filter))
                file_list = [
                    os.path.split(filename)[1] for filename in file_list
                ]
            else:
                file_list = GetFilesInDirectory(path)
            # if no files are left skip this folder
            if len(file_list) == 0:
                print(
                    "WARNING: folder %s doesn't contain any files ClickPoints can read."
                    % path)
                continue
            # add the folder to the database
            path_entry = data_file.add_path(path)
            # maybe sort the files
            if use_natsort:
                file_list = iter(natsorted(file_list))
            else:
                file_list = iter(sorted(file_list))
            # iterate over all files
            while True:
                for filename in file_list:
                    # extract the extension and frame number
                    extension = os.path.splitext(filename)[1]
                    frames = getFrameNumber(os.path.join(path, filename),
                                            extension)
                    # if the file is not properly readable, skip it
                    if frames == 0:
                        continue
                    # add the file to the database
                    try:
                        data.extend(
                            data_file.add_image(filename,
                                                extension,
                                                None,
                                                frames,
                                                path=path_entry,
                                                layer=layer_entry,
                                                full_path=os.path.join(
                                                    path, filename),
                                                commit=False))
                    except OSError as err:
                        print("ERROR:", err)
                    if len(data) > 100 or filename == select_file:
                        # split the data array in slices of 100
                        for i in range(int(len(data) / 100) + 1):
                            data_file.add_bulk(data[i * 100:i * 100 + 100])
                        data = []
                        # if the file is the file which should be selected jump to that frame
                        if filename == select_file:
                            file = data_file.table_image.get(
                                filename=select_file)
                            window.first_frame = file.sort_index
                            select_file = None
                        break
                else:
                    break
            if len(data) > 100:
                data_file.add_bulk(data)
                data = []
        else:
            data_file.add_bulk(data)
            break
    # data_file.start_adding_timestamps()
    BroadCastEvent2("ImagesAdded")
コード例 #9
0
    def __init__(self, window: "ClickPointsWindow", data_file: DataFileExtended, parent: "OptionEditor") -> None:
        QtWidgets.QWidget.__init__(self)
        self.window = window
        self.data_file = data_file
        self.parent = parent

        # Widget
        self.setMinimumWidth(450)
        self.setMinimumHeight(200)
        self.setWindowTitle("Options - ClickPoints")

        self.main_layout = QtWidgets.QVBoxLayout(self)
        self.version_widget = VersionDisplay(self, self.main_layout, window)

        self.list_layout = QtWidgets.QVBoxLayout()
        self.stackedLayout = QtWidgets.QStackedLayout()
        self.top_layout = QtWidgets.QHBoxLayout()
        self.top_layout.addLayout(self.list_layout)
        self.main_layout.addLayout(self.top_layout)

        layout = QtWidgets.QHBoxLayout()
        self.button_export = QtWidgets.QPushButton("&Export")
        self.button_export.clicked.connect(self.Export)
        layout.addWidget(self.button_export)
        self.button_import = QtWidgets.QPushButton("&Import")
        self.button_import.clicked.connect(self.Import)
        layout.addWidget(self.button_import)
        layout.addStretch()
        self.button_ok = QtWidgets.QPushButton("&Ok")
        self.button_ok.clicked.connect(self.Ok)
        layout.addWidget(self.button_ok)
        self.button_cancel = QtWidgets.QPushButton("&Cancel")
        self.button_cancel.clicked.connect(self.Cancel)
        layout.addWidget(self.button_cancel)
        self.button_apply = QtWidgets.QPushButton("&Apply")
        self.button_apply.clicked.connect(self.Apply)
        self.button_apply.setDisabled(True)
        layout.addWidget(self.button_apply)
        self.main_layout.addLayout(layout)

        self.list = QtWidgets.QListWidget()
        self.list_layout.addWidget(self.list)
        self.list.setMaximumWidth(80)

        self.list.currentRowChanged.connect(self.stackedLayout.setCurrentIndex)
        self.top_layout.addLayout(self.stackedLayout)

        self.setWindowIcon(qta.icon("fa.gears"))

        self.edits = []
        self.edits_by_name = {}

        options = data_file.getOptionAccess()

        for category in self.data_file._options:
            count = len([option for option in self.data_file._options[category] if not option.hidden])
            if count == 0:
                continue
            item = QtWidgets.QListWidgetItem(category, self.list)

            group = QtWidgets.QGroupBox(category)
            group.setFlat(True)
            self.layout = QtWidgets.QVBoxLayout()
            group.setLayout(self.layout)
            self.stackedLayout.addWidget(group)

            for option in self.data_file._options[category]:
                if option.hidden:
                    continue
                edit = getOptionInputWidget(option, self.layout)
                edit.valueChanged.connect(lambda value, edit=edit, option=option: self.Changed(edit, value, option))
                edit.current_value = None
                edit.option = option
                edit.error = None
                edit.has_error = False
                self.edits.append(edit)
                self.edits_by_name[option.key] = edit
            self.layout.addStretch()

        self.edits_by_name["buffer_size"].setDisabled(options.buffer_mode != 1)
        self.edits_by_name["buffer_memory"].setDisabled(options.buffer_mode != 2)
コード例 #10
0
ファイル: VideoExporter.py プロジェクト: fabrylab/clickpoints
    def __init__(self, parent: "VideoExporter", window: "ClickPointsWindow", data_file: DataFileExtended,
                 config: OptionAccess, modules: List[Any]) -> None:
        QtWidgets.QWidget.__init__(self)
        # default settings and parameters
        self.window = window
        self.data_file = data_file
        self.config = config
        self.modules = modules
        options = data_file.getOptionAccess()
        self.options = options

        # widget layout and elements
        self.setMinimumWidth(700)
        self.setMinimumHeight(300)
        self.setWindowIcon(qta.icon('fa.film'))
        self.setWindowTitle('Video Export - ClickPoints')
        self.layout = QtWidgets.QVBoxLayout(self)
        self.parent = parent

        # add combo box to choose export mode
        Hlayout = QtWidgets.QHBoxLayout()
        self.cbType = QtWidgets.QComboBox(self)
        self.cbType.insertItem(0, "Video")
        self.cbType.insertItem(1, "Images")
        self.cbType.insertItem(2, "Gif")
        self.cbType.insertItem(3, "Single Image")
        Hlayout.addWidget(self.cbType)
        self.layout.addLayout(Hlayout)

        # add stacked widget to store export mode parameter
        self.StackedWidget = QtWidgets.QStackedWidget(self)
        self.layout.addWidget(self.StackedWidget)

        self.cbType.currentIndexChanged.connect(self.StackedWidget.setCurrentIndex)

        """ Video """
        videoWidget = QtWidgets.QGroupBox("Video Settings")
        self.StackedWidget.addWidget(videoWidget)
        Vlayout = QtWidgets.QVBoxLayout(videoWidget)

        self.leAName = QtShortCuts.QInputFilename(Vlayout, 'Filename:', os.path.abspath(options.export_video_filename),
                                                  "Choose Video - ClickPoints", "Videos (*.mp4 *.mpeg *.avi)",
                                                  lambda name: self.checkExtension(name, ".mp4"))
        self.leCodec = QtShortCuts.QInputString(Vlayout, "Codec:", options.video_codec, stretch=True)
        self.sbQuality = QtShortCuts.QInputNumber(Vlayout, 'Quality (0 lowest, 10 highest):', options.video_quality,
                                                  min=0, max=10, float=False, stretch=True)

        Vlayout.addStretch()

        """ Image """
        imageWidget = QtWidgets.QGroupBox("Image Settings")
        self.StackedWidget.addWidget(imageWidget)
        Vlayout = QtWidgets.QVBoxLayout(imageWidget)

        self.leANameI = QtShortCuts.QInputFilename(Vlayout, 'Filename:', os.path.abspath(options.export_image_filename),
                                                   "Choose Image - ClickPoints", "Images (*.jpg *.png *.tif, *.svg)",
                                                   self.CheckImageFilename)
        QtShortCuts.QInput(Vlayout, 'Image names have to contain %d as a placeholder for the image number.')

        Vlayout.addStretch()

        """ Gif """
        gifWidget = QtWidgets.QGroupBox("Animated Gif Settings")
        self.StackedWidget.addWidget(gifWidget)
        Vlayout = QtWidgets.QVBoxLayout(gifWidget)

        self.leANameG = QtShortCuts.QInputFilename(Vlayout, 'Filename:', os.path.abspath(options.export_gif_filename),
                                                   "Choose Gif - ClickPoints", "Animated Gifs (*.gif)",
                                                   lambda name: self.checkExtension(name, ".gif"))

        Vlayout.addStretch()

        """ Single Image """
        imageWidget = QtWidgets.QGroupBox("Single Image Settings")
        self.StackedWidget.addWidget(imageWidget)
        Vlayout = QtWidgets.QVBoxLayout(imageWidget)

        self.leANameIS = QtShortCuts.QInputFilename(Vlayout, 'Filename:',
                                                    os.path.abspath(options.export_single_image_filename),
                                                    "Choose Image - ClickPoints", "Images (*.jpg *.png *.tif *.svg)",
                                                    lambda name: self.checkExtension(name, ".jpg"))
        QtShortCuts.QInput(Vlayout,
                           'Single Image will only export the current frame. Optionally, a %d placeholder will be filled with the frame number')

        Vlayout.addStretch()

        """ Time """
        timeWidget = QtWidgets.QGroupBox("Time")
        self.layout.addWidget(timeWidget)
        Hlayout = QtWidgets.QHBoxLayout(timeWidget)
        Vlayout = QtWidgets.QVBoxLayout()
        Hlayout.addLayout(Vlayout)

        self.cbTime = QtShortCuts.QInputBool(Vlayout, 'Display time:', options.export_display_time, stretch=True)
        self.cbTimeZero = QtShortCuts.QInputBool(Vlayout, 'Start from zero:', options.export_time_from_zero,
                                                 stretch=True)
        self.cbTimeFontSize = QtShortCuts.QInputNumber(Vlayout, 'Font size:', options.export_time_font_size,
                                                       float=False, stretch=True)
        self.cbTimeColor = QtShortCuts.QInputColor(Vlayout, "Color:", options.export_time_font_color, stretch=True)
        self.cbTimeFormat = QtShortCuts.QInputString(Vlayout, "Format:", options.export_time_format, stretch=True)
        self.cbTimeDeltaFormat = QtShortCuts.QInputString(Vlayout, "Format:", options.export_timedelta_format,
                                                          stretch=True)

        def updateTimeFormat(self):
            if self.cbTimeZero.value():
                self.cbTimeDeltaFormat.show()
                self.cbTimeFormat.hide()
            else:
                self.cbTimeDeltaFormat.hide()
                self.cbTimeFormat.show()

        self.cbTimeZero.checkbox.stateChanged.connect(lambda x, self=self: updateTimeFormat(self))
        updateTimeFormat(self)

        Vlayout = QtWidgets.QVBoxLayout()
        Hlayout.addLayout(Vlayout)

        self.cbCustomTime = QtShortCuts.QInputBool(Vlayout, 'Custom time:', options.export_custom_time)
        self.cbCustomTimeDelta = QtShortCuts.QInputNumber(Vlayout, 'Time between two frames (s):',
                                                          options.export_custom_time_delta, decimals=3)

        Vlayout.addStretch()

        """ Scale """
        scaleWidget = QtWidgets.QGroupBox("Scale")
        self.layout.addWidget(scaleWidget)
        Vlayout = QtWidgets.QVBoxLayout(scaleWidget)

        self.cbImageScaleSize = QtShortCuts.QInputNumber(Vlayout, 'Image scale:', options.export_image_scale,
                                                         float=True, stretch=True)
        self.cbMarkerScaleSize = QtShortCuts.QInputNumber(Vlayout, 'Marker scale:', options.export_marker_scale,
                                                          float=True, stretch=True)

        Vlayout.addStretch()

        self.cbType.setCurrentIndex(options.export_type)

        """ Progress bar """

        Hlayout = QtWidgets.QHBoxLayout()
        self.progressbar = QtWidgets.QProgressBar()
        Hlayout.addWidget(self.progressbar)
        self.button_start = QtWidgets.QPushButton("Start")
        self.button_start.pressed.connect(self.SaveImage)
        Hlayout.addWidget(self.button_start)
        self.button_stop = QtWidgets.QPushButton("Stop")
        self.button_stop.pressed.connect(self.StopSaving)
        self.button_stop.setHidden(True)
        Hlayout.addWidget(self.button_stop)
        self.layout.addLayout(Hlayout)