Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/panel to dialog #17

Merged
merged 8 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified imgs/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 8 additions & 3 deletions jaxaEarthApiDockWidget.py → jaxaEarthApiDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
license : GNU General Public License v2.0
***************************************************************************/
"""

import os
import json
import datetime
Expand Down Expand Up @@ -78,13 +79,13 @@ def has_yearly_data(data_id: str) -> bool:


# uiファイルの定義と同じクラスを継承する
class JaxaEarthApiDockWidget(QDockWidget):
class JaxaEarthApiDialog(QDialog):
closingPlugin = pyqtSignal()

def __init__(self):
super().__init__()
self.ui = uic.loadUi(
os.path.join(os.path.dirname(__file__), "jaxaEarthApiDockWidget.ui"), self
os.path.join(os.path.dirname(__file__), "jaxaEarthApiDialog.ui"), self
)

self.init_gui()
Expand Down Expand Up @@ -140,6 +141,8 @@ def init_gui(self):
lambda: self.loadButton.setEnabled(self.is_executable())
)

self.adjustSize()

def is_executable(self):
return (
self.datasetCombobox.currentData() is not None
Expand Down Expand Up @@ -256,7 +259,9 @@ def load_dataset(self):
self.startDateEdit.dateTime().secsTo(self.endDateEdit.dateTime())
> 365 * 24 * 60 * 60
):
QMessageBox.information(self, "Error", "1年を超える期間を指定することは出来ません。")
QMessageBox.information(
self, "Error", "1年を超える期間を指定することは出来ません。"
)
return

dataset_name = self.datasetCombobox.currentData()["key"]
Expand Down
54 changes: 23 additions & 31 deletions jaxaEarthApiDockWidget.ui → jaxaEarthApiDialog.ui
Original file line number Diff line number Diff line change
@@ -1,42 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>jaxaEarthApiDockWidget</class>
<widget class="QDockWidget" name="jaxaEarthApiDockWidget">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>380</width>
<height>105</height>
<width>473</width>
<height>84</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>380</width>
<height>105</height>
</size>
</property>
<property name="windowTitle">
<string>JAXA Earth API</string>
</property>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="3" rowspan="2">
<widget class="QPushButton" name="loadButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Load</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="datasetCombobox">
<property name="sizePolicy">
Expand All @@ -60,6 +37,22 @@
</property>
</widget>
</item>
<item row="1" column="3" rowspan="2">
<widget class="QPushButton" name="loadButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Load</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
Expand All @@ -79,9 +72,9 @@
</property>
<property name="dateTime">
<datetime>
<hour>23</hour>
<minute>59</minute>
<second>59</second>
<hour>0</hour>
<minute>0</minute>
<second>0</second>
<year>2000</year>
<month>1</month>
<day>1</day>
Expand Down Expand Up @@ -179,7 +172,6 @@
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
Expand Down
49 changes: 43 additions & 6 deletions jaxaEarthApiPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from qgis.core import *
from qgis.gui import *

from .jaxaEarthApiDockWidget import JaxaEarthApiDockWidget
from .jaxaEarthApiDialog import JaxaEarthApiDialog

PLUGIN_NAME = "JAXA Earth Api"

Expand All @@ -32,20 +32,57 @@ def __init__(self, iface):
self.win = self.iface.mainWindow()
self.plugin_dir = os.path.dirname(__file__)
self.actions = []
self.icon_path = os.path.join(self.plugin_dir, "imgs", "icon.png")
self.menu = PLUGIN_NAME
self.toolbar = self.iface.addToolBar(PLUGIN_NAME)
self.toolbar.setObjectName(PLUGIN_NAME)
self.dockwidget = None
self.dialog = None
self.action = None

def add_action(
self,
icon_path,
text,
callback,
enabled_flag=True,
add_to_menu=True,
add_to_toolbar=True,
status_tip=None,
whats_this=None,
parent=None,
):
icon = QIcon(icon_path)
action = QAction(icon, text, parent)
action.triggered.connect(callback)
action.setEnabled(enabled_flag)
if status_tip is not None:
action.setStatusTip(status_tip)
if whats_this is not None:
action.setWhatsThis(whats_this)
if add_to_toolbar:
self.toolbar.addAction(action)
if add_to_menu:
self.iface.addPluginToMenu(self.menu, action)
self.actions.append(action)
return action

def initGui(self):
# メニュー設定
self.dockwidget = JaxaEarthApiDockWidget()
self.iface.addDockWidget(Qt.RightDockWidgetArea, self.dockwidget)
self.add_action(
icon_path=os.path.join(self.plugin_dir, "imgs", "icon.png"),
text="JAXA Earth API Plugin",
callback=self.show_window,
parent=self.win,
)

self.dialog = JaxaEarthApiDialog()

def unload(self):
self.iface.removePluginMenu(PLUGIN_NAME, self.action)
self.iface.removeToolBarIcon(self.action)
self.action = None

self.iface.removeDockWidget(self.dockwidget)
self.dockwidget = None
del self.toolbar

def show_window(self):
self.dialog.show()
Loading