def _set_reloading(self): with QtCore.QMutexLocker(self._lock): while self._reloading: self._reloading_cond.wait(self._lock) self._reloading = True while self._query_count != 0: self._query_count_cond.wait(self._lock)
def data(self, index, role): """Get value for a specific table cell and QT role. Args: index: QT object indicating table cell. role: QT role. Returns: Value to render in the table cell depending on QT role. """ if not index.isValid(): return None # Set cell background color from config. if role == QtCore.Qt.BackgroundRole: column_color = self._config['column_colors'][index.column()] return QtGui.QColor(column_color[0], column_color[1], column_color[2]) # Set cell string contents from price ladder. if role == QtCore.Qt.DisplayRole: # pylint: disable=unused-variable locker = QtCore.QMutexLocker(self._mutex) if self._price_ladder_df is not None: return self._price_ladder_df.iloc[index.row(), index.column()] return None
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()
def _render(self): frame_index, frame_time = self._clock.get_playback_time_info() with QtCore.QMutexLocker(self._mutex): self._viewer.draw(frame_time) if self._wait_first_frame: self._clock.reset_running_time() self._wait_first_frame = False self.onFrame.emit(frame_index, frame_time)
def _handle_events(self): should_stop = False with QtCore.QMutexLocker(self._mutex): if not self._events and not self._clock.is_running(): self._cond.wait(self._mutex) while self._events: event = self._events.pop(0) should_stop = event() if should_stop: break return should_stop
def set_scene(self, cfg): with QtCore.QMutexLocker(self._mutex): self._scene = cfg['scene'] self._framerate = cfg['framerate'] self._duration = cfg['duration'] self._clear_color = cfg['clear_color'] self._aspect_ratio = cfg['aspect_ratio'] self._samples = cfg['samples'] if self._backend != cfg['backend']: self._backend = cfg['backend'] self._viewer = ngl.Viewer() self._configure_viewer() self._push_event(lambda: self._set_scene())
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()
def update_logic(self): """Function repeatedly called by the worker thread to update the table. Returns: Bool indicating whether table data needs to be updated. """ # Calculate time delay until next price ladder, taking into account # speed of animation. Sleep to ensure animation pace is correct. price_ladder_time_elapsed = ( self._market_data.get_price_ladder_time_elapsed()) time_elapsed = pd.Timestamp.now() - self._start_timestamp # pylint: disable=too-many-function-args delay = (price_ladder_time_elapsed - self._config['speed'] * \ time_elapsed / self._config['speed']) / \ np.timedelta64(1, 's') if delay > 0.0: time.sleep(delay) # Safely update the price ladder and return. # pylint: disable=unused-variable locker = QtCore.QMutexLocker(self._mutex) self._price_ladder_df = self._market_data.get_next_price_ladder_df() return self._price_ladder_df is not None
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: stuff_pass = str(stuff + self.passwd).encode('utf-8') if hashedPassword != hashlib.sha224(stuff_pass).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
def set_scene(self, cfg): with QtCore.QMutexLocker(self._mutex): need_reconfigure = False self._scene = cfg['scene'] self._framerate = cfg['framerate'] self._duration = cfg['duration'] self._aspect_ratio = cfg['aspect_ratio'] if self._clear_color != cfg['clear_color']: self._clear_color = cfg['clear_color'] need_reconfigure = True if self._samples != cfg['samples']: self._samples = cfg['samples'] need_reconfigure = True if self._backend != cfg['backend']: self._backend = cfg['backend'] need_reconfigure = True if need_reconfigure: self._viewer.set_scene(None) self._configure_viewer() else: viewport = misc.get_viewport(self._width, self._height, self._aspect_ratio) self._viewer.resize(self._width, self._height, viewport) self._push_event(lambda: self._set_scene())
def dec_query_count(self): with QtCore.QMutexLocker(self._lock): self._query_count -= 1 self._query_count_cond.wakeAll()
def inc_query_count(self): with QtCore.QMutexLocker(self._lock): while self._reloading: self._reloading_cond.wait(self._lock) self._query_count += 1
def resize(self, width, height): with QtCore.QMutexLocker(self._mutex): self._width = width self._height = height viewport = misc.get_viewport(width, height, self._aspect_ratio) self._viewer.resize(width, height, viewport)
def _push_event(self, event): with QtCore.QMutexLocker(self._mutex): self._events.append(event) self._cond.wakeAll()
def stop(self): with QtCore.QMutexLocker(self.mutex): self.stopped = True
def restart(self): with QtCore.QMutexLocker(self.mutex): self.stopped = False
def resize(self, width, height): with QtCore.QMutexLocker(self._mutex): self._width = width self._height = height self._configure_viewer()
def _set_reloaded(self): with QtCore.QMutexLocker(self._lock): self._reloading = False self._reloading_cond.wakeAll()
def cancel(self, stop): with QtCore.QMutexLocker(self.mutex): self.should_stop = stop self.notify_is_running.emit(not stop)