Example #1
0
 def run(self):
     self.finished.connect(self.onThreadTermination)
     self.avgUpdateProc = QtCore.QProcess()
     # self.avgUpdateProc.open(QtCore.QIODevice.Unbuffered)
     self.avgUpdateProc.destroyed.connect(self.avgProcDestroyed)
     self.avgUpdateProc.readyRead.connect(self.printOut)
     self.avgUpdateProc.finished.connect(self.onAVGProcFinish)
     self.avgUpdateProc.start("gksu", [
         "--description=" + langmodule.avgUpdate,
         "--message=" + langmodule.mustSudo, "avgupdate"
     ])
     try:
         startLocker = QtCore.QMutexLocker(mutexStartCheck)
         while not self.avgUpdateProc.waitForStarted(msecs=2000):
             print(" - avgupdate failed to start - ")
             #self.avgUpdateProc.readyRead.disconnect()
             #self.avgUpdateProc.kill()
             #self.avgUpdateProc.close()
             self.exitCode = 1
             self.avgUpdateProc.finished.emit(self.exitCode)
             #self.avgUpdateProc.start("gksu", ["avgupdate"])
             self.exit()
             return
     except Exception as err:
         print("Failed to initialize Update Process" + str(err))
         return
     self.exec_()
Example #2
0
 def _keyEvent(self, event_type, key):
     if not self.active():
         return
     lock = QtCore.QMutexLocker(self.imgMutex)
     cMods = self.hook.get_current_mods()
     try:
         if not "Shift" in cMods and len(key) == 1:
             key = key.lower()
         qkey = QtGui.QKeySequence(key)[0]
         qtype = QtCore.QEvent.KeyPress if event_type == self.hook.KEY_DOWN else QtCore.QEvent.KeyRelease
         qmod = QtCore.Qt.KeyboardModifiers()
         for m in cMods:
             if m == "Shift":
                 qmod = qmod | QtCore.Qt.ShiftModifier
             if m == "Alt":
                 qmod = qmod | QtCore.Qt.AltModifier
             if m == "Ctrl":
                 qmod = qmod | QtCore.Qt.ControlModifier
         e = QtGui.QKeyEvent(qtype, qkey, qmod, key)
         acdebug("QtKeyEvent for '%s': %d %d %d '%s'", key, e.key(), int(e.modifiers()), qtype, e.text())
         if len(key) == 1 or qkey in [QtCore.Qt.Key_Backspace,
                                      QtCore.Qt.Key_Return,
                                      QtCore.Qt.Key_Enter,
                                      QtCore.Qt.Key_Delete,
                                      QtCore.Qt.Key_Home,
                                      QtCore.Qt.Key_End,
                                      QtCore.Qt.Key_Left,
                                      QtCore.Qt.Key_Up,
                                      QtCore.Qt.Key_Down,
                                      QtCore.Qt.Key_Right]:
             self.app.postEvent(self.page, e)
             return
     except:
         pass
     acdebug("Ignoring key %s", key)
Example #3
0
 def _newPage(self, url, ptsInfo):
     acdebug("qtbrowser: newPage %s", url)
     lock = QtCore.QMutexLocker(self.imgMutex)
     if self.hook is None:
         from ptracker_lib import hooked
         self.hook = hooked.hook()
         self.hook.MouseHandler(self._mouseHook)
         self.hook.RawKeyboardHandler(callback=self._keyEvent, callID=self)
     self.page = MyWebPage()
     # connect signals
     self.page.loadStarted.connect(self.loadStarted)
     self.page.loadFinished.connect(self.loadFinished)
     self.page.loadFinished.connect(self.render)
     self.page.contentsChanged.connect(self.render)
     self.page.repaintRequested.connect(self.renderRect)
     self.page.frameCreated.connect(self.render)
     self.page.scrollRequested.connect(self.render)
     self.page.mainFrame().javaScriptWindowObjectCleared.connect(functools.partial(self.addJavaScriptObjects, page=self.page, ptsInfo=ptsInfo))
     # create a network manager for the page
     #acdebug("creating network manager")
     self.ptsManager = ptsInfo.PtsNetworkAccessManager(self.page.networkAccessManager(), ptsInfo.http_server, ptsInfo.ptracker)
     #acdebug("setting network manager")
     self.page.setNetworkAccessManager(self.ptsManager)
     # load the new url
     #acdebug("load url")
     self.page.mainFrame().load(url)
     # post an event that the page gets the focus (for keyboard inputs)
     self.app.postEvent(self.page, QtGui.QFocusEvent(QtCore.QEvent.FocusIn, QtCore.Qt.MouseFocusReason))
