本文整理汇总了Python中ui.Ui_MainWindow.setupUi方法的典型用法代码示例。如果您正苦于以下问题:Python Ui_MainWindow.setupUi方法的具体用法?Python Ui_MainWindow.setupUi怎么用?Python Ui_MainWindow.setupUi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ui.Ui_MainWindow
的用法示例。
在下文中一共展示了Ui_MainWindow.setupUi方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mainForm
# 需要导入模块: from ui import Ui_MainWindow [as 别名]
# 或者: from ui.Ui_MainWindow import setupUi [as 别名]
class mainForm(QtGui.QMainWindow):
def __init__(self, parent = None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.pannel = []
# 기본 패널
self.pannel.append(tab_widget(addTab, self))
self.func_insert_tab(u'새로운 탭')
self.pannel.append(tab_widget(communicationPannel, self))
self.func_insert_tab(u'DataPort')
QtCore.QObject.connect(self.pannel[0].pannel.ui.clb, QtCore.SIGNAL("clicked()"), self.AddTab)
def AddTab(self):
current_index = len(self.ui.tabWidget)
self.pannel.append(tab_widget(communicationPannel, self))
self.func_insert_tab(u'DataPort')
# 프로그램을 닫으려 할때
def closeEvent(self, event):
reply = QtGui.QMessageBox.warning(self,
u'프로그램 종료', u"진행중인 모든 데이터 송·수신을 중지합니다.\n프로그램을 종료하시겠습니까?",
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
event.accept()
elif reply == QtGui.QMessageBox.No:
event.ignore()
def func_insert_tab(self, tab_name):
"""
* 탭이 추가되면 항상 '새탭추가탭' 앞 쪽에 위치
* 추가된 탭이 활성화
"""
current_index = len(self.ui.tabWidget)
self.ui.tabWidget.insertTab(current_index - 1, self.pannel[current_index], unicode(tab_name))
self.ui.tabWidget.setCurrentIndex(current_index - 1)
def slot_close_tab(self, tab_index):
print tab_index
if 1 == self.ui.tabWidget.count():
# '새탭 추가탭'을 닫으려 할 경우
return
reply = QtGui.QMessageBox.warning(
self,u'탭 닫기', u"저장하지 않은 작업 내용은 잃게됩니다.\n탭을 닫으시겠습니까?",
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
self.pannel.pop(tab_index + 1)
self.ui.tabWidget.removeTab(tab_index)
elif reply == QtGui.QMessageBox.No: pass
示例2: Gui
# 需要导入模块: from ui import Ui_MainWindow [as 别名]
# 或者: from ui.Ui_MainWindow import setupUi [as 别名]
class Gui(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.video = Video(cv2.VideoCapture(0))
self._timer = QtCore.QTimer(self)
self._timer.timeout.connect(self.play)
self._timer.start(27)
self.update()
def play(self):
'''
capture frame and display
'''
try:
self.video.capture_next_frame()
self.ui.videoFrame.setPixmap(
self.video.convert_frame())
self.ui.videoFrame.setScaledContents(True)
except TypeError:
print "No frame"
def mousePressEvent(self, event):
'''
click mouse and put point on opencv window
'''
self.video.add_point(QtCore.QPoint(event.pos()),
self.ui.videoFrame.geometry())
示例3: MyForm
# 需要导入模块: from ui import Ui_MainWindow [as 别名]
# 或者: from ui.Ui_MainWindow import setupUi [as 别名]
class MyForm(QtGui.QMainWindow):
def showMessage(self,string):
self.ui.messageTextbox.setText(string)
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
#here start
downloader.fileLabel = self.ui.fileLabel
downloader.nowSizeLabel = self.ui.nowSizeLabel
downloader.totalSizeLabel = self.ui.totalSizeLabel
downloader.messageTextbox = self.ui.messageTextbox
#pass para
self.connect(self.ui.aButton,QtCore.SIGNAL('clicked()'),self.aButton_clicked)
self.connect(self.ui.bButton,QtCore.SIGNAL('clicked()'),self.bButton_clicked)
self.connect(self.ui.aAfternoonButton,QtCore.SIGNAL('clicked()'),self.aAfternoonButton_clicked)
self.connect(self.ui.bAfternoonButton,QtCore.SIGNAL('clicked()'),self.bAfternoonButton_clicked)
self.connect(self.ui.downloadPercentButton,QtCore.SIGNAL('clicked()'),self.downloadPercentButton_clicked)
self.connect(self.ui.nextButton,QtCore.SIGNAL('clicked()'),self.nextButton_clicked)
#event
def aButton_clicked(self):
thread.start_new_thread(downloader.main,(1,True))
def bButton_clicked(self):
thread.start_new_thread(downloader.main,(0,True))
def aAfternoonButton_clicked(self):
thread.start_new_thread(downloader.main,(1,False))
def bAfternoonButton_clicked(self):
thread.start_new_thread(downloader.main,(0,False))
def nextButton_clicked(self):
downloader.goNext = True
def downloadPercentButton_clicked(self):
downloader.refreshPercent()
示例4: Gui
# 需要导入模块: from ui import Ui_MainWindow [as 别名]
# 或者: from ui.Ui_MainWindow import setupUi [as 别名]
class Gui(QtGui.QMainWindow):
def __init__(self,capture, getFrame, parent = None):
QtGui.QWidget.__init__(self,parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.video = Video(capture, getFrame)
self._timer = QtCore.QTimer(self)
self._timer.timeout.connect(self.play)
self._timer.start(27)
self.update()
def play(self):
try:
self.video.captureNextFrame()
self.ui.videoFrame.setPixmap(self.video.convertFrame())
self.ui.videoFrame.setScaledContents(True)
gethistogram(self.ui.axes,tuple(self.video.histogram.values()),tuple(self.video.histogram.keys()))
# l = [random.randint(0, 10) for i in range(4)]
# self.ui.axes.plot(self.video.histogram.values(), 'r')
self.ui.canvas.draw()
if(len(self.video.labels)!=0):
self.ui.label1.setText(self.video.name)
# self.ui.label2.setText(self.video.labels[1])
# self.ui.label3.setText(self.video.labels[2])
# self.ui.label4.setText(self.video.labels[3])
# self.ui.label5.setText(self.video.labels[4])
except TypeError as e:
print("No Frame", e)
示例5: StartQT4
# 需要导入模块: from ui import Ui_MainWindow [as 别名]
# 或者: from ui.Ui_MainWindow import setupUi [as 别名]
class StartQT4(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.clidict = Param_To_Cli()
self.ui.interface_choice.addItems(netifaces.interfaces())
QtCore.QObject.connect(
self.ui.start, QtCore.SIGNAL("clicked()"), self.start_sniffer)
# QtCore.QObject.connect(
# self.ui.interface_choice, QtCore.SIGNAL("activated(const QString&)"), self.get_interface)
#
# QtCore.QObject.connect(
# self.ui.mode_choice, QtCore.SIGNAL("activated(const QString&)"), self.get_mode)
# QtCore.QObject.connect(
# self.ui.lineEdit, QtCore.SIGNAL("editingFinished()"), self.get_filter)
def start_sniffer(self):
self.clidict.interface = str(self.ui.interface_choice.currentText())
self.clidict.mode = str(self.ui.mode_choice.currentText())
self.clidict.filter = str(self.ui.lineEdit.text())
log.debug(self.clidict.interface + '' +
self.clidict.mode + '' + self.clidict.filter)
sniffer_prepare(self.clidict)
self.sniff_queue = Queue()
sniffer = SnifferProcess(
self.sniff_queue, iface=self.clidict.interface)
sniffer.start()
while True:
item = self.sniff_queue.get()
self.ui.packet_list.addItem(item.summary())
QtGui.QApplication.processEvents()
示例6: main
# 需要导入模块: from ui import Ui_MainWindow [as 别名]
# 或者: from ui.Ui_MainWindow import setupUi [as 别名]
class main(QtGui.QMainWindow):
def __init__(self,parent=None):
QtGui.QWidget.__init__(self,parent)
self.file_dialog=QtGui.QFileDialog()
self.ui=Ui_MainWindow()
self.ui.setupUi(self)
self.fn=None
QtCore.QObject.connect(self.ui.action_Save,QtCore.SIGNAL("triggered()"),self.save_file)
QtCore.QObject.connect(self.ui.actionNew,QtCore.SIGNAL("triggered()"),self.new_file)
QtCore.QObject.connect(self.ui.actionOpen,QtCore.SIGNAL("triggered()"),self.open_file)
QtCore.QObject.connect(self.ui.action_Saveas,QtCore.SIGNAL("triggered()"),self.saveas_file)
QtCore.QObject.connect(self.ui.actionPrint,QtCore.SIGNAL("triggered()"),self.save_file)
QtCore.QObject.connect(self.ui.actionPrint_Preview,QtCore.SIGNAL("triggered()"),self.save_file)
QtCore.QObject.connect(self.ui.action_quit,QtCore.SIGNAL("triggered()"),self.quit)
def save_file(self):
if self.fn!=None:
fileobj=open(self.fn,'w')
fileobj.write(self.ui.textEdit.toPlainText())
fileobj.close()
else:
filename=self.file_dialog.getSaveFileName(self,u"保存文件")
try:
fileobj=open(filename,'w')
fileobj.write(self.ui.textEdit.toPlainText())
self.fn=filename
fileobj.close()
except Exception ,e:
pass
示例7: MyForm
# 需要导入模块: from ui import Ui_MainWindow [as 别名]
# 或者: from ui.Ui_MainWindow import setupUi [as 别名]
class MyForm(QtGui.QMainWindow):
def __init__(self, logAnalyser, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self, len(logAnalyser.files))
self.logAnalyser = logAnalyser
self.threadLogAnalyser = ThreadedLogAnalyser(self, self.logAnalyser)
self.connect(self.threadLogAnalyser, QtCore.SIGNAL("appendLogs"), self.ui.appendLogs)
def main(self):
self.threadLogAnalyser.start()
示例8: StartQT4
# 需要导入模块: from ui import Ui_MainWindow [as 别名]
# 或者: from ui.Ui_MainWindow import setupUi [as 别名]
class StartQT4(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.clidict = Param_To_Cli()
self.ui.interface_choice.addItems(netifaces.interfaces())
QtCore.QObject.connect(
self.ui.start, QtCore.SIGNAL("clicked()"), self.start_sniffer)
QtCore.QObject.connect(
self.ui.action_stop, QtCore.SIGNAL("triggered()"), self.stop_sniffer)
#self.ui.packet_list.setHorizontalHeaderLabels(['时间','源地址','目的地址','内容'])
# QtCore.QObject.connect(
# self.ui.interface_choice, QtCore.SIGNAL("activated(const QString&)"), self.get_interface)
#
# QtCore.QObject.connect(
# self.ui.mode_choice, QtCore.SIGNAL("activated(const QString&)"), self.get_mode)
# QtCore.QObject.connect(
# self.ui.lineEdit, QtCore.SIGNAL("editingFinished()"), self.get_filter)
def start_sniffer(self):
self.clidict.interface = str(self.ui.interface_choice.currentText())
self.clidict.mode = str(self.ui.mode_choice.currentText())
self.clidict.filter = str(self.ui.lineEdit.text())
log.debug(self.clidict.interface + '' + self.clidict.mode + '' + self.clidict.filter)
sniffer_prepare(self.clidict)
self.sniff_queue = multiprocessing.JoinableQueue()
self.sniffer = SnifferProcess(self.sniff_queue, iface=str(self.clidict.interface))
self.sniffer.start()
self.displaythreading = DisplayPacket(self.sniff_queue, self.ui.packet_list)
self.displaythreading.start()
self.ui.action_stop.setEnabled(True)
def stop_sniffer(self):
self.sniffer.terminate()
self.sniff_queue.close()
while True:
if self.sniff_queue.empty():
break
self.displaythreading.terminate()
示例9: Gui
# 需要导入模块: from ui import Ui_MainWindow [as 别名]
# 或者: from ui.Ui_MainWindow import setupUi [as 别名]
class Gui(QtGui.QMainWindow):
def __init__(self,parent=None):
QtGui.QWidget.__init__(self,parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.start_button.clicked.connect(self.start_master)
self.ui.connect_button.clicked.connect(self.start_client)
self.ui.close_button.clicked.connect(self.close)
self.CONNECTION_PORT = 1111
self.update()
def start_master(self):
hablar_master(self.CONNECTION_PORT, self.ui.label)
def start_client(self):
ip = self.ui.ip.getText()
hablar_client(ip, self.CONNECTION_PORT, self.ui.label)
def close(self):
sys.exit()
示例10: FreereaderUi
# 需要导入模块: from ui import Ui_MainWindow [as 别名]
# 或者: from ui.Ui_MainWindow import setupUi [as 别名]
class FreereaderUi(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self,parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.readButton, QtCore.SIGNAL("clicked()"), self.readButton)
QtCore.QMetaObject.connectSlotsByName(self)
def readButton(self):
self.notify('please wait')
try:
obj = feedparser.parse(str(self.ui.urlText.text()))
self.notify('feed readed')
if obj.entries != []:
for entry in obj.entries:
self.ui.listWidget.addItem(entry.title)
except:
self.notify('error in parsing url')
def notify(self, string = ''):
self.ui.notification.setText(string)
示例11: MainWindow
# 需要导入模块: from ui import Ui_MainWindow [as 别名]
# 或者: from ui.Ui_MainWindow import setupUi [as 别名]
class MainWindow(QMainWindow):
'''First application window the user sees'''
def __init__(self, pod):
super().__init__()
self._pod = pod
self._ui = Ui_MainWindow()
self._ui.setupUi(self)
self._ui.actionNetwork.triggered.connect(self.networkDialog)
def networkDialog(self):
'''Open a window for changing network settings'''
la = self._pod.get_local_addr()
ra = self._pod.get_remote_addr()
info = NetworkInfo(local=la, remote=ra)
dialog = NetworkDialog(info)
if dialog.exec_() == QDialog.Accepted:
la, old = info.local, la
if la != old:
self._pod.set_local_addr(info.local)
ra, old = info.remote, ra
if ra != old:
self._pod.set_remote_addr(info.remote)
示例12: MainWindow
# 需要导入模块: from ui import Ui_MainWindow [as 别名]
# 或者: from ui.Ui_MainWindow import setupUi [as 别名]
class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
# UI Setup
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
# Set the default icons for UI actions
self.ui.actionNew.setIcon(QtGui.QIcon.fromTheme("document-new"))
self.ui.actionOpen.setIcon(QtGui.QIcon.fromTheme("document-open"))
self.ui.actionSave.setIcon(QtGui.QIcon.fromTheme("document-save"))
self.ui.actionSave_As.setIcon(QtGui.QIcon.fromTheme("document-save-as"))
self.ui.actionPrint.setIcon(QtGui.QIcon.fromTheme("document-print"))
self.ui.actionQuit.setIcon(QtGui.QIcon.fromTheme("system-log-out"))
self.ui.actionUndo.setIcon(QtGui.QIcon.fromTheme("edit-undo"))
self.ui.actionRedo.setIcon(QtGui.QIcon.fromTheme("edit-redo"))
self.ui.actionCut.setIcon(QtGui.QIcon.fromTheme("edit-cut"))
self.ui.actionCopy.setIcon(QtGui.QIcon.fromTheme("edit-copy"))
self.ui.actionPaste.setIcon(QtGui.QIcon.fromTheme("edit-paste"))
self.ui.actionDelete.setIcon(QtGui.QIcon.fromTheme("edit-delete"))
self.ui.actionPreferences.setIcon(QtGui.QIcon.fromTheme("preferences"))
self.ui.actionAbout.setIcon(QtGui.QIcon.fromTheme("help-browser"))
self.ui.actionRun.setIcon(QtGui.QIcon.fromTheme("go-next"))
# UI ToolBox
self.buttonGroup = QtGui.QButtonGroup()
self.buttonGroup.setExclusive(False)
self.buttonGroup.buttonClicked[int].connect(self.toolBoxButtonClicked)
self.toolBox = self.ui.componentBrowser
# Populate the toolbox
self.createToolBox()
# Create a scene for the GraphicsView
self.scene=DiagramScene()
self.ui.graphicsView.setScene(self.scene)
self.scene.setSceneRect(0,0,600,400)
# Make it bigger
self.setWindowState(QtCore.Qt.WindowMaximized)
# Create an UNDO stack and view
self.undoStack = QtGui.QUndoStack(self)
self.undoView = QtGui.QUndoView(self.undoStack)
self.undoView.setWindowTitle("Undo View")
self.undoView.show()
self.undoView.setAttribute(QtCore.Qt.WA_QuitOnClose, False)
self.createActions()
self.createMenus()
# Set the window title
self.setWindowTitle("Schematix")
def createActions(self):
self.ui.actionDelete = QtGui.QAction("&Delete Item", self)
self.ui.actionDelete.setShortcut("Del");
QtCore.QObject.connect(self.ui.actionDelete,
QtCore.SIGNAL("triggered()"),
self.deleteItem)
# QtCore.QObject.connect(self.scene,
# QtCore.SIGNAL("itemMoved()"),
# self.itemMoved)
self.scene.itemMoved.connect(self.itemMoved)
self.ui.actionUndo = self.undoStack.createUndoAction(self, "&Undo")
self.ui.actionUndo.setShortcuts(QtGui.QKeySequence.Undo)
self.ui.actionRedo = self.undoStack.createRedoAction(self, "&Redo")
self.ui.actionRedo.setShortcuts(QtGui.QKeySequence.Redo)
def createMenus(self):
self.newEditMenu = self.ui.menubar.addMenu("&EditNew")
self.newEditMenu.addAction(self.ui.actionUndo)
self.newEditMenu.addAction(self.ui.actionRedo)
self.newEditMenu.addSeparator()
self.newEditMenu.addAction(self.ui.actionDelete)
QtCore.QObject.connect(self.ui.menuEdit,
QtCore.SIGNAL("aboutToShow()"),
self.itemMenuAboutToShow)
QtCore.QObject.connect(self.ui.menuEdit,
QtCore.SIGNAL("aboutToHide()"),
self.itemMenuAboutToHide)
def itemMenuAboutToHide(self):
self.ui.actionDelete.setEnabled(True)
def itemMenuAboutToShow(self):
self.ui.actionDelete.setEnabled(len(self.scene.selectedItems())!=0)
def deleteItem(self):
print "Delete called..."
if (len(self.scene.selectedItems()) == 0):
return
deleteCommand = DeleteCommand(self.scene)
self.undoStack.push(deleteCommand);
def addComponent(self, component):
# TODO: Make it so that the component has to be dragged onto the
# canvas from the toolbox, or clicked once in the toolbox and then
# clicked again on the canvas to place or right click/esc to cancel.
action = AddCommand(component, self.scene)
self.undoStack.push(action)
def itemMoved(self, movedItem, oldPosition):
print "MAINWINDOW: An item in the graphics view got moved..."
self.undoStack.push(MoveCommand(movedItem, oldPosition))
def createToolBox(self):
""" Populates the toolbox widget of the main UI with components
#.........这里部分代码省略.........
示例13: MainWindow
# 需要导入模块: from ui import Ui_MainWindow [as 别名]
# 或者: from ui.Ui_MainWindow import setupUi [as 别名]
class MainWindow(QtGui.QMainWindow):
def __init__(self, N):
super(MainWindow, self).__init__()
# This is always the same
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
# no resizing
self.setFixedSize(self.width(), self.height())
from sph_demo import SPHDemo
enable_advanced_rendering = not '--disable-advanced-rendering' in sys.argv
self.sph_demo = SPHDemo(N, size=(self.ui.fluid.width(), self.ui.fluid.height()), enable_advanced_rendering=enable_advanced_rendering)
# ui.fluid is the FluidWidget QGLWidget-widget.
self.ui.fluid.init(self.sph_demo)
self.ui.fluid.gl_initialized.connect(self.update_gui_from_params)
self.setup_signals()
statusBarInfo = QtGui.QLabel()
statusBarInfo.setText("%s particles, initial density: %s, mass: %.02f, gas constant k: %s, timestep: %.05f" % (
self.sph_demo.fluid_simulator.N,
self.sph_demo.fluid_simulator.density0,
self.sph_demo.fluid_simulator.mass,
self.sph_demo.fluid_simulator.k,
self.sph_demo.fluid_simulator.dt
))
self.statusBarFps = QtGui.QLabel()
self.statusBar().addPermanentWidget(self.statusBarFps)
self.statusBar().addWidget(statusBarInfo)
if not self.sph_demo.enable_advanced_rendering:
# disable ui elements dealing with advanced rendering
self.ui.rm_points.setChecked(True)
for el in (self.ui.rm_balls,
self.ui.rm_advanced,
self.ui.advanced,):
el.setEnabled(False)
def setup_signals(self):
"""
Set up callbacks for the widgets.
"""
ui = self.ui
self.fps_timer = QtCore.QTimer()
def callback():
self.statusBarFps.setText("%.2f fps" % self.sph_demo.fps)
self.fps_timer.timeout.connect(callback)
self.fps_timer.start(1000)
def callback(p):
self.sph_demo.params.paused = p
ui.paused.toggled.connect(callback)
if self.sph_demo.enable_advanced_rendering:
#from fluid_rendering.fluid_renderer import FluidRenderer
def callback(p):
self.sph_demo.params.blur_thickness_map = p
ui.blur_thickness_map.toggled.connect(callback)
def callback(p):
self.sph_demo.params.render_mean_curvature = p
ui.render_mean_curvature.toggled.connect(callback)
def callback():
self.sph_demo.params.render_mode = 0
ui.rm_points.pressed.connect(callback)
def callback():
self.sph_demo.params.render_mode = 1
ui.rm_balls.pressed.connect(callback)
def callback():
self.sph_demo.params.render_mode = 2
ui.rm_advanced.pressed.connect(callback)
ui.rm_advanced.toggled.connect(ui.advanced.setEnabled)
def callback(n):
self.sph_demo.params.smoothing_iterations = n
ui.smoothing_iterations.valueChanged.connect(callback)
def callback(n):
self.sph_demo.params.smoothing_z_contrib = n
ui.smoothing_z_contrib.valueChanged.connect(callback)
def update_gui_from_params(self):
params = self.sph_demo.params
if not params.dirty:
return
ui = self.ui
ui.paused.setOn(params.paused)
if self.sph_demo.enable_advanced_rendering:
from fluid_rendering.fluid_renderer import FluidRenderer
ui.blur_thickness_map.setOn(params.blur_thickness_map)
ui.render_mean_curvature.setOn(params.render_mean_curvature)
#.........这里部分代码省略.........
示例14: jaabaGUI
# 需要导入模块: from ui import Ui_MainWindow [as 别名]
# 或者: from ui.Ui_MainWindow import setupUi [as 别名]
class jaabaGUI(QMainWindow):
""" controller for the blob labeling GUI"""
def __init__(self,parent=None):
QMainWindow.__init__(self,parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
#add new slider
# self.positionSlider=QSlider(Qt.Horizontal)
# self.positionSlider.setGeometry (800,800,100,30)
# self.positionSlider.setRange(0, 0)
# self.positionSlider.sliderMoved.connect(self.setPosition)
#setup Video
#video player
self.mediaPlayer1 = QMediaPlayer(None, QMediaPlayer.VideoSurface)
self.mediaPlayer2 = QMediaPlayer(None, QMediaPlayer.VideoSurface)
#self.mediaPlayer.metaDataChanged.connect(self.metaDataChanged)
self.mediaPlayer1.durationChanged.connect(self.durationChanged)
self.mediaPlayer1.positionChanged.connect(self.positionChanged)
self.mediaPlayer2.positionChanged.connect(self.positionChanged)
#visualizetion
self.scene = QGraphicsScene()
self.ui.graphicsView.setScene(self.scene)
#self.scene.setBackgroundBrush(Qt.black)
self.videoItem1 = QGraphicsVideoItem()
self.videoItem2 = QGraphicsVideoItem()
self.scene.addItem(self.videoItem1)
self.scene.addItem(self.videoItem2)
self.mediaPlayer1.setVideoOutput(self.videoItem1)
self.mediaPlayer2.setVideoOutput(self.videoItem2)
#slide bar
print self.ui.horizontalSlider
self.ui.horizontalSlider.setRange(0, 0)
self.ui.horizontalSlider.sliderMoved.connect(self.setPosition)
# self.ui.horizontalSlider.sliderPressed.connect(self.sliderPressed)
#print self.ui.graphicsView.width()/2,self.ui.graphicsView.height()
#self.videoItem1.setSize(QSizeF(self.ui.graphicsView.width()/2,self.ui.graphicsView.height()))
#self.videoItem2.setSize(QSizeF(self.ui.graphicsView.width()*10,self.ui.graphicsView.height()*10))
# self.videoItem2.setSize(graphicsView.size())
#self.videoItem2.setOffset(QPointF(500,500))
#self.videoItem2.setOffset(QPointF(self.ui.graphicsView.width()/2,0))
#self.videoItem2.setPos(QPointF(0,0))
# print self.ui.graphicsView.width(), self.ui.graphicsView.height()
# print self.ui.graphicsView.size()
# print self.videoItem2.boundingRect().width(), self.videoItem2.boundingRect().height()
# print self.ui.graphicsView.sceneRect()
#self.mediaPlayer.stateChanged.connect(self.mediaStateChanged)
#callbacks
self.ui.actionQuit.triggered.connect(self.quit)
self.ui.actionLoad_Project.triggered.connect(self.loadVideo)
#self.ui.buttonPlay.clicked[bool].connect(self.setToggleText)
self.ui.buttonPlay.clicked.connect(self.play)
#print self.ui.graphicsView.sizeHint()
#initialization
self.loaded = False
self.videoFilename = None
self.frame_count=None
self.width=None
self.height=None
self.frame_trans=None
# ###actions starts from here###
def quit(self):
QApplication.quit()
def loadVideo(self):
self.writeLog("Loading video...")
self.videoFilename = QFileDialog.getOpenFileName(self, 'Open File', '.')[0]
if not self.videoFilename:
self.writeLog("User cancelled - no video loaded")
return
else:
cap=cv2.VideoCapture(self.videoFilename)
self.frame_count=cap.get(cv2.CAP_PROP_FRAME_COUNT)
self.width=cap.get(3)
self.height=cap.get(4)
self.mediaPlayer2.setMedia(QMediaContent(QUrl.fromLocalFile(self.videoFilename )))
self.mediaPlayer1.setMedia(QMediaContent(QUrl.fromLocalFile(self.videoFilename )))
self.ui.buttonPlay.setEnabled(True)
# self.mediaPlayer2.setVideoOutput(self.videoItem2)
# self.mediaPlayer1.setVideoOutput(self.videoItem1)
# size= self.videoItem2.nativeSize()
# print size
#print self.mediaPlayer.duration()
#print self.mediaPlayer.metaData()
#.........这里部分代码省略.........
示例15: Gui
# 需要导入模块: from ui import Ui_MainWindow [as 别名]
# 或者: from ui.Ui_MainWindow import setupUi [as 别名]
class Gui(QtGui.QMainWindow):
"""
Main GUI Class
It contains the main function and interfaces between
the GUI and functions
"""
def __init__(self,parent=None):
QtGui.QWidget.__init__(self,parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
""" Main Variables Using Other Classes"""
self.rex = Rexarm()
self.video = Video(cv2.VideoCapture(0))
self.world_coord = np.float32()
""" Play and Repeat Variable """
self.wayPoints = []
self.wayPointsPos = []
self.wayPointsSpeed = []
self.wayPointsTime = []
""" Other Variables """
self.last_click = np.float32([-1,-1])
self.define_template_flag = -1
self.click_point1 = np.float32([-1,-1])
self.click_point2 = np.float32([-1,-1])
self.template = None
self.targets = []
self.waypointsfp = csv.writer(open("waypoint.csv","wb"))
self.currtime = 0
""" Set GUI to track mouse """
QtGui.QWidget.setMouseTracking(self,True)
"""
Video Function
Creates a timer and calls play() function
according to the given time delay (27mm)
"""
self._timer = QtCore.QTimer(self)
self._timer.timeout.connect(self.play)
self._timer.start(27)
"""
LCM Arm Feedback
Creates a timer to call LCM handler continuously
No delay implemented. Reads all time
"""
self._timer2 = QtCore.QTimer(self)
self._timer2.timeout.connect(self.rex.get_feedback)
self._timer2.start()
"""
ARM Plan and Command Thread
Creates a timer to call REXARM.plan_command function continuously
"""
self._timer3 = QtCore.QTimer(self)
self._timer3.timeout.connect(self.rex.plan_command)
self._timer3.start()
"""
Connect Sliders to Function
TO DO: CONNECT THE OTHER 5 SLIDERS IMPLEMENTED IN THE GUI
"""
self.ui.sldrBase.valueChanged.connect(self.slider_change)
self.ui.sldrShoulder.valueChanged.connect(self.slider_change)
self.ui.sldrElbow.valueChanged.connect(self.slider_change)
self.ui.sldrWrist.valueChanged.connect(self.slider_change)
self.ui.sldrMaxTorque.valueChanged.connect(self.slider_change)
self.ui.sldrSpeed.valueChanged.connect(self.slider_change)
""" Commands the arm as the arm initialize to 0,0,0,0 angles """
self.slider_change()
""" Connect Buttons to Functions """
self.ui.btnLoadCameraCal.clicked.connect(self.load_camera_cal)
self.ui.btnPerfAffineCal.clicked.connect(self.affine_cal)
self.ui.btnTeachRepeat.clicked.connect(self.tr_initialize)
self.ui.btnAddWaypoint.clicked.connect(self.tr_add_waypoint)
self.ui.btnSmoothPath.clicked.connect(self.tr_smooth_path)
self.ui.btnPlayback.clicked.connect(self.tr_playback)
self.ui.btnLoadPlan.clicked.connect(self.tr_load)
self.ui.btnDefineTemplate.clicked.connect(self.def_template)
self.ui.btnLocateTargets.clicked.connect(self.template_match)
self.ui.btnExecutePath.clicked.connect(self.exec_path)
def play(self):
"""
Play Funtion
Continuously called by GUI
"""
""" Renders the Video Frame """
try:
self.video.captureNextFrame()
for t in self.targets:
self.video.addTarget(t)
self.ui.videoFrame.setPixmap(self.video.convertFrame())
self.ui.videoFrame.setScaledContents(True)
#.........这里部分代码省略.........