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

use relative imports #21

Closed
wants to merge 8 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/nodezator/logs
44 changes: 44 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import sys
import asyncio


NATIVE_FILE_EXTENSION = '.ndz'

if __name__ == "__main__":

### parse arguments received, looking for a filepath
### (or using None instead, a filepath wasn't provided)

## import argument parser
from argparse import ArgumentParser

## instantiate and configure it

parser = ArgumentParser(
description = " - Python Node Editor"
)

parser.add_argument(

'filepath',

type = str,
nargs = '?',
default = None,

help = (
"path of "
+ NATIVE_FILE_EXTENSION
+ " file to be loaded."
)
)

## parse arguments
args = parser.parse_args()


### finally call the main function, passing along
### the filepath argument received (which might be the
### default, None)
from nodezator.mainloop import run_app
asyncio.run(run_app(args.filepath))
2 changes: 1 addition & 1 deletion nodezator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

__version__ = '1.0.15'
__version__ = '1.1.1'

8 changes: 5 additions & 3 deletions nodezator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"""
### standard library imports

import asyncio

from pathlib import Path

from sys import path
Expand Down Expand Up @@ -37,7 +39,7 @@
logger = get_new_logger(__name__)


def main(filepath=None):
async def main(filepath=None):
"""Launch application.

Parameters
Expand Down Expand Up @@ -69,7 +71,7 @@ def main(filepath=None):

logger.info("Starting application session.")

run_app(filepath)
await run_app(filepath)

logger.info("Finished application session.")

Expand Down Expand Up @@ -110,4 +112,4 @@ def main(filepath=None):
### finally call the main function, passing along
### the filepath argument received (which might be the
### default, None)
main(args.filepath)
asyncio.run( main(args.filepath) )
31 changes: 20 additions & 11 deletions nodezator/alphamask/basicop.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class used as an extension for the AlphaMask class;
stored anywhere, since we are only interested in its alpha
values and size.

The masking operations carried out in this module are
different from the ones carried out by pygame.mask module
because pygame.mask only deals with bitmasks (a pixel is
either fully opaque or fully transparent), while the mask
The masking operations carried out in this module are
different from the ones carried out by pygame.mask module
because pygame.mask only deals with bitmasks (a pixel is
either fully opaque or fully transparent), while the mask
operations here doesn't rely on bitmasks and work with
pixels in all ranges of transparency, (fully opaque, fully
transparent and partially transparent pixels).
Expand All @@ -59,13 +59,13 @@ class used as an extension for the AlphaMask class;
Technique 1 is best suited for usage in target surfaces
which only have solid colors, that is, surfaces whose
all alpha values equal 255.

This is usually so because source surfaces usually have
their visible area (or at least most of it) rendered with
solid colors (alpha is 255) and when such values are
applied in target surfaces with semitransparent areas
such areas would then be rendered solid.

In other words, if the target surface had alpha values
different than 255, they would be reverted back to the
full 255 alpha value, that is, the alpha of the source
Expand Down Expand Up @@ -96,8 +96,8 @@ class used as an extension for the AlphaMask class;
that the resulting alpha value is assigned to the target
surface.

When such multiplications are carried out, the pixels of
the target surface whose alpha are multiplied by 0
When such multiplications are carried out, the pixels of
the target surface whose alpha are multiplied by 0
become completely transparent. Naturally, the pixels
whose alpha is multiplied by a number between 0 and 1
retain only a percentage of its original alpha value.
Expand All @@ -124,7 +124,7 @@ class used as an extension for the AlphaMask class;

In other words, this technique takes into account the
original alpha values of the target surface.

However, when dealing with target surfaces that only have
solid colors, the first technique is preferable, since it
achieves the same effect with less steps.
Expand All @@ -137,8 +137,11 @@ class used as an extension for the AlphaMask class;

from pygame import Rect, Surface

from pygame.surfarray import pixels_alpha

try:
import numpy
from pygame.surfarray import pixels_alpha
except:
numpy = None

