def load_data(self, param_file): with open(param_file, 'r') as inputf: self.parameters = json.load(inputf) # Set imported parameters as properties for parameter in self.parameters: setattr(self, parameter, self.parameters[parameter]) # use for threadsafe commnications with the GUI thread self.mutex = QMutex() self.atmosphere = Atmosphere() # TODO Error analysis vs. ticksize self.ticksize = 0.001 self.time = 0 self.height = self.launch_height self.velocity = 0 self.acceleration = 0 self.max_height = 0 self.max_velocity = 0 self.max_acceleration = 0 self.mass = self.launch_mass self.thruster = Thruster() self.data = {} self.data['time'] = [] self.data['height'] = [] self.data['velocity'] = [] self.data['acceleration'] = []
def __init__(self, parent, db): QObject.__init__(self, parent) self.internet_connection_failed = False self._parent = parent self.no_internet_msg = _('Cannot download news as no internet connection ' 'is active') self.no_internet_dialog = d = error_dialog(self._parent, self.no_internet_msg, _('No internet connection'), show_copy_button=False) d.setModal(False) self.recipe_model = RecipeModel() self.db = db self.lock = QMutex(QMutex.Recursive) self.download_queue = set() self.news_menu = QMenu() self.news_icon = QIcon(I('news.png')) self.scheduler_action = QAction(QIcon(I('scheduler.png')), _('Schedule news download'), self) self.news_menu.addAction(self.scheduler_action) self.scheduler_action.triggered[bool].connect(self.show_dialog) self.cac = QAction(QIcon(I('user_profile.png')), _('Add or edit a custom news source'), self) self.cac.triggered[bool].connect(self.customize_feeds) self.news_menu.addAction(self.cac) self.news_menu.addSeparator() self.all_action = self.news_menu.addAction( _('Download all scheduled news sources'), self.download_all_scheduled) self.timer = QTimer(self) self.timer.start(int(self.INTERVAL * 60 * 1000)) self.timer.timeout.connect(self.check) self.oldest = gconf['oldest_news'] QTimer.singleShot(5 * 1000, self.oldest_check)
def __init__(self, parent=None): super(ZOpenGLView, self).__init__(parent) self.parent = parent self.timerThread = None self.renderingInterval = 30 self.mutex = QMutex()
def __init__(self, parent=None, delay=50): QtCore.QObject.__init__(self) self.parent = parent self.delay = delay self.mutex = QMutex() self.run = True self.actionModule = ActionModule(None)
def __init__(self): super().__init__() self.ui = Ui_Dialog() self.ui.setupUi(self) self.canvasMutex = QMutex( ) # protects canvas (probably redundant since I don't use workers) self.timer = QtCore.QTimer() self.timer.timeout.connect(self.draw_step) # connect actions self.ui.drawPushButton.clicked.connect(self.redraw_background) self.ui.startPushButton.clicked.connect(self.start_presentation) self.ui.stopPushButton.clicked.connect(self.timer.stop) self.ui.stepPushButton.clicked.connect(self.on_step_pushed) self.ui.functionEdit.textChanged.connect(self.set_redraw_needed) self.ui.x0DoubleSpinBox.valueChanged.connect(self.set_redraw_needed) self.ui.leftIntervalSpinBox.valueChanged.connect( self.set_redraw_needed) self.ui.rightIntervalSpinBox.valueChanged.connect( self.set_redraw_needed) self.ui.xyCheckBox.clicked.connect(self.set_redraw_needed) self.eps = 1e-15 self.itTBD = 0 self.xx = None # x axes - linspace from left self.gx = None # lambda function g(x) self.xc = None # current value of x self.redraw = True # indicates that old values are no longer valid! self.show()
def __init__(self, parent=None, sizey=100, rangey=[0, 100], delay=1000): QtCore.QObject.__init__(self) self.parent = parent self.sizey = sizey self.rangey = rangey self.delay = delay self.mutex = QMutex() self.y = [0 for i in range(sizey)] self.run = True
def __init__(self): self.mutex = QMutex() self.timeStamps = None self.stream = None self.inlet = None self.info = None self.channelCount = None self.doRec = False self.srate = None self.data = None self.bufferUpdateThread = None
def __init__(self, ip_port, game_rules): self.server_data = dict.copy(self.get_network_packet_definition()) self.setup_game_rules_to_server_data(game_rules) self._dealer = DealerClass(data=self.server_data) self.mutex = QMutex() self.conn_player_number = 0 self.conn_players_addresses = [0 for x in range(MAX_CLIENTS)] self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: self.s.bind(ip_port) except socket.error as e: str(e) self.s.listen(MAX_CLIENTS) print("Server Started... Waiting for a connection") thread = threading.Thread(target=self.server_listening_for_new_connections_loop, args=()) thread.start()
def __init__(self): super().__init__() self.setupUi(self) self.rec_selction() self.send_selction() self.timer = QTimer() self.timer1 = QTimer() # self.time_now = time.strftime('%H:%M:%S',time.localtime()) self.timer1.timeout.connect(self.time_now) self.timer.timeout.connect(self.data_send) self.ser = serial.Serial() self.port_check() self.thread = Worker() self.qmut = QMutex() con = config.Myform() self.comboBox_port.addItem(con.com) self.comboBox_baud.setCurrentText(con.baud) self.comboBox_databit.setCurrentText(con.databit) self.comboBox_polarity.setCurrentText(con.polarity) self.comboBox_stopbit.setCurrentText(con.stopbit) self.comboBox_baud.currentIndexChanged.connect(self.combox_baud_cb) self.comboBox_databit.currentIndexChanged.connect(self.combox_databit_cb) self.comboBox_polarity.currentIndexChanged.connect(self.combox_polarity_cb) self.comboBox_stopbit.currentIndexChanged.connect(self.combox_stopbit_cb) self.btn_send.clicked.connect(self.btn_send_cb) self.action_start.setEnabled(True) self.action_Pause.setEnabled(False) self.action_Stop.setEnabled(False) self.action_start.triggered.connect(self.action_start_cb) self.action_Pause.triggered.connect(self.action_Pause_cb) self.action_Clear.triggered.connect(self.action_Clear_cb) self.action_Stop.triggered.connect(self.action_Stop_cb) self.Infor = QAction('串口信息',self) self.menu_2.addAction(self.Infor) self.Infor.triggered.connect(self.display_cb)
def __init__(self, rest): QObject().__init__(self) self.mutex = QMutex()
} Range = [ 0.002, 0.00632, 0.02, 0.0632, 0.2, 0.632, 2, 6.32, 20, 63.2, 200, 632, 2000, 6320, 20000, 63200, 200000, 632000, 2000000, 6320000, 20000000, 63200000 ] def find_n_sub_str(src, sub, pos, start): index = src.find(sub, start) if index != -1 and pos > 0: return find_n_sub_str(src, sub, pos - 1, index + 1) return index mutex = QMutex() class Write(QObject): signal_begin = pyqtSignal(str) def __init__(self, rest): QObject().__init__(self) self.mutex = QMutex() def WriteCMD(self, command): self.mutex.lock() print("Command: " + command) BridgeSerial.write(str.encode(command)) readline = BridgeSerial.readline() if command.startswith('RDGRNG '):
def __init__(self, tray_icon): QThread.__init__(self) self.tray_icon = tray_icon self.mutex = QMutex()
from PyQt5.Qt import (QApplication, QWidget, QPushButton, QThread, QMutex, pyqtSignal) import sys import time qmutex_1 = QMutex() # 创建线程锁 qmutex_2 = QMutex() # 继承QThread class Thread_1(QThread): # 线程1 def __init__(self): super().__init__() def run(self): qmutex_1.lock() # 加锁 values = [1, 2, 3, 4, 5] for i in values: print(i) time.sleep(0.5) # 休眠 qmutex_1.unlock() # 解锁 class Thread_2(QThread): # 线程2 _signal = pyqtSignal() def __init__(self): super().__init__() def run(self): # qmutex_2.lock() # 加锁
from PyQt5.Qt import (QApplication, QWidget, QPushButton, QThread, QMutex, pyqtSignal) import sys import time qmut_1 = QMutex() # 创建线程锁 qmut_2 = QMutex() # 继承QThread class Thread_1(QThread): # 线程1 def __init__(self): super().__init__() def run(self): qmut_1.lock() # 加锁 values = [1, 2, 3, 4, 5] for i in values: print(i) time.sleep(0.5) # 休眠 qmut_1.unlock() # 解锁 class MyWin(QWidget): def __init__(self): super().__init__() # 按钮初始化 self.btn_1 = QPushButton('按钮1', self) self.btn_1.move(120, 80) self.btn_1.clicked.connect(self.click_1) # 绑定槽函数
self.flag_time_edit.text()) self.close() def dele_staff(self): temp = "<font size='9'>是否删除id为" + self.dele_staff_edit.text( ) + "的员工</font>" message = QMessageBox.warning(self, "警告", temp, QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if message == QMessageBox.Yes: delete_data(int(self.dele_staff_edit.text())) elif message == QMessageBox.No: self.dele_staff_edit.clear() lock = QMutex() # 创建进程锁 class ThreadIntoDB(QThread): def __init__(self, idn=None, parent=None): super().__init__(parent) self.id = idn def run(self): lock.lock() pics = os.listdir(Path_face + self.id) feature_list = [] feature_average = [] for i in range(len(pics)): pic_path = Path_face + self.id + "/" + pics[i] print("读取成功:", pic_path)
self.display.setText("请选择文件!") else: self.write_sign = auto_w.Read(self.docx_in.text()) self.write_sign.str_out.connect(self.display_out) self.write_sign.start() @pyqtSlot(str) def prompt_out(self, i): self.prompt.setText(i) @pyqtSlot(str) def display_out(self, i): self.display.setText(i) lock = QMutex() class ThreadRW(QThread): str_out = pyqtSignal(str) def __init__(self, wfile=None, item=None, parent=None): super().__init__(parent) self.W_file = wfile # word文件名 self.Item = item # 类型选项 self.number = 0 # 记录差 self.num = 0 # 列表下表值 self.t_number = 5 # 表格index self.t_number_copy = 0 # 复制表格index self.t_rows = 1 # 表格的行index self.example_name = [] # 用例名称
from oil_hmi_pro_ui import * from save_states import create_group_state # QT相关 from PyQt5.Qt import QMutex, pyqtSignal from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QApplication, QMainWindow, QDesktopWidget from PyQt5.QtGui import QIcon fake = False # 虚拟执行标志 """ python中内置数据类型(int、list、dict)的操作都是原子的,多线程读写不需要加锁 """ # 互斥锁 command_arr_mutex = QMutex() # 发送给Oil_driver的控制指令 command_arr = Int32MultiArray() # ROS中自定义的数据类型,保险起见,对其读写加锁 command_cnt = 4 command_arr.data = [0]*command_cnt # 0:使能 1:复位 2:置零 3:急停, PubThread及主线程按钮函数均会写,须加锁 joint_ctl_arr = [0]*7 # 关节控制标志位, 可弃用 vel_scaling = 0.0 # 速度调整比例 movej_rad_deg_flag = 1 # 角度显示单位切换标志, 默认为角度 movel_rad_deg_flag = 1 # 角度显示单位切换标志, 默认为角度 movel_m_cm_flag = 1 # 距离显示单位切换标志, 默认为米 curr_joints = [0.0]*7 # 当前关节角 goal_joints = [0.0]*7 # 目标关节角 curr_pose = [0.0]*7 # 当前位置