Skip to content

Instantly share code, notes, and snippets.

@bols-blue
Created July 25, 2013 13:20
Show Gist options
  • Save bols-blue/6079542 to your computer and use it in GitHub Desktop.
Save bols-blue/6079542 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import sys
import webbrowser
from Tkinter import Tk, Button
from PySide import QtGui
from pyside_from_ui_desiner import Ui_Dialog
class HelloDialog(QtGui.QWidget):
def __init__(self, parent=None):
super(HelloDialog, self).__init__(parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
def accept(data):
print data
return
def reject(data):
print data
return
def openGoogle(data):
webbrowser.open('http://google.com/')
def openYahoo(data):
webbrowser.open('http://yahoo.com/')
def openMS(data):
webbrowser.open('http://microsoft.com/')
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
dlg = HelloDialog()
dlg.show()
sys.exit(app.exec_())
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'untitled.ui'
#
# Created: Thu Jul 25 22:16:46 2013
# by: pyside-uic 0.2.13 running on PySide 1.1.0
#
# WARNING! All changes made in this file will be lost!
from PySide import QtCore, QtGui
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 300)
self.buttonBox = QtGui.QDialogButtonBox(Dialog)
self.buttonBox.setGeometry(QtCore.QRect(30, 240, 341, 32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.gridLayoutWidget = QtGui.QWidget(Dialog)
self.gridLayoutWidget.setGeometry(QtCore.QRect(10, 10, 180, 95))
self.gridLayoutWidget.setObjectName("gridLayoutWidget")
self.gridLayout = QtGui.QGridLayout(self.gridLayoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.label = QtGui.QLabel(self.gridLayoutWidget)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.bButton = QtGui.QPushButton(self.gridLayoutWidget)
self.bButton.setObjectName("bButton")
self.gridLayout.addWidget(self.bButton, 1, 1, 1, 1)
self.label_2 = QtGui.QLabel(self.gridLayoutWidget)
self.label_2.setObjectName("label_2")
self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1)
self.cButton = QtGui.QPushButton(self.gridLayoutWidget)
self.cButton.setObjectName("cButton")
self.gridLayout.addWidget(self.cButton, 2, 1, 1, 1)
self.label_3 = QtGui.QLabel(self.gridLayoutWidget)
self.label_3.setObjectName("label_3")
self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1)
self.aButton = QtGui.QPushButton(self.gridLayoutWidget)
self.aButton.setObjectName("aButton")
self.gridLayout.addWidget(self.aButton, 0, 1, 1, 1)
self.retranslateUi(Dialog)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), Dialog.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), Dialog.reject)
QtCore.QObject.connect(self.aButton, QtCore.SIGNAL("clicked()"), Dialog.openGoogle)
QtCore.QObject.connect(self.bButton, QtCore.SIGNAL("clicked()"), Dialog.openYahoo)
QtCore.QObject.connect(self.cButton, QtCore.SIGNAL("clicked()"), Dialog.openMS)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("Dialog", "googleです", None, QtGui.QApplication.UnicodeUTF8))
self.bButton.setText(QtGui.QApplication.translate("Dialog", "B", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("Dialog", "yahooです", None, QtGui.QApplication.UnicodeUTF8))
self.cButton.setText(QtGui.QApplication.translate("Dialog", "C", None, QtGui.QApplication.UnicodeUTF8))
self.label_3.setText(QtGui.QApplication.translate("Dialog", "MSです", None, QtGui.QApplication.UnicodeUTF8))
self.aButton.setText(QtGui.QApplication.translate("Dialog", "A", None, QtGui.QApplication.UnicodeUTF8))
@bols-blue
Copy link
Author

pysideのインストールはpipはダメだった
仕方ないのでバイナリをaptitudeで入れた
入れたのは
$ sudo aptitude install python-pyside pyside-tools qt4-dev-tools qt4-designer
デザイナの起動は
$ designer-qt4
で行える。
シグナルはスロットでうけるので
スロットの追加をするとUIデザイナから呼ぶ関数を選べる
http://blog.qt.digia.com/jp/2011/03/23/go-to-slot/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment