本文整理汇总了Python中PyQt5.QtWidgets.QWidget.resize方法的典型用法代码示例。如果您正苦于以下问题:Python QWidget.resize方法的具体用法?Python QWidget.resize怎么用?Python QWidget.resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QWidget
的用法示例。
在下文中一共展示了QWidget.resize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_should_resize_to_match_height_for_width_when_user_enters_text
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import resize [as 别名]
def test_should_resize_to_match_height_for_width_when_user_enters_text(self):
size_hint = self.auto_resizing_text_edit.sizeHint()
parent_height = size_hint.height() + 200
layout = QVBoxLayout()
layout.setSpacing(0)
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(self.auto_resizing_text_edit)
layout.addStretch()
parent = QWidget()
self.auto_resizing_text_edit.setParent(parent)
parent.resize(size_hint.width(), parent_height)
parent.setLayout(layout)
# The window needs to get shown for the size changes to be propagated to layout.
# Show it minimized to avoid stealing focus from the console running the tests.
parent.showMinimized()
assert self.auto_resizing_text_edit.height(), size_hint.height()
assert self.auto_resizing_text_edit.width(), parent.width()
self.auto_resizing_text_edit.setPlainText('a\nb\nc\d')
new_height_hint = self.auto_resizing_text_edit.heightForWidth(self.auto_resizing_text_edit.width())
application.processEvents()
self.assertNotEqual(new_height_hint, size_hint.height())
self.assertEqual(self.auto_resizing_text_edit.height(), new_height_hint)
self.assertEqual(self.auto_resizing_text_edit.width(), parent.width())
示例2: input_dialog
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import resize [as 别名]
def input_dialog(prompt,def_answer=None,name='Type Parameters'):
ok = False
def _pressed_ok():
nonlocal ok
w.close()
app.quit()
ok |= True
def _pressed_cancel():
nonlocal ok
w.close()
app.quit()
ok &= False
if isinstance(prompt,str): prompt = [prompt]
if def_answer is None: def_answer = len(prompt)*['']
if isinstance(def_answer,str): def_answer = [def_answer]
if len(prompt) != len(def_answer):
raise IndexError("'prompt' and 'def_answer' must be the same length.")
app = QCoreApplication.instance() or QApplication([])
w = QWidget()
w.setWindowTitle(name)
grid = QGridLayout()
grid.setSpacing(10)
edit = []
for i in range(len(prompt)):
title = QLabel(prompt[i])
edit += [QLineEdit()]
if def_answer is not None: edit[i].setText(def_answer[i])
grid.addWidget(title, 2*i, 0,1,2)# title, row,col,spanrow,spancol
grid.addWidget(edit[i], 2*i+1, 0,1,2)
#Ok Button
qbtn = QPushButton('Ok', w)
qbtn.clicked.connect(_pressed_ok)
qbtn.resize(qbtn.sizeHint())
grid.addWidget(qbtn, 2*(i+1), 0)
#Cancel Button
qbtn = QPushButton('Cancel', w)
qbtn.clicked.connect(_pressed_cancel)
qbtn.resize(qbtn.sizeHint())
grid.addWidget(qbtn, 2*(i+1), 1)
#Defining the layout of the window:
w.setLayout(grid)
w.resize(50, i*50)
qr = w.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
w.move(qr.topLeft())
w.show()
app.exec_()
text = []
for ed in edit:
text += [ed.text()]
return ok, text
示例3: radio_dialog
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import resize [as 别名]
def radio_dialog(options, name='Selection', default_idx=0):
ok = False
def _pressed_ok():
nonlocal ok
w.close()
app.quit()
ok |= True
def _pressed_cancel():
nonlocal ok
w.close()
app.quit()
ok &= False
app = QCoreApplication.instance() or QApplication([])
w = QWidget()
w.setWindowTitle(name)
grid = QGridLayout()
grid.setSpacing(10)
edit = []
for i in range(len(options)):
r = QRadioButton(options[i])
if i == default_idx:
r.setChecked(True)
edit.append(r)
grid.addWidget(r,0,i)
#Ok Button
qbtn = QPushButton('Ok', w)
qbtn.clicked.connect(_pressed_ok)
qbtn.resize(qbtn.sizeHint())
grid.addWidget(qbtn, 2*(i+1), 0)
#Cancel Button
qbtn = QPushButton('Cancel', w)
qbtn.clicked.connect(_pressed_cancel)
qbtn.resize(qbtn.sizeHint())
grid.addWidget(qbtn, 2*(i+1), 1)
#Defining the layout of the window:
w.setLayout(grid)
w.resize(50, i*50)
qr = w.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
w.move(qr.topLeft())
w.show()
app.exec_()
for r in edit:
if r.isChecked(): text = r.text()
return ok, text
示例4: main
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import resize [as 别名]
def main():
app = QApplication(sys.argv)
w = QWidget()
w.resize(250, 150)
w.move(300, 300)
w.setWindowTitle('Simple')
w.show()
sys.exit(app.exec_())
示例5: test
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import resize [as 别名]
def test():
app = QApplication(sys.argv)
w = QWidget()
w.resize(250, 150)
w.move(300, 300)
w.setWindowTitle('Simple')
b = QPushButton(parent=w, text='test')
b.ac
w.show()
sys.exit(app.exec_())
示例6: _initUi
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import resize [as 别名]
def _initUi(self):
self.resize(250, 150)
self.move(300, 300)
self.setWindowTitle("Simple")
layout = QVBoxLayout()
headWidget = QWidget()
headLayout = QHBoxLayout()
headWidget.setLayout(headLayout)
layout.addWidget(headWidget)
edit_icon = QWidget(self)
edit_icon.resize(30,30)
edit_icon.setStyleSheet("background: url(:/images/edit-icon);")
edit_icon.move(20,15)
label = QLabel("Login Form", self)
label.resize(label.sizeHint())
label.move(60,20)
edit = QLineEdit()
edit.setObjectName("username")
edit.setPlaceholderText("username")
layout.addWidget(edit)
edit = QLineEdit()
edit.setObjectName("password")
edit.setPlaceholderText("password")
layout.addWidget(edit)
widget = QWidget()
layout.addWidget(widget)
loginLayout = QHBoxLayout()
loginLayout.setContentsMargins(0,-10,0,0)
loginLayout.setSpacing(30)
widget.setLayout(loginLayout)
# widget.setStyleSheet("background-color:blue")
btn = QPushButton("登录")
loginLayout.addWidget(btn)
btn.clicked.connect(self.login)
btn.setStyleSheet("margin:0;padding:5 0;border:0px;background-color: #26b9a5;color:white;")
btn.setAutoDefault(False)
btn = QPushButton("取消")
loginLayout.addWidget(btn)
btn.clicked.connect(self.close)
btn.setStyleSheet("padding:5px 0;border:0px;background-color: #26b9a5;color:white;")
btn.setAutoDefault(False)
# layout.setContentsMargins(11,11,11,11)
self.setLayout(layout)
示例7: test_should_keep_preferred_height_when_extra_space_is_available
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import resize [as 别名]
def test_should_keep_preferred_height_when_extra_space_is_available(self):
size_hint = self.auto_resizing_text_edit.sizeHint()
parent_height = size_hint.height() + 100
layout = QVBoxLayout()
layout.setSpacing(0)
layout.setContentsMargins(0, 0, 0, 0)
layout.addWidget(self.auto_resizing_text_edit)
layout.addStretch()
parent = QWidget()
self.auto_resizing_text_edit.setParent(parent)
parent.resize(size_hint.width(), parent_height)
parent.setLayout(layout)
# The window needs to get shown for the size changes to be propagated to layout.
# Show it minimized to avoid stealing focus from the console running the tests.
parent.showMinimized()
self.assertEqual(self.auto_resizing_text_edit.height(), size_hint.height())
self.assertEqual(self.auto_resizing_text_edit.width(), parent.width())
示例8: E5AnimatedWidget
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import resize [as 别名]
class E5AnimatedWidget(QWidget):
"""
Class implementing an animated widget.
"""
DirectionDown = 0
DirectionUp = 1
def __init__(self, direction=DirectionDown, duration=300, parent=None):
"""
Constructor
@param direction direction of the animation
@type int (one of DirectionDown or DirectionUp)
@param duration duration of the animation
@type int
@param parent reference to the parent widget
@type QWidget
"""
super(E5AnimatedWidget, self).__init__(parent)
self.__direction = direction
self.__stepHeight = 0.0
self.__stepY = 0.0
self.__startY = 0
self.__widget = QWidget(self)
self.__timeline = QTimeLine(duration)
self.__timeline.setFrameRange(0, 100)
self.__timeline.frameChanged.connect(self.__animateFrame)
self.setMaximumHeight(0)
def widget(self):
"""
Public method to get a reference to the animated widget.
@return reference to the animated widget
@rtype QWidget
"""
return self.__widget
@pyqtSlot()
def startAnimation(self):
"""
Public slot to start the animation.
"""
if self.__timeline.state() == QTimeLine.Running:
return
shown = 0
hidden = 0
if self.__direction == self.DirectionDown:
shown = 0
hidden = -self.__widget.height()
self.__widget.move(QPoint(self.__widget.pos().x(), hidden))
self.__stepY = (hidden - shown) / 100.0
self.__startY = hidden
self.__stepHeight = self.__widget.height() / 100.0
self.__timeline.setDirection(QTimeLine.Forward)
self.__timeline.start()
@pyqtSlot(int)
def __animateFrame(self, frame):
"""
Private slot to animate the next frame.
@param frame frame number
@type int
"""
self.setFixedHeight(frame * self.__stepHeight)
self.__widget.move(self.pos().x(),
self.__startY - frame * self.__stepY)
@pyqtSlot()
def hide(self):
"""
Public slot to hide the animated widget.
"""
if self.__timeline.state() == QTimeLine.Running:
return
self.__timeline.setDirection(QTimeLine.Backward)
self.__timeline.finished.connect(self.close)
self.__timeline.start()
p = self.parentWidget()
if p is not None:
p.setFocus()
def resizeEvent(self, evt):
"""
Protected method to handle a resize event.
@param evt reference to the event object
@type QResizeEvent
"""
#.........这里部分代码省略.........
示例9: MyApp
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import resize [as 别名]
#.........这里部分代码省略.........
# palette.setBrush(self.backgroundRole(), color)
# self.setPalette(palette)
# self.setAutoFillBackground(True)
# self.setBackgroundRole(QPalette.Window)
#创建房间的Button和 输入框
self.roomName=QPlainTextEdit()
self.roomName.setPlaceholderText('请输入房间名')
# self.roomName.resize(50,20)
# self.roomName.move(0,0)
# self.roomName.setBackgroundVisible(False)
self.createBtn=QPushButton("创建/进入")
self.hideBtn=QPushButton('隐藏本设置窗口')
self.hideBtn.clicked.connect(self.joinRoom)
# lambda:self.switchVisible(self.settingWindow))
# self.createBtn.resize(50,20)
# self.move(0,100)
# self.d
settingLayout=QVBoxLayout()
hLayout=QHBoxLayout()
settingLayout.addWidget(self.roomName)
hLayout.addWidget(self.hideBtn)
hLayout.addWidget(self.createBtn)
self.settingWindow=QWidget()
# self.hideBtn=setShortcut(QtGui.QKeySequence('Ctrl+B'))
settingLayout.addLayout(hLayout)
self.settingWindow.setLayout(settingLayout)
# Qt.Tool的作用是 不在任务栏显示
self.settingWindow.setWindowFlags(Qt.FramelessWindowHint|Qt.Tool\
|Qt.X11BypassWindowManagerHint|Qt.Popup)
self.roomName.show()
self.createBtn.show()
self.settingWindow.resize(160,26)
self.settingWindow.show()
# self.btnFire=QPushButton("Fire",self)
# self.btnFire.resize(60,60)
# self.btnFire.move(100,30)
# self.btnFire.show()
# self.btnLock=QPushButton("Lock",self)
# self.btnLock.resize(40,40)
# self.btnLock.move(self.screenWidth/2,30)
# self.btnLock.setFlat(True)
# self.btnLock.setIcon(QtGui.QIcon("tmpIcon.png"))
# self.btnLock.show()
# self.danmakuEditText=QPlainTextEdit(self)
# self.danmakuEditText.resize(200,100)
# self.danmakuEditText.move(100,100)
# self.danmakuEditText.setBackgroundVisible(False)
# self.danmakuEditText.show()
def joinRoom(self):
name=self.roomName.toPlainText()
self.socketio.emit('join',name)
def connect2Server(self):
self.socketio=SocketIO('115.159.102.76/bulletgo_client',80,LoggingNamespace)
self.registerEvents()
# 开新线程监听服务器发来的消息,否则主线程被阻塞
_thread.start_new_thread(self.socketio.wait,())
示例10: QApplication
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import resize [as 别名]
【简介】
PyQt5中坐标系统
'''
from PyQt5.QtWidgets import QApplication ,QWidget ,QPushButton
import sys
app = QApplication(sys.argv)
widget = QWidget()
btn = QPushButton( widget )
btn.setText("Button")
#以QWidget左上角为(0, 0)点
btn.move(20, 20)
#不同操作系统可能对窗口最小宽度有规定,若设置宽度小于规定值,则会以规定值进行显示
widget.resize(300, 200)
#以屏幕左上角为(0, 0)点
widget.move(250, 200)
widget.setWindowTitle('PyQt坐标系统例子')
widget.show()
print("#1 QWidget")
print("widget.x()=%d" % widget.x() )
print("widget.y()=%d" % widget.y() )
print("widget.width()=%d" % widget.width() )
print("widget.height()=%d" % widget.height() )
print("#2 QWidget.geometry")
print("widget.geometry().x()=%d" % widget.geometry().x() )
print("widget.geometry().y()=%d" % widget.geometry().y() )
print("widget.geometry().width()=%d" % widget.geometry().width() )
示例11: BrowserController
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import resize [as 别名]
class BrowserController(QObject):
def __init__(self, parent, fullscreen, sizes):
"""
This constructor function initializes a layout of the Arius output
module but doesn`t displays it on the screen.
Firstly, it creates a new app and detects screens configuration.
Then, QGridLayout is created and its appearance is configured: margins
and spaces between elements is set to 0.
After that, we create three QWebViews: one for our main content view
and two others for header and footer views.
Immideately after creating these instances we assign them their heights
according to percentages given by user and dimensions of the screen.
Next, we remove scroll bars from top and bottom views and load predefined
pages into them.
Then we allow QWebKit to run all extensions it needs to render the page.
After that, wee set the layout design as a grid of three rows.
Finally, we create an updater object which will run in another stream and
a timer instance which checks that stream for new commands
from the server, and in case if there`s some update handles it.
"""
super(BrowserController, self).__init__()
if not fullscreen and not sizes:
print 'You must initialize windows size'
raise Exception
self._fullscreen = fullscreen
if sizes:
self._screen_width = sizes[0]
self._screen_height = sizes[1]
self._app = QtWidgets.QApplication(sys.argv)
self._app.setStyle("Fusion")
if self._fullscreen:
self._get_screen_height()
self._layout = QGridLayout()
self._layout.setSpacing(0)
self._layout.setContentsMargins(0, 0, 0, 0)
self._main_browser = QWebView()
main_page = FakePage(self)
self._main_browser.setPage(main_page)
self._top_browser = QWebView()
self._bottom_browser = QWebView()
self._top_browser_height = config['output_header_height'] * self._screen_height
self._bottom_browser_height = config['output_footer_height'] * self._screen_height
self._top_browser.setMaximumHeight(self._top_browser_height)
self._top_browser.setMinimumHeight(self._top_browser_height)
self._bottom_browser.setMaximumHeight(self._bottom_browser_height)
self._bottom_browser.setMinimumHeight(self._bottom_browser_height)
self._top_browser.page().mainFrame().setScrollBarPolicy(
QtCore.Qt.Vertical, QtCore.Qt.ScrollBarAlwaysOff)
self._main_browser.page().mainFrame().setScrollBarPolicy(
QtCore.Qt.Vertical, QtCore.Qt.ScrollBarAlwaysOff)
self._main_browser.page().mainFrame().setScrollBarPolicy(
QtCore.Qt.Horizontal, QtCore.Qt.ScrollBarAlwaysOff)
self._bottom_browser.page().mainFrame().setScrollBarPolicy(
QtCore.Qt.Vertical, QtCore.Qt.ScrollBarAlwaysOff)
self._top_browser_load_url(
config['flask_server_home'] + config['output_browser_top_page'])
self._bottom_browser_load_url(
config['flask_server_home'] + config['output_browser_bottom_page'])
self._main_browser.settings().setAttribute(
QWebSettings.DeveloperExtrasEnabled, True)
self._main_browser.settings().setAttribute(QWebSettings.PluginsEnabled, True)
QWebSettings.setObjectCacheCapacities(0, 0, 0)
self._main_browser.settings().setAttribute(
QWebSettings.AcceleratedCompositingEnabled, True)
self._main_browser.settings().setAttribute(QWebSettings.WebGLEnabled, True)
self._layout.addWidget(self._top_browser, 1, 0)
self._layout.addWidget(self._main_browser, 2, 0)
self._layout.addWidget(self._bottom_browser, 3, 0)
self._parent = parent
self._parent.load_url.connect(self._load_url)
self._parent.js_execution.connect(self._execute_js)
self._parent.zooming.connect(self._zoom)
def run(self):
self._main_window = QWidget() # create a window as a QWidget
self._main_window.setLayout(self._layout) # assign a layout to it
if self._fullscreen:
self._main_window.showFullScreen() # set full screen enabled
else:
self._main_window.resize(self._screen_width, self._screen_height)
self._main_window.show() # and finally, show the window
# and set a trigger to exit the app, as window is closed
#.........这里部分代码省略.........
示例12: SystemTrayIcon
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import resize [as 别名]
class SystemTrayIcon(QSystemTrayIcon):
newWindowRequested = Signal()
windowReopenRequested = Signal()
def __init__(self, parent=None):
super(SystemTrayIcon, self).__init__(common.app_icon, parent)
# Set tooltip.
self.setToolTip(common.app_name)
self.widget = QWidget(None)
self.widget.resize(0, 0)
self.widget.setWindowFlags(Qt.FramelessWindowHint)
# Set context menu.
self.menu = QMenu(None)
self.setContextMenu(self.menu)
# New window action
newWindowAction = QAction(common.complete_icon("window-new"), tr("&New Window"), self)
newWindowAction.triggered.connect(self.newWindowRequested.emit)
self.menu.addAction(newWindowAction)
# Reopen window action
reopenWindowAction = QAction(common.complete_icon("reopen-window"), tr("R&eopen Window"), self)
reopenWindowAction.triggered.connect(self.reopenWindow)
self.menu.addAction(reopenWindowAction)
self.menu.addSeparator()
self.sessionManager = session.SessionManager(None)
# Load session action
loadSessionAction = QAction(common.complete_icon("document-open"), tr("&Load Session..."), self)
loadSessionAction.triggered.connect(self.loadSession)
self.menu.addAction(loadSessionAction)
# Save session action
saveSessionAction = QAction(common.complete_icon("document-save-as"), tr("Sa&ve Session..."), self)
saveSessionAction.triggered.connect(self.saveSession)
self.menu.addAction(saveSessionAction)
self.menu.addSeparator()
# Settings action
settingsAction = QAction(common.complete_icon("preferences-system"), tr("&Settings..."), self)
settingsAction.triggered.connect(self.openSettings)
self.menu.addAction(settingsAction)
# Clippings manager
clippingsAction = QAction(common.complete_icon("edit-paste"), tr("&Manage Clippings..."), self)
clippingsAction.triggered.connect(self.openClippings)
self.menu.addAction(clippingsAction)
self.menu.addSeparator()
# About Nimbus action.
aboutAction = QAction(common.complete_icon("help-about"), tr("A&bout %s") % (common.app_name,), self)
aboutAction.triggered.connect(self.about)
self.menu.addAction(aboutAction)
# Quit action
quitAction = QAction(common.complete_icon("application-exit"), tr("Quit"), self)
quitAction.triggered.connect(QApplication.quit)
self.menu.addAction(quitAction)
"""if self.geometry().width() < 8:
self.toolBar = BackgroundToolBar(None)
self.toolBar.setWindowTitle(common.app_name)
#self.toolBar.setStyleSheet("QToolBar{background:palette(window);border:0;}")
self.button = QToolButton(self.toolBar)
self.button.setIcon(common.app_icon)
self.button.clicked.connect(self.showMenu)
self.toolBar.addWidget(self.button)
extender = QLabel(common.app_name, self.toolBar)
self.toolBar.addWidget(extender)
self.toolBar.hide()
timer = QTimer(timeout=self.toggleButton, parent=self)
timer.start(500)"""
def dontBeImpatient(self):
self.showMessage(tr("You already clicked this button"), tr("Don't be impatient."))
def toggleButton(self):
if len(browser.windows) == 0:
self.toolBar.show()
else:
self.toolBar.hide()
# About.
def about(self):
try: parent = browser.activeWindow()
except:
parent = self.widget
self.widget.show()
QMessageBox.about(parent, tr("About %s") % (common.app_name,),\
"<h3>" + common.app_name + " " +\
common.app_version +\
"</h3>" +\
tr("A Qt-based web browser made in Python.<br><br>%s is provided to you free of charge, with no promises of security or stability. By using this software, you agree not to sue me for anything that goes wrong with it.") % (common.app_name,))
self.widget.hide()
#.........这里部分代码省略.........
示例13: QtFits
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import resize [as 别名]
class QtFits(QApplication):
def __init__(self, filename=None):
super().__init__([])
self.header = None
self.setStyle('Fusion')
self.setApplicationName('QtFits')
self.overlord = QWidget()
self.overlord.resize(800, 500)
overlord_layout = QVBoxLayout()
self.overlord.setLayout(overlord_layout)
overlord_layout.setContentsMargins(0, 0, 0, 0)
overlord_layout.setSpacing(0)
self.window = QWidget()
self.window.resizeEvent = self.resizeEvent
self.window.keyPressEvent = self.keyPressEvent
grid = QGridLayout()
grid.setContentsMargins(0, 0, 0, 0)
self.window.setLayout(grid)
self.minimap = MiniMap()
grid.addWidget(self.minimap, 0, 1, 1, 1)
self.main = ImageDisplay()
grid.addWidget(self.main, 0, 0, 3, 1)
self.cursordisplay = CursorDisplay()
grid.addWidget(self.cursordisplay, 1, 1, 1, 1)
self.box = DirList()
grid.addWidget(self.box, 2, 1, 2, 1)
self.histogram = ImageHistogram()
grid.addWidget(self.histogram, 3, 0, 1, 1)
self.menubar = MenuBar(self)
overlord_layout.addWidget(self.menubar)
overlord_layout.addWidget(self.window)
self.box.main = self.main
self.box.list.app = self
self.main.histogram = self.histogram
self.histogram.main = self.main
self.minimap.main = self.main
self.main.minimap = self.minimap
self.main.cursordisplay = self.cursordisplay
self.handlers = {
Qt.Key_Escape: self.overlord.close,
Qt.Key_Equal: self.main.increase_zoom,
Qt.Key_Minus: self.main.decrease_zoom,
Qt.Key_Down: self.box.list.selection_down,
Qt.Key_Up: self.box.list.selection_up,
Qt.Key_Return: self.box.list.select,
Qt.Key_Right: self.box.list.select,
Qt.Key_Backspace: self.box.list.back,
Qt.Key_Left: self.box.list.back,
}
self.window.setFocusPolicy(Qt.ClickFocus)
if filename is not None:
self.open(filename)
self.overlord.show()
self.exec_()
def open(self, path, hdu=None):
with open(path, 'rb') as input_file:
self.hdulist = fits.open(input_file)
if hdu is None:
hdu = 0
while self.hdulist[hdu].data is None:
hdu += 1
self.set_hdu(hdu)
def set_hdu(self, hdu):
image = self.hdulist[hdu].data.astype(np.float32)
self.main.image = image
self.header = repr(self.hdulist[hdu].header)
self.menubar.set_hdulist(self.hdulist)
def open_dialog(self):
filename = QFileDialog.getOpenFileName(self.main, 'Open file', '.')
if filename[0]:
self.open(filename[0])
def show_header(self):
header_window = HeaderDisplay(self.header)
header_window.show()
header_window.exec_()
def keyPressEvent(self, event):
#.........这里部分代码省略.........
示例14: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import resize [as 别名]
class MainWindow(QMainWindow):
def __init__(self, screen_height, screen_width, version, parent=None):
super(MainWindow, self).__init__(parent)
self.screen_width = screen_width
self.screen_height = screen_height
self.version = version
# basic main window settings
self.resize(MAIN_WINDOW_WIDTH, MAIN_WINDOW_HEIGHT)
self.setWindowTitle('Linguistica {}'.format(self.version))
# lexicon and lexicon tree
self.lexicon = None
self.lexicon_tree = None
self.initialize_lexicon_tree()
# set up major display, parameter window, then load main window
self.majorDisplay = QWidget()
self.parameterWindow = QWidget()
self.load_main_window()
# 'File' menu and actions
select_corpus_action = self.create_action(text='&Select corpus...',
slot=self.corpus_dir_dialog,
tip='Select a corpus file',
shortcut='Ctrl+N')
select_wordlist_action = self.create_action(text='&Select wordlist...',
slot=self.wordlist_dir_dialog,
tip='Select a wordlist file',
shortcut='Ctrl+W')
run_file_action = self.create_action(text='&Run...',
slot=self.run_file,
tip='Run the input file',
shortcut='Ctrl+D')
parameters_action = self.create_action(text='&Parameters...',
slot=self.parameters_dialog,
tip='Change parameters',
shortcut='Ctrl+P')
file_menu = self.menuBar().addMenu('&File')
file_menu.addAction(select_corpus_action)
file_menu.addAction(select_wordlist_action)
file_menu.addAction(run_file_action)
file_menu.addAction(parameters_action)
self.status = self.statusBar()
self.status.setSizeGripEnabled(False)
self.status.showMessage('No input file loaded. To select one: File --> '
'Select corpus... or Select wordlist...')
def initialize_lexicon_tree(self):
self.lexicon_tree = QTreeWidget()
self.lexicon_tree.setEnabled(True)
self.lexicon_tree.setMinimumWidth(TREEWIDGET_WIDTH_MIN)
self.lexicon_tree.setMaximumWidth(TREEWIDGET_WIDTH_MAX)
self.lexicon_tree.setMinimumHeight(TREEWIDGET_HEIGHT_MIN)
self.lexicon_tree.setHeaderLabel('')
self.lexicon_tree.setItemsExpandable(True)
# noinspection PyUnresolvedReferences
self.lexicon_tree.itemClicked.connect(self.tree_item_clicked)
def create_action(self, text=None, slot=None, tip=None, shortcut=None):
"""
This create actions for the File menu, things like
Read Corpus, Rerun Corpus etc
"""
action = QAction(text, self)
if shortcut:
action.setShortcut(shortcut)
if tip:
action.setToolTip(tip)
action.setStatusTip(tip)
if slot:
# noinspection PyUnresolvedReferences
action.triggered.connect(slot)
if shortcut:
# noinspection PyUnresolvedReferences
QShortcut(QKeySequence(shortcut), self).activated.connect(slot)
return action
def _get_filename_from_dialog(self, ftype='input'):
self.determine_last_file()
if self.last_file_path and self.last_file_type == ftype:
open_dir = self.last_file_path
else:
open_dir = os.getcwd()
# noinspection PyTypeChecker,PyCallByClass
fname = QFileDialog.getOpenFileName(self,
'Select the {} file'.format(ftype),
open_dir)
process_all_gui_events()
# HACK: fname is supposed to be a string (at least according to the
# PyQt5 documentation), but for some reason fname is a tuple.
# So we need this hack to make sure that fname is a string of a filename
# -- Jackson Lee, 2015/06/22
# update: it's turned out that this behavior is due to compatibility
# between PyQt and PySide. The "tuple" behavior is in line with the
#.........这里部分代码省略.........
示例15: QWidget
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import resize [as 别名]
from PyQt5.QtWidgets import QSpinBox, QWidget, QVBoxLayout
from PyQt5.QtCore import Qt
w = QWidget()
w.setWindowFlags(Qt.WindowStaysOnTopHint)
w.setAttribute(Qt.WA_ShowWithoutActivating)
vbox = QVBoxLayout()
vbox.addStretch(1)
w.setLayout(vbox)
w.setWindowTitle('Test editor')
w.resize(300,100)
w.show()
b = QSpinBox()
vbox.addWidget(b)
b.valueChanged.connect(PINS.value.set)