#!/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("ボタン1"),self) @pb1.setGeometry(300,5,100,30) connect(@pb1,QSIGNAL("clicked()"), self, 'cnt3') @pb2 = QPushButton.new(tr("ボタン2"),self) @pb2.setGeometry(405,5,100,30) # connect(@pb2,QSIGNAL("clicked()"), self, 'cnt4') connect(@pb2,QSIGNAL("clicked()"), self, 'cnt5') @pb3 = QPushButton.new(tr("ボタン3"),self) @pb3.setGeometry(510,5,100,30) connect(@pb3,QSIGNAL("clicked()"), self, 'cntAbort') @a = Array.new @execCnt3 = false @abort = false end def cnt1 t = Thread.new do Thread.pass for i in 1..100 do @ebox1.insertLine(i.to_s) sleep 0.1 end end end def cnt2 for i in 101..200 do @ebox1.insertLine(i.to_s) sleep 0.1 end end def cnt3 t = Thread.new do Thread.pass @execCnt3 = true @ebox1.insertLine("cnt3 start") c = catch(:exit){ for i in 0..99 do if @abort then throw :exit, "abt" else @a[i] = i sleep 0.1 end end @execCnt3 = false } if c == "abt" then @ebox1.insertLine("cnt3 abort") end @ebox1.insertLine("cnt3 end") end end def cnt4 @ebox1.insertLine("cnt4 start") @a.each do |i| @ebox1.insertLine(i.to_s) end @ebox1.insertLine("cnt4 end") end def cnt5 t = Thread.new do Thread.pass @ebox1.insertLine("cnt5 start") i = 0 c = catch(:exit){ while @execCnt3 if @abort then throw :exit, "abt" elsif @a[i].nil? then sleep 0.5 else @ebox1.insertLine(@a[i].to_s) i = i + 1 end end until @a[i].nil? @ebox1.insertLine(@a[i].to_s) i = i + 1 end } if c == "abt" then @ebox1.insertLine("cnt5 abort") end @ebox1.insertLine("cnt5 end") # QMessageBox.information(self, "End", "End") end end def cntAbort @ebox1.insertLine("Push pb3") @abort = 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