Python源码示例:PyQt5.QtCore.Qt.ApplicationModal()
示例1
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.setWindowModality(Qt.ApplicationModal)
self.setLayout(QVBoxLayout())
self.setMaximumSize(300, 200)
self.setMinimumSize(300, 200)
self.resize(300, 200)
self.listWidget = QListWidget(self)
self.listWidget.setAlternatingRowColors(True)
self.listWidget.setSelectionMode(self.listWidget.MultiSelection)
self.layout().addWidget(self.listWidget)
self.dialogButton = QDialogButtonBox(self)
self.dialogButton.setStandardButtons(self.dialogButton.Ok)
self.dialogButton.accepted.connect(self.accept)
self.layout().addWidget(self.dialogButton)
self.retranslateUi()
self._discoverer = Discoverer()
self._discoverer.discovered.connect(self._new_peer, Connection.QtQueued)
示例2
def __init__(self, pkmeter, parent=None):
with open(self.TEMPLATE) as tmpl:
template = ElementTree.fromstring(tmpl.read())
PKWidget.__init__(self, template, self, parent)
self.pkmeter = pkmeter # Save reference to pkmeter
self._init_window() # Init ui window elements
self.values = self.load() # Active configuration values
self.listitems = [] # List of items in the sidebar
self.datatable = self._init_datatable() # Init reusable data table
self.pconfigs = self._init_pconfigs() # Reference to each plugin config
self.setWindowFlags(Qt.Dialog)
self.setWindowModality(Qt.ApplicationModal)
示例3
def __init__(self, pipe, app_mode=False, **kwargs):
super().__init__(**kwargs)
self.setWindowTitle(translate('GstPipelineEdit', 'Edit Pipeline'))
self.setWindowModality(Qt.ApplicationModal)
self.setMaximumSize(500, 400)
self.setMinimumSize(500, 400)
self.resize(500, 400)
self.setLayout(QVBoxLayout())
# GstPipeEdit
self.pipeEdit = GstPipeEdit(pipe, app_mode=app_mode, parent=self)
self.layout().addWidget(self.pipeEdit)
# Confirm/Cancel buttons
self.dialogButtons = QDialogButtonBox(self)
self.dialogButtons.setStandardButtons(QDialogButtonBox.Cancel |
QDialogButtonBox.Ok)
self.layout().addWidget(self.dialogButtons)
self.dialogButtons.accepted.connect(self.accept)
self.dialogButtons.rejected.connect(self.reject)
示例4
def __init__(self, service: VideoService, parent=None, flags=Qt.Dialog | Qt.WindowCloseButtonHint):
super(StreamSelector, self).__init__(parent, flags)
self.service = service
self.parent = parent
self.streams = service.streams
self.config = service.mappings
self.setObjectName('streamselector')
self.setWindowModality(Qt.ApplicationModal)
self.setWindowTitle('Media streams - {}'.format(os.path.basename(self.parent.currentMedia)))
buttons = QDialogButtonBox(QDialogButtonBox.Ok, self)
buttons.accepted.connect(self.close)
layout = QVBoxLayout()
layout.setSpacing(15)
if len(self.streams.video):
layout.addWidget(self.video())
if len(self.streams.audio):
layout.addWidget(self.audio())
if len(self.streams.subtitle):
layout.addWidget(self.subtitles())
layout.addWidget(buttons)
self.setLayout(layout)
示例5
def __init__(self, parent=None):
with open(self.TEMPLATE) as tmpl:
template = ElementTree.fromstring(tmpl.read())
PKWidget.__init__(self, template, self, parent)
self.setWindowTitle('About PKMeter')
self.setWindowFlags(Qt.Dialog)
self.setWindowModality(Qt.ApplicationModal)
self.setWindowIcon(QtGui.QIcon(QtGui.QPixmap('img:logo.png')))
self.layout().setContentsMargins(0,0,0,0)
self.layout().setSpacing(0)
self._init_stylesheet()
self.manifest.version.setText('Version %s' % VERSION)
self.manifest.qt.setText('QT v%s, PyQT v%s' % (QT_VERSION_STR, PYQT_VERSION_STR))
示例6
def _init_window(self):
# Load core stylesheet
stylepath = os.path.join(SHAREDIR, 'pkmeter.css')
with open(stylepath) as handle:
self.setStyleSheet(handle.read())
# Init self properties
self.setWindowTitle('PKMeter Preferences')
self.setWindowModality(Qt.ApplicationModal)
self.setWindowIcon(QtGui.QIcon(QtGui.QPixmap('img:logo.png')))
self.layout().setContentsMargins(10,10,10,10)
# Init window elements
self.manifest.tabbar.setExpanding(False)
self.manifest.tabbar.addTab('Settings')
self.manifest.tabbar.addTab('Data')
self.manifest.contents.setSizePolicy(QtWidgets.QSizePolicy(
QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Expanding))
self.manifest.tabbar.currentChanged.connect(self.load_tab)
# Init the ListWidget
listwidget = self.manifest.list
for module in sorted(self.pkmeter.modules.values(), key=self._sortKey):
if getattr(module, 'Plugin', None) or getattr(module, 'Config', None):
item = QtWidgets.QListWidgetItem(utils.name(module), parent=listwidget, type=0)
item.setData(NAMESPACE_ROLE, utils.namespace(module))
listwidget.addItem(item)
self.manifest.list.itemSelectionChanged.connect(self.load_tab)
示例7
def __init__(self, maximum, parent=None):
super().__init__(parent)
self.setWindowModality(Qt.ApplicationModal)
self.setWindowTitle(translate('ReplayGain', 'Processing files ...'))
self.setMaximumSize(320, 110)
self.setMinimumSize(320, 110)
self.resize(320, 110)
self.setMaximum(maximum)
self.setLabelText('0 / {0}'.format(maximum))
示例8
def __init__(self, parent=None, theme: str='light', flags=Qt.Dialog | Qt.WindowCloseButtonHint):
super(UpdaterMsgBox, self).__init__(parent, flags)
self.parent = parent
self.theme = theme
self.setWindowTitle('{} updates'.format(qApp.applicationName()))
self.setWindowModality(Qt.ApplicationModal)
self.setObjectName('updaterdialog')
self.loading = VCProgressDialog(self.parent)
self.loading.setText('contacting server')
self.loading.setMinimumWidth(485)
self.loading.show()
示例9
def __init__(self, center_widget, title, parent, hide_close=False):
super().__init__(None)
self.setupUi(self)
self.setModal(True)
self.setObjectName("GreyedDialog")
self.setWindowModality(Qt.ApplicationModal)
self.button_close.apply_style()
if platform.system() == "Windows":
# SplashScreen on Windows freezes the Window
self.setWindowFlags(Qt.FramelessWindowHint)
else:
# FramelessWindowHint on Linux (at least xfce) is less pretty
self.setWindowFlags(Qt.SplashScreen)
self.setAttribute(Qt.WA_TranslucentBackground)
self.center_widget = center_widget
self.main_layout.addWidget(center_widget)
if not title and hide_close:
self.widget_title.hide()
if title:
self.label_title.setText(title)
if hide_close:
self.button_close.hide()
main_win = ParsecApp.get_main_window()
if main_win:
if main_win.isVisible():
self.setParent(main_win)
self.resize(main_win.size())
else:
self.showMaximized()
self.move(0, 0)
else:
logger.error("GreyedDialog did not find the main window, this is probably a bug")
self.setFocus()
self.accepted.connect(self.on_finished)
self.rejected.connect(self.on_finished)
示例10
def show_login_dialog(self):
"""显示登录对话框"""
login_dialog = LoginDialog(self._config)
login_dialog.clicked_ok.connect(self.call_login_luncher)
login_dialog.setWindowModality(Qt.ApplicationModal)
login_dialog.exec()
示例11
def __init__(self):
super().__init__(None, Qt.WindowSystemMenuHint | Qt.WindowTitleHint)
self.setWindowTitle('Help')
self.setWindowModality(Qt.ApplicationModal)
self.create_dialog()
示例12
def __init__(self, parent):
super().__init__(None, Qt.WindowSystemMenuHint | Qt.WindowTitleHint)
self.parent = parent
self.setWindowModality(Qt.ApplicationModal)
self.create_dialog()
示例13
def __init__(self, parent=None):
if Figure is None:
return
super().__init__(parent)
self.setWindowModality(Qt.ApplicationModal)
self.parent = parent
self.canvas = PlotCanvas(self)
self.toolbar = NavigationToolbar(self.canvas, self)
self.create_dialog()
示例14
def create_contract_win(self):
# 增加合约槽函数,弹出合约设置窗口
self.set_default_value()
self.main_contractWin.setWindowModality(Qt.ApplicationModal) # 阻塞父窗口
self.main_contractWin.show()
示例15
def contractSelect(self, exchange, commodity, contract):
self.contractSelectWin = ContractSelect(exchange, commodity, contract)
self.contractSelectWin.setObjectName("ContractSelectWin")
self.main_contractSelectWin = FramelessWindow()
# self.main_contractSelectWin.setFixedSize(750, 550)
# 设置窗口的大小和位置
_pGeometry = self.main_contractWin.frameGeometry()
self.main_contractSelectWin.resize(_pGeometry.width() * 1.5, _pGeometry.height() * 1.5)
self.main_contractSelectWin.center(_pGeometry)
self.main_contractSelectWin.titleBar.theseSelect.hide()
self.main_contractSelectWin.titleBar.iconLabel.hide()
self.main_contractSelectWin.disabledMaximumBtn()
self.main_contractSelectWin.disabledMinimunBtn()
self.main_contractSelectWin.setWindowTitle('选择合约')
self.main_contractSelectWin.titleBar.buttonClose.clicked.connect(self.main_contractSelectWin.close)
self.main_contractSelectWin.setWidget(self.contractSelectWin)
if self._control.mainWnd.getWinThese() == '浅色':
style = CommonHelper.readQss(WHITESTYLE)
else:
style = CommonHelper.readQss(DARKSTYLE)
self.main_contractSelectWin.setStyleSheet('')
self.main_contractSelectWin.setStyleSheet(style)
self.main_contractSelectWin.setWindowModality(Qt.ApplicationModal) # 阻塞父窗口
self.main_contractSelectWin.show()
self.contractSelectWin.confirm.clicked.connect(self.set_contract)
self.contractSelectWin.cancel.clicked.connect(self.main_contractSelectWin.close)
示例16
def update_contract(self):
items = self.contractTableWidget.selectedItems()
if not items:
return
row = items[0].row()
item = self.contractTableWidget.item(row, 4)
sample_dict = json.loads(item.text())
# ------------------设置合约-----------------------------
self.contractWin.contractCodeLineEdit.setText(sample_dict.get('contract'))
self.contractWin.contractCodeLineEdit.setEnabled(False)
self.contractWin.select.setEnabled(False)
# ------------------设置k线类型--------------------------
k_type = ['T', 'S', 'M', 'D']
t = sample_dict.get('KLineType')
self.contractWin.kLineTypeComboBox.setCurrentIndex(k_type.index(t))
# ------------------设置k线周期--------------------------
if not t == 'T': # k线类型不是分笔的时候设置k线周期
k_period = [1, 2, 3, 5, 10, 15, 30, 60, 120]
self.contractWin.kLinePeriodComboBox.setCurrentIndex(k_period.index(int(sample_dict.get('KLineSlice'))))
else: # k线类型为分笔的时候,k线周期设置不可用
self.contractWin.kLinePeriodComboBox.setEnabled(False)
# ------------------设置运算起始点-----------------------
if sample_dict.get('AllK'):
self.contractWin.AllkLineRadioButton.setChecked(True)
elif sample_dict.get('BeginTime'):
self.contractWin.startDateRadioButton.setChecked(True)
temp = sample_dict.get('BeginTime')
text = "".join(temp.split("-"))
self.contractWin.startDateLineEdit.setText(text)
elif sample_dict.get('UseSample'): # TODO 确认条件True还是False时候执行
self.contractWin.historyRadioButton.setChecked(True)
elif sample_dict.get('KLineCount'):
self.contractWin.qtyRadioButton.setChecked(True)
self.contractWin.qtylineEdit.setText(str(sample_dict.get('KLineCount')))
else:
pass
self.contractWin.row = row
self.main_contractWin.setWindowModality(Qt.ApplicationModal) # 阻塞父窗口
self.main_contractWin.show()
示例17
def __init__(self, parent=None):
super().__init__(parent)
self.filepath = ''
self.setWindowModality(Qt.ApplicationModal)
self.setWindowTitle(translate('LayoutSelect', 'Layout selection'))
self.setMaximumSize(675, 300)
self.setMinimumSize(675, 300)
self.resize(675, 300)
self.setLayout(QGridLayout(self))
self.layout().setContentsMargins(5, 5, 5, 5)
self.layoutCombo = QComboBox(self)
self.layoutCombo.currentIndexChanged.connect(self.show_description)
self.layout().addWidget(self.layoutCombo, 0, 0)
self.confirmButton = QPushButton(self)
self.confirmButton.setText(translate('LayoutSelect', 'Select layout'))
self.layout().addWidget(self.confirmButton, 0, 1)
self.fileButton = QPushButton(self)
self.fileButton.setText(translate('LayoutSelect', 'Open file'))
self.layout().addWidget(self.fileButton, 0, 2)
self.layout().setColumnStretch(0, 3)
self.layout().setColumnStretch(1, 2)
self.layout().setColumnStretch(2, 1)
line = QFrame(self)
line.setFrameShape(QFrame.HLine)
line.setFrameShadow(QFrame.Sunken)
self.layout().addWidget(line, 1, 0, 1, 3)
self.description = QTextBrowser(self)
self.layout().addWidget(self.description, 2, 0, 1, 3)
for layout_class in layouts.get_layouts():
self.layoutCombo.addItem(layout_class.NAME, layout_class)
if self.layoutCombo.count() == 0:
raise Exception('No layout installed!')
self.confirmButton.clicked.connect(self.accept)
self.fileButton.clicked.connect(self.open_file)
示例18
def __init__(self, peers, **kwargs):
super().__init__(**kwargs)
self.peers = peers
self.setWindowModality(Qt.ApplicationModal)
self.setMaximumSize(500, 200)
self.setMinimumSize(500, 200)
self.resize(500, 200)
self.setLayout(QHBoxLayout())
self.listWidget = QListWidget(self)
self.listWidget.setAlternatingRowColors(True)
self.layout().addWidget(self.listWidget)
for peer in self.peers:
self.listWidget.addItem(peer['uri'])
self.buttonsLayout = QVBoxLayout()
self.layout().addLayout(self.buttonsLayout)
self.discoverPeersButton = QPushButton(self)
self.addPeerButton = QPushButton(self)
self.removePeerButton = QPushButton(self)
self.removeAllButton = QPushButton(self)
self.discoverPeersButton.clicked.connect(self.discover_peers)
self.addPeerButton.clicked.connect(self.add_peer)
self.removePeerButton.clicked.connect(self.remove_peer)
self.removeAllButton.clicked.connect(self.remove_all)
self.buttonsLayout.addWidget(self.discoverPeersButton)
self.buttonsLayout.addWidget(self.addPeerButton)
self.buttonsLayout.addWidget(self.removePeerButton)
self.buttonsLayout.addWidget(self.removeAllButton)
self.buttonsLayout.addSpacing(70)
self.dialogButton = QDialogButtonBox(self)
self.dialogButton.setStandardButtons(self.dialogButton.Ok)
self.dialogButton.accepted.connect(self.accept)
self.buttonsLayout.addWidget(self.dialogButton)
self.layout().setStretch(0, 2)
self.layout().setStretch(1, 1)
self.retranslateUi()
示例19
def change_ok_btn(self):
if self._user and self._pwd:
if self._user not in self._config.users_name:
self._cookie = None
if self._cookie:
up_info = {"name": self._user, "pwd": self._pwd, "cookie": self._cookie, "work_id": -1}
if self.ok_btn.text() == "切换用户":
self._config.change_user(self._user)
else:
self._config.set_infos(up_info)
self.clicked_ok.emit()
self.close()
elif USE_WEB_ENG:
self.web = LoginWindow(self._user, self._pwd)
self.web.cookie.connect(self.get_cookie_by_web)
self.web.setWindowModality(Qt.ApplicationModal)
self.web.exec()
elif os.path.isfile(self._cookie_assister):
try:
result = os.popen(f'{self._cookie_assister} {self._user} {self._pwd}')
cookie = result.read()
try:
self._cookie = {kv.split("=")[0].strip(" "): kv.split("=")[1].strip(" ") for kv in cookie.split(";")}
except: self._cookie = None
if not self._cookie:
return None
up_info = {"name": self._user, "pwd": self._pwd, "cookie": self._cookie, "work_id": -1}
self._config.set_infos(up_info)
self.clicked_ok.emit()
self.close()
except: pass
else:
title = "请使用 Cookie 登录或是选择 登录辅助程序"
msg = '没有输入 Cookie,或者没有找到登录辅助程序!\n\n' + \
'推荐使用浏览器获取 cookie 填入 cookie 输入框\n\n' + \
'如果不嫌文件体积大,请下载登录辅助程序:\n' + \
'https://github.com/rachpt/lanzou-gui/releases'
message_box = QMessageBox(self)
message_box.setStyleSheet(btn_style)
message_box.setWindowTitle(title)
message_box.setText(msg)
message_box.setStandardButtons(QMessageBox.Close)
buttonC = message_box.button(QMessageBox.Close)
buttonC.setText('关闭')
message_box.exec()
示例20
def __call__(self, data, parent=None):
"""Detect slow waves on the data.
Parameters
----------
data : instance of Data
data used for detection
parent : QWidget
for use with GUI, as parent widget for the progress bar
Returns
-------
instance of graphoelement.Arousals
description of the detected arousals
"""
if parent is not None:
progress = QProgressDialog('Finding arousals', 'Abort',
0, data.number_of('chan')[0], parent)
progress.setWindowModality(Qt.ApplicationModal)
arousal = Arousals()
arousal.chan_name = data.axis['chan'][0]
all_arousals = []
for i, chan in enumerate(data.axis['chan'][0]):
lg.info('Detecting arousals on chan %s', chan)
time = hstack(data.axis['time'])
dat_orig = hstack(data(chan=chan))
if 'HouseDetector' in self.method:
arou_in_chan = detect_HouseDetector(dat_orig, data.s_freq, time,
self)
else:
raise ValueError('Unknown method')
for ar in arou_in_chan:
ar.update({'chan': chan})
all_arousals.extend(arou_in_chan)
if parent is not None:
progress.setValue(i)
if progress.wasCanceled():
return
# end of loop over chan
arousal.events = sorted(all_arousals, key=lambda x: x['start'])
if parent is not None:
progress.setValue(i + 1)
return arousal
示例21
def __call__(self, data, parent=None):
"""Detect slow waves on the data.
Parameters
----------
data : instance of Data
data used for detection
parent : QWidget
for use with GUI, as parent widget for the progress bar
Returns
-------
instance of graphoelement.SlowWaves
description of the detected SWs
"""
if parent is not None:
progress = QProgressDialog('Finding slow waves', 'Abort',
0, data.number_of('chan')[0], parent)
progress.setWindowModality(Qt.ApplicationModal)
slowwave = SlowWaves()
slowwave.chan_name = data.axis['chan'][0]
all_slowwaves = []
for i, chan in enumerate(data.axis['chan'][0]):
lg.info('Detecting slow waves on chan %s', chan)
time = hstack(data.axis['time'])
dat_orig = hstack(data(chan=chan))
if 'Massimini2004' in self.method:
sw_in_chan = detect_Massimini2004(dat_orig, data.s_freq, time,
self)
else:
raise ValueError('Unknown method')
for sw in sw_in_chan:
sw.update({'chan': chan})
all_slowwaves.extend(sw_in_chan)
if parent is not None:
progress.setValue(i)
if progress.wasCanceled():
return
# end of loop over chan
slowwave.events = sorted(all_slowwaves, key=lambda x: x['start'])
if parent is not None:
progress.setValue(i + 1)
return slowwave
示例22
def add_events(self, event_list, name=None, chan=None, parent=None):
"""Add series of events. Faster than calling add_event in a loop.
Parameters
----------
event_list : list of dict
each dict is an event with 'start' and 'end' times
name : str, optional
save events to this event type.
chan : str or list of str, optional
save events to this or these channel(s). If None, channel will be
read from the event list dict under 'chan'
"""
if name is not None:
evt_name = name
if name not in self.event_types:
self.add_event_type(name)
events = self.rater.find('events')
if parent is not None:
progress = QProgressDialog('Saving events', 'Abort',
0, len(events) - 1, parent)
progress.setWindowModality(Qt.ApplicationModal)
for i, evt in enumerate(event_list):
if name is None:
evt_name = evt['name']
if evt_name not in self.event_types:
self.add_event_type(evt_name)
pattern = "event_type[@type='" + evt_name + "']"
event_type = events.find(pattern)
new_event = SubElement(event_type, 'event')
event_start = SubElement(new_event, 'event_start')
event_start.text = str(evt['start'])
event_end = SubElement(new_event, 'event_end')
event_end.text = str(evt['end'])
one_chan = chan
if chan is None:
one_chan = evt['chan']
if isinstance(one_chan, (tuple, list)):
one_chan = ', '.join(one_chan)
event_chan = SubElement(new_event, 'event_chan')
event_chan.text = one_chan
event_qual = SubElement(new_event, 'event_qual')
event_qual.text = 'Good'
if parent is not None:
progress.setValue(i)
if progress.wasCanceled():
return
self.save()
if parent is not None:
progress.close()