#!/usr/bin/env ruby require "qte" require "qpe" 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,280,635,120) @ebox1.setReadOnly(true) @pb1 = QPushButton.new(tr("ボタン1"),self) @pb1.setGeometry(320,5,100,30) connect(@pb1,QSIGNAL("clicked()"), self, 'openSubWindow') end def openSubWindow sw = SubWindow.new(self) @ebox1.clear if (sw.exec() != 0) || (sw.pbSel?) then @ebox1.setText( sw.getFilePath ) end end end class SubWindow < QDialog def initialize(parent) super( nil, "", true) setCaption(tr("ファイル選択")) setFixedSize(500,360) @label = QLabel.new(tr("/"),self) @label.setGeometry(0,0,500,30) @list = QListView.new(self) @list.setGeometry(0,30,500,270) @list.addColumn(tr("ファイル")) @list.setColumnWidth(0, 490) # @list.setAllColumnsShowFocus(true) connect(@list, QSIGNAL("clicked(QListViewItem *)"), self, "selectFile") connect(@list, QSIGNAL("returnPressed(QListViewItem *)"), self, "selectFile") @ebox = QLineEdit.new(self) @ebox.setGeometry(0,300,500,30) @ebox.setReadOnly(true) @pb = QPushButton.new(tr("選択"),self) @pb.setGeometry(200,330,100,30) connect(@pb,QSIGNAL("clicked()"), self, 'closeSubWindow') @pwd = "/home/zaurus" listFile(@pwd) @file = nil @pbSel = false end def selectFile(item) if !item.nil? then @file = item.text(0).local8Bit.to_str pwd1 = File.join(@pwd, @file) if @file == ".." then @pwd = File.split(@pwd)[0] Dir.chdir(@pwd) listFile(@pwd) @file = nil elsif File.directory?(pwd1) then Dir.chdir(pwd1) @pwd = pwd1 listFile(@pwd) @file = nil else @ebox.setText(tr(@file)) end end end def listFile(path) @label.setText(path) @ebox.clear @list.clear dir = Dir.open(path) dir.each{ |name| next if name == "." next if name =~ /^\.[^\.]+/ QListViewItem.new(@list, tr(name)) } dir.close end def closeSubWindow if !@file.nil? then @pbSel = true close() end end def getFilePath return tr(File.join(@pwd, @file)) end def pbSel? return @pbSel 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