Skip to content

Commit

Permalink
Added browse file functionality to datasets and projections
Browse files Browse the repository at this point in the history
  • Loading branch information
fintanosullivan committed Dec 18, 2020
1 parent ab59b87 commit d292384
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 1,252 deletions.
32 changes: 24 additions & 8 deletions helloworld/helloworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"""
from qgis.PyQt.QtCore import QSettings, QTranslator, QCoreApplication
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction
from qgis.PyQt.QtWidgets import QAction, QFileDialog
from qgis.core import QgsProject


# Initialize Qt resources from file resources.py
from .resources import *
Expand Down Expand Up @@ -179,6 +181,18 @@ def unload(self):
action)
self.iface.removeToolBarIcon(action)

def browse_datasets(self):
filename = QFileDialog.getOpenFileName()
fname = filename[0].split('/')[-1]
self.dlg.comboBox.addItem(fname)
self.dlg.comboBox.setCurrentText(fname)


def browse_projections(self):
filename = QFileDialog.getOpenFileName()
fname = filename[0].split('/')[-1]
self.dlg.projText.setText(fname)


def run(self):
"""Run method that performs all the real work"""
Expand All @@ -188,13 +202,15 @@ def run(self):
if self.first_start == True:
self.first_start = False
self.dlg = helloWorldDialog()

# Fetch the currently loaded layers
layers = QgsProject.instance().layerTreeRoot().children()
# Clear the contents of the comboBox from previous runs
self.dlg.comboBox.clear()
# Populate the comboBox with names of all the loaded layers
self.dlg.comboBox.addItems([layer.name() for layer in layers])
self.dlg.browseButton.clicked.connect(self.browse_datasets)
self.dlg.browseButton2.clicked.connect(self.browse_projections)

# Fetch the currently loaded layers
layers = QgsProject.instance().layerTreeRoot().children()
# Clear the contents of the comboBox from previous runs
self.dlg.comboBox.clear()
# Populate the comboBox with names of all the loaded layers
self.dlg.comboBox.addItems([layer.name() for layer in layers])

# show the dialog
self.dlg.show()
Expand Down
116 changes: 96 additions & 20 deletions helloworld/helloworld_dialog_base.ui
Original file line number Diff line number Diff line change
@@ -1,33 +1,109 @@
<ui version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>helloWorldDialogBase</class>
<widget class="QDialog" name="helloWorldDialogBase" >
<property name="geometry" >
<widget class="QDialog" name="helloWorldDialogBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string>Hello World</string>
</property>
<widget class="QDialogButtonBox" name="button_box" >
<property name="geometry" >
<widget class="QDialogButtonBox" name="button_box">
<property name="geometry">
<rect>
<x>30</x>
<y>240</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation" >
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QLabel" name="datasetLabel">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>81</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Select a dataset</string>
</property>
</widget>
<widget class="QComboBox" name="comboBox">
<property name="geometry">
<rect>
<x>130</x>
<y>30</y>
<width>201</width>
<height>22</height>
</rect>
</property>
<property name="maxVisibleItems">
<number>100</number>
</property>
</widget>
<widget class="QLabel" name="projLabel">
<property name="geometry">
<rect>
<x>20</x>
<y>80</y>
<width>91</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Select a projection</string>
</property>
</widget>
<widget class="QPushButton" name="browseButton2">
<property name="geometry">
<rect>
<x>340</x>
<y>80</y>
<width>31</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
<widget class="QLineEdit" name="projText">
<property name="geometry">
<rect>
<x>130</x>
<y>80</y>
<width>201</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="browseButton">
<property name="geometry">
<rect>
<x>340</x>
<y>30</y>
<width>31</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</widget>
<resources/>
<connections>
Expand All @@ -37,13 +113,13 @@
<receiver>helloWorldDialogBase</receiver>
<slot>accept()</slot>
<hints>
<hint type="source_label" >
<x>248</x>
<y>254</y>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destination_label" >
<x>157</x>
<y>274</y>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
Expand All @@ -53,13 +129,13 @@
<receiver>helloWorldDialogBase</receiver>
<slot>reject()</slot>
<hints>
<hint type="source_label" >
<x>316</x>
<y>260</y>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destination_label" >
<x>286</x>
<y>274</y>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
Expand Down
35 changes: 0 additions & 35 deletions helloworld/ptobler/__init__.py

This file was deleted.

Loading

0 comments on commit d292384

Please sign in to comment.