Example #4
0
 def check(self, mousePos):
     lock = QtCore.QMutexLocker(self.imgMutex)
     self.lastCheckTime = time.time()
     if mousePos != self.lastMousePos:
         self.lastMousePos = mousePos
         self.app.postEvent(self.page, QtGui.QMouseEvent(QtCore.QEvent.MouseMove, mousePos, QtCore.Qt.NoButton, QtCore.Qt.NoButton, QtCore.Qt.NoModifier))
     return self.cnt
Example #5
0
 def run(self):
     self.theOutput = ""
     result = None
     #self.avgchkupProc = QtCore.QProcess()
     self.avgchkupProc = QtCore.QProcess()
     self.avgchkupProc.started.connect(self.emitProcStarted)
     self.avgchkupProc.setStandardErrorFile("errfile.txt")
     self.avgchkupProc.open(QtCore.QIODevice.Unbuffered)
     self.avgchkupProc.destroyed.connect(self.procDestroyed)
     self.avgchkupProc.readyRead.connect(self.parseOutput)
     self.avgchkupProc.finished.connect(self.onAVGprocFinish)
     self.finished.connect(self.onThreadTermination)
     #self.avgchkupProc.set
     try:
         startLocker = QtCore.QMutexLocker(mutexStartCheck)
         #print("starting AVGUPDATE process with EUID: " + str(os.geteuid()))
         #print("Now EUID is: " + str(os.geteuid()))
         QtGui.QApplication.processEvents()
         # self.avgchkupProc.start("gksu", ["avgupdate -c"])
         self.avgchkupProc.start("gksu", [
             "--description=" + langmodule.chkUpdate,
             "--message=" + langmodule.mustSudo, "avgupdate -c"
         ])
         #print("started UPDATE PROCESS with state: " + str(self.avgchkupProc.state()))
         if not self.avgchkupProc.waitForStarted(msecs=3000):
             print("SOS: " + str(self.avgchkupProc.state()))
             self.sigFailed.emit(True, "")
             self.exit()
             return
         self.exec_()
         QtGui.QApplication.processEvents()
     except Exception as err:
         print("Failed to initialize QProcess: " + str(err))
         return
Example #6
0
 def generate_output(self,input_file, output_file, temp_hdf5):
     locker = QtCore.QMutexLocker(self.rebin_mutex)
     shutil.copy(input_file, output_file)
     output_hdf5 = h5py.File(output_file, 'r+')   
     del output_hdf5["Experiments/__unnamed__/data"]
     new_ycube = output_hdf5.create_dataset("Experiments/__unnamed__/data",
                                            data = temp_hdf5['cube'])
     output_hdf5.close()
 def requestNewFortune(self, hostname, port):
     locker = QtCore.QMutexLocker(self.mutex)
     self.hostName = hostname
     self.port = port
     if not self.isRunning():
         self.start()
     else:
         self.cond.wakeOne()
Example #8
0
 def _clickEvent(self, x,y):
     if not self.active():
         return
     lock = QtCore.QMutexLocker(self.imgMutex)
     # emulate a mouse click on a position
     pos = QtCore.QPoint(x,y)
     self.app.sendEvent(self.page, QtGui.QMouseEvent(QtCore.QEvent.MouseButtonPress, pos, QtCore.Qt.LeftButton, QtCore.Qt.LeftButton, QtCore.Qt.NoModifier))
     self.app.sendEvent(self.page, QtGui.QMouseEvent(QtCore.QEvent.MouseButtonRelease, pos, QtCore.Qt.LeftButton, QtCore.Qt.LeftButton, QtCore.Qt.NoModifier))
Example #9
0
 def _newSize(self, w, h, zoom):
     lock = QtCore.QMutexLocker(self.imgMutex)
     w = round(w*zoom)
     h = round(h*zoom)
     acdebug("qtbrowser: setting browser size: %d %d", w, h)
     self.size = QtCore.QSize(w,h)
     self.page.mainFrame().setZoomFactor(zoom)
     self.render()
Example #10
0
    def consume(self):
        # when this goes out of scope the lock is opened
        locker = QtCore.QMutexLocker(QdImageLoader._mutex)
        if self._index == len(self._paths):
            return None

        path = self._paths[self._index]
        self._index +=1
        return path
