def menu(self, title, actions=None): menu = self.menuBar().addMenu(title) if actions: addActions(menu, actions) return menu
def toolbar(self, title, actions=None): toolbar = ToolBar(title) toolbar.setObjectName(u'%sToolBar' % title) # toolbar.setOrientation(Qt.Vertical) toolbar.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) if actions: addActions(toolbar, actions) self.addToolBar(Qt.LeftToolBarArea, toolbar) return toolbar
def __init__(self, main_window, settings_dialog): super(TrackingServerLog, self).__init__() self.main_window = main_window self.settings_dialog = settings_dialog self.CWD = os.path.abspath(os.getcwd()) self.setWindowTitle('Object Tracker Server Log') self.setMinimumSize(800, 600) wid = QWidget(self) self.setCentralWidget(wid) layout = QVBoxLayout() wid.setLayout(layout) self.output = QTextEdit() self.output.setReadOnly(True) # self.output.setTextBackgroundColor(Qt.black) # self.output.setTextColor(Qt.white) layout.addWidget(self.output) action = partial(newAction, self) hide = action("&Hide Window", self.hide, "Ctrl+H") stop = action("&Stop Tracker", self.stop, "Ctrl+S", enabled=True) self.actions = struct(hide=hide,stop=stop, all_actions=(hide,stop)) self.tools = self.toolbar("Tools", position=Qt.TopToolBarArea) self.tools.clear() addActions(self.tools, self.actions.all_actions) self.process = None self.__is_running = False self.cfg_text = self.settings_dialog.cfg_text self.mtf_cfg_text = self.settings_dialog.mtf_cfg_text self.start_server()
def populateModeActions(self): tool, menu = self.actions.advanced, self.actions.advancedContext self.tools.clear() addActions(self.tools, tool) self.canvas.menus[0].clear() addActions(self.canvas.menus[0], menu) self.menus.edit.clear() actions = (self.actions.create, ) if self.beginner() else ( self.actions.createMode, self.actions.editMode) addActions(self.menus.edit, actions + self.actions.advancedContext)
def __init__(self, defaultFilename=None, defaultPrefdefClassFile=None): super(MainWindow, self).__init__() self.setWindowTitle(__appname__) # Load setting in the main thread self.settings = Settings() self.settings.load() settings = self.settings self.defaultSaveDir = None # Whether we need to save or not. self.dirty = False # For loading all image under a directory self.mImgList = [] self.dirname = None # Main widgets and related state. # self.labelDialog = LabelDialog(parent=self, listItem=self.labelHist) # File and Notes self.noteArea = QPlainTextEdit() self.fileListWidget = QListWidget() self.fileListWidget.itemDoubleClicked.connect( self.fileitemDoubleClicked) self.fileNoteLayout = QVBoxLayout() self.fileNoteLayout.addWidget(self.fileListWidget) self.fileNoteLayout.addWidget(self.noteArea) self.fileNoteArea = QWidget() self.fileNoteArea.setLayout(self.fileNoteLayout) # File and Notes to Dock self.fileNoteDock = QDockWidget(u'Files and Notes', self) self.fileNoteDock.setObjectName(u'file_note') self.fileNoteDock.setWidget(self.fileNoteArea) self.addDockWidget(Qt.LeftDockWidgetArea, self.fileNoteDock) #First Search self.firstText = QLineEdit() self.firsrSearchResultArea = QListWidget() self.firsrSearchResultArea.itemDoubleClicked.connect( self.fileitemDoubleClicked) self.firstSearchLayout = QVBoxLayout() self.firstSearchLayout.addWidget(self.firstText) self.firstSearchLayout.addWidget(self.firsrSearchResultArea) self.firstSearchArea = QWidget() self.firstSearchArea.setLayout(self.firstSearchLayout) #Locode Search self.locodeText = QLineEdit() self.locodeDataLayout = QFormLayout() self.storeKw = QLineEdit() self.locodeDataLayout.addRow('Store KeyWord', self.storeKw) self.mallKw = QLineEdit() self.locodeDataLayout.addRow('Mall KeyWord', self.mallKw) self.gstNo = QLineEdit() self.locodeDataLayout.addRow('GST NO', self.gstNo) self.locodeSearchLayout = QVBoxLayout() self.locodeDataArea = QWidget() self.locodeDataArea.setLayout(self.locodeDataLayout) self.locodeSearchLayout.addWidget(self.locodeText) self.locodeSearchLayout.addWidget(self.locodeDataArea) self.locodeSearchArea = QWidget() self.locodeSearchArea.setLayout(self.locodeSearchLayout) # FirstchSearch and LocodeSearch to Doct self.inputAreaLayout = QHBoxLayout() self.inputAreaLayout.addWidget(self.firstSearchArea) self.inputAreaLayout.addWidget(self.locodeSearchArea) self.inputArea = QWidget() self.inputArea.setLayout(self.inputAreaLayout) self.inputDock = QDockWidget(u'Input Area', self) self.inputDock.setObjectName(u'input_area') self.inputDock.setWidget(self.inputArea) self.addDockWidget(Qt.RightDockWidgetArea, self.inputDock) #Canvas self.zoomWidget = ZoomWidget() self.canvas = Canvas(parent=self) self.canvas.zoomRequest.connect(self.zoomRequest) scroll = QScrollArea() scroll.setWidget(self.canvas) scroll.setWidgetResizable(True) self.scrollBars = { Qt.Vertical: scroll.verticalScrollBar(), Qt.Horizontal: scroll.horizontalScrollBar() } self.scrollArea = scroll self.canvas.scrollRequest.connect(self.scrollRequest) self.setCentralWidget(scroll) # Actions action = partial(newAction, self) quit = action('&Quit', self.close, 'Ctrl+Q', 'quit', u'Quit application') opendir = action('&Open Dir', self.openDirDialog, 'Ctrl+o', 'open', u'Open Dir') changeSavedir = action('&Change Save Dir', self.changeSavedirDialog, 'Ctrl+r', 'open', u'Change default saved Annotation dir') openNextImg = action('&Next Image', self.openNextImg, 'd', 'next', u'Open Next') openPrevImg = action('&Prev Image', self.openPrevImg, 'a', 'prev', u'Open Prev') saveAs = action('&Save As', self.saveFileAs, 'Ctrl+s', 'save-as', u'Save labels to a different file', enabled=False) zoom = QWidgetAction(self) zoom.setDefaultWidget(self.zoomWidget) self.zoomWidget.setWhatsThis( u"Zoom in or out of the image. Also accessible with" " %s and %s from the canvas." % (fmtShortcut("Ctrl+[-+]"), fmtShortcut("Ctrl+Wheel"))) self.zoomWidget.setEnabled(False) fitWidth = action('Fit &Width', self.setFitWidth, 'Ctrl+Shift+F', 'fit-width', u'Zoom follows window width', checkable=True, enabled=False) # Group zoom controls into a list for easier toggling. zoomActions = (self.zoomWidget, fitWidth) self.zoomMode = self.MANUAL_ZOOM self.scalers = { self.FIT_WIDTH: self.scaleFitWidth, # Set to one to scale to 100% when loading files. self.MANUAL_ZOOM: lambda: 1, } # Store actions for further handling. self.actions = struct(saveAs=saveAs, zoom=zoom, fitWidth=fitWidth, zoomActions=zoomActions, fileMenuActions=(open, saveAs, quit)) self.menus = struct(file=self.menu('&File'), edit=self.menu('&Edit'), view=self.menu('&View')) addActions(self.menus.file, (opendir, changeSavedir, saveAs, quit)) addActions(self.menus.view, (fitWidth, openPrevImg, openNextImg)) self.statusBar().showMessage('%s started.' % __appname__) self.statusBar().show() # Application state. self.image = QImage() self.filePath = ustr(defaultFilename) self.recentFiles = [] self.maxRecent = 7 self.lineColor = None self.fillColor = None self.zoom_level = 100 self.fit_window = False # Add Chris self.difficult = False size = settings.get(SETTING_WIN_SIZE, QSize(600, 500)) position = settings.get(SETTING_WIN_POSE, QPoint(0, 0)) self.resize(size) self.move(position) saveDir = ustr(settings.get(SETTING_SAVE_DIR, None)) self.lastOpenDir = ustr(settings.get(SETTING_LAST_OPEN_DIR, None)) if saveDir is not None and os.path.exists(saveDir): self.defaultSaveDir = saveDir self.statusBar().showMessage( '%s started. Annotation will be saved to %s' % (__appname__, self.defaultSaveDir)) self.statusBar().show() self.restoreState(settings.get(SETTING_WIN_STATE, QByteArray())) print self.filePath # Since loading the file may take some time, make sure it runs in the background. if self.filePath and os.path.isdir(self.filePath): self.queueEvent(partial(self.importDirImages, self.filePath or "")) elif self.filePath: self.queueEvent(partial(self.loadFile, self.filePath or "")) # Callbacks: self.zoomWidget.valueChanged.connect(self.paintCanvas) # Display cursor coordinates at the right of status bar self.labelCoordinates = QLabel('') self.statusBar().addPermanentWidget(self.labelCoordinates) # Open Dir if deafult file if self.filePath and os.path.isdir(self.filePath): self.openDirDialog(dirpath=self.filePath)
def __init__(self, parent_window, num_frames, dataset_path, **kwargs): super(DatasetDetailsDialog, self).__init__(**kwargs) self.CWD = os.path.abspath(os.getcwd()) self.dataset_path = dataset_path self.parent_window = parent_window self.setWindowTitle('Dataset Details') self.setMinimumSize(400, 300) wid = QWidget(self) self.setCentralWidget(wid) layout = QVBoxLayout() wid.setLayout(layout) self.filepath_label = QLabel("Path: {}".format(dataset_path)) layout.addWidget(self.filepath_label) set_roi_dir_widget = QWidget() set_roi_dir_layout = QHBoxLayout() set_roi_dir_widget.setLayout(set_roi_dir_layout) roi_dir_label = QLabel("ROI dir: ") self.roi_dir_text = QLineEdit() self.roi_dir_button = QPushButton("Select") self.roi_dir_button.clicked.connect(self.roi_dir_button_clicked) set_roi_dir_layout.addWidget(roi_dir_label) set_roi_dir_layout.addWidget(self.roi_dir_text) set_roi_dir_layout.addWidget(self.roi_dir_button) layout.addWidget(set_roi_dir_widget) self.table = QTableWidget() self.table.setColumnCount(3) self.table.setHorizontalHeaderLabels( ["Start frame", "End frame", "Jump Interval"]) self.table.resize(400, 300) self.table.setSelectionBehavior(QAbstractItemView.SelectRows) self.table.setSelectionMode(QAbstractItemView.SingleSelection) layout.addWidget(self.table) action = partial(newAction, self) add = action("&Add", self.add, "Ctrl+A") delete = action("&Delete", self.delete, "Ctrl+D") clear = action("Clear", self.clear) ok = action("&OK", self.ok, "Ctrl+O") cancel = action("&Close", self.close, "Ctrl+C") self.actions = struct(add=add, delete=delete, clear=clear, cancel=cancel, ok=ok, all_actions=(add, delete, clear, ok, cancel)) self.tools = self.toolbar("Tools", position=Qt.BottomToolBarArea) self.tools.clear() addActions(self.tools, self.actions.all_actions) if os.path.isdir(dataset_path): tentative_annotations_path = os.path.join(dataset_path, 'annotations') else: tentative_annotations_path = os.path.join( os.path.dirname(dataset_path), os.path.splitext(os.path.basename(dataset_path))[0], 'annotations') if not os.path.exists(tentative_annotations_path): os.makedirs(tentative_annotations_path) self.config_path = os.path.join(tentative_annotations_path, '.config.pkl') self.num_frames = num_frames self.load_roi_path() self.load_and_populate_table()
def __init__(self, main_window): super(SaveTFRecordsDialog, self).__init__() self.main_window = main_window self.CWD = os.path.abspath(os.getcwd()) self.DEFAULT_TFRECORDS_SAVE_DIR = self.main_window.DEFAULT_TFRECORDS_SAVE_DIR if not os.path.exists(self.DEFAULT_TFRECORDS_SAVE_DIR): os.makedirs(self.DEFAULT_TFRECORDS_SAVE_DIR) self.setWindowTitle('Save TFRecords') self.setMinimumSize(750, 500) wid = QWidget(self) self.setCentralWidget(wid) layout = QVBoxLayout() wid.setLayout(layout) self.list = QListWidget() self.list.itemDoubleClicked.connect(self.edit_dataset) layout.addWidget(self.list) self.use_ground_truth_bboxes = QCheckBox("Use ground truth bounding boxes") self.use_ground_truth_bboxes.setChecked(True) layout.addWidget(self.use_ground_truth_bboxes) self.use_detection_bboxes = QCheckBox("Use detection bounding boxes") self.use_detection_bboxes.setChecked(False) layout.addWidget(self.use_detection_bboxes) self.use_tracking_bboxes = QCheckBox("Use tracking bounding boxes") self.use_tracking_bboxes.setChecked(True) layout.addWidget(self.use_tracking_bboxes) pbtxt_label = QLabel("You can load a pbtxt file for label list here or leave it empty for automatic generation." " Automatically generated file will be put in the same dir as .tfrecords file.") layout.addWidget(pbtxt_label) self.pbtxt_text = QLineEdit() layout.addWidget(self.pbtxt_text) self.pbtxt_button = QPushButton("Browse .pbtxt label file") layout.addWidget(self.pbtxt_button) self.pbtxt_button.clicked.connect(self.pbtxt_button_clicked) self.output = QTextEdit() # self.output.setDisabled(True) layout.addWidget(self.output) action = partial(newAction, self) save = action("&Save", self.save, "Ctrl+S") add_files = action("Add Video &Files", self.add_files, "Ctrl+F") add_dirs = action("Add Directo&ry", self.add_dirs, "Ctrl+R") edit_dataset = action("Edit Dataset", self.edit_dataset, "Ctrl+E") delete = action("&Delete", self.delete, "Ctrl+D") cancel = action("&Cancel", self.cancel, "Ctrl+C", enabled=False) hide = action("&Hide Window", self.hide, "Ctrl+H") self.actions = struct(save=save, add_files=add_files, add_dirs=add_dirs, edit_dataset=edit_dataset, delete=delete, cancel=cancel, hide=hide, all_actions=(save, add_files, add_dirs, edit_dataset, delete, cancel, hide)) self.tools = self.toolbar("Tools", position=Qt.TopToolBarArea) self.tools.clear() addActions(self.tools, self.actions.all_actions)
def __init__(self, main_window): super(TrackingSettingDialog, self).__init__() self.main_window = main_window if self.main_window is None: default_cfg_path = "../tracking/cfg/params.cfg" default_mtf_cfg_path = "../tracking/mtf/" else: try: default_cfg_path = self.main_window.tracking_settings.cfg_path default_mtf_cfg_path = self.main_window.tracking_settings.mtf_cfg_path except AttributeError: default_cfg_path = "../tracking/cfg/params.cfg" default_mtf_cfg_path = "../tracking/cfg/mtf/" self.CWD = os.path.abspath(os.getcwd()) self.setWindowTitle('Tracker Settings') self.setMinimumSize(800, 300) wid = QWidget(self) self.setCentralWidget(wid) layout = QVBoxLayout() wid.setLayout(layout) self.custom_settings_group = QGroupBox("Server Settings:") layout.addWidget(self.custom_settings_group) custom_settings_layout = QVBoxLayout() self.custom_settings_group.setLayout(custom_settings_layout) cfg_layout = QHBoxLayout() cfg_label = QLabel("Config file:") cfg_layout.addWidget(cfg_label) self.cfg_text = QLineEdit() self.cfg_text.setText(default_cfg_path) cfg_layout.addWidget(self.cfg_text) self.cfg_button = QPushButton("Browse") cfg_layout.addWidget(self.cfg_button) self.cfg_button.clicked.connect(self.cfg_button_clicked) custom_settings_layout.addLayout(cfg_layout) self.mtf_settings_group = QGroupBox("MTF settings:") layout.addWidget(self.mtf_settings_group) mtf_settings_layout = QVBoxLayout() self.mtf_settings_group.setLayout(mtf_settings_layout) mtf_cfg_label = QLabel( "Select directory containing MTF configuration files:") mtf_settings_layout.addWidget(mtf_cfg_label) self.mtf_cfg_text = QLineEdit() self.mtf_cfg_text.setText(default_mtf_cfg_path) mtf_settings_layout.addWidget(self.mtf_cfg_text) self.mtf_cfg_button = QPushButton("Choose directory") mtf_settings_layout.addWidget(self.mtf_cfg_button) self.mtf_cfg_button.clicked.connect(self.mtf_cfg_button_clicked) # tfrecords_label = QLabel("Select dataset .tfrecords file:") # custom_settings_layout.addWidget(tfrecords_label) # self.tfrecords_text = QLineEdit(default_tfrecords_path) # custom_settings_layout.addWidget(self.tfrecords_text) # self.tfrecords_button = QPushButton("Browse .tfrecords file") # custom_settings_layout.addWidget(self.tfrecords_button) # self.tfrecords_button.clicked.connect(self.tfrecords_button_clicked) action = partial(newAction, self) save_settings = action("&Save Settings", self.save_settings, "Ctrl+S") close = action("&Close", self.close, "Ctrl+C") self.actions = struct(save_settings=save_settings, close=close, all_actions=(save_settings, close)) self.tools = self.toolbar("Tools", position=Qt.BottomToolBarArea) self.tools.clear() addActions(self.tools, self.actions.all_actions)
def __init__(self, defaultFilename=None, defaultPrefdefClassFile=None): super(MainWindow, self).__init__() self.setWindowTitle(__appname__) self.defaultSaveDir = None self.usingPascalVocFormat = True self.mImgList = [] self.dirname = None self.labelHist = [] self.lastOpenDir = None self.dirty = False self._noSelectionSlot = False self._beginner = True self.screencastViewer = "firefox" self.screencast = "https://www.youtube.com/?gl=UA&hl=ru" self.loadPredefinedClasses(defaultPrefdefClassFile) self.labelDialog = LabelDialog(parent=self, listItem=self.labelHist) self.itemsToShapes = {} self.shapesToItems = {} self.prevLabelText = '' listLayout = QVBoxLayout() listLayout.setContentsMargins(0, 0, 0, 0) self.useDefaultLabelCheckbox = QCheckBox(u'Default label') self.useDefaultLabelCheckbox.setChecked(True) self.defaultLabelTextLine = QLineEdit('Object') useDefaultLabelQHBoxLayout = QHBoxLayout() useDefaultLabelQHBoxLayout.addWidget(self.useDefaultLabelCheckbox) useDefaultLabelQHBoxLayout.addWidget(self.defaultLabelTextLine) useDefaultLabelContainer = QWidget() useDefaultLabelContainer.setLayout(useDefaultLabelQHBoxLayout) self.editButton = QToolButton() self.editButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) listLayout.addWidget(self.editButton) listLayout.addWidget(useDefaultLabelContainer) self.labelList = QListWidget() labelListContainer = QWidget() labelListContainer.setLayout(listLayout) self.labelList.itemActivated.connect(self.labelSelectionChanged) self.labelList.itemSelectionChanged.connect(self.labelSelectionChanged) self.labelList.itemDoubleClicked.connect(self.editLabel) self.labelList.itemChanged.connect(self.labelItemChanged) listLayout.addWidget(self.labelList) self.dock = QDockWidget(u'Label List', self) self.dock.setObjectName(u'Labels') self.dock.setWidget(labelListContainer) self.fileListWidget = QListWidget() self.fileListWidget.itemDoubleClicked.connect( self.fileitemDoubleClicked) filelistLayout = QVBoxLayout() filelistLayout.setContentsMargins(0, 0, 0, 0) filelistLayout.addWidget(self.fileListWidget) fileListContainer = QWidget() fileListContainer.setLayout(filelistLayout) self.filedock = QDockWidget(u'File List', self) self.filedock.setObjectName(u'Files') self.filedock.setWidget(fileListContainer) self.zoomWidget = ZoomWidget() self.colorDialog = ColorDialog(parent=self) self.canvas = Canvas() self.canvas.zoomRequest.connect(self.zoomRequest) scroll = QScrollArea() scroll.setWidget(self.canvas) scroll.setWidgetResizable(True) self.scrollBars = { Qt.Vertical: scroll.verticalScrollBar(), Qt.Horizontal: scroll.horizontalScrollBar() } self.scrollArea = scroll self.canvas.scrollRequest.connect(self.scrollRequest) self.canvas.newShape.connect(self.newShape) self.canvas.shapeMoved.connect(self.setDirty) self.canvas.selectionChanged.connect(self.shapeSelectionChanged) self.canvas.drawingPolygon.connect(self.toggleDrawingSensitive) self.setCentralWidget(scroll) self.addDockWidget(Qt.RightDockWidgetArea, self.dock) self.addDockWidget(Qt.RightDockWidgetArea, self.filedock) self.dockFeatures = QDockWidget.DockWidgetClosable | QDockWidget.DockWidgetFloatable self.dock.setFeatures(self.dock.features() ^ self.dockFeatures) action = partial(newAction, self) open = action('&Open Image', self.openFile, 'I', 'open', u'Open image file') opendir = action('&Open Folder', self.openDir, 'F', 'open', u'Open directory') openNextImg = action('&Next Image', self.openNextImg, 'D', 'next', u'Open next image') openPrevImg = action('&Previous Image', self.openPrevImg, 'A', 'prev', u'Open previous image') save = action('&Save Label', self.saveFile, 'S', 'save', u'Save labels to file', enabled=False) createMode = action('Create Label', self.setCreateMode, 'W', 'new', u'Create new label', enabled=False) editMode = action('&Edit Label', self.setEditMode, 'E', 'edit', u'Move and edit label', enabled=False) delete = action('Delete label', self.deleteSelectedShape, 'Delete', 'delete', u'Delete label', enabled=False) advancedMode = action('&Advanced Mode', self.toggleAdvancedMode, 'Ctrl+Shift+A', 'expert', u'Switch to advanced mode', checkable=True) help = action('&Tutorial', self.tutorial, 'T', 'help', u'Show demo video') zoom = QWidgetAction(self) zoom.setDefaultWidget(self.zoomWidget) self.zoomWidget.setWhatsThis( u"Zoom in or out of the image. Also accessible with" " %s and %s from the canvas." % (fmtShortcut("Ctrl+[-+]"), fmtShortcut("Ctrl+Wheel"))) self.zoomWidget.setEnabled(False) zoomIn = action('Zoom &In', partial(self.addZoom, 10), 'Ctrl++', 'zoom-in', u'Increase zoom level', enabled=False) zoomOut = action('&Zoom Out', partial(self.addZoom, -10), 'Ctrl+-', 'zoom-out', u'Decrease zoom level', enabled=False) zoomOrg = action('&Original size', partial(self.setZoom, 100), 'Ctrl+=', 'zoom', u'Zoom to original size', enabled=False) fitWindow = action('&Fit Window', self.setFitWindow, 'Ctrl+F', 'fit-window', u'Zoom follows window size', checkable=True, enabled=False) fitWidth = action('Fit &Width', self.setFitWidth, 'Ctrl+Shift+F', 'fit-width', u'Zoom follows window width', checkable=True, enabled=False) zoomActions = (self.zoomWidget, zoomIn, zoomOut, zoomOrg, fitWindow, fitWidth) self.zoomMode = self.MANUAL_ZOOM self.scalers = { self.FIT_WINDOW: self.scaleFitWindow, self.FIT_WIDTH: self.scaleFitWidth, self.MANUAL_ZOOM: lambda: 1, } edit = action('&Edit Label', self.editLabel, 'Ctrl+E', 'edit', u'Modify the label of the selected Box', enabled=False) self.editButton.setDefaultAction(edit) shapeLineColor = action( 'Shape &Line Color', self.chshapeLineColor, icon='color_line', tip=u'Change the line color for this specific shape', enabled=False) shapeFillColor = action( 'Shape &Fill Color', self.chshapeFillColor, icon='color', tip=u'Change the fill color for this specific shape', enabled=False) labels = self.dock.toggleViewAction() labels.setText('Label Panel') labels.setShortcut('Ctrl+Shift+L') files = self.filedock.toggleViewAction() files.setText('File Panel') files.setShortcut('Ctrl+Shift+F') labelMenu = QMenu() addActions(labelMenu, (edit, delete)) self.labelList.setContextMenuPolicy(Qt.CustomContextMenu) self.labelList.customContextMenuRequested.connect( self.popLabelListMenu) self.actions = struct(save=save, open=open, create=createMode, delete=delete, edit=edit, createMode=createMode, editMode=editMode, advancedMode=advancedMode, shapeLineColor=shapeLineColor, shapeFillColor=shapeFillColor, zoom=zoom, zoomIn=zoomIn, zoomOut=zoomOut, zoomOrg=zoomOrg, fitWindow=fitWindow, fitWidth=fitWidth, zoomActions=zoomActions, fileMenuActions=(open, opendir, save), beginner=(), advanced=(), editMenu=(edit, delete), beginnerContext=(edit, delete), advancedContext=(save, createMode, editMode), onLoadActive=(createMode, editMode)) self.menus = struct(file=self.menu('&File'), edit=self.menu('&Edit'), view=self.menu('&View'), help=self.menu('&Help'), recentFiles=QMenu('Open &Recent'), labelList=labelMenu) self.autoSaving = QAction("Auto Saving", self) self.autoSaving.setCheckable(True) self.singleClassMode = QAction("Single Class Mode", self) self.singleClassMode.setShortcut("Ctrl+Shift+S") self.singleClassMode.setCheckable(True) self.lastLabel = None addActions(self.menus.file, (open, opendir, openNextImg, openPrevImg)) addActions(self.menus.help, (help, )) addActions(self.menus.view, (labels, files, zoomIn, zoomOut)) self.menus.file.aboutToShow.connect(self.updateFileMenu) addActions(self.canvas.menus[0], self.actions.beginnerContext) addActions(self.canvas.menus[1], (action('&Copy here', self.copyShape), action('&Move here', self.moveShape))) self.tools = self.toolbar('Tools') self.actions.advanced = (None, open, opendir, None, openNextImg, openPrevImg, None, save, createMode, editMode, None, zoomIn, zoomOut, None) self.statusBar().showMessage('%s started.' % __appname__) self.statusBar().show() self.image = QImage() self.filePath = ustr(defaultFilename) self.recentFiles = [] self.maxRecent = 7 self.lineColor = None self.fillColor = None self.zoom_level = 100 self.fit_window = False self.difficult = False self.settings = Settings() self.settings.load() settings = self.settings if settings.get(SETTING_RECENT_FILES): if have_qstring(): recentFileQStringList = settings.get(SETTING_RECENT_FILES) self.recentFiles = [ustr(i) for i in recentFileQStringList] else: self.recentFiles = recentFileQStringList = settings.get( SETTING_RECENT_FILES) size = settings.get(SETTING_WIN_SIZE, QSize(300, 500)) position = settings.get(SETTING_WIN_POSE, QPoint(0, 0)) self.resize(size) self.move(position) saveDir = ustr(settings.get(SETTING_SAVE_DIR, None)) self.lastOpenDir = ustr(settings.get(SETTING_LAST_OPEN_DIR, None)) if saveDir is not None and os.path.exists(saveDir): self.defaultSaveDir = saveDir self.statusBar().showMessage( '%s started. Annotation will be saved to %s' % (__appname__, self.defaultSaveDir)) self.statusBar().show() self.restoreState(settings.get(SETTING_WIN_STATE, QByteArray())) self.lineColor = QColor( settings.get(SETTING_LINE_COLOR, Shape.line_color)) self.fillColor = QColor( settings.get(SETTING_FILL_COLOR, Shape.fill_color)) Shape.line_color = self.lineColor Shape.fill_color = self.fillColor Shape.difficult = self.difficult def xbool(x): if isinstance(x, QVariant): return x.toBool() return bool(x) if xbool(settings.get(SETTING_ADVANCE_MODE, False)): self.actions.advancedMode.setChecked(True) self.toggleAdvancedMode() self.updateFileMenu() self.queueEvent(partial(self.loadFile, self.filePath or "")) self.zoomWidget.valueChanged.connect(self.paintCanvas) self.populateModeActions()
def setAdvanced(self): self.tools.clear() addActions(self.tools, self.actions.advanced)
def setBeginner(self): self.tools.clear() addActions(self.tools, self.actions.beginner)