ggarra13 / mrv2

Professional player and review tool for vfx, animation and computer graphics.
https://mrv2.sourceforge.io
BSD 3-Clause "New" or "Revised" License
222 stars 14 forks source link

Python panel enter on Windows doesn't default to correct new lines #138

Closed BigRoy closed 1 year ago

BigRoy commented 1 year ago

Issue

This is likely a Windows issue - but testing 0.8.1 I noticed that the Python panel often gave syntax errors:

image

My entry in the script field:


import mrv2
from mrv2 import annotations, cmd, math, image, io, media
from mrv2 import playlist, timeline, usd, settings

print(0)
print(1)

Would execute as:

import mrv2
from mrv2 import annotations, cmd, math, image, io, media
from mrv2 import playlist, timeline, usd, settings

print(0)print(1)

Giving:

SyntaxError: invalid syntax (<string>, line 7)

It seems that the Enter key maybe does not generate the new lines as it expects (maybe \r instead of \n?)

My keyboard locale settings on Windows 10 are set to: image

BigRoy commented 1 year ago

This version also addresses your Python Editor issues.

Just cross-referencing the comment from another issue. Should be fixed in 0.8.2 beta.

BigRoy commented 1 year ago

Fixed in 0.8.2 beta.

BigRoy commented 1 year ago

Note a huge issue but I do believe it's new behavior - whenever the command you run does not end with an empty new line the return value gets printed in the top report view on the same line. Like this:

image

Note how the returned list appears directly after the image.ocioIcsList().

It would be nicer if it'd appear like this:

image

In this case I just added a # line since that was the only thing that worked to get the return value onto a new line. Would be great if the output could always report "\n".join([command, result]) especially because you seem to already perform a command.strip() or alike on the input since any empty new lines already appear removed.

ggarra13 commented 1 year ago

I have fixed that and updated the beta of v0.8.2 on all platforms and put it on sourceforge, on the beta folder (that way it is easier for people to find it instead of looking through the mrv2 issues). Anyway, look for it in:

https://sourceforge.net/projects/mrv2/files/beta/

These are full releases not nightly builds, so they are compatible with RH 8.1 and have USD support on Windows.

BigRoy commented 1 year ago

Can confirm it's fixed in latest beta of v0.8.2

image

BigRoy commented 1 year ago

Actually there seems to be another issue. It fails to close brackets over multiple lines in some cases, e.g. this fails:


import mrv2
from mrv2 import annotations, cmd, math, image, io, media
from mrv2 import playlist, timeline, usd, settings

image_options = image.ImageOptions(
  videoLevels=image.InputVideoLevels.FromFile,
  alphaBlend=image.AlphaBlend.None,
  imageFilters=image.ImageFilters(
      minify=image.ImageFilter.Linear,
      magnify=image.ImageFilter.Linear
  )
)

With the simplest reproducable of the issue being:

image_options = image.ImageOptions(
)

Whereas this works:

image_options = image.ImageOptions()
ggarra13 commented 1 year ago

What error do you get (and what Input does it print in the Python Display Window)? Also, what happens if you select the section from the beginning of the assignment to the end of the parenthesis?

BigRoy commented 1 year ago

It seems to strip off the end ) bracket:

SyntaxError: '(' was never closed (<string>, line 7)

Note the code that it runs: image

This does work:


import mrv2
from mrv2 import annotations, cmd, math, image, io, media
from mrv2 import playlist, timeline, usd, settings

image_options = image.ImageOptions(
  # 
)

Or if I add a statement after it also works:


import mrv2
from mrv2 import annotations, cmd, math, image, io, media
from mrv2 import playlist, timeline, usd, settings

image_options = image.ImageOptions(
)
print("A")
ggarra13 commented 1 year ago

This one I'll leave it to investigate it tomorrow.

BigRoy commented 1 year ago

Python Editor fixes (hopefully, there are no more errors, but let me know if there are still things broken).

Latest beta still produces this error for me: image

ggarra13 commented 1 year ago

I uploaded a new beta that should fix the issues. Grab it from sourceforge.net mrv2 beta directory.

ggarra13 commented 1 year ago

There's still an issue left. If you do:

cmd.ImageOptions( keyword = var )

