#!/usr/bin/env ruby require "qte" require "qpe" require "thread" include Qte include Qpe class SampleWindow < QMainWindow def initialize() super() setCaption(tr("サンプル")) @msg = QLabel.new(tr("これはサンプルプログラム"),self) @msg.setGeometry(10,10,300,30) @ebox1 = QMultiLineEdit.new(self) @ebox1.setGeometry(0,100,635,300) @ebox1.setReadOnly(true) @pb1 = QPushButton.new(tr("Start"),self) @pb1.setGeometry(300,5,100,30) connect(@pb1,QSIGNAL("clicked()"), self, 'cnt') @pb2 = QPushButton.new(tr("Stop1"),self) @pb2.setGeometry(405,5,100,30) connect(@pb2,QSIGNAL("clicked()"), self, 'stop1') @pb3 = QPushButton.new(tr("Stop2"),self) @pb3.setGeometry(510,5,100,30) connect(@pb3,QSIGNAL("clicked()"), self, 'stop2') @pbStop1 = false @pbStop2 = false end def cnt Thread.new { Thread.pass @ebox1.clear @pbStop1 = false @pbStop2 = false i = catch(:exit) { @ebox1.insertLine("loop1 start") while true @ebox1.insertLine("loop2 start") while true if @pbStop1 then throw :exit, "Pb1" end if @pbStop2 then throw :exit, "Pb2" end end end } @ebox1.insertLine("stop by #{i}") } end def stop1 @pbStop1 = true end def stop2 @pbStop2 = true end end $defaultCodec = QTextCodec.codecForName("utf8") app = QPEApplication.new([$0]+ARGV) app.setDefaultCodec($defaultCodec) QApplication.setFont(QFont.new("lcfont",18)) app.showMainWidget(SampleWindow.new) app.exec