QGISでアプリケーションを作成する その1
引き続き下記ブログを参考に進めます。
Creating a Standalone GIS Application
QtDesignerでGUI作成
Qtのインストールの説明は省きます。
QtDesignerを起動して、[templaets\forms]から[Main Window]を選択し、[作成]をクリック。
左に表示されているwidgetから[Frame widget]をドラッグして、main windowへ配置します。
[フォーム」→[格子状に並べる]でFrameの大きさを調整しておきます。
作成したGUIを"shapeviewer_gui.ui"という名前で保存しておきます。
python scriptへ変換するために下記コンパイルを行います。
pyuic4 -o shapeviewer_gui.py shapeviewer_gui.ui
shapeviewer_gui.py の中身は下記ですが、いじらずにこのまま。
QtDesignerの工程を飛ばしたい場合は、下記をファイルに保存して使用してもらっても動きます。
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'shapeviewer_gui.ui' # # Created: Fri Nov 19 17:07:47 2010 # by: PyQt4 UI code generator 4.5.2 # # WARNING! All changes made in this file will be lost! from PyQt4 import QtCore, QtGui #@UnresolvedImport class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(800, 600) self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.gridLayout = QtGui.QGridLayout(self.centralwidget) self.gridLayout.setObjectName("gridLayout") self.frame = QtGui.QFrame(self.centralwidget) self.frame.setFrameShape(QtGui.QFrame.StyledPanel) self.frame.setFrameShadow(QtGui.QFrame.Raised) self.frame.setObjectName("frame") self.gridLayout.addWidget(self.frame, 0, 0, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtGui.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 19)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
Eclipseに取り込んで動作させる
Creating a Standalone GIS Application
の通りに shapeviewer.py を作成しておきます。
eclipseを起動して新しいプロジェクトを作成します。
当然Pydevv Projectを選択。
[Grammar Version]は[2.5]を、[Interpreter]は[osgeo](QGIS開発環境として設定しておいたもの)を選択します。
出来たプロジェクトに、shapeviewer_gui.py、shapeviewer.pyを追加すれば終了です。
breakpointを入れながらdebug出来ます。