without a variable at the beginning like:

o = cmd.imageOptions( keyword = var )

You will still get a syntax error.

ggarra13 commented 1 year ago

I fixed that final issue too. Latest beta on sourceforge.

BigRoy commented 1 year ago

Unfortunately the new line issue still exists. In Python this should technically work:

image.ImageFilters(minify=image.ImageFilter.Nearest
)

But it fails in latest beta. This is what it shows in the report:

import mrv2
from mrv2 import annotations, cmd, math, image, io, media
from mrv2 import playlist, timeline, usd, session, settings

image.ImageFilters(minify=image.ImageFilter.Nearest)
image.ImageFilters(minify
SyntaxError: '(' was never closed (<string>, line 2)

It seems to duplicate the last line, including a split off one?

This fails the same way:


import mrv2
from mrv2 import annotations, cmd, math, image, io, media
from mrv2 import playlist, timeline, usd, session, settings

image.ImageFilters(
    minify=image.ImageFilter.Nearest,
    magnify=image.ImageFilter.Nearest
)

But this works:

import mrv2
from mrv2 import annotations, cmd, math, image, io, media
from mrv2 import playlist, timeline, usd, session, settings

image.ImageFilters(
    minify=image.ImageFilter.Nearest,
    magnify=image.ImageFilter.Nearest)

image

ggarra13 commented 1 year ago

New beta on sourceforge. I am betting that this time it will all work. I cleaned up the code and documented the algorithm.

BigRoy commented 1 year ago

That does seem to work now - the only thing I can't seem to get to work is to set the video levels in this call:

image_options = image.ImageOptions(
  videoLevels=image.InputVideoLevels.FromFile,
  alphaBlend=image.AlphaBlend.kNone,
  imageFilters=image.ImageFilters(
      minify=image.ImageFilter.Linear,
      magnify=image.ImageFilter.Linear
  )
)

Results in:

TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
    1. mrv2.image.ImageOptions()
    2. mrv2.image.ImageOptions(videoLevels: mrv2.image.InputVideoLevels, alphaBlend: mrv2.image.AlphaBlend, imageFilter: mrv2.image.ImageFilters)

Invoked with: kwargs: videoLevels=<InputVideoLevels.FromFile: 0>, alphaBlend=<AlphaBlend.kNone: 0>, imageFilters=<mrv2.image.ImageFilters minify=Linear magnify=Linear>

At:
  <string>(10): <module>

This works though:

video_levels = image.InputVideoLevels(0)

image_options = image.ImageOptions(
  videoLevels=video_levels,
  alphaBlend=image.AlphaBlend.kNone,
  imageFilters=image.ImageFilters(
      minify=image.ImageFilter.Linear,
      magnify=image.ImageFilter.Linear
  )
)

But the constructor for InputVideoLevels still seems off. It also feels weird it needs it own constructor since it only takes one value?

This also does not work:

video_levels = image.InputVideoLevels(image.InputVideoLevels.FromFile)

It requires an integer.

ggarra13 commented 1 year ago

Try this. It is imageFilter not imageFilters. This works for me:

image_options = image.ImageOptions( videoLevels=image.InputVideoLevels.FromFile, alphaBlend=image.AlphaBlend.kNone, imageFilter=image.ImageFilters( minify=image.ImageFilter.Linear, magnify=image.ImageFilter.Linear ) )

ggarra13 commented 1 year ago

Oh. Wait. It was a typo on my part in the constructor parameters. I'll fix it.

BigRoy commented 1 year ago

I was just about to post this:

I must've been blind staring at that snippet thinking it was video levels giving the issue. Thanks - my bad.

This does indeed work:

image_options = image.ImageOptions(
    videoLevels=image.InputVideoLevels.FromFile,
    alphaBlend=image.AlphaBlend.kNone,
    imageFilter=image.ImageFilters(
        minify=image.ImageFilter.Linear,
        magnify=image.ImageFilter.Linear
    )
)

All seems solved.

But apparently it is a typo still?

ggarra13 commented 1 year ago

Yes, it is a typo on my part. I'll have a fix in 30 mins the beta sourceforge site.

ggarra13 commented 1 year ago

Can I close this issue?