Example #11
0
 def read_into_temp_hdf5(self, temp_hdf5, ycube, rows, columns, slices):
     locker = QtCore.QMutexLocker(self.rebin_mutex)
     temp_cube = temp_hdf5.create_dataset('cube', (rows, columns, slices))
     for input_slice in np.arange(slices):
         if self.stop_rebin:
             return
         image = ycube[:,:,input_slice]
         rebinned_image = self.rebin(image, rows, columns)
         temp_cube[:,:,input_slice] = rebinned_image
         self.update_progress(input_slice)  
     self.progress_window.close()
Example #12
0
    def load(self, paths):
        self._stopped = False
        self.stopLoading()

        # when this goes out of scope the lock is opened
        locker = QtCore.QMutexLocker(QdImageLoader._mutex)

        self._paths = paths
        self._index = 0

        for thread in self._threads:
            thread.start(QtCore.QThread.IdlePriority)
Example #13
0
    def stopLoading(self, emitSignal=False):
        self._stopped = True
        for thread in self._threads:
            thread.wait()
        self._stopped = False

        # when this goes out of scope the lock is opened
        locker = QtCore.QMutexLocker(QdImageLoader._mutex)
        self._paths = []

        if emitSignal:
            self.emit(SIGNAL('loadFinished()'))
Example #14
0
 def generate_output(self, output_filename, temp_hdf5, global_bool, header,
                     list_xdata, dimension1, dimension2):
     locker = QtCore.QMutexLocker(self.convert_mutex)
     output_file = h5py.File(output_filename,'w')
     data_holder = output_file.create_group("Experiments/__unnamed__")       
     self.build_xdata(data_holder, temp_hdf5, list_xdata)
     #self.info = self.build_info()
     self.build_ycube(data_holder, temp_hdf5, global_bool)
     self.write_header(data_holder, header)
     self.add_formatting(output_file, data_holder, list_xdata,
                         dimension1, dimension2)            
     output_file.close()
    def fit_cube_process(self):
        locker = QtCore.QMutexLocker(self.spectrum_holder.cube_mutex)
        self.spectrum_holder.notify_cube_fitting()
        self.spectrum_viewer.textbox_spectrum_box.setReadOnly(True)
        (rows,columns,slices) = np.shape(self.data.ycube[...])
        #self.progress_bar = self.fit_cube_progress_bar(rows*columns)

        value = 0
        self.stop_fit = False
        row_count=0
        for i in np.arange(rows):
            column_count = 0
            for j in np.arange(columns):
                peak_holder = DataHolder()
                ydata = analysis.ydata_calc2(input_ydata=self.data.ycube[i,j,:],
                                             input_xdata = self.data.xdata,
                                             dtype=self.data.xdata_info['data_type'],
                                             display_ev = self.display_ev)
                ydata = np.float64(ydata)
                peak_holder.load_from_mf1_cube(self.xdata[:],
                                               ydata,
                                               j,
                                               i)
                spectrum = peak_holder.get_spectrum(0)
                if row_count == 0:                  
                    self.fit_from_spectrum_holder(spectrum)
                    row_count = 1
                    column_count = 1

                elif column_count == 0:                 
                    index = i*(columns-1)
                    self.fit_from_cube_peaks(spectrum, index)
                    column_count = 1

                else:                    
                    index = -1
                    self.fit_from_cube_peaks(spectrum, index)

                peak_list = []
                for peak in spectrum.peaks.peak_list:
                    peak_list.append(peak.get_spec())
                self.spectrum_holder.cube_peaks.append(peak_list)
                norm_int_res = self.get_normalized_integrated_residuals(spectrum)
                self.spectrum_holder.cube_residuals.append(norm_int_res)
                if self.stop_fit is True:
                    return
                value += 1
                self.update_progress(value)  
        self.progress_window.close()
        self.spectrum_holder.notify_cube_fitted()
        self.spectrum_viewer.textbox_spectrum_box.setReadOnly(False)
        self.spectrum_viewer.label_cube_fitted.setText("Cube Box Loaded")
Example #16
0
    def render(self, centerX, centerY, scaleFactor, resultSize):
        locker = QtCore.QMutexLocker(self.mutex)

        self.centerX = centerX
        self.centerY = centerY
        self.scaleFactor = scaleFactor
        self.resultSize = resultSize

        if not self.isRunning():
            self.start(QtCore.QThread.LowPriority)
        else:
            self.restart = True
            self.condition.wakeOne()