### class definition

Expand Down Expand Up @@ -197,6 +200,9 @@ def mask_by_replacing(self, surf):
### the surface remains locked for the lifetime of
### this array (which is why we'll soon delete it
### once we don't need it anymore)
if numpy is None:
print(__file__,"204: pixels_alpha need numpy")
return
surf_alpha_values = pixels_alpha(surf)

### iterate over the columns of full alpha values
Expand Down Expand Up @@ -246,6 +252,9 @@ def mask_by_multiplying(self, surf):
### the surface remains locked for the lifetime of
### this array (which is why we'll soon delete it
### once we don't need it anymore)
if numpy is None:
print(__file__,"254: pixels_alpha need numpy")
return
surf_alpha_values = pixels_alpha(surf)

### multiply the alpha of each pixel in the surface
Expand Down
18 changes: 9 additions & 9 deletions nodezator/alphamask/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
described earlier.


Alpha Masking
Alpha Masking
=============

Alpha masking here refers to the operation of using the
Expand Down Expand Up @@ -55,10 +55,10 @@
pygame.Surface.convert_alpha(), but blitting has nothing
to do with alpha masking.

Additionally, even if images without alpha channels were
loaded faster, which we haven't tested, such advantage
wouldn't be relevant to the masking out operations, which
are carried out several times during the lifetime of the
Additionally, even if images without alpha channels were
loaded faster, which we haven't tested, such advantage
wouldn't be relevant to the masking out operations, which
are carried out several times during the lifetime of the
mask, whereas loading is only performed once.

Furthermore, even if loading speed became an issue,
Expand All @@ -71,9 +71,9 @@

### local import

from imagesman.cache import IMAGE_SURFS_DB
from ..imagesman.cache import IMAGE_SURFS_DB

from alphamask.utils import (
from .utils import (
size_from_alpha_values,
unit_from_full_alpha_values,
full_from_unit_alpha_values,
Expand All @@ -82,8 +82,8 @@

## class extensions

from alphamask.basicop import AlphaMaskBasicOperations
from alphamask.masksop import (
from .basicop import AlphaMaskBasicOperations
from .masksop import (
AlphaMaskOperationsBetweenMasks
)

Expand Down
2 changes: 1 addition & 1 deletion nodezator/alphamask/masksop.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class used as an extension for the AlphaMask class;

### local imports

from alphamask.utils import (
from .utils import (
size_from_alpha_values,
unit_from_full_alpha_values,
full_from_unit_alpha_values,
Expand Down
13 changes: 10 additions & 3 deletions nodezator/alphamask/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@

from pygame import Rect

from pygame.surfarray import pixels_alpha
try:
import numpy
from pygame.surfarray import pixels_alpha
except:
numpy = None


def size_from_alpha_values(alpha_values):
Expand Down Expand Up @@ -124,7 +128,7 @@ def full_alpha_values_from_surface(surf):
==========
surf (pygame.Surface instance)
surface used as source of alpha values.

How it works
============

Expand All @@ -133,7 +137,7 @@ def full_alpha_values_from_surface(surf):
which represent columns of the source surface
and hold the alpha value of each pixel in that
column.

To be more specific, the columns are listed from
the leftmost to the rightmost pixel column of the
source surface and the values within each column
Expand Down Expand Up @@ -182,6 +186,9 @@ def full_alpha_values_from_surface(surf):
### method), but even when they would not (as with the
### mask_by_replacing() method), the differences
### observed in practice cannot be perceived by a human;
if numpy is None:
print(__file__,"190: pixels_alpha requires numpy")
return [[0]]

return [

Expand Down
2 changes: 1 addition & 1 deletion nodezator/appinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
'major minor micro release_level'
)

APP_VERSION = AppVersion(1, 0, 15, 'release_candidate')
APP_VERSION = AppVersion(1, 1, 0, 'release_candidate')


### titles for the application
Expand Down
Loading