Пример #1
0
    def eventFilter(self, watched, event):

        if event.type() == QC.QEvent.Resize:

            parent = self.parent()

            if isinstance(parent, ResizingScrolledPanel):

                # weird hack fix for a guy who was getting QPaintEvents in here
                if not hasattr(event, 'oldSize'):

                    return False

                old_size = event.oldSize()
                size = event.size()

                width_larger = size.width() > old_size.width() and size.height(
                ) >= old_size.height()
                height_larger = size.width() >= old_size.width(
                ) and size.height() > old_size.height()

                if width_larger or height_larger:

                    QP.CallAfter(parent.WidgetJustSized, width_larger,
                                 height_larger)

        return False
Пример #2
0
 def THREADdo_it():
     
     try:
         
         mappings = HydrusNATPunch.GetUPnPMappings()
         
     except Exception as e:
         
         HydrusData.ShowException( e )
         
         QP.CallAfter( QW.QMessageBox.critical, self, 'Error', 'Could not load mappings:'+os.linesep*2+str(e) )
         
         return
         
     
     QP.CallAfter( qt_code, mappings )
Пример #3
0
 def __init__( self, parent, controller, read_only, can_generate_more_pages, gallery_seed_log ):
     
     ClientGUIScrolledPanels.EditPanel.__init__( self, parent )
     
     self._controller = controller
     self._read_only = read_only
     self._can_generate_more_pages = can_generate_more_pages
     self._gallery_seed_log = gallery_seed_log
     
     self._text = ClientGUICommon.BetterStaticText( self, 'initialising' )
     
     # add index control row here, hide it if needed and hook into showing/hiding and postsizechangedevent on gallery_seed add/remove
     
     self._list_ctrl = ClientGUIListCtrl.BetterListCtrl( self, CGLC.COLUMN_LIST_GALLERY_SEED_LOG.ID, 30, self._ConvertGallerySeedToListCtrlTuples )
     
     #
     
     self._list_ctrl.AddDatas( self._gallery_seed_log.GetGallerySeeds() )
     
     self._list_ctrl.Sort()
     
     #
     
     vbox = QP.VBoxLayout()
     
     QP.AddToLayout( vbox, self._text, CC.FLAGS_EXPAND_PERPENDICULAR )
     QP.AddToLayout( vbox, self._list_ctrl, CC.FLAGS_EXPAND_BOTH_WAYS )
     
     self.widget().setLayout( vbox )
     
     self._list_ctrl.AddMenuCallable( self._GetListCtrlMenu )
     
     self._controller.sub( self, 'NotifyGallerySeedsUpdated', 'gallery_seed_log_gallery_seeds_updated' )
     
     QP.CallAfter( self._UpdateText )
Пример #4
0
    def CallBlockingToQt(self, win, func, *args, **kwargs):
        def qt_code(win: QW.QWidget, job_key: ClientThreading.JobKey):

            try:

                if win is not None and not QP.isValid(win):

                    raise HydrusExceptions.QtDeadWindowException(
                        'Parent Window was destroyed before Qt command was called!'
                    )

                result = func(*args, **kwargs)

                job_key.SetVariable('result', result)

            except (HydrusExceptions.QtDeadWindowException,
                    HydrusExceptions.DBCredentialsException,
                    HydrusExceptions.ShutdownException) as e:

                job_key.SetErrorException(e)

            except Exception as e:

                job_key.SetErrorException(e)

                HydrusData.Print('CallBlockingToQt just caught this error:')
                HydrusData.DebugPrint(traceback.format_exc())

            finally:

                job_key.Finish()

        job_key = ClientThreading.JobKey()

        QP.CallAfter(qt_code, win, job_key)

        while not job_key.IsDone():

            if HG.model_shutdown:

                raise HydrusExceptions.ShutdownException(
                    'Application is shutting down!')

            time.sleep(0.05)

        if job_key.HasVariable('result'):

            # result can be None, for qt_code that has no return variable

            result = job_key.GetIfHasVariable('result')

            return result

        if job_key.HadError():

            e = job_key.GetErrorException()

            raise e

        raise HydrusExceptions.ShutdownException()
    def __init__(self, parent, title, style=QC.Qt.Dialog, position='topleft'):

        QP.Dialog.__init__(self, parent)

        self.setWindowFlags(style)

        self.setWindowTitle(title)

        if parent is not None and position == 'topleft':

            parent_tlw = self.parentWidget().window()

            pos = parent_tlw.pos() + QC.QPoint(50, 50)

            self.move(pos)

        self.setWindowFlag(QC.Qt.WindowContextHelpButtonHint, on=False)

        self._new_options = HG.client_controller.new_options

        self.setWindowIcon(QG.QIcon(HG.client_controller.frame_icon_pixmap))

        self._widget_event_filter = QP.WidgetEventFilter(self)

        if parent is not None and position == 'center':

            QP.CallAfter(QP.CenterOnWindow, parent, self)

        HG.client_controller.ResetIdleTimer()