Example #17
0
    def __del__(self):
        """
        Destructor for the worker thread, makes sure that it exits event
        loop gracefully by enqueuing a destructor flag
        """

        locker = QtCore.QMutexLocker(self.mutex)

        # If there are still commands in the queue, clear it
        if len(self.simQueue) != 0:
            self.simQueue.clear()

        self.quit()
        self.wait()
Example #18
0
 def convert_progress_bar(self, maximum):
     """
     progress bar window with stop button
     """
     locker = QtCore.QMutexLocker(self.progress_mutex)
     self.progress_window = QtGui.QWidget()
     self.progress_window.setWindowTitle("Conversion Progress")
     progress_bar = QtGui.QProgressBar()
     button_stop_conversion = QtGui.QPushButton("&Stop Conversion")
     button_stop_conversion.clicked.connect(self.stop_conversion_now)
     progress_bar.setMaximum(maximum)
     box = QtGui.QVBoxLayout()
     box.addWidget(progress_bar)
     box.addWidget(button_stop_conversion)
     self.progress_window.setLayout(box)
     self.progress_window.show()
     return progress_bar
Example #19
0
	def run(self, stuff, hashedPassword, path, binary, arguments, yakuakeTabName):
		print 'BINARY', binary
		print 'PATH', path
		print 'TABNAME', yakuakeTabName
		print 'ARGS', arguments
	
		time.sleep(0.5)
		with QtCore.QMutexLocker(self.mutex) as locker:
			if hashedPassword != hashlib.sha224(stuff+self.passwd).hexdigest():
				print 'WRONG PASSWORD', hashedPassword
				return False
			else:
				if not yakuakeTabName in self.onTheirWay:
					self.onTheirWay.append(yakuakeTabName)
					p = subprocess.Popen(['/opt/robocomp/bin/rcremoteshell', binary, path, yakuakeTabName]+arguments)
					self.onTheirWay.remove(yakuakeTabName)
			time.sleep(0.5)
		return True
Example #20
0
 def render(self, *args):
     if not self.active():
         return
     #acdebug("qtbrowser: rendering %d", self.cnt)
     self.page.setViewportSize(self.size)
     img = QtGui.QImage(self.size, QtGui.QImage.Format_ARGB32_Premultiplied)
     img.fill(QtCore.Qt.transparent)
     palette = QtGui.QApplication.palette()
     palette.setBrush(QtGui.QPalette.Base, QtCore.Qt.transparent)
     self.page.setPalette(palette)
     painter = QtGui.QPainter(img)
     painter.setRenderHint(QtGui.QPainter.Antialiasing)
     painter.setRenderHint(QtGui.QPainter.TextAntialiasing)
     painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform)
     self.page.mainFrame().render(painter)
     painter.end()
     lock = QtCore.QMutexLocker(self.imgMutex)
     self.cnt += 1
     self.img = img
Example #21
0
 def read_into_cube(self, fid, temp_hdf5, global_bool,
                    dimension1, dimension2):
     """read from mf1 file into temporary hdf5 file"""
     locker = QtCore.QMutexLocker(self.convert_mutex)
     if global_bool:
         cube = temp_hdf5.create_dataset('cube',
                                              (dimension1,
                                               dimension2, 1664))
 
         list_xdata = np.fromfile(file=fid, dtype='>f', count=1600)
         
         for i in np.arange(dimension1):
             for j in np.arange(dimension2):
                 if self.stop_convert:
                     return
                 try:
                     cube[i,j,:] = np.fromfile(file=fid,
                                               dtype='>f', count=1664)
                 except:
                     return list_xdata
                 current_spectrum = i*dimension2 + j
                 self.update_progress(current_spectrum)
     else:
         
         cube = temp_hdf5.create_dataset('cube',(dimension1,
                                                 dimension2,
                                                 3264))  
         for i in np.arange(dimension1):
             for j in np.arange(dimension2):
                 if self.stop_convert:
                     return
                 try:
                     cube[i,j,:] = np.fromfile(file=fid, dtype='>f',
                                               count=3264)
                 except:
                     list_xdata = cube[0,0,0:1600]
                     return 
                 current_spectrum = i*dimension2 + j
                 self.update_progress(current_spectrum)
         list_xdata = cube[0,0,0:1600]
     return list_xdata
