Пример #1
0
    def update_cache(self, parent=None, timeout=10, force=False,
            suppress_progress=False):
        if self.lock.acquire(False):
            try:
                update_thread = CacheUpdateThread(self.config, self.seralize_books, timeout)
                if not suppress_progress:
                    progress = CacheProgressDialog(parent)
                    progress.set_message(_('Updating MobileRead book cache...'))

                    update_thread.total_changed.connect(progress.set_total)
                    update_thread.update_progress.connect(progress.set_progress)
                    update_thread.update_details.connect(progress.set_details)
                    progress.rejected.connect(update_thread.abort)

                    progress.open()
                    update_thread.start()
                    while update_thread.is_alive() and not progress.canceled:
                        QCoreApplication.processEvents()

                    if progress.isVisible():
                        progress.accept()
                    return not progress.canceled
                else:
                    update_thread.start()
            finally:
                self.lock.release()
Пример #2
0
    def update_cache(self,
                     parent=None,
                     timeout=10,
                     force=False,
                     suppress_progress=False):
        if self.lock.acquire(False):
            try:
                update_thread = CacheUpdateThread(self.cache,
                                                  self.seralize_books, timeout)
                if not suppress_progress:
                    progress = CacheProgressDialog(parent)
                    progress.set_message(
                        _('Updating MobileRead book cache...'))

                    update_thread.total_changed.connect(progress.set_total)
                    update_thread.update_progress.connect(
                        progress.set_progress)
                    update_thread.update_details.connect(progress.set_details)
                    progress.rejected.connect(update_thread.abort)

                    progress.open()
                    update_thread.start()
                    while update_thread.is_alive() and not progress.canceled:
                        QCoreApplication.processEvents()

                    if progress.isVisible():
                        progress.accept()
                    return not progress.canceled
                else:
                    update_thread.start()
            finally:
                self.lock.release()
Пример #3
0
    def emit(self, record):
        """Try to log the message to QGIS if available, otherwise do nothing.

        Args:
            record (): logging record containing whatever info needs to be logged.

        Returns:

        """
        # ToDo:Add the warning/info messages to the form messagebar look at QGIS-master\python\utils.py\showException
        # ??https://gis.stackexchange.com/questions/152730/how-to-add-a-message-bar-to-custom-canvas
        # https://gis.stackexchange.com/questions/135711/why-is-the-display-of-qgsmessagebar-delayed
        # https://gis.stackexchange.com/a/216444
        # Check logging.LogRecord properties for lots of other goodies like line number etc. you can get
        # from the log message.
        try:
            if QgsMessageBar is None:
                return

            if self.lastRec is None or self.lastRec.getMessage(
            ) != record.getMessage():
                QgsMessageLog.logMessage(record.getMessage(), PLUGIN_SHORT,
                                         LOG_MAP[record.levelname]['qgis'])
                self.lastRec = record
            QCoreApplication.processEvents()

        except MemoryError:
            message = 'Due to memory limitations on this machine, PrecisionAg can not handle the full log'
            print(message)
            QgsMessageLog.logMessage(message, PLUGIN_SHORT, 0)
        except IOError:
            pass
        except AttributeError:
            pass
Пример #4
0
 def message(self, msg, ms=2000, sub=False):
     if sub:
         if self._prev_msg:
             msg = ": ".join((self._prev_msg, msg))
     else:
         self._prev_msg = msg
     self.statusBar().showMessage(msg, ms)
     QCoreApplication.processEvents(QEventLoop.ExcludeUserInputEvents)
Пример #5
0
 def message(self, msg, ms=2000, sub=False):
     if sub:
         if self._prev_msg:
             msg = ": ".join((self._prev_msg, msg))
     else:
         self._prev_msg = msg
     self.statusBar().showMessage(msg, ms)
     QCoreApplication.processEvents(QEventLoop.ExcludeUserInputEvents)
Пример #6
0
    def check_library(self):
        from calibre.gui2.dialogs.check_library import CheckLibraryDialog, DBCheck, DBCheckNew

        self.gui.library_view.save_state()
        m = self.gui.library_view.model()
        m.stop_metadata_backup()
        db = m.db
        db.prefs.disable_setting = True

        if hasattr(db, "new_api"):
            d = DBCheckNew(self.gui, db)
        else:
            d = DBCheck(self.gui, db)
        d.start()
        try:
            d.conn.close()
        except:
            pass
        d.break_cycles()
        self.gui.library_moved(db.library_path, call_close=not d.closed_orig_conn)
        if d.rejected:
            return
        if d.error is None:
            if not question_dialog(
                self.gui,
                _("Success"),
                _(
                    "Found no errors in your calibre library database."
                    " Do you want calibre to check if the files in your "
                    " library match the information in the database?"
                ),
            ):
                return
        else:
            return error_dialog(
                self.gui,
                _("Failed"),
                _("Database integrity check failed, click Show details" " for details."),
                show=True,
                det_msg=d.error[1],
            )

        self.gui.status_bar.show_message(_("Starting library scan, this may take a while"))
        try:
            QCoreApplication.processEvents()
            d = CheckLibraryDialog(self.gui, m.db)

            if not d.do_exec():
                info_dialog(
                    self.gui,
                    _("No problems found"),
                    _("The files in your library match the information " "in the database."),
                    show=True,
                )
        finally:
            self.gui.status_bar.clear_message()
