def __init__(self): """ Constructor """ super(WebBrowserSpellCheckingPage, self).__init__() self.setupUi(self) self.setObjectName("WebBrowserSpellCheckingPage") # set initial values self.spellCheckEnabledCheckBox.setChecked( Preferences.getWebBrowser("SpellCheckEnabled")) self.on_spellCheckEnabledCheckBox_clicked() if Globals.isMacPlatform(): self.__dictionaryDirectories = { QDir.cleanPath(QCoreApplication.applicationDirPath() + "/../Resources/qtwebengine_dictionaries"), QDir.cleanPath(QCoreApplication.applicationDirPath() + "/../Frameworks/QtWebEngineCore.framework" "/Resources/qtwebengine_dictionaries"), } else: self.__dictionaryDirectories = { QDir.cleanPath(QCoreApplication.applicationDirPath() + "/qtwebengine_dictionaries"), QDir.cleanPath( QLibraryInfo.location(QLibraryInfo.DataPath) + "/qtwebengine_dictionaries"), } self.spellCheckDictionaryDirectoriesEdit.setPlainText("\n".join( self.__dictionaryDirectories)) # try to create these directories, if they don't exist for directory in self.__dictionaryDirectories: if not os.path.exists(directory): try: os.makedirs(directory) except os.error: # ignore it pass self.__writeableDirectories = [] for directory in self.__dictionaryDirectories: if os.access(directory, os.W_OK): self.__writeableDirectories.append(directory) self.manageDictionariesButton.setEnabled( bool(self.__writeableDirectories)) self.__populateDictionariesList()
def slot_ok(self): self.setWindowModality(Qt.ApplicationModal) imgStretch_dict['input_dir'] = self.lineEdit_input.text() imgStretch_dict['output_dir'] = self.lineEdit_output.text() # nodata = self.spinBox_nodata.value() imgStretch_dict['NoData'] = self.spinBox_nodata.value() imgStretch_dict['OutBits'] = self.comboBox_outbits.currentText() imgStretch_dict['StretchRange']=self.spinBox_range.value() imgStretch_dict['CutValue']=self.spinBox_cutvalue.value() # ss = QCoreApplication.applicationDirPath() QDir.setCurrent(QCoreApplication.applicationDirPath()) # change current dir to "venv/bin/" ''' save parameters into xml ''' ret =0 ret = image_normalize(imgStretch_dict) if ret !=0: print("Error: failed to normalize images") else: QMessageBox.information(self, 'Prompt', self.tr("Images stretched !")) self.setWindowModality(Qt.NonModal) # xmlfile = '../../metadata/image_stretch_inputs.xml' # generate_xml_from_dict(imgStretch_dict, xmlfile) # # QMessageBox.information(self, 'Prompt', self.tr("Have saved the xml file !")) # # one_stretch = ImageStretch(imgStretch_dict) # # one_stretch.stretch_all_image_from_dict() # one_stretch = ImageStretch(inputXml=xmlfile) # one_stretch.stretch_all_image_from_xml() # QMessageBox.information(self, 'Prompt', self.tr("Images stretched !")) self.setWindowModality(Qt.NonModal)
def launch_qt_gui(bk, prefs): supports_theming = (bk.launcher_version() >= 20200117) app = QApplication(sys.argv) # Make plugin match Sigil's light/dark theme if supports_theming: if bk.colorMode() == "dark": app.setStyle(QStyleFactory.create("Fusion")) app.setPalette(dark_palette(bk.color)) print('Application dir: {}'.format(QCoreApplication.applicationDirPath())) # Install qtbase translator for standard dialogs and such. # Use the Sigil language setting unless manually overridden. qt_translator = QTranslator() if prefs['language_override'] is not None: print('Plugin preferences language override in effect') qmf = 'qtbase_{}'.format(prefs['language_override']) else: qmf = 'qtbase_{}'.format(bk.sigil_ui_lang) # Get bundled or external translations directory qt_trans_dir = getQtTranslationsPath(bk._w.appdir) print('Qt translation dir: {}'.format(qt_trans_dir)) print('Looking for {} in {}'.format(qmf, qt_trans_dir)) qt_translator.load(qmf, qt_trans_dir) print('Translator succesfully installed: {}'.format( app.installTranslator(qt_translator))) ex = App(bk, prefs) ex.show() app.exec_() return _DETAILS
def _appDirPath(cls): ''' string path to app's dir. This wraps Qt method of same name, but succeeds even if not exist a QApplication instance. Credit K.Knowles see http://qt-project.org/forums/viewthread/20672 ''' # temp instance because applicationDirPath requires it and sys.argv _ = QCoreApplication(sys.argv) result = QCoreApplication.applicationDirPath() logAlert('appDirPath: {}'.format(result)) # !!! temp instance of QCA will now be garbage collected. # We don't want it to hang around, so QApplication.instance() won't find it. return result
def slot_ok(self): self.setWindowModality(Qt.ApplicationModal) QDir.setCurrent(QCoreApplication.applicationDirPath()) # change current dir to "venv/bin/" min =self.spinBox_min.value() max=self.spinBox_max.value() assert (min<=max) valid_labels=list(range(min,max+1)) input_path = self.lineEdit_input.text() if not os.path.isdir(input_path): QMessageBox.warning(self, "Warning", self.tr("input path is not exist!")) sys.exit(-1) instance = DataCheck_and_modify(valid_labels) instance.select_invalid_values(input_path) QMessageBox.information(self, 'Prompt', self.tr("Check completely !")) self.setWindowModality(Qt.NonModal)
def __init__(self, parent=None): super(Dice, self).__init__(parent) self.application_dir = QCoreApplication.applicationDirPath() self.__project = Project( self ) # used as an empty default project, replaced by load_project() self.__desk = None self.__settings = None self.__home = None qmlRegisterType(Project, "DICE", 1, 0, "Project") self.__theme = Theme(self) self.__memory = MemoryInfo(self) self.__error = ErrorHandler(self) qmlRegisterType(MemoryInfo, "DICE", 1, 0, "MemoryInfo") qmlRegisterType(ErrorHandler, "DICE", 1, 0, "ErrorHandler") qmlRegisterType(BasicWrapper, "DICE", 1, 0, "BasicWrapper") qmlRegisterType(Camera, "DICE", 1, 0, "Camera") self.__app_log_buffer = {} self.__app_log_write_interval = 500 self.__app_log_writer = self.__init_log_writer() self.__qml_engine = None self.__qml_context = None self.__app_window = None self.__main_window = None self.__core_apps = CoreAppListModel(self) qmlRegisterType(CoreApp, "DICE", 1, 0, "CoreApp") qmlRegisterType(BasicApp, "DICE", 1, 0, "BasicApp") self.executor = ThreadPoolExecutor( max_workers=2) # TODO: set the max_workers from a configuration self.core_app_loaded.connect(self.__insert_core_app, Qt.QueuedConnection) self.__app_candidates = None self.__current_loading_core_app_index = 0 self.__load_next_core_app( ) # load the first core app in this thread, but the other in the executor
def slot_ok(self): self.setWindowModality(Qt.ApplicationModal) inputDict = imgClip_dict inputDict['input_file']=self.lineEdit_input.text() inputDict['output_file']=self.lineEdit_output.text() inputDict['x']=self.spinBox_x.value() inputDict['y']=self.spinBox_y.value() inputDict['row']=self.spinBox_row.value() inputDict['column']=self.spinBox_column.value() QDir.setCurrent(QCoreApplication.applicationDirPath()) # change current dir to "venv/bin/" ret =0 ret = image_clip(inputDict) if ret !=0: print("Error: failed to clip images") else: QMessageBox.information(self, 'Prompt', self.tr("Images cliped !")) self.setWindowModality(Qt.NonModal)
def slot_ok(self): self.setWindowModality(Qt.ApplicationModal) inputDict = imgClip_dict inputDict['input_file'] = self.lineEdit_input.text() inputDict['output_file'] = self.lineEdit_output.text() inputDict['x'] = self.spinBox_x.value() inputDict['y'] = self.spinBox_y.value() inputDict['row'] = self.spinBox_row.value() inputDict['column'] = self.spinBox_column.value() QDir.setCurrent(QCoreApplication.applicationDirPath() ) # change current dir to "venv/bin/" xmlFileName = '../../metadata/image_clip_inputs.xml' generate_xml_from_dict(inputDict, xmlFileName) QMessageBox.information(self, 'Prompt', self.tr("Have saved the xml file !")) instance = ImageClip(inputDict) instance.image_clip_from_dict() QMessageBox.information(self, 'Prompt', self.tr("Images clipped !")) self.setWindowModality(Qt.NonModal)
def __init__(self, parent=None): super(Dice, self).__init__(parent) self.application_dir = QCoreApplication.applicationDirPath() self.__project = Project(self) # used as an empty default project, replaced by load_project() self.__desk = None self.__settings = None self.__home = None qmlRegisterType(Project, "DICE", 1, 0, "Project") self.__theme = Theme(self) self.__memory = MemoryInfo(self) self.__error = ErrorHandler(self) qmlRegisterType(MemoryInfo, "DICE", 1, 0, "MemoryInfo") qmlRegisterType(ErrorHandler, "DICE", 1, 0, "ErrorHandler") qmlRegisterType(BasicWrapper, "DICE", 1, 0, "BasicWrapper") qmlRegisterType(Camera, "DICE", 1, 0, "Camera") self.__app_log_buffer = {} self.__app_log_write_interval = 500 self.__app_log_writer = self.__init_log_writer() self.__qml_engine = None self.__qml_context = None self.__app_window = None self.__main_window = None self.__core_apps = CoreAppListModel(self) qmlRegisterType(CoreApp, "DICE", 1, 0, "CoreApp") qmlRegisterType(BasicApp, "DICE", 1, 0, "BasicApp") self.executor = ThreadPoolExecutor(max_workers=2) # TODO: set the max_workers from a configuration self.core_app_loaded.connect(self.__insert_core_app, Qt.QueuedConnection) self.__app_candidates = None self.__current_loading_core_app_index = 0 self.__load_next_core_app() # load the first core app in this thread, but the other in the executor
class ApplicationWindow(QMainWindow): ## Accessing files in Processed Stuff ## QDir.setCurrent(QCoreApplication.applicationDirPath()) processedVideoPath = QDir.currentPath() + "/ProcessedStuff/horses_1_predicted.mp4"; textFilePath = QDir.currentPath() + "/ProcessedStuff/labels_example.txt"; # Environmental Variable # os.environ['PYTHONPATH'] = "$(pwd)/detection:$(pwd)/detection/slim" # subprocess.check_call(['sqsub', '-np', sys.argv[1], 'application.py'], # env=dict(os.environ, SQSUB_VAR="visible in this subprocess")) ## Important variables ## videoLoaded = False fileReceived = False playing = False fileName = None labels = [] nextLine = 0 def __init__(self): # Create the Qt5 application backend super(ApplicationWindow, self).__init__() # Load in and display the UI self.ui = Ui_MainWindow() self.ui.setupUi(self) ## CONNECT EVENTS (like button presses) to functions ## self.ui.button_play_pause.clicked.connect(self.playPauseButtonClicked) self.ui.button_load.clicked.connect(self.loadButtonClicked) self.ui.button_track.clicked.connect(self.trackButtonClicked) # Configure the original video widget self.original_video_player = QMediaPlayer(None, QMediaPlayer.VideoSurface) self.original_video_player.durationChanged.connect(self.durationChanged) self.original_video_player.setVideoOutput(self.ui.original_video_widget) # Configure the processed video widget self.video_player = QMediaPlayer(None, QMediaPlayer.VideoSurface) self.video_player.setNotifyInterval(30) self.video_player.durationChanged.connect(self.durationChanged) self.video_player.positionChanged.connect(self.positionChanged) self.video_player.stateChanged.connect(self.stopped) self.video_player.setVideoOutput(self.ui.video_widget) # Configure the video slider self.ui.video_slider.sliderPressed.connect(self.sliderPressed) self.ui.video_slider.sliderReleased.connect(self.sliderReleased) # Update states self.updateStates() ## CALLBACK FUNCTIONS ## def playPauseButtonClicked(self): if self.playing: print("Pause!") self.pause() else: print("Play!") self.play() def saveButtonClicked(self): print("Save!") def loadButtonClicked(self): print("Load!") # fileName, _ = QFileDialog.getOpenFileName( # self, # "Choose a video", # QStandardPaths.writableLocation(QStandardPaths.DocumentsLocation), # "Vide files (*mp4 *mp3)") # file = open("ProcessedStuff/labels_example.txt","w") # file.write("labels = []\n") # file.close() fileName, _ = QFileDialog.getOpenFileName(self, "Open Files") if fileName != "": self.ui.file_info.setText(fileName) print("Video filepath: " + fileName) self.fileName = fileName self.fileReceived = True self.nextLine = 0 self.updateStates() def trackButtonClicked(self): print("Track!") # Do processing and call following method when completed # detection.detection_code(self.fileName) self.processingFinished() def sliderReleased(self): newPosition = self.ui.video_slider.value() self.setPosition(newPosition) def sliderPressed(self): self.pause() def durationChanged(self): self.videoLoaded = True self.updateStates() self.ui.video_slider.setMaximum(self.video_player.duration()) def positionChanged(self): if not self.playing: return position = self.video_player.position() # Update video progress bar self.ui.video_slider.setValue(position) # Update information label self.updateLabel(position) def stopped(self): if self.video_player.state() == QMediaPlayer.StoppedState: self.playing = False self.ui.label_info.setText("") ## Helper Functions ## def play(self): self.original_video_player.play() self.video_player.play() self.playing = True def pause(self): self.playing = False self.original_video_player.pause() self.video_player.pause() def setPosition(self, position): self.resetNextLine(position) self.updateLabel(position) self.original_video_player.setPosition(position) self.video_player.setPosition(position) self.play() def updateStates(self): self.ui.button_play_pause.setEnabled(self.videoLoaded) self.ui.video_slider.setEnabled(self.videoLoaded) self.ui.button_track.setEnabled(self.fileReceived and not self.playing) def processingFinished(self): print("Text file location: " + self.textFilePath) file = open(self.textFilePath, "r") self.labels = [line.split(',') for line in file] file.close() print(self.processedVideoPath) self.video_player.setMedia(QMediaContent(QUrl.fromLocalFile(self.processedVideoPath))) self.original_video_player.setMedia(QMediaContent(QUrl.fromLocalFile(self.fileName))) self.play() # When the user changes the slider the next line changes def resetNextLine(self, position): while (position < int(self.labels[self.nextLine][0])): self.nextLine -= 1 if (self.nextLine <= 0): break if self.nextLine+1<=len(self.labels)-1: while (position >= int(self.labels[self.nextLine+1][0])): self.nextLine += 1 if (self.nextLine >= len(self.labels)-1): break def updateLabel(self, position): if position >= int(self.labels[self.nextLine][0]): label = self.labels[self.nextLine] messageStr = "Count: " + label[1] for i in range(2,len(label),2): messageStr += ("\n%s. %s %s" % (i-int(i/2),label[i],label[i+1])) self.ui.label_info.setText(messageStr) if self.nextLine < len(self.labels)-1: self.nextLine += 1