设计模式七(采用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_()
    


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值