Example #22
0
 def renderRect(self, dirtyrect):
     if not self.active():
         return
     # avoid a lock over the whole (sometimes quite long lasting) rendering of the page
     # we make a copy of the image at the start, unlock everything
     # and when ready with rednering we can lock ourselfs again
     lock = QtCore.QMutexLocker(self.imgMutex)
     img = QtGui.QImage(self.img)
     lock.unlock()
     #acdebug("qtbrowser: rendering rect %d / %s", self.cnt, dirtyrect)
     painter = QtGui.QPainter(img)
     painter.setRenderHint(QtGui.QPainter.Antialiasing)
     painter.setRenderHint(QtGui.QPainter.TextAntialiasing)
     painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform)
     painter.setCompositionMode(QtGui.QPainter.CompositionMode_Clear)
     painter.fillRect(dirtyrect, QtCore.Qt.transparent)
     painter.setCompositionMode(QtGui.QPainter.CompositionMode_SourceOver)
     self.page.mainFrame().render(painter, dirtyrect)
     painter.end()
     lock.relock()
     self.cnt += 1
     self.img = img
Example #23
0
    def addCommand(self, command, fileName=None):
        """
        Enqueue a new command to the worker thread queue
        """

        locker = QtCore.QMutexLocker(self.mutex)

        # Only enqueue a new command if the thread isn't working on an
        # identical command
        #if command != self.status:
        # Enqueue new command
        self.simQueue.append({'command': command, 'fileName': fileName})

        # If the thread has not started yet, start it
        if not self.keepProcessing and not self.isRunning():
            self.keepProcessing = True
            self.start()

        self.keepProcessing = True

        # Wake the worker thread
        self.commandAdded.wakeOne()
Example #24
0
 def loadStarted(self):
     lock = QtCore.QMutexLocker(self.imgMutex)
     #acdebug("loadStarted")
     self.loading = time.time()
Example #25
0
 def loadFinished(self, ok):
     lock = QtCore.QMutexLocker(self.imgMutex)
     #acdebug("loadFinished")
     self.loading = None
Example #26
0
 def stop_rebin_now(self):
     self.stop_rebin = True
     locker = QtCore.QMutexLocker(self.rebin_mutex)
     self.input_hdf5.close()
     self.temp_hdf5.close()
     self.progress_window.close()
Example #27
0
 def stop(self):
     with QtCore.QMutexLocker(self.mutex):
         self.stopped = True
Example #28
0
 def isStopped(self):
     with QtCore.QMutexLocker(self.mutex):
         return self.stopped
Example #29
0
    def run(self):
        """
        Event loop for worker thread
        """

        self.nextCommand = None
        self.keepProcessing = True

        # Enter event loop
        while True:
            # Lock the thread resources
            locker = QtCore.QMutexLocker(self.mutex)

            # If there are no more commands in the queue, unlock the mutex
            # and wait for a command to be added
            if (self.status == 'stopped' and len(self.simQueue) == 0):
                self.keepProcessing = False
                self.commandAdded.wait(self.mutex)

            # Get the next command from the queue
            self.nextCommand = self.simQueue.popleft()

            # Update status to reflect next command to be run
            self.status = self.nextCommand['command']

            # Let the GUI know that the next command has started
            self.getStatus()

            # If next command comes from the destructor method, break the
            # run loop, delete the network, and exit
            if self.status == 'deleting':
                # Delete the network object and break the loop
                del self.network
                break

            # If a time limit was passed, start the timer only if the next
            # command is a learning task
            if self.stopTimer and self.status == 'learning':
                self.stopTimer.start()

            # stopped flag acts as a check for the learning algorithm's event
            # loop; each iteration of the loop is a single learning cycle. For
            # non-iterative simulator commands, this loop only iterates once
            if self.keepProcessing:
                # Run the next command in queue
                self.network.run(**self.nextCommand)

            # If the next command finishes before the timer times out,
            # stop the timer
            if self.stopTimer and self.stopTimer.isActive():
                self.stopTimer.stop()

            # Unlock the mutex
            locker.unlock()
            # Check if all requested commands are completed
            if len(self.simQueue) == 0:
                # Special case: let the manager know that the thread is stopped
                self.status = 'stopped'
                self.keepProcessing = False

                self.getStatus()

                # Reset the simulator status flags
                self.network.__reset__()
Example #30
0
 def stop_conversion_now(self):
     self.stop_convert = True
     locker = QtCore.QMutexLocker(self.convert_mutex)
     self.temp_hdf5.close()
     os.remove(self.output_filename+'temporary')
     self.progress_window.close()