Пример #6
0
 def publish_callable( result ):
     
     if isinstance( result, Exception ):
         
         e = result
         
         QP.CallAfter( QW.QMessageBox.critical, self, 'Error', 'Could not load mappings:'+os.linesep*2+str(e) )
         
         self._status_st.setText( str( e ) )
         
         return
         
     
     self._mappings_listctrl_panel.setEnabled( True )
     
     mappings = result
     
     self._mappings_lookup = { ( external_port, protocol ) for ( description, internal_ip, internal_port, external_port, protocol, duration ) in mappings }
     
     self._mappings_list.SetData( mappings )
     
     self._status_st.clear()
     
     if self._external_ip is not None:
         
         self._status_st.setText( self._external_ip )
         
     elif not self._started_external_ip_fetch:
         
         self._started_external_ip_fetch = True
         
         self._RefreshExternalIP()
Пример #7
0
 def __init__( self, parent, controller, file_seed_cache ):
     
     ClientGUIScrolledPanels.EditPanel.__init__( self, parent )
     
     self._controller = controller
     self._file_seed_cache = file_seed_cache
     
     self._text = ClientGUICommon.BetterStaticText( self, 'initialising' )
     
     # add index control row here, hide it if needed and hook into showing/hiding and postsizechangedevent on file_seed add/remove
     
     self._list_ctrl = ClientGUIListCtrl.BetterListCtrl( self, CGLC.COLUMN_LIST_FILE_SEED_CACHE.ID, 30, self._ConvertFileSeedToListCtrlTuples, activation_callback = self._ShowSelectionInNewPage, delete_key_callback = self._DeleteSelected )
     
     #
     
     self._list_ctrl.AddDatas( self._file_seed_cache.GetFileSeeds() )
     
     self._list_ctrl.Sort()
     
     #
     
     vbox = QP.VBoxLayout()
     
     QP.AddToLayout( vbox, self._text, CC.FLAGS_EXPAND_PERPENDICULAR )
     QP.AddToLayout( vbox, self._list_ctrl, CC.FLAGS_EXPAND_BOTH_WAYS )
     
     self.widget().setLayout( vbox )
     
     self._list_ctrl.AddMenuCallable( self._GetListCtrlMenu )
     
     self._controller.sub( self, 'NotifyFileSeedsUpdated', 'file_seed_cache_file_seeds_updated' )
     
     QP.CallAfter( self._UpdateText )
Пример #8
0
        def do_it(service):

            try:

                success = service.EnableNoCopy(True)

            except Exception as e:

                message = 'Problem: {}'.format(str(e))

                QP.CallAfter(QW.QMessageBox.critical, None, 'Error', message)

                success = False

            finally:

                QP.CallAfter(qt_clean_up, success)
Пример #9
0
        def do_it():

            try:

                runner.run(suite)

            finally:

                QP.CallAfter(self.win.deleteLater)
Пример #10
0
    def _BootWorker(self):
        def qt_code():

            if self._window is None or not QP.isValid(self._window):

                return

            self.Work()

        QP.CallAfter(qt_code)
Пример #11
0
        def qt_done(quit_afterwards):

            if not QP.isValid(self) or not QP.isValid(
                    self._export) or not self._export:

                return

            self._export.setEnabled(True)

            if quit_afterwards:

                QP.CallAfter(self.parentWidget().close)