Пример #7
0
    def check_library(self):
        from calibre.gui2.dialogs.check_library import CheckLibraryDialog, DBCheck, DBCheckNew
        self.gui.library_view.save_state()
        m = self.gui.library_view.model()
        m.stop_metadata_backup()
        db = m.db
        db.prefs.disable_setting = True

        if hasattr(db, 'new_api'):
            d = DBCheckNew(self.gui, db)
        else:
            d = DBCheck(self.gui, db)
        d.start()
        try:
            d.conn.close()
        except:
            pass
        d.break_cycles()
        self.gui.library_moved(db.library_path,
                               call_close=not d.closed_orig_conn)
        if d.rejected:
            return
        if d.error is None:
            if not question_dialog(
                    self.gui, _('Success'),
                    _('Found no errors in your calibre library database.'
                      ' Do you want calibre to check if the files in your '
                      ' library match the information in the database?')):
                return
        else:
            return error_dialog(
                self.gui,
                _('Failed'),
                _('Database integrity check failed, click Show details'
                  ' for details.'),
                show=True,
                det_msg=d.error[1])

        self.gui.status_bar.show_message(
            _('Starting library scan, this may take a while'))
        try:
            QCoreApplication.processEvents()
            d = CheckLibraryDialog(self.gui, m.db)

            if not d.do_exec():
                info_dialog(
                    self.gui,
                    _('No problems found'),
                    _('The files in your library match the information '
                      'in the database.'),
                    show=True)
        finally:
            self.gui.status_bar.clear_message()
Пример #8
0
def openLogPanel():
    logMessagesPanel = iface.mainWindow().findChild(QDockWidget, 'MessageLog')

    # Check to see if it is already open
    if not logMessagesPanel.isVisible():
        logMessagesPanel.setVisible(True)

    # find and set the active tab
    tabWidget = logMessagesPanel.findChildren(QTabWidget)[0]
    for iTab in range(0, tabWidget.count()):
        if tabWidget.tabText(iTab) == PLUGIN_SHORT:
            tabWidget.setCurrentIndex(iTab)
            break

    QCoreApplication.processEvents()
Пример #9
0
    def updateGraph(self):
        #         try:
        #             self.graph.clear()
        #             print 'yes'
        #         except AttributeError:
        #             print "error"
        #         else:
        #             pass
        #         QtGui.QWidget.__init__(self)
        #         self.canvas = MplCanvas()
        #         #We instantiate the Matplotlib canvas object.
        #         self.vbl = QtGui.QVBoxLayout()
        #         #Here, we create a layout manager (in this case a vertical box).
        #         self.vbl.addWidget(self.canvas)
        #         # We add the Matplotlib canvas to the layout manager.
        #         self.graph.setLayout(self.vbl)
        #         # a figure instance to plot on
        self.figure = plt.figure()
        # this is the Canvas Widget that displays the `figure`
        # it takes the `figure` instance as a parameter to __init__
        self.canvas = FigureCanvas(self.figure)

        #         self.canvas.clf()
        # this is the Navigation widget
        # it takes the Canvas widget and a parent
        self.toolbar = NavigationToolbar(self.canvas, self)

        #         self.layout.reLayout()
        if self.hasLayOUT == True:
            self.clearLayout()
        if self.hasLayOUT == False:
            self.layout = QtGui.QVBoxLayout()
        self.hasLayOUT = True
        self.layout.addWidget(self.toolbar)
        self.layout.addWidget(self.canvas)
        #         self.graph.layout().deleteLater()
        self.graph.setLayout(self.layout)
        self.ControlButton.setVisible(False)
        pos = {}
        for nm, ob in self.provisionals.iteritems():
            x = ob.x
            y = ob.y
            pos[nm] = (x, y)
        for nm, ob in self.control.iteritems():
            x = ob.x
            y = ob.y
            pos[nm] = (x, y)
        nx.draw_networkx_nodes(self.N,
                               pos,
                               node_color='y',
                               node_size=800,
                               alpha=1)
        nx.draw_networkx_nodes(self.N,
                               pos,
                               nodelist=self.control,
                               node_color='r',
                               node_size=800,
                               alpha=1)

        #         ellipse = mpl.patches.Ellipse(xy=(58305,49663), width=1000, height=1000)
        #         fig,ax = plt.subplots()
        # #         self.figure.add_artist(ellipse)
        #         nx.draw_networkx_nodes(ellipse, xy=(self.control['SUR09'].x,self.control['SUR09'].y))
        edges = {}
        for v, u, d in self.N.edges(data=True):
            if d.has_key("distance") and d.has_key('direction'):
                edges[v, u] = 'b'
#         fig = figure()
#         ax = fig.add_subplot(111, aspect='equal')
#         e=(Ellipse((self.control['SUR09'].x,self.control['SUR09'].y), width=100, height=5, angle=45))
#         ax.add_artist(e)
#         plt.plot(self.control['SUR09'].x,self.control['SUR09'].y,'g.', markersize=100.0)                  #([e], [e], 'g.', markersize=20.0)

        nx.draw(self.N, pos)
        nx.draw_networkx_edges(self.N,
                               pos,
                               edgelist=edges,
                               width=8,
                               alpha=0.5,
                               edge_color='b')
        #         nx.draw(Ellipse((self.control['SUR09'].x,self.control['SUR09'].y), width=100, height=5, angle=45,edgecolor=('green')))

        plt.axis('scaled')
        #         nx.set_aspect('auto')

        #         forceAspect(nx,aspect=1)
        #         plt.show()
        #         nx.draw(ellipse)
        #         nx.add_artist(ellipse)
        #     matplotlib.pyplot.ion()
        #     plt.draw()
        #         self.canvas.addAction(ellipse)
        QCoreApplication.processEvents()
        self.canvas.draw()
Пример #10
0
    def updateGraph(self):
#         try:
#             self.graph.clear()
#             print 'yes'
#         except AttributeError:
#             print "error"
#         else:
#             pass
#         QtGui.QWidget.__init__(self)
#         self.canvas = MplCanvas()
#         #We instantiate the Matplotlib canvas object.
#         self.vbl = QtGui.QVBoxLayout()
#         #Here, we create a layout manager (in this case a vertical box).
#         self.vbl.addWidget(self.canvas)
#         # We add the Matplotlib canvas to the layout manager.
#         self.graph.setLayout(self.vbl)
#         # a figure instance to plot on
        self.figure = plt.figure()
        # this is the Canvas Widget that displays the `figure`
        # it takes the `figure` instance as a parameter to __init__
        self.canvas = FigureCanvas(self.figure)

#         self.canvas.clf()
        # this is the Navigation widget
        # it takes the Canvas widget and a parent
        self.toolbar = NavigationToolbar(self.canvas, self)
        
#         self.layout.reLayout()
        if self.hasLayOUT==True:
            self.clearLayout()
        if self.hasLayOUT==False:
            self.layout = QtGui.QVBoxLayout()
        self.hasLayOUT=True
        self.layout.addWidget(self.toolbar)
        self.layout.addWidget(self.canvas)
#         self.graph.layout().deleteLater()
        self.graph.setLayout(self.layout)
        self.ControlButton.setVisible(False)
        pos={}
        for nm,ob in self.provisionals.iteritems():
            x=ob.x
            y=ob.y
            pos[nm]=  (x,y)         
        for nm,ob in self.control.iteritems():
            x=ob.x
            y=ob.y
            pos[nm]=  (x,y)
        nx.draw_networkx_nodes(self.N,pos,
                           node_color='y',
                           node_size=800,
                           alpha=1)
        nx.draw_networkx_nodes(self.N,pos,
                       nodelist=self.control,
                       node_color='r',
                       node_size=800,
                       alpha=1)
        
#         ellipse = mpl.patches.Ellipse(xy=(58305,49663), width=1000, height=1000)
#         fig,ax = plt.subplots()
# #         self.figure.add_artist(ellipse) 
#         nx.draw_networkx_nodes(ellipse, xy=(self.control['SUR09'].x,self.control['SUR09'].y))
        edges={}
        for v,u,d in self.N.edges(data=True):
            if d.has_key("distance") and d.has_key('direction'):
                edges[v,u]='b'
#         fig = figure()
#         ax = fig.add_subplot(111, aspect='equal')
#         e=(Ellipse((self.control['SUR09'].x,self.control['SUR09'].y), width=100, height=5, angle=45))    
#         ax.add_artist(e)
#         plt.plot(self.control['SUR09'].x,self.control['SUR09'].y,'g.', markersize=100.0)                  #([e], [e], 'g.', markersize=20.0) 
          
        nx.draw(self.N,pos)
        nx.draw_networkx_edges(self.N,pos,
                       edgelist=edges,
                       width=8,alpha=0.5,edge_color='b')
#         nx.draw(Ellipse((self.control['SUR09'].x,self.control['SUR09'].y), width=100, height=5, angle=45,edgecolor=('green')))
        
        plt.axis('scaled')
#         nx.set_aspect('auto')
        
#         forceAspect(nx,aspect=1)
#         plt.show()
#         nx.draw(ellipse)
#         nx.add_artist(ellipse)
    #     matplotlib.pyplot.ion()
    #     plt.draw()
#         self.canvas.addAction(ellipse)
        QCoreApplication.processEvents()
        self.canvas.draw()