Skip to content

Commit

Permalink
QGIS refactors - kamangir/bolt#746
Browse files Browse the repository at this point in the history
  • Loading branch information
kamangir committed Jan 17, 2025
1 parent 62b4e8e commit b5c11e7
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 93 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ graph LR

[![pylint](https://github.com/kamangir/blue-geo/actions/workflows/pylint.yml/badge.svg)](https://github.com/kamangir/blue-geo/actions/workflows/pylint.yml) [![pytest](https://github.com/kamangir/blue-geo/actions/workflows/pytest.yml/badge.svg)](https://github.com/kamangir/blue-geo/actions/workflows/pytest.yml) [![bashtest](https://github.com/kamangir/blue-geo/actions/workflows/bashtest.yml/badge.svg)](https://github.com/kamangir/blue-geo/actions/workflows/bashtest.yml) [![PyPI version](https://img.shields.io/pypi/v/blue-geo.svg)](https://pypi.org/project/blue-geo/) [![PyPI - Downloads](https://img.shields.io/pypi/dd/blue-geo)](https://pypistats.org/packages/blue-geo)

built by 🌀 [`blue_options-4.190.1`](https://github.com/kamangir/awesome-bash-cli), based on 🌐 [`blue_geo-4.967.1`](https://github.com/kamangir/blue-geo).
built by 🌀 [`blue_options-4.190.1`](https://github.com/kamangir/awesome-bash-cli), based on 🌐 [`blue_geo-4.969.1`](https://github.com/kamangir/blue-geo).
34 changes: 28 additions & 6 deletions blue_geo/QGIS/console/QGIS.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@


if not QGIS_is_live:
from dependency import list_of_dependencies
from .application import BLUE_GEO_QGIS_APPLICATION
from .help import Q_help
from .graphics import Q_screenshot
from .logger import Q_log, Q_verbose, Q_clear
from dependency import list_of_dependencies
from .mock import QgsSettings
from .objects import Q_get_thing_path, Q_upload
from .path import Q_open_path
from .testing import Q_test

ABCLI_OBJECT_ROOT = ""
Expand Down Expand Up @@ -50,19 +53,20 @@ def Q_list_recent_projects() -> str:
return ",".join(output)


def Q_QGIS_help():
Q_log("Q_list_recent_projects()", "list recent projects.")


class ABCLI_QGIS:
def __init__(self):
self.app_list: List[BLUE_GEO_QGIS_APPLICATION] = []

def add_app(self, app: BLUE_GEO_QGIS_APPLICATION):
self.app_list += [app]

def help(log):
def help_(self):
Q_log("Q.clear", "clear Python Console.")
Q_log("Q.list_recent_projects", "list recent projects.")
Q_log('Q.open(" | <object-name> | layer | project")', "open.")
Q_log("Q.screenshot([filename],[object_name])", "screenshot.")
Q_log("Q.test", "test Q.")
Q_log('Q.upload(" | <object-name> | layer | project | qgz")', "upload.")

def intro(self):
Q_log(self.version)
Expand All @@ -89,9 +93,27 @@ def clear(self):
def help(self):
Q_help(clear=True)

def list_recent_projects(self):
Q_list_recent_projects()

def open(thing="object"):
Q_open_path(Q_get_thing_path(thing))

@property
def test(self):
Q_test()

def upload(
self,
thing: str = "",
dryrun: bool = False,
):
Q_upload(
thing=thing,
dryrun=dryrun,
)


QGIS = ABCLI_QGIS()

Q = QGIS
21 changes: 0 additions & 21 deletions blue_geo/QGIS/console/alias.py

This file was deleted.

2 changes: 1 addition & 1 deletion blue_geo/QGIS/console/file_load.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import yaml


def Q_load_yaml(filename):
def Q_load_yaml(filename: str):
with open(filename, "r") as file:
return yaml.safe_load(file)
21 changes: 21 additions & 0 deletions blue_geo/QGIS/console/file_save.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from typing import List

if not QGIS_is_live:
from .logger import Q_log


def Q_save_text(
filename: str,
text: List[str],
log: bool = True,
):
with open(filename, "w") as fp:
fp.writelines([string + "\n" for string in text])

if log:
Q_log(
"Q_save_text: {:,} line(s) -> {}".format(
len(text),
filename,
)
)
8 changes: 1 addition & 7 deletions blue_geo/QGIS/console/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ def Q_refresh(deep=False):
iface.mapCanvas().refresh()


def Q_screenshot(
filename="",
):
def Q_screenshot(filename=""):
filename = Q_file_path_in_object(
filename=filename if filename else f"{Q_timestamp()}.png",
object_name=Q_project.name,
Expand All @@ -28,7 +26,3 @@ def Q_screenshot(
qgis.utils.iface.mapCanvas().saveAsImage(filename)

Q_log(filename, icon="🖼️")


def Q_graphics_help():
Q_log("Q_screenshot([filename],[object_name])", "screenshot.")
17 changes: 3 additions & 14 deletions blue_geo/QGIS/console/help.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
if not QGIS_is_live:
from .alias import Q_alias_help
from .graphics import Q_graphics_help
from .layer import Q_layer
from .logger import Q_clear
from .objects import Q_objects_help
from .QGIS import QGIS, Q_QGIS_help
from .QGIS import QGIS
from .project import Q_project
from .testing import Q_testing_help


def Q_help(clear=False):
if clear:
Q_clear()
Q_clear(log=False)

for thing in [
Q_layer,
Q_project,
] + [app for app in QGIS.app_list if app.name != "template"]:
thing.help()

for func in [
Q_graphics_help,
Q_testing_help,
Q_objects_help,
Q_QGIS_help,
Q_alias_help,
]:
func()
QGIS.help_()
4 changes: 2 additions & 2 deletions blue_geo/QGIS/console/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .mock import iface


def Q_clear():
def Q_clear(log: bool = True):
# https://gis.stackexchange.com/a/480025/250728
from qgis.PyQt.QtWidgets import QDockWidget

Expand All @@ -17,7 +17,7 @@ def Q_clear():

QGIS.intro()

Q_seed("clear")
Q_seed("clear", log=log)


def Q_hr(length: int = 3):
Expand Down
9 changes: 0 additions & 9 deletions blue_geo/QGIS/console/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
if not QGIS_is_live:
from .logger import Q_log
from .layer import Q_layer
from .path import Q_open_path
from .project import Q_project
from .seed import Q_seed

Expand Down Expand Up @@ -67,10 +66,6 @@ def Q_file_path_in_object(
)


def Q_open(thing="object"):
Q_open_path(Q_get_thing_path(thing))


def Q_upload(
thing="object",
dryrun: bool = False,
Expand All @@ -83,7 +78,3 @@ def Q_upload(
],
dryrun=dryrun,
)


def Q_objects_help():
Q_log('Q_open(" | <object-name> | layer | project")', "open.")
17 changes: 10 additions & 7 deletions blue_geo/QGIS/console/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import random

if not QGIS_is_live:
from logger import Q_log
from .file_save import Q_save_text
from .logger import Q_log

blue_geo_QGIS_path_server = os.path.join(
os.getenv("HOME", ""),
Expand All @@ -17,6 +18,7 @@
def Q_seed(
command: Union[str, List[str]],
dryrun: bool = False,
log: bool = True,
):
if isinstance(command, list):
command = " ".join(command)
Expand All @@ -27,13 +29,14 @@ def Q_seed(
)

if not dryrun:
with open(
os.path.join(
Q_save_text(
filename=os.path.join(
blue_geo_QGIS_path_server,
f"{command_name}.command",
),
"w",
) as f:
f.write(command)
text=[command],
log=log,
)

Q_log(command_name, command, icon="🌱")
if log:
Q_log(command_name, command, icon="🌱")
4 changes: 0 additions & 4 deletions blue_geo/QGIS/console/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,3 @@ def Q_test():
Q_hr()

Q_log(f"ran {description}.", icon="✅")


def Q_testing_help():
Q_log("Q.test", f"test Q.")
6 changes: 0 additions & 6 deletions blue_geo/QGIS/console/tests/alias.py

This file was deleted.

2 changes: 1 addition & 1 deletion blue_geo/QGIS/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def generate_seed(
"console/layer",
"console/file",
"console/file_load",
"console/file_save",
"console/graphics",
"console/objects",
"console/path",
Expand All @@ -41,7 +42,6 @@ def generate_seed(
"console/seed",
"console/help",
"console/QGIS",
"console/alias",
]
]
+ sorted(glob(f"{apps_path}/*.py"))
Expand Down
2 changes: 1 addition & 1 deletion blue_geo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

DESCRIPTION = f"{ICON} AI for a Blue Planet."

VERSION = "4.967.1"
VERSION = "4.969.1"

REPO_NAME = "blue-geo"

Expand Down
Loading

0 comments on commit b5c11e7

Please sign in to comment.