Пример #12
0
        def do_it():

            try:

                result = runner.run(suite)

                self.run_finished = True
                self.was_successful = result.wasSuccessful()

            finally:

                QP.CallAfter(self.win.deleteLater)
        def THREADdo_it():

            try:

                external_ip = HydrusNATPunch.GetExternalIP()

                external_ip_text = 'External IP: {}'.format(external_ip)

            except Exception as e:

                external_ip_text = 'Error finding external IP: ' + str(e)

            QP.CallAfter(qt_code, external_ip_text)
Пример #14
0
        def do_it(service_key):
            def qt_code(recent_tags):

                if not self or not QP.isValid(self):

                    return

                self._last_fetched_tags = recent_tags

                self._UpdateTagDisplay()

            recent_tags = HG.client_controller.Read('recent_tags', service_key)

            QP.CallAfter(qt_code, recent_tags)
Пример #15
0
    def THREADFetchTags(self, script, job_key, file_identifier):
        def qt_code(tags):

            if not self or not QP.isValid(self):

                return

            self._SetTags(tags)

            self._have_fetched = True

        parse_results = script.DoQuery(job_key, file_identifier)

        tags = ClientParsing.GetTagsFromParseResults(parse_results)

        QP.CallAfter(qt_code, tags)
Пример #16
0
 def _doWork( self ):
     
     def qt_deliver_result( result ):
         
         if self._win is None or not QP.isValid( self._win ):
             
             self._win = None
             
             return
             
         
         self._publish_callable( result )
         
     
     with self._lock:
         
         self._calllater_waiting = False
         self._work_needs_to_restart = False
         self._is_working = True
         
     
     try:
         
         result = self._work_callable()
         
         try:
             
             HG.client_controller.CallBlockingToQt( self._win, qt_deliver_result, result )
             
         except ( HydrusExceptions.QtDeadWindowException, HydrusExceptions.ShutdownException ):
             
             self._win = None
             
             return
             
         
     finally:
         
         with self._lock:
             
             self._is_working = False
             
             if self._work_needs_to_restart and not self._calllater_waiting:
                 
                 QP.CallAfter( self.update )
Пример #17
0
    def Update(self, *args, **kwargs):

        if self._win is None:

            return

        with self._lock:

            self._args = args
            self._kwargs = kwargs

            if self._is_working:

                self._work_needs_to_restart = True

            elif not self._callafter_waiting:

                QP.CallAfter(self.QtDoIt)
Пример #18
0
        def do_it(service):

            try:

                version = service.GetDaemonVersion()

                result = 'Running version {}.'.format(version)

                is_running = True

            except Exception as e:

                result = 'Problem: {}'.format(str(e))

                is_running = False

            finally:

                QP.CallAfter(qt_clean_up, result, is_running)
Пример #19
0
 def do_it( service_key, hash, search_tags, max_results, max_time_to_take ):
     
     def qt_code( predicates ):
         
         if not self or not QP.isValid( self ):
             
             return
             
         
         self._last_fetched_predicates = predicates
         
         self._UpdateTagDisplay()
         
         self._have_fetched = True
         
     
     predicates = HG.client_controller.Read( 'related_tags', service_key, hash, search_tags, max_results, max_time_to_take )
     
     predicates = ClientSearch.SortPredicates( predicates )
     
     QP.CallAfter( qt_code, predicates )
Пример #20
0
    def eventFilter(self, watched, event):

        if event.type() == QC.QEvent.Resize:

            parent = self.parent()

            if isinstance(parent, ResizingScrolledPanel):

                old_size = event.oldSize()
                size = event.size()

                width_larger = size.width() > old_size.width() and size.height(
                ) >= old_size.height()
                height_larger = size.width() >= old_size.width(
                ) and size.height() > old_size.height()

                if width_larger or height_larger:

                    QP.CallAfter(parent.WidgetJustSized, width_larger,
                                 height_larger)

        return False
Пример #21
0
 def QtDoIt( self ):
     
     if self._win is None or not QP.isValid( self._win ):
         
         self._win = None
         
         return
         
     
     with self._lock:
         
         self._callafter_waiting = False
         self._work_needs_to_restart = False
         self._is_working = True
         
         args = self._args
         kwargs = self._kwargs
         
     
     try:
         
         self._func( *args, **kwargs )
         
     except HydrusExceptions.ShutdownException:
         
         pass
         
     finally:
         
         with self._lock:
             
             self._is_working = False
             
             if self._work_needs_to_restart and not self._callafter_waiting:
                 
                 self._callafter_waiting = True
                 
                 QP.CallAfter( self.QtDoIt )
Пример #22
0
        def do_it():
            def qt_code():

                if not self or not QP.isValid(self):

                    return

                script_names_to_scripts = {
                    script.GetName(): script
                    for script in scripts
                }

                for (name, script) in list(script_names_to_scripts.items()):

                    self._script_choice.addItem(script.GetName(), script)

                new_options = HG.client_controller.new_options

                favourite_file_lookup_script = new_options.GetNoneableString(
                    'favourite_file_lookup_script')

                if favourite_file_lookup_script in script_names_to_scripts:

                    self._script_choice.SetValue(
                        script_names_to_scripts[favourite_file_lookup_script])

                else:

                    self._script_choice.setCurrentIndex(0)

                self._script_choice.setEnabled(True)
                self._fetch_button.setEnabled(True)

            scripts = HG.client_controller.Read(
                'serialisable_named',
                HydrusSerialisable.SERIALISABLE_TYPE_PARSE_ROOT_FILE_LOOKUP)

            QP.CallAfter(qt_code)
Пример #23
0
        def do_it(service):

            try:

                nocopy_enabled = service.GetNoCopyEnabled()

                if nocopy_enabled:

                    result = 'Nocopy is enabled.'

                else:

                    result = 'Nocopy is not enabled.'

            except Exception as e:

                result = 'Problem: {}'.format(str(e))

                nocopy_enabled = False

            finally:

                QP.CallAfter(qt_clean_up, result, nocopy_enabled)
Пример #24
0
        def do_it(service):

            try:

                nocopy_available = service.GetNoCopyAvailable()

                if nocopy_available:

                    result = 'Nocopy is available.'

                else:

                    result = 'Nocopy is not available.'

            except Exception as e:

                result = 'Problem: {}'.format(str(e))

                nocopy_available = False

            finally:

                QP.CallAfter(qt_clean_up, result, nocopy_available)
Пример #25
0
 def EventShowMenu( self ):
     
     QP.CallAfter( self._ShowMenu )
Пример #26
0
 def _ClickActivated( self, activation_reason ):
     
     # if we click immediately, some users get frozen ui, I assume a mix-up with the icon being destroyed during the same click event or similar
     
     QP.CallAfter( self._WasActivated, activation_reason )
    def EventText(self, text):

        QP.CallAfter(self._CheckText)
Пример #28
0
def boot():

    args = sys.argv[1:]

    if len(args) > 0:

        only_run = args[0]

    else:

        only_run = None

    try:

        threading.Thread(target=reactor.run,
                         kwargs={
                             'installSignalHandlers': 0
                         }).start()

        QP.MonkeyPatchMissingMethods()
        app = QW.QApplication(sys.argv)

        app.call_after_catcher = QP.CallAfterEventCatcher(app)

        try:

            # we run the tests on the Qt thread atm
            # keep a window alive the whole time so the app doesn't finish its mainloop

            win = QW.QWidget(None)
            win.setWindowTitle('Running tests...')

            controller = TestController.Controller(win, only_run)

            def do_it():

                controller.Run(win)

            QP.CallAfter(do_it)

            app.exec_()

        except:

            HydrusData.DebugPrint(traceback.format_exc())

        finally:

            HG.started_shutdown = True

            HG.view_shutdown = True

            controller.pubimmediate('wake_daemons')

            HG.model_shutdown = True

            controller.pubimmediate('wake_daemons')

            controller.TidyUp()

    except:

        HydrusData.DebugPrint(traceback.format_exc())

    finally:

        reactor.callFromThread(reactor.stop)

        print('This was version ' + str(HC.SOFTWARE_VERSION))

        if sys.stdin.isatty():

            input('Press any key to exit.')

        if controller.was_successful:

            sys.exit(0)

        else:

            sys.exit(1)
Пример #29
0
 def seek_event( event ):
     
     QP.CallAfter( qt_seek_event )
Пример #30
0
    def _BootWorker(self):

        QP.CallAfter(self._QTWork)