I am using jupyter-cadquery to visualize some 3D models made with CadQuery.
When visualizing the models on a Jupyter notebook, everything works as expected.
But when trying to embed the widget in an HTML document, it seems the camera, on load, is pointing to (0, 0, 0), not as expected. Once you interact with the widget, the camera will point to the expected coordinate.
Here is the code to reproduce the error and an animation of the mentioned problem (see instructions bellow on how to reproduce it with Binder):
from cadquery import Workplane
from ipywidgets import embed
from jupyter_cadquery.cad_view import CadqueryView
from jupyter_cadquery.cadquery import Assembly
from jupyter_cadquery.cadquery import Part
# Create a simple assembly
box1 = Workplane('XY').box(10, 10, 10).translate((0, 0, 5))
a1 = Assembly([Part(box1)], "example 1")
# Generate HTML
a1.collect_shapes()
view = CadqueryView()
for shape in a1.collect_shapes():
view.add_shape(shape["name"], shape["shape"], shape["color"])
renderer = view.render()
embed.embed_minimal_html('export.html', views=renderer, title='Renderer')
renderer
Note how the view of the cube "jumps" suddenly on interaction.
Could it be an issue with ipywidgets? Since the view is okay when displayed in the notebook.
How could it be fixed?
How to reproduce
You can reproduce it with Binder, without needing to create a local environment (admitedly, installing CadQuery/jupyter-cadquery is not the easiest/fastest thing to do):
https://mybinder.org/v2/gh/bernhard-42/jupyter-cadquery/master?urlpath=lab&filepath=examples%2Fcadquery.ipynb
Just execute the code above in a new empty notebook. See how the renderer shows the 3D model without any issues on the notebook:
After execution, an export.html document will also appear in the file list on the left. Open it and make sure to click on the "Trust HTML" button on top of the viewer and hit refresh. If you interact with the view, you can reproduce the issue.
Note that, also, the perspective is lost (that is not an orthogonal view). Fixing that would be a plus! ^^
This can be reproduced without the need of jupyter-cadquery, so a new question has been opened instead:
Embed widgets with pythreejs: wrong perspective and camera look-at
It took a few days, didn't get cadquery working properly, but your second question on this topic without cadquery made it possible to look at the issue...
The jumping happens because orbit.update() for target does not occurs and the function update() is not available in python; only in c++ or c#, etc. From the docs:
When animating the camera rotation above, we used the camera’s
quaternion
. This is the most robust method for
animating free-form rotations. For example, the animation above was created by first moving the camera manually, and then reading out its position and quaternion properties at the wanted views...
The text can be found here on page 12. And also discussed here at github.
However, the jumping can be reproduced in IPython if you apply the following:
renderer = Renderer(scene=scene, camera=camera, controls=[orbit], position=target, width=view_width, height=view_height)
here position is added with target coordinates [0, 5, 0] but the update for this is only done when you mouse-click and adjust to position of the cube/camera. The jump is similar/equal to the jump as seen in the export.HTML.
Conclusion: the programmed camera position is seen as a jump after manual interference due to the absense of the .update() function of the OrbitControls python class and thus not a bug or mistake.
Related
To create tooltips for my application I'm using the Balloon widget from Tix. This works great and does exactly what I need. However, I run into a bug when moving the application's window from one monitor to the next.
When moving to my second monitor the tooltips show up on my first monitor on the edge where my monitors are extended. It looks like the y-coordinate is still correct but the x-coordinate is erroneous. I added the relevant code below. I have tried to find any prior mention of this behaviour or similar behaviour but couldn't find any references. I don't know where to begin solving this problem.
def create_tooltips(self):
self.tooltips = dict()
for i, (column_name, filter_data) in enumerate(self.filters.items()):
self.tooltips[column_name] = tix.Balloon(self.frame)
tooltip_msg = "e.g. " + str(self.example_column_values[column_name])
self.tooltips[column_name].bind_widget(self.input_labels[column_name],
balloonmsg = tooltip_msg)
So my question is: Why is the Balloon showing up on the wrong monitor and how do I fix it?
I use Paraview 5.8.1 but my question holds for older versions.
I want to generate a Python script to automate my visualizations. I use the "trace recorder" tool which records the actions I do in the GUI and translate them into
the Python script that would lead to the same result.
However this tool does not record everything : for instance camera position or orientation axes size modications are not translated whereas the Python functions to hold this do exist.
Is there any way to get the trace recorder to record everything ?
Simple answer: nope.
ParaView use a property mechanism. Lot of things are properties (filter parameters, color setting, ...) and are available for record. But camera are not. When the trace stops, an internal hook adds the last camera in the trace.
You can use this as a Macro to add the current Camera in the trace:
from paraview import simple
from paraview import smtrace
smtrace.Trace.get_accessor(simple.GetActiveView())
camera_trace = smtrace.SaveCameras.get_trace(None)
if camera_trace:
a = smtrace.Trace.Output.append_separated(
"#### saving camera placements for all active views")
a = smtrace.Trace.Output.append_separated(camera_trace)
That said, I'm not sure to see a use case ... If you want to see an animation of your scene, you cannot use the Trace mechanism but you should use the Animation View instead.
I've been practicing my python/mel coding and have been interested in creating a graph editor. I did a lot of research online and found this previous question (How can I keep an object selected in the outliner after physically deselecting it in the 3d view?) that helped me out a lot. However, I am having an issue were I cannot manually edit the curves that are generated. I'm unsure as to why this is happening and can't seem to find any clear documentation. (I've looked up the command references for mel/python in Maya but it doesn't seem to have detailed explanations).
To be more clear, my goal is to use my mouse to move the curve information based on keyframe data (Exactly like Maya's own graph editor). I am using the code solution from the previous example (edited to include my own selection connections and frame conventions).
So after some research I decided the easiest thing was to use Maya's own graph editor within my interface
# GRAPH ROW
# Section for the graph editor to allow the user to change attributes
paneLayout( configuration='single', parent=form, width=620, height=320 )
# queries Maya's graph editor and places it within my frame
graph = cmds.getPanel(scriptType='graphEditor')
cmds.scriptedPanel( graph[0], e=True, unParent=True)
cmds.scriptedPanel( graph[0], e=True, parent=frame1)
I've been looking for a graphical / ipython console based means to turn lines on and off in a 2D graph generated with matplotlib, but I haven't found anything thus far.
Does anyone know a way to do something like this? What I have in mind specifically is incorporated in MATLAB, and can be seen here:
http://matlab.izmiran.ru/help/techdoc/creating_plots/plot_to5.html
All of the check boxes in the plot browser window will turn the lines on and off; their properties can also be altered graphically in another dialogue box. For now, I've been clicking on the properties button, and setting linetype to none, but this is cumbersome for a graph with many lines...
Thanks Vadim for your answer - you're right that the widgets provide an example with this functionality - to an extent. The example you provide doesn't give the graphical feedback I had in mind; instead, the widgets example closest to my request is actually check_buttons.py (see: http://matplotlib.org/examples/widgets/check_buttons.html)
Here, a side-box of labelled check buttons can be created, where upon clicking the checked buttons, it will turn the lines on and off - see the figure below. I suppose this could be built up into something along the lines of a plot browser like in matlab, but would require additional work to incorporate simple changes to the line style, etc.
I am still interested to know if someone has already done all of the work in making such functionality available; if not, I will post my best attempt when I get around to it.
plot_browser
I don't have sufficient rep points to add the image inline; my apologies.
Yes, there exists module named matplotlib.widgets. There are some example here. It allows you to do exactly what you asked for (source):
I am writing an open configurable taskbar using PyQt4, and I want to add a start orb. I want the orb to support the common image format of start orbs, which is usually three 54x54 squares for a 54x162 image.
My program takes those images, cuts them in thirds using PIL, and I try to load them using .setIcon(QIcon(icon)). Unfortunately, this isn't working. The image is loaded, calling .show() displays the image perfectly.
For various reasons, I did not choose style sheets, including that I would have trouble loading the cut images. Instead, (as the code shows) I had the QPushButton change icons on hover, press, and release. None of them work. Not even the default image.
My code is on this github. Note the warning in the readme! The program quite literally replaces (and removes) the taskbar (but you can get it back).
tl;dr
I have the code (see link below). It won't load using .setIcon(), and I don't know why. I thought it would work, used ImageQt, but no.
EDIT:Unfortunately, going from a PIL object to a Imagqt object to a QImage didn't solve the problem.
EDIT2: as #Trilarion requeted here is a link to a gist of the slimmed down code: https://gist.github.com/IronManMark20/85b00104c9bb52b78add