Python PyQt5.QtGui 模块,QIcon() 实例源码
我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用PyQt5.QtGui.QIcon()。
def __init__(self, ebeveyn=None):
super(Son, self).__init__(ebeveyn)
self.e = ebeveyn
self.kapanacak_mi =False
kutu = qgridLayout()
self.setLayout(kutu)
milis_logo = QLabel()
milis_logo.setAlignment(Qt.AlignCenter)
milis_logo.setpixmap(Qpixmap("./resimler/milis-logo.svg"))
kutu.addWidget(milis_logo,0,1,2)
self.veda_label = QLabel()
self.veda_label.setAlignment(Qt.AlignCenter)
self.veda_label.setWordWrap(True)
kutu.addWidget(self.veda_label,2)
self.denemeye_devam = qradiobutton()
self.denemeye_devam.setIcon(QIcon("./resimler/cik.svg"))
self.denemeye_devam.setIconSize(QSize(50,50))
self.denemeye_devam.toggled.connect(self.degisti)
kutu.addWidget(self.denemeye_devam,2,1)
self.kapat = qradiobutton()
self.kapat.setIcon(QIcon("./resimler/yeniden-baslat.svg"))
self.kapat.setIconSize(QSize(50,50))
self.kapat.toggled.connect(self.degisti)
kutu.addWidget(self.kapat,1)
self.denemeye_devam.setChecked(True)
def setupUi(self, FileInfoDialog):
FileInfoDialog.setobjectName("FileInfoDialog")
FileInfoDialog.resize(579, 472)
icon = QtGui.QIcon()
icon.addpixmap(QtGui.Qpixmap("icons/157-stats-bars.png"), QtGui.QIcon.normal, QtGui.QIcon.Off)
FileInfoDialog.setwindowIcon(icon)
self.gridLayout = QtWidgets.qgridLayout(FileInfoDialog)
self.gridLayout.setobjectName("gridLayout")
self.gridLayout_2 = QtWidgets.qgridLayout()
self.gridLayout_2.setobjectName("gridLayout_2")
self.tabWidget = QtWidgets.QTabWidget(FileInfoDialog)
self.tabWidget.setobjectName("tabWidget")
self.gridLayout_2.addWidget(self.tabWidget, 0, 1, 1)
self.buttonBox = QtWidgets.QDialogButtonBox(FileInfoDialog)
self.buttonBox.setorientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Close)
self.buttonBox.setobjectName("buttonBox")
self.gridLayout_2.addWidget(self.buttonBox, 1)
self.gridLayout.addLayout(self.gridLayout_2, 1)
self.retranslateUi(FileInfoDialog)
self.tabWidget.setCurrentIndex(-1)
self.buttonBox.accepted.connect(FileInfoDialog.accept)
self.buttonBox.rejected.connect(FileInfoDialog.reject)
QtCore.QMetaObject.connectSlotsByName(FileInfoDialog)
def __init__(self):
super(ProjectsWidget, self).__init__()
self.projects_list = ProjectListWidget()
# Buttons
self.new_project_button = QtWidgets.QPushButton(QtGui.QIcon(icons.add), 'New')
self.copy_project_button = QtWidgets.QPushButton(QtGui.QIcon(icons.copy), 'copy current')
self.delete_project_button = QtWidgets.QPushButton(QtGui.QIcon(icons.delete), 'Delete current')
# Layout
self.h_layout = QtWidgets.QHBoxLayout()
self.h_layout.addWidget(header('Current Project:'))
self.h_layout.addWidget(self.projects_list)
self.h_layout.addWidget(self.new_project_button)
self.h_layout.addWidget(self.copy_project_button)
self.h_layout.addWidget(self.delete_project_button)
self.setLayout(self.h_layout)
self.setSizePolicy(QtWidgets.QSizePolicy(
QtWidgets.QSizePolicy.Maximum,
QtWidgets.QSizePolicy.Maximum)
)
self.connect_signals()
def setup_help_menu(self):
bug_icon = QtGui.QIcon(icons.debug)
help_menu = QtWidgets.QMenu('&Help', self.window)
help_menu.addAction(
self.window.icon,
'&About Activity browser',
self.about)
help_menu.addAction(
'&About Qt',
lambda: QtWidgets.QMessageBox.aboutQt(self.window)
)
help_menu.addAction(
bug_icon,
'&Report Bug on github',
self.raise_issue_github
)
help_menu.addAction(
bug_icon,
'&Report Bug',
self.raise_issue_from_app
)
return help_menu
def progress_start(title: str = '', length: int = 100, label: str = ''):
MainUiProgress.progress = QProgressDialog()
MainUiProgress.progress.setwindowFlags(Qt.FramelessWindowHint)
MainUiProgress.progress.setwindowFlags(Qt.WindowTitleHint)
MainUiProgress.progress.setMinimumWidth(400)
from PyQt5.QtWidgets import QPushButton
# QString() seems to be deprecated in v5
# PyQt does not support setCancelButton(0) as it expects a QPushButton instance
# Get your shit together,Qt !
MainUiProgress.progress.findChild(QPushButton).hide()
MainUiProgress.progress.setMinimumDuration(1)
MainUiProgress.progress.setwindowModality(Qt.ApplicationModal)
MainUiProgress.progress.setCancelButtonText('')
MainUiProgress.progress.setwindowIcon(QIcon(':/ico/app.ico'))
MainUiProgress.progress.setwindowTitle(title)
MainUiProgress.progress.setLabelText(label)
MainUiProgress.progress.setMaximum(length)
MainUiProgress.progress.show()
def __init__(self, root, source):
super(Application, self).__init__(sys.argv)
self.setwindowIcon(QtGui.QIcon(ICON_PATH))
engine = QtQml.QQmlApplicationEngine()
engine.objectCreated.connect(self.on_object_created)
engine.warnings.connect(self.on_warnings)
engine.addImportPath(QML_IMPORT_DIR)
try:
io.install()
except IOError:
raise # Server refused to connect
terminal.init()
controller = control.Controller(root, self)
engine.rootContext().setContextProperty("controller", controller)
engine.rootContext().setContextProperty("terminal", terminal.model)
self.engine = engine
self.controller = controller
engine.load(QtCore.QUrl.fromLocalFile(source))
def __init__(self, user_data_control):
super().__init__()
sys.excepthook = self._displayError
self._udc = user_data_control
self.check = Qpixmap("res/check.png")
self.cancel = Qpixmap("res/cancel.png")
self.setGeometry(500, 500, 465)
self.init_ui()
self.init_window()
self.init_user_data()
self.setwindowTitle(self.APP_TITLE)
self.setwindowIcon(QIcon('res/rabbit.png'))
center(self)
self.show()
# PyQt Error Handling
def __init__(self, addons, parent):
super().__init__()
self.setGeometry(300, 300, 300)
self.setwindowTitle('Open Addon')
self.setwindowIcon(QIcon(ICON_PATH))
label = QLabel('Choose the addon you want to open.')
grid = qgridLayout()
grid.setSpacing(4)
grid.addWidget(label, 0)
self.addonList = addons.split('-')
self.addonList.remove('')
self.parent = parent
for i,j in enumerate(self.addonList):
l = QLabel(str(i)+' -> '+j)
grid.addWidget(l, i+1, 0)
self.setLayout(grid)
self.show()
def __init__(self):
"""
Set up the interface
"""
super(Application, self).__init__()
global selector
self.setwindowTitle("OnCue")
self.setwindowIcon(QtGui.QIcon("OnCue.ico"))
self.resize(900, 900)
self.setMinimumSize(self.size())
self.setMaximumSize(self.size())
self.setwindowFlags(QtCore.Qt.FramelessWindowHint)
selector = QtWidgets.QStackedWidget()
self.setCentralWidget(selector)
states["interface"]["ui"] = [MAIN(), PREFERENCES()]
[selector.addWidget(ui) for ui in states["interface"]["ui"]]
def main_window(app, translator, cntlr=None):
"""Run the main exectuable."""
from PyQt5.QtCore import QSize
from PyQt5.QtGui import QIcon
from scctool.controller import MainController
from scctool.view.main import MainWindow
try:
"""Run the main program."""
icon = QIcon()
icon.addFile(getAbsPath('src/scct.ico'), QSize(32, 32))
icon.addFile(getAbsPath('src/scct.png'), QSize(256, 256))
app.setwindowIcon(icon)
if cntlr is None:
cntlr = MainController()
MainWindow(cntlr, app, translator)
logger.info("Starting...")
return cntlr
except Exception as e:
logger.exception("message")
raise
def regime_batch_finished(self, status):
self.runningBatch = False
self.actSimulateall.setdisabled(False)
self.actSave.setdisabled(True)
self.actSimulateall.setText("Simulate &All Regimes")
self.actSimulateall.setIcon(QIcon(get_resource("execute_regimes.png")))
self.actSimulateall.triggered.disconnect(self.stop_regime_excecution)
self.actSimulateall.triggered.connect(self.start_regime_execution)
if status:
self.statusLabel.setText("All regimes have been simulated")
self._logger.info("All Regimes have been simulated")
else:
self._logger.error("Batch simulation has been aborted")
if self._settings.value("control/exit_on_batch_completion") == "True":
self._logger.info("Shutting down SimulationGUI")
self.close()
def __init__(self, parent):
self.parent = parent
self.workerAccepted = False # Whether or not the worker accepted the controller
self.workerTreeItem = QTreeWidgetItem()
self.monitorState = {}
self.inbuf = ""
self.connection = None
self.requestJar = {}
# Refresh monitors every 5 seconds
self.monitorTimer = QTimer()
self.monitorTimer.timeout.connect(self.requestMonitors)
self.monitorTimer.start(5000)
#
self.errorIcon = QIcon("resources/icons/exclamation.png")
def itemClicked(self, treeItem, columnIndex):
self.sheethandler.itemClickedWorker(treeItem, columnIndex)
self.lastItemClicked = treeItem
monitorFound = False
for key in self.connections:
for monitor in self.connections[key][1].monitorState:
if treeItem == self.connections[key][1].monitorState[monitor]["treeitem"]:
self.currentMonitor = monitor
self.currentWorker = self.connections[key][1]
monitorFound = True
self.updateMonitorControls(self.connections[key][1].monitorState[monitor]["state"])
if not monitorFound:
self.workerDockWidget.startRepeatButton.setEnabled(False)
self.workerDockWidget.startRepeatButton.setIcon(QIcon("resources/icons/control_play.png"))
self.workerDockWidget.stopButton.setEnabled(False)
def createIconGroupBox(self):
self.iconGroupBox = qgroupbox("Tray Icon")
self.iconLabel = QLabel("Icon:")
self.iconComboBox = QComboBox()
self.iconComboBox.addItem(QIcon('assets/yugioh.ico'), "Duel-Card")
self.showIconCheckBox = QCheckBox("Show icon")
self.showIconCheckBox.setChecked(True)
iconLayout = QHBoxLayout()
iconLayout.addWidget(self.iconLabel)
iconLayout.addWidget(self.iconComboBox)
iconLayout.addStretch()
iconLayout.addWidget(self.showIconCheckBox)
self.iconGroupBox.setLayout(iconLayout)
def initUI(self):
self.setwindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('File')
editMenu = mainMenu.addMenu('Edit')
viewMenu = mainMenu.addMenu('View')
searchMenu = mainMenu.addMenu('Search')
toolsMenu = mainMenu.addMenu('Tools')
helpMenu = mainMenu.addMenu('Help')
exitButton = QAction(QIcon('exit24.png'), 'Exit', self)
exitButton.setShortcut('Ctrl+Q')
exitButton.setStatusTip('Exit application')
exitButton.triggered.connect(self.close)
fileMenu.addAction(exitButton)
self.show()
def init_ui(self):
v_layout = QVBoxLayout()
h_layout = QHBoxLayout()
h_layout.addWidget(self.clr_btn)
h_layout.addWidget(self.sav_btn)
h_layout.addWidget(self.opn_btn)
v_layout.addWidget(self.text)
v_layout.addLayout(h_layout)
self.sav_btn.clicked.connect(self.save_text)
self.clr_btn.clicked.connect(self.clear_text)
self.opn_btn.clicked.connect(self.open_text)
self.setLayout(v_layout)
#self.setwindowTitle("notepad")
#self.setwindowIcon(QIcon('notepad.png'))
self.show()
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setwindowTitle(_translate("MainWindow", "Calculator"))
MainWindow.setwindowIcon(QtGui.QIcon('calculator.png'))
self.btn_clear.setText(_translate("MainWindow", "C"))
self.btn_allclear.setText(_translate("MainWindow", "AC"))
self.btn_8.setText(_translate("MainWindow", "8"))
self.btn_add.setText(_translate("MainWindow", "+"))
self.btn_2.setText(_translate("MainWindow", "2"))
self.btn_multiply.setText(_translate("MainWindow", "*"))
self.btn_decimal.setText(_translate("MainWindow", "."))
self.btn_equals.setText(_translate("MainWindow", "="))
self.btn_9.setText(_translate("MainWindow", "9"))
self.btn_divide.setText(_translate("MainWindow", "/"))
self.btn_7.setText(_translate("MainWindow", "7"))
self.btn_4.setText(_translate("MainWindow", "4"))
self.btn_5.setText(_translate("MainWindow", "5"))
self.btn_sub.setText(_translate("MainWindow", "-"))
self.btn_3.setText(_translate("MainWindow", "3"))
self.btn_0.setText(_translate("MainWindow", "0"))
self.btn_6.setText(_translate("MainWindow", "6"))
self.btn_1.setText(_translate("MainWindow", "1"))
def init_ui(self):
v_layout = QVBoxLayout()
h_layout = QHBoxLayout()
h_layout.addWidget(self.clr_btn)
h_layout.addWidget(self.sav_btn)
h_layout.addWidget(self.opn_btn)
v_layout.addWidget(self.text)
v_layout.addLayout(h_layout)
self.sav_btn.clicked.connect(self.save_text)
self.clr_btn.clicked.connect(self.clear_text)
self.opn_btn.clicked.connect(self.open_text)
self.setLayout(v_layout)
#self.setwindowTitle("notepad")
#self.setwindowIcon(QIcon('notepad.png'))
self.show()
def __init__(self, parent=None):
"""display a dialog that shows application information."""
super(AboutDialog, self).__init__(parent)
self.setwindowTitle('About')
help_icon = pkg_resources.resource_filename('{{ cookiecutter.package_name }}.images',
'ic_help_black_48dp_1x.png')
self.setwindowIcon(QIcon(help_icon))
self.resize(300, 200)
author = QLabel('{{ cookiecutter.full_name }}')
author.setAlignment(Qt.AlignCenter)
icons = QLabel('Material design icons created by Google')
icons.setAlignment(Qt.AlignCenter)
github = QLabel('GitHub: {{ cookiecutter.github_username }}')
github.setAlignment(Qt.AlignCenter)
self.layout = QVBoxLayout()
self.layout.setAlignment(Qt.AlignVCenter)
self.layout.addWidget(author)
self.layout.addWidget(icons)
self.layout.addWidget(github)
self.setLayout(self.layout)
def _init_menu_bar(self) -> None:
exit_action = QAction(QIcon('exit.png'), '&Exit', self)
exit_action.setShortcut('Ctrl+Q')
exit_action.setStatusTip('Exit application')
exit_action.triggered.connect(qApp.quit)
menu_bar = self.widget.menuBar()
file_menu = menu_bar.addMenu('&File')
file_menu.addAction(exit_action)
edit_menu = menu_bar.addMenu('&Edit')
edit_menu.addAction(exit_action)
view_menu = menu_bar.addMenu('&View')
view_menu.addAction(exit_action)
about_menu = menu_bar.addMenu('&About')
about_menu.addAction(exit_action)
def __init__(self, title, icon_path):
self._title = title
self._icon = QtGui.QIcon(icon_path)
# IDA 7+ Widgets
if using_ida7api:
import sip
self._form = idaapi.create_empty_widget(self._title)
self._widget = sip.wrapinstance(long(self._form), QtWidgets.QWidget) # NOTE: LOL
# legacy IDA PluginForm's
else:
self._form = idaapi.create_tform(self._title, None)
if using_pyqt5:
self._widget = idaapi.PluginForm.FormToPyQtWidget(self._form)
else:
self._widget = idaapi.PluginForm.FormToPySideWidget(self._form)
self._widget.setwindowIcon(self._icon)
def __init__(self, parent=None, ui_widget=None, home=None, window=None, logr=None):
global ui, MainWindow, logger
QtWidgets.QSystemTrayIcon.__init__(self, parent)
ui = parent
MainWindow = window
logger = logr
icon_img = os.path.join(home, 'src', 'tray.png')
self.right_menu = RightClickMenuIndicator(ui_widget=ui_widget,
window=window, logr=logr)
self.setContextMenu(self.right_menu)
self.activated.connect(self.onTrayIconActivated)
self.p = QtGui.Qpixmap(24, 24)
self.p.fill(QtGui.QColor("transparent"))
painter = QtGui.QPainter(self.p)
if os.path.exists(icon_img):
self.setIcon(QtGui.QIcon(icon_img))
else:
self.setIcon(QtGui.QIcon(""))
self.full_scr = 1
del painter
def thumbnail_generated(self, row=None, picn=None):
try:
if os.path.exists(picn):
if not os.stat(picn).st_size:
picn = self.default_background
if self.list_with_thumbnail:
icon_new_pixel = self.create_new_image_pixel(picn, 128)
if os.path.exists(icon_new_pixel):
try:
if row < self.list2.count():
self.list2.item(row).setIcon(QtGui.QIcon(icon_new_pixel))
except Exception as err:
print(err, '--6238--')
except Exception as err:
print(err, '--6240--')
print("Thumbnail Process Ended")
self.threadPoolthumb = self.threadPoolthumb[1:]
length = len(self.threadPoolthumb)
if length > 0:
if not self.threadPoolthumb[0].isRunning():
self.threadPoolthumb[0].start()
def set_up_button(self, style, str_icon_on, str_icon_off, auto_repeat,
size, receiver, key, str_key):
self.__size = size
self.__style = style
self.__icon_on = str_icon_on
self.__icon_off = str_icon_off
self.__auto_repeat = auto_repeat
self.__receiver = receiver
self.__key = key
self.__str_key = str_key
if str_key not in ['KB', 'A?', '?', 'backspace']:
self.setText(str_key)
self.setFixedSize(size[0], size[1])
self.setStyleSheet(style)
self.setIconSize(QSize(size[0], size[1]))
self.setIcon(QIcon(self.__path + str_icon_off + ".png"))
self.setAutoRepeat(auto_repeat)
# pix_map = Qpixmap(self.__path + str_icon_off + ".png")
# self.setMask(pix_map.mask())
self.pressed.connect(self.key_pressed)
self.released.connect(self.key_released)
def init_ui(self):
self.setwindowTitle(_('Start times'))
self.setwindowIcon(QIcon(config.ICON))
self.setSizegripEnabled(False)
self.setModal(True)
self.layout = qformlayout(self)
self.text = QTextEdit()
self.text.setMinimumHeight(450)
self.text.setMinimumWidth(450)
self.text.setMaximumHeight(450)
self.layout.addRow(self.text)
self.set_text()
def cancel_changes():
self.close()
def apply_changes():
try:
self.apply_changes_impl()
except Exception as e:
logging.exception(str(e))
self.close()
self.button_ok = QPushButton(_('Save to file'))
self.button_ok.clicked.connect(apply_changes)
self.button_cancel = QPushButton(_('Cancel'))
self.button_cancel.clicked.connect(cancel_changes)
self.layout.addRow(self.button_ok, self.button_cancel)
self.show()
def _setup_ui(self):
geometry = ConfigFile.GEOMETRY
x = Configuration().parser.getint(geometry, 'x', fallback=480)
y = Configuration().parser.getint(geometry, 'y', fallback=320)
width = Configuration().parser.getint(geometry, 'width', fallback=880)
height = Configuration().parser.getint(geometry, 'height', fallback=474)
self.setMinimumSize(QtCore.QSize(480, 320))
self.setGeometry(x, y, 480, 320)
self.setwindowIcon(QtGui.QIcon(config.ICON))
self.set_title()
self.resize(width, height)
self.setLayoutDirection(QtCore.Qt.LeftToRight)
self.setDocknestingEnabled(False)
self.setDockOptions(QtWidgets.QMainWindow.AllowTabbedDocks
| QtWidgets.QMainWindow.AnimatedDocks
| QtWidgets.QMainWindow.ForceTabbedDocks)
def _create_menu(self, parent, actions_list):
for action_item in actions_list:
if 'type' in action_item:
if action_item['type'] == 'separator':
parent.addSeparator()
elif 'action' in action_item:
action = QtWidgets.QAction(self)
parent.addAction(action)
action.setText(action_item['title'])
action.triggered.connect(action_item['action'])
if 'shortcut' in action_item:
action.setShortcut(action_item['shortcut'])
if 'icon' in action_item:
action.setIcon(QtGui.QIcon(action_item['icon']))
if 'status_tip' in action_item:
action.setStatusTip(action_item['status_tip'])
if 'property' in action_item:
self.menu_property[action_item['property']] = action
else:
menu = QtWidgets.QMenu(parent)
menu.setTitle(action_item['title'])
self._create_menu(menu, action_item['actions'])
parent.addAction(menu.menuAction())
def createMenu(self):
def quitGame():
#???????
reply = QMessageBox.question(self,'??','?????',QMessageBox.Yes,QMessageBox.No)
if reply == QMessageBox.Yes:
qApp.quit()
def aboutUs():
QMessageBox.about(self,'????',str(self))
menubar = self.menuBar()
#???
main_menu = menubar.addMenu('&???')
main_menu.addAction(QAction(QIcon('images/icon.jpg'),
self, statusTip="???????", triggered=quitGame))
#????
about_menu = menubar.addMenu('&??')
about_menu.addAction(QAction(QIcon('images/icon.jpg'), statusTip="????", triggered=aboutUs))
def _fix_icons(self):
# fix icon stuff
self.ui.actionNew.setIcon(QIcon(":/new.svg"))
self.ui.actionopen.setIcon(QIcon(":/open.svg"))
self.ui.actioncopy.setIcon(QIcon(":/copy.svg"))
self.ui.actionPaste.setIcon(QIcon(":/paste.svg"))
self.ui.actionDelete.setIcon(QIcon(":/delete.svg"))
self.ui.actionSave.setIcon(QIcon(":/save.svg"))
self.ui.actionAddFolder.setIcon(QIcon(":/folder.svg"))
self.ui.actionAddobject.setIcon(QIcon(":/object.svg"))
self.ui.actionAddMethod.setIcon(QIcon(":/method.svg"))
self.ui.actionAddobjectType.setIcon(QIcon(":/object_type.svg"))
self.ui.actionAddProperty.setIcon(QIcon(":/property.svg"))
self.ui.actionAddVariable.setIcon(QIcon(":/variable.svg"))
self.ui.actionAddVariableType.setIcon(QIcon(":/variable_type.svg"))
self.ui.actionAddDataType.setIcon(QIcon(":/data_type.svg"))
self.ui.actionAddReferenceType.setIcon(QIcon(":/reference_type.svg"))
def __init__(self, current_colormap):
# call widget init
QDialog.__init__(self, parent)
# define available colormaps
colormaps = ['bwr', 'gnuplot', 'gnuplot2', 'inferno', 'nipy_spectral', 'seismic', 'viridis']
# load and set up UI
self.ui = UiColormapDialog(self)
# fill comboBox with colormaps
current_id = 0
for i_colormap in range(len(colormaps)):
if colormaps[i_colormap] == current_colormap:
current_id = i_colormap
self.ui.colormap_comboBox.addItem(QIcon('./img/cm_'+colormaps[i_colormap]+'.png'), colormaps[i_colormap])
self.ui.colormap_comboBox.setCurrentIndex(current_id)
def handle_edit_button(self):
if self.edit_button.text() == 'Edit':
self.edit_button.setText('Save')
self.edit_button.setIcon(QIcon('images/save-preferences.png'))
self.output_path_label.setEnabled(True)
self.image_format_groupBox.setEnabled(True)
self.output_path_line_edit.setEnabled(True)
self.output_path_button.setEnabled(True)
else:
self.edit_button.setText('Edit')
self.edit_button.setIcon(QIcon('images/edit-preferences.png'))
self.output_path_label.setEnabled(False)
self.image_format_groupBox.setEnabled(False)
self.output_path_line_edit.setEnabled(False)
self.output_path_button.setEnabled(False)
self._save_preferences()
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.setupUi(self)
self.about_action.setIcon(QIcon('images/about.png'))
self.preferences_action.setIcon(QIcon('images/preferences.png'))
self.quit_action.setIcon(QIcon('images/quit.png'))
self.quit_action.triggered.connect(lambda : exit(0))
self.preferences_action.triggered.connect(self.handle_preferences_menu_action)
self.title_line_edit.returnpressed.connect(self._extract_from_wiki)
self.content_text_browser.anchorClicked.connect(self.handle_anchor_clicked)
self.run_push_button.clicked.connect(self.handle_run_button)
self.run_push_button.setIcon(QIcon('images/run.png'))
self.run_push_button.setText('Download')
self.setwindowIcon(QIcon('images/copas-logo.png'))
self.page_combo_Box.addItems(
['Content', 'Images', 'Summary', 'Images Links', 'References Links'])
self.about_action.triggered.connect(self.handle_about_menu_action)
for lang in sorted(wikipedia.languages()):
self.lang_combo_Box.addItem(lang)
def handle_run_button(self):
if self.run_push_button.text() == 'Download':
self._extract_from_wiki()
self.run_push_button.setIcon(QIcon('images/stop.png'))
self.run_push_button.setText('Stop')
self._set_disabled_widget(True)
else:
self.run_push_button.setIcon(QIcon('images/run.png'))
self.run_push_button.setText('Download')
if self.page_combo_Box.currentText() == 'Images':
self.progress_thread.content_image_arrived.emit(self.progress_thread.valid_images,
self.progress_thread.des_dir)
else:
self.__load_finished()
self.progress_thread.terminate()
self._set_disabled_widget(False)
def createLayout(self):
self.setwindowTitle('News Reader')
self.addressBar = QLineEdit()
self.backButton = QPushButton('')
self.summaryButton = QPushButton('')
self.summaryButton.setIcon(QtGui.QIcon('/usr/share/icons/mate/scalable/actions/edit-cut-symbolic.svg'))
self.backButton.setIcon(QtGui.QIcon('/usr/share/icons/mate/scalable/actions/go-prevIoUs-symbolic.svg'))
bl = QHBoxLayout()
bl.addWidget(self.backButton)
bl.addWidget(self.summaryButton)
self.webView = QWebView()
self.webView.titleChanged.connect(self.adjustTitle)
layout = QVBoxLayout()
layout.addLayout(bl)
layout.addWidget(self.webView)
layout.setContentsMargins(1,5,1)
self.setLayout(layout)
self.showMaximized()
def updateColor(self, item):
pixmap = Qpixmap(16, 16)
color = QColor()
if item:
color = item.backgroundColor()
if not color.isValid():
color = self.palette().base().color()
painter = QPainter(pixmap)
painter.fillRect(0, 16, color)
lighter = color.lighter()
painter.setPen(lighter)
# light frame
painter.drawpolyline(QPoint(0, 15), QPoint(0, 0), QPoint(15, 0))
painter.setPen(color.darker())
# dark frame
painter.drawpolyline(QPoint(1, 1))
painter.end()
self.colorAction.setIcon(QIcon(pixmap))
def layout(self):
"""
Layout the row for this experiment.
"""
self._main_layout = QW.qgridLayout(self)
# Construct the header for the experiment
self._main_layout.addWidget(QW.QLabel(self._expt_label),0)
# -------------- Buttons --------------------
# Button to show experiment options
self._show_options_button = QW.QPushButton("", self)
self._show_options_button.clicked.connect(self._options_callback)
self._show_options_button.setIcon(QG.QIcon(os.path.join(self._image_base,"icons","more-info.png")))
self._show_options_button.setIconSize(QC.QSize(21,21))
self._show_options_button.setFixedWidth(30)
self._main_layout.addWidget(self._show_options_button,1)
# Button to remove experiment
self._remove_button = QW.QPushButton("", self)
self._remove_button.clicked.connect(self._remove_callback)
self._remove_button.setIcon(QG.QIcon(os.path.join(self._image_base,"delete-icon.png")))
self._remove_button.setIconSize(QC.QSize(21,21))
self._remove_button.setFixedWidth(30)
self._main_layout.addWidget(self._remove_button,2)
self.setFrameShape(QW.qframe.StyledPanel)
if self._experiment is None:
self._show_options_button.setdisabled(True)
self._remove_button.setdisabled(True)
def preferences_menu(self):
settings_action = QtWidgets.QAction(QtGui.QIcon('assets/icons/config.png'), '&Settings', self)
settings_action.setStatusTip('Open Settings')
settings_action.setShortcut('Ctrl+Shift+P')
preferences_menu = self.menu_bar.addMenu('Prefere&nces')
preferences_menu.addAction(settings_action)
def format_menu(self):
""" Add Format Menu """
font_action = QtWidgets.QAction(QtGui.QIcon('assets/icons/font.png'), '&Font', self)
font_action.setStatusTip('Change the document font')
font_action.triggered.connect(self.font_dialog)
date_action = QtWidgets.QAction(QtGui.QIcon('assets/icons/date.png'), '&Append Date', self)
date_action.setStatusTip('Insert date and time at cursor location')
date_action.setShortcut('F5')
date_action.triggered.connect(self.insert_date)
self.default_Syntax = QtWidgets.QAction('&Default', self)
self.default_Syntax.setStatusTip('Turn off Syntax highlighting')
self.python_Syntax = QtWidgets.QAction('&Python', self)
self.python_Syntax.setStatusTip('Turn on Syntax highlighting for Python language')
self.default_Syntax.triggered.connect(self.assign_Syntax_def)
self.python_Syntax.triggered.connect(self.assign_Syntax_py)
format_menu = self.menu_bar.addMenu('Forma&t')
Syntax_menu = format_menu.addMenu(QtGui.QIcon('assets/icons/synthax.png'), '&Syntax')
Syntax_menu.addAction(self.default_Syntax)
Syntax_menu.addAction(self.python_Syntax)
format_menu.addSeparator()
format_menu.addAction(font_action)
format_menu.addAction(date_action)
# Text Finder
def __init__(self):
super(DownloaderDlg, self).__init__()
self.ui = Ui_DownloaderDlg()
self.ui.setupUi(self)
self.setwindowTitle(self.tr("Tools downloader"))
icon = QIcon("./icons/097-download.png")
self.setwindowIcon(icon)
self.tw = self.findChild(QTreeWidget, "downloads_treeWidget")
self.statusLabel = self.findChild(QLabel, "statusLabel")
bBox = self.findChild(QDialogButtonBox, "downloads_buttonBox")
bBox.setStandardButtons(QDialogButtonBox.Close)
self.install_button = QPushButton(self.tr("Install selected"), self.tw)
self.install_button.clicked.connect(self.installSelected)
bBox.addButton(self.install_button, QDialogButtonBox.ActionRole)
self.loadToolsJSON(self.tw)
def set_project_label(self):
name = projects.current
self.project_name_label.setText('Project: {}'.format(name))
self.project_read_only.setText('')
if projects.read_only:
self.project_read_only.setText('Read Only Project')
self.window.warning("Read Only Project", """Read Only Project.\nAnother Python process is working with this project,no writes are allowed.\nCheck to make sure no other Python interpreters are running,and then re-select this project.""")
# def get_search_Box(self):
# search_Box = QtWidgets.QLineEdit()
# search_Box.setMaximumSize(QtCore.QSize(150,25))
# # Search
# search_action = QtWidgets.QAction(
# QtGui.QIcon(icons.search),
# 'Search activites (see help for search Syntax)',
# self.window
# )
# return search_Box
# def get_key_search(self):
# key_search_action = QtWidgets.QAction(
# QtGui.QIcon(icons.key),
# 'Search by key',
# self.window
# )
# # key_search_action.triggered.connect(self.search_by_key)
# return key_search_action
def setup_context_menu(self):
# delete database
self.delete_database_action = QtWidgets.QAction(
QtGui.QIcon(icons.delete), "Delete database", None
)
self.addAction(self.delete_database_action)
self.delete_database_action.triggered.connect(
lambda x: signals.delete_database.emit(
self.currentItem().db_name
)
)
# copy database
self.copy_database_action = QtWidgets.QAction(
QtGui.QIcon(icons.duplicate), "copy database", None
)
self.addAction(self.copy_database_action)
self.copy_database_action.triggered.connect(
lambda x: signals.copy_database.emit(
self.currentItem().db_name
)
)
# add activity (important for empty databases,where the activities table will not show up)
self.add_activity_action = QtWidgets.QAction(
QtGui.QIcon(icons.add), "Add new activity", None
)
self.addAction(self.add_activity_action)
self.add_activity_action.triggered.connect(
lambda x: signals.new_activity.emit(
self.currentItem().db_name
)
)
def setup_context_menu(self):
self.add_activity_action = QtWidgets.QAction(
QtGui.QIcon(icons.add), None
)
self.copy_activity_action = QtWidgets.QAction(
QtGui.QIcon(icons.copy), "copy activity", None
)
self.delete_activity_action = QtWidgets.QAction(
QtGui.QIcon(icons.delete), "Delete activity", None
)
self.open_left_tab_action = QtWidgets.QAction(
QtGui.QIcon(icons.left), "Open in new tab", None
)
self.addAction(self.add_activity_action)
self.addAction(self.copy_activity_action)
self.addAction(self.delete_activity_action)
self.addAction(self.open_left_tab_action)
self.add_activity_action.triggered.connect(
lambda: signals.new_activity.emit(self.database.name)
)
self.copy_activity_action.triggered.connect(
lambda x: signals.copy_activity.emit(self.currentItem().key)
)
self.delete_activity_action.triggered.connect(
lambda x: signals.delete_activity.emit(self.currentItem().key)
)
self.open_left_tab_action.triggered.connect(
lambda x: signals.open_activity_tab.emit("activities", self.currentItem().key)
)
def setup_context_menu(self):
self.delete_row_action = QtWidgets.QAction(
QtGui.QIcon(icons.delete), "Remove row", None
)
self.addAction(self.delete_row_action)
self.delete_row_action.triggered.connect(self.delete_rows)
def setup_context_menu(self):
self.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
self.delete_row_action = QtWidgets.QAction(
QtGui.QIcon(icons.delete), None
)
self.addAction(self.delete_row_action)
self.delete_row_action.triggered.connect(self.delete_rows)
def setup_context_menu(self):
self.delete_exchange_action = QtWidgets.QAction(
QtGui.QIcon(icons.delete), "Delete exchange(s)", None
)
self.addAction(self.delete_exchange_action)
self.delete_exchange_action.triggered.connect(self.delete_exchanges)
def setup_file_menu(self):
menu = QtWidgets.QMenu('&File', self.window)
# Switch BW2 directory
# switch_bw2_dir = QtWidgets.QAction(QtGui.QIcon('exit.png'),'&Database directory...',self.window)
# # switch_bw2_dir.setShortcut('Ctrl+Q')
# switch_bw2_dir.setStatusTip('Change database directory')
# switch_bw2_dir.triggered.connect(signals.switch_bw2_dir_path.emit)
# menu.addAction(switch_bw2_dir)
menu.addAction(
'&Database directory...',
signals.switch_bw2_dir_path.emit
)
menu.addAction(
'&Import database...',
signals.import_database.emit
)
return menu
# def setup_extensions_menu(self):
# extensions_menu = QtWidgets.QMenu('&Extensions',self.window)
# # extensions_menu.addAction(
# # self.add_Metaprocess_menu_item()
# # )
# return extensions_menu
def get_app_icon():
global _APP_ICON_OBJECT
try:
return _APP_ICON_OBJECT
except NameError:
pass
# noinspection PybroadException
try:
fn = pkg_resources.resource_filename('uavcan_gui_tool', os.path.join('icons', 'logo_256x256.png'))
_APP_ICON_OBJECT = QIcon(fn)
except Exception:
logger.error('Could not load icon', exc_info=True)
_APP_ICON_OBJECT = QIcon()
return _APP_ICON_OBJECT
def show_error(message):
"""display "message" in a "Critical error" message Box with 'OK' button."""
# Create a QMessageBox
message_Box = QtWidgets.QMessageBox()
message_Box.setText(message)
message_Box.setwindowTitle("Error")
message_Box.setwindowIcon(QtGui.QIcon(QtGui.Qpixmap(":/icons/grid.png")))
message_Box.setIcon(QtWidgets.QMessageBox.Critical)
message_Box.setStandardButtons(QtWidgets.QMessageBox.Ok)
message_Box.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
#Show the window
message_Box.exec_()
def show_notification(message):
"""display "message" in a "information" message Box with 'OK' button."""
# Create a QMessageBox
message_Box = QtWidgets.QMessageBox()
message_Box.setText(message)
message_Box.setwindowTitle("Note")
message_Box.setwindowIcon(QtGui.QIcon(QtGui.Qpixmap(":/icons/grid.png")))
message_Box.setIcon(QtWidgets.QMessageBox.information)
message_Box.setStandardButtons(QtWidgets.QMessageBox.Ok)
message_Box.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
#Show the window
message_Box.exec_()
def valueIcon(self):
ico = self.d__ptr.m_manager.valueIcon(self)
if not ico:
return QIcon()
return ico
###
# Returns a string representing the current state of this property.
#
# If the given property type can not generate such a string,this:
# function returns an empty string.
#
# \sa QtAbstractPropertyManager::valueText()
###