티스토리 뷰

PySide - Combine (Show, About, Close)


combine.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>731</width>
    <height>475</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QGridLayout" name="gridLayout">
    <item row="0" column="0">
     <widget class="QTextEdit" name="textEdit"/>
    </item>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>731</width>
     <height>21</height>
    </rect>
   </property>
   <widget class="QMenu" name="menu_File">
    <property name="title">
     <string>&amp;File</string>
    </property>
    <addaction name="actionShow_CCPL"/>
    <addaction name="action_About"/>
    <addaction name="action_Close"/>
   </widget>
   <addaction name="menu_File"/>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
  <action name="actionShow_CCPL">
   <property name="text">
    <string>Show &amp;CCPL</string>
   </property>
  </action>
  <action name="action_About">
   <property name="text">
    <string>&amp;About</string>
   </property>
  </action>
  <action name="action_Close">
   <property name="checkable">
    <bool>false</bool>
   </property>
   <property name="text">
    <string>Close   &amp;X</string>
   </property>
  </action>
 </widget>
 <resources/>
 <connections>
  <connection>
   <sender>action_Close</sender>
   <signal>triggered()</signal>
   <receiver>MainWindow</receiver>
   <slot>close()</slot>
   <hints>
    <hint type="sourcelabel">
     <x>-1</x>
     <y>-1</y>
    </hint>
    <hint type="destinationlabel">
     <x>365</x>
     <y>237</y>
    </hint>
   </hints>
  </connection>
 </connections>
</ui>

cs


$ pyside-uic combine.ui > ui_combine.py


combine.qrc

<!DOCTYPE RCC>
<RCC version="1.0">
<qresource>
<file alias="quit.png">image/quit.png</file>
<file alias="about.png">image/about.png</file>
<file alias="show.png">image/show.png</file>
</qresource>
</RCC>

cs


$ pyside-rcc combine.qrc -o qrc_combine.py


combine.py

#!/usr/bin/python
# -*- coding: utf-8 -*-
 
# combine.py - combination of ShowGPL, About, Close scripts
 
import sys
import platform
import PySide
 
from PySide.QtGui import (QApplication, QMainWindow, QMessageBox,  QIcon)
 
__version__ = '1.0.0'
 
from ui_combine import Ui_MainWindow
 
if int(platform.python_version()[0]) < 3:
    import qrc_combine
 
class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.setWindowTitle('Combine Code Blocks.')
        self.actionShow_CCPL.triggered.connect(self.showCCPL)
        self.action_About.triggered.connect(self.about)                
        iconToolBar = self.addToolBar(''
#------------------------------------------------------
# Add icons to appear in tool bar - step 1
        self.actionShow_CCPL.setIcon(QIcon(":/show.png"))
        self.action_About.setIcon(QIcon(":/about.png"))
        self.action_Close.setIcon(QIcon(":/quit.png"))
#------------------------------------------------------
# Show a tip on the Status Bar - step 2
        self.actionShow_CCPL.setStatusTip("Show CCP Licence")
        self.action_About.setStatusTip("Pop up the About dialog.")
        self.action_Close.setStatusTip("Close the program.")
#------------------------------------------------------        
        iconToolBar.addAction(self.actionShow_CCPL)
        iconToolBar.addAction(self.action_About)
        iconToolBar.addAction(self.action_Close)
        
    def showCCPL(self):
        'Read and display CCPL licence.'
        with open('licence.txt') as fi:                  
            self.textEdit.setText(fi.read())        
        
    def about(self):
        '''Popup a box with about message.'''
        QMessageBox.about(self, "About PySide, Platform and version.",
                """<b> about.py version %s </b> 
                <p>Copyright &copy; 2015 by do9dark. 
                <p>This application is useful for displaying  
                Qt version and other details.
                <p>Python %s -  PySide version %s - Qt version %s on %s""" %
                (__version__, platform.python_version(), PySide.__version__,
                 PySide.QtCore.__version__, platform.system()))                      
                
if __name__ == '__main__':
    app = QApplication(sys.argv)
    frame = MainWindow()
    frame.show()
    sys.exit(app.exec_())

cs




'Programming > Python' 카테고리의 다른 글

(PEP 8) Style Guide for Python Code  (0) 2016.08.15
Python Modules  (0) 2016.01.16
Scapy 사용하기  (0) 2015.04.11
Scapy 설치하기  (0) 2015.04.11
PySide - Show Licence (File Open)  (0) 2015.04.07
PySide - About Box  (0) 2015.04.07
PySide - Close Button  (0) 2015.04.05
PySide - QMessageBox  (0) 2015.04.05
OS X에서 PySide 설치하기  (0) 2015.04.05
쉘 스크립트(shell script)의 시작 #!(shebang)  (0) 2014.11.14
댓글
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
링크
공지사항
Total
Today
Yesterday