Skip to content

Commit

Permalink
Merge pull request #83 from MIERUNE/rfctr
Browse files Browse the repository at this point in the history
refactor, lint, fix minor bug
  • Loading branch information
Kanahiro authored May 8, 2024
2 parents 22e1f39 + 46bfbe0 commit fa119d6
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 292 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Lint

on:
pull_request:
push:
branches: [main]

jobs:
Test:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install poetry
run: python -m pip install poetry

- uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'poetry'

- name: Install dependencies
run: poetry install

- name: Check poetry.lock
run: poetry lock --check

# - name: Type-check with Pyright
# run: poetry run pyright .

- name: Lint with ruff
run: poetry run ruff --output-format=github .

- name: Format with ruff
run: poetry run ruff format .
28 changes: 1 addition & 27 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************
GTFSGo
A QGIS plugin
The plugin to show routes and stops from GTFS
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
-------------------
begin : 2020-10-29
copyright : (C) 2020 by Kanahiro Iguchi
email : [email protected]
git sha : $Format:%H$
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
This script initializes the plugin, making it known to QGIS.
"""


# noinspection PyPep8Naming
def classFactory(iface): # pylint: disable=invalid-name
"""Load GTFSGo class from file GTFSGo.
Expand All @@ -33,4 +6,5 @@ def classFactory(iface): # pylint: disable=invalid-name
"""
#
from .gtfs_go import GTFSGo

return GTFSGo(iface)
77 changes: 25 additions & 52 deletions gtfs_go.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************
GTFSGo
A QGIS plugin
The plugin to show routes and stops from GTFS
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
-------------------
begin : 2020-10-29
git sha : $Format:%H$
copyright : (C) 2020 by MIERUNE Inc.
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
import os

from qgis.PyQt.QtCore import QSettings, QTranslator, QCoreApplication, Qt
from qgis.PyQt.QtCore import QCoreApplication, QSettings, QTranslator
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction

Expand All @@ -49,11 +26,10 @@ def __init__(self, iface):
self.plugin_dir = os.path.dirname(__file__)

# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
locale = QSettings().value("locale/userLocale")[0:2]
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'GTFSGo_{}.qm'.format(locale))
self.plugin_dir, "i18n", "GTFSGo_{}.qm".format(locale)
)

if os.path.exists(locale_path):
self.translator = QTranslator()
Expand All @@ -62,10 +38,10 @@ def __init__(self, iface):

# Declare instance attributes
self.actions = []
self.menu = self.tr(u'&GTFS GO')
self.menu = self.tr("&GTFS GO")
# TODO: We are going to let the user set this up in a future iteration
self.toolbar = self.iface.addToolBar(u'GTFSGo')
self.toolbar.setObjectName(u'GTFSGo')
self.toolbar = self.iface.addToolBar("GTFSGo")
self.toolbar.setObjectName("GTFSGo")

# print "** INITIALIZING GTFSGo"

Expand All @@ -86,19 +62,20 @@ def tr(self, message):
:rtype: QString
"""
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
return QCoreApplication.translate('GTFSGo', message)
return QCoreApplication.translate("GTFSGo", message)

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):
self,
icon_path,
text,
callback,
enabled_flag=True,
add_to_menu=True,
add_to_toolbar=True,
status_tip=None,
whats_this=None,
parent=None,
):
"""Add a toolbar icon to the toolbar.
:param icon_path: Path to the icon for this action. Can be a resource
Expand Down Expand Up @@ -153,9 +130,7 @@ def add_action(
self.toolbar.addAction(action)

if add_to_menu:
self.iface.addPluginToWebMenu(
self.menu,
action)
self.iface.addPluginToWebMenu(self.menu, action)

self.actions.append(action)

Expand All @@ -164,14 +139,14 @@ def add_action(
def initGui(self):
"""Create the menu entries and toolbar icons inside the QGIS GUI."""

icon_path = os.path.join(os.path.dirname(
__file__), 'imgs', 'busstop.png')
icon_path = os.path.join(os.path.dirname(__file__), "imgs", "busstop.png")
self.add_action(
icon_path,
text=self.tr(u'GTFS GO'),
text=self.tr("GTFS GO"),
callback=self.run,
parent=self.iface.mainWindow(),
add_to_menu=True)
add_to_menu=True,
)

# --------------------------------------------------------------------------

Expand All @@ -197,9 +172,7 @@ def unload(self):
# print "** UNLOAD GTFSGo"

for action in self.actions:
self.iface.removePluginWebMenu(
self.tr(u'&GTFS GO'),
action)
self.iface.removePluginWebMenu(self.tr("&GTFS GO"), action)
self.iface.removeToolBarIcon(action)
# remove the toolbar
del self.toolbar
Expand Down
66 changes: 22 additions & 44 deletions gtfs_go_dialog.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,22 @@
# -*- coding: utf-8 -*-
"""
/***************************************************************************
GTFSGoDockWidget
A QGIS plugin
The plugin to show routes and stops from GTFS
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
-------------------
begin : 2020-10-29
git sha : $Format:%H$
copyright : (C) 2020 by MIERUNE Inc.
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""

import csv
import datetime
import json
import os
import shutil
import tempfile
import urllib
import uuid
import csv

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from qgis.core import *
from qgis.gui import *
from PyQt5.QtCore import QDate, QSortFilterProxyModel, Qt
from PyQt5.QtWidgets import QAbstractItemView, QDialog, QLineEdit, QMessageBox
from qgis.core import (
QgsCoordinateReferenceSystem,
QgsProject,
QgsSymbolLayer,
QgsVectorLayer,
)
from qgis.gui import QgisInterface
from qgis.PyQt import uic
from qgis.utils import iface

from . import constants, repository
from .gtfs_go_labeling import get_labeling_for_stops
Expand All @@ -55,7 +34,7 @@


class GTFSGoDialog(QDialog):
def __init__(self, iface):
def __init__(self, iface: QgisInterface):
"""Constructor."""
super().__init__()
self.ui = uic.loadUi(
Expand Down Expand Up @@ -129,7 +108,7 @@ def init_japan_dpf_gui(self):
now = datetime.datetime.now()
self.ui.japanDpfTargetDateEdit.setDate(QDate(now.year, now.month, now.day))

self.japanDpfExtentGroupBox.setMapCanvas(iface.mapCanvas())
self.japanDpfExtentGroupBox.setMapCanvas(self.iface.mapCanvas())
self.japanDpfExtentGroupBox.setOutputCrs(
QgsCoordinateReferenceSystem("EPSG:4326")
)
Expand Down Expand Up @@ -162,7 +141,6 @@ def download_zip(self, url: str) -> str:

return download_path


def get_target_feed_infos(self):
feed_infos = []
if self.repositoryCombobox.currentData() == REPOSITORY_ENUM["preset"]:
Expand Down Expand Up @@ -304,7 +282,7 @@ def execution(self):
mode="w",
encoding="utf-8",
errors="ignore",
newline='',
newline="",
) as f:
writer = csv.DictWriter(f, fieldnames=stop_relations[0].keys())
writer.writeheader()
Expand Down Expand Up @@ -335,10 +313,10 @@ def get_delimiter(self):
return ""
return self.ui.delimiterLineEdit.text()

def get_time_filter(self, lineEdit):
def get_time_filter(self, line_edit: QLineEdit):
if not self.ui.timeFilterCheckBox.isChecked():
return ""
return lineEdit.text().replace(":", "")
return line_edit.text().replace(":", "")

def show_geojson(
self,
Expand Down Expand Up @@ -368,7 +346,7 @@ def show_geojson(
stops_geojson, os.path.basename(stops_geojson).split(".")[0], "ogr"
)
# make and set labeling for stops
stops_labeling = get_labeling_for_stops("stop_names")
stops_labeling = get_labeling_for_stops("stop_name")
stops_vlayer.setLabelsEnabled(True)
stops_vlayer.setLabeling(stops_labeling)

Expand Down Expand Up @@ -477,7 +455,7 @@ def refresh(self):
self.ui.freqFrame.setEnabled(self.ui.aggregateCheckbox.isChecked())

@staticmethod
def validate_time_lineedit(lineedit):
def validate_time_lineedit(lineedit: QLineEdit):
digits = "".join(
list(filter(lambda char: char.isdigit(), list(lineedit.text())))
).ljust(6, "0")[-6:]
Expand Down Expand Up @@ -545,12 +523,12 @@ def japan_dpf_set_table(self, results: list):
result["feed_pref_id"]
]
model = repository.japan_dpf.table.Model(results)
proxyModel = QSortFilterProxyModel()
proxyModel.setDynamicSortFilter(True)
proxyModel.setSortCaseSensitivity(Qt.CaseInsensitive)
proxyModel.setSourceModel(model)
proxy_model = QSortFilterProxyModel()
proxy_model.setDynamicSortFilter(True)
proxy_model.setSortCaseSensitivity(Qt.CaseInsensitive)
proxy_model.setSourceModel(model)

self.japanDpfResultTableView.setModel(proxyModel)
self.japanDpfResultTableView.setModel(proxy_model)
self.japanDpfResultTableView.setCornerButtonEnabled(True)
self.japanDpfResultTableView.setSortingEnabled(True)
# -1 is no sort indicator
Expand Down
15 changes: 10 additions & 5 deletions gtfs_go_labeling.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from qgis.core import (
QgsPalLayerSettings,
QgsTextBufferSettings,
QgsTextFormat,
QgsVectorLayerSimpleLabeling,
)
from qgis.PyQt.QtGui import QColor, QFont
from qgis.core import *

from .gtfs_go_settings import (
STOPS_LABEL_FONT,
STOPS_LABEL_SIZE_MM,
STOPS_LABEL_BUFFER_SIZE_MM,
STOPS_LABEL_BUFFER_COLOR,
STOPS_LABEL_BUFFER_SIZE_MM,
STOPS_LABEL_DIST_MM,
STOPS_LABEL_MINUMUM_VISIBLE_SCALE
STOPS_LABEL_FONT,
STOPS_LABEL_MINUMUM_VISIBLE_SCALE,
STOPS_LABEL_SIZE_MM,
)


Expand Down
Loading

0 comments on commit fa119d6

Please sign in to comment.