设计模式七(采用pyside实现模式六的GUI)

直接给实例:

 

 

# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from future_builtins import *


import sys
from PySide.QtCore import *
from PySide.QtGui import *

from codes import *

QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8"))

 

class Dialog(QDialog):
    def __init__(self,parent=None):
        
        super(Dialog,self).__init__(parent)
        self.builder=None#Builder()
        self.builder_type=['未定义','出口类产品','内销类产品']
        
        layout=QGridLayout(self)
        
        label=QLabel("选择建造者类型")
        layout.addWidget(label,0,0)
        
        self.combox=QComboBox()
        self.combox.addItems(self.builder_type)
        layout.addWidget(self.combox,0,1)
        
        self.log=QLabel()
        layout.addWidget(self.log,1,0,1,2)
        
        button=QPushButton('指挥者 OK')
        layout.addWidget(button,2,2)
        
        
        self.combox.currentIndexChanged.connect(self.select_builder)
        button.clicked.connect(self.director_click)
        pass
    @Slot(str)
    def select_builder(self,str):
        str=self.combox.currentText()
        if str==self.builder_type[1]:
            self.builder=ConcreteBuilderA()
            
        elif str==self.builder_type[2]:
            self.builder=ConcreteBuilderB()
        else:
            self.builder=None
        pass
    
    @Slot()
    def director_click(self):
        
        if self.builder!=None:
            director=Director()
            director.Construct(self.builder)
            
            product=self.builder.GetResult()
            log=product.getLog()
            
            self.log.setText(self.log.text()+'\n\r')
            for x in log:
                self.log.setText(self.log.text()+'\n\r'+x)
                pass
            pass
        else:
            QMessageBox.about(None,"提示","请选择建造者类型")
            pass
        pass
    
    
    
    pass

 

if(__name__=="__main__"):
    app=QApplication(sys.argv)
    
    form=Dialog()
    form.setWindowTitle('建造者模式')
    form.show()
    app.exec_()
    


 

你可能感兴趣的:(架构设计,编程语言,python,Python,设计模式)