I'm new on paraview, and I want to make a script that render a vtk file, using only pvpython. Therefore, I wrote this script
from paraview.simple import *
from paraview.vtk.vtkFiltersSources import vtkSphereSource
paraview.simple._DisableFirstRenderCameraReset()
renderView1 = GetActiveViewOrCreate('RenderView')
renderView1.ViewSize = [1080, 860]
reader = OpenDataFile([nameFile...])
Interact()
Render()
But when I launch the script with pvpython using the command .\pvpython.exe .\myscript.py, the visualisation shows an empty window, without my mesh
Does someone have an idea, of why my mesh isn't rendered in the view ?
In order to add your reader output in the view, you have to call Show() before Interact().
Show() will add the current active object in the view. To explicitly add your reader output in the view, you may use Show(reader)
Calling Render() is also unneeded just after Interact()
edit Here is a minimal script to load a file and display it centered in a default 3d view:
from paraview.simple import *
reader = OpenDataFile("/path/to/your/file")
Show()
Interact()
Related
I have searched for examples, but all the examples were the opposite direction (my app is getting file drag-and-drop from another application). But this must be possible because I can drag a file from Files (Nautilus) to another app, Text Editor (gedit).
Could you show me a very simple example of a GTK Window with one widget on it, and when I drag from the widget to Text Editor, it passes a text file on the system (such as /home/user/.profile) to the Text Editor so that it will open the text file?
In order to make it so that your application can receive files, you need to use uri. In the function you bind to drag-data-received, you can use data.get_uris() to get a list of the files that were dropped. Make sure that you call drag_dest_add_uri_targets(), so that the widget can receive URIs.
This code example has one button that drags a file, and another button that can receive it. You can also drag the file and drop it into any file-receiving app, such as gedit (Text Editor) or VSCode.
import gi
gi.require_version("Gdk", "3.0")
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk
window = Gtk.Window()
window.connect("delete-event", Gtk.main_quit)
box = Gtk.HBox()
window.add(box)
# Called when the Drag button is dragged on
def on_drag_data_get(widget, drag_context, data, info, time):
data.set_uris(["file:///home/user/test.html"])
# Called when the Drop button is dropped on
def on_drag_data_received(widget, drag_context, x, y, data, info, time):
print("Received uris: %s" % data.get_uris())
# The button from which the file is dragged
drag_button = Gtk.Button(label="Drag")
drag_button.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, [], Gdk.DragAction.LINK)
drag_button.drag_source_add_uri_targets() # This makes sure that the buttons are using URIs, not text
drag_button.connect("drag-data-get", on_drag_data_get)
box.add(drag_button)
# The button into which the file can be dropped
drop_button = Gtk.Button(label="Drop")
drop_button.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.LINK)
drop_button.drag_dest_add_uri_targets() # This makes sure that the buttons are using URIs, not text
drop_button.connect("drag-data-received", on_drag_data_received)
box.add(drop_button)
window.show_all()
Gtk.main()
Mr Kruin's answer was for Python's GTK. The language I actually wanted was C#. Using his code as a hint, I modified the default GtkApplication project like so, and it worked on Linux.
private MainWindow(Builder builder) : base(builder.GetRawOwnedObject("MainWindow"))
{
builder.Autoconnect(this);
DeleteEvent += Window_DeleteEvent;
_button1.DragDataGet += (o, args) =>
{
args.SelectionData.SetUris(new string[]{fullFilePath});
};
Gtk.Drag.SourceSet(_button1, Gdk.ModifierType.Button1Mask,
new TargetEntry[0],
Gdk.DragAction.Link);
Gtk.Drag.SourceAddUriTargets(_button1);
}
On Windows, however, it did not work. I have tried both string fullFilePath = "file:///c:/windows/win.ini" and string fullFilePath = "c:\\windows\\win.ini" and none of them seemed to work.
I'm making a small billiards game in THREE.js, and have opted to use Dat.Gui as a GUI library. I have a few small questions regarding the latter:
First Question: Can I make a class that returns the GUI?
Currently I have a mygui.js file where I put the code of the gui (the example code[1], let's say), and I include that in mygame.html before the main.js. However, all other objects (table, balls, lights, etc) are classes and I'd like to do that too with the GUI. When I place everything inside a
class MyGUI {
constructor() {
//javascript part of the example here
return gui;
}
}
and then call in main.js
var mygui = new MyGUI();
the GUI isn't showing up, but when I don't include the class and the line in main.js, it works. I have downloaded dat.gui.min.js and included it in the html.
Second Question: I want to change variables now and then based on when I call the gui's change function, but how would I go about that without classes (should that not work)?
Third Question: I want to use the GUI, only to display values. Users are not supposed to change it. Can I make the GUI read-only? (to be clear: changing the values in the GUI will not change gameplay, they're just textual representations of the state of the game)
Fourth Question: I want to remove the top part of the GUI (where you can load/save presets or something). How do I do that?
Progressive insights:
As linked by #prisoner849: Page 9 of the example/tutorial.
gui.add(param, 'theSetting').listen();
function updateTheSetting(newVal){ param.theSetting = newVal; }
When param.theSetting is updated, and the added param listen()s to it, a change in the param.theSetting will automatically update the GUI.
Don't use gui.remember( someParameters ) and the save part will dissapear.
I'm designing a GUI in Qt and I need to use a form to save an image. The user would be able to save a file in any location (a simple save form that we see under Save as...). How can make a save-as form in Qt?
thanks!
You can do, for example, the following:
QImage image(128, 128);
image.fill(Qt::red); // A red rectangle.
QString fileName = QFileDialog::getSaveFileName(this, tr("Save Image File"),
QString(),
tr("Images (*.png)"));
if (!fileName.isEmpty())
{
image.save(fileName);
}
I have created a custom editor in eclipse plugin which shows a XML in Tree-Table(TreeViewer) format with couple of its attributes. For showing remaining attributes I am trying to tie it up with "Properties View", but not really able to make progress on it.
I went through similar question on SO like
How to handle property sheet from customized editor in eclipse plugin development? where it talk about make your viewer contribute to workbench selection and implementing an IPropertySource on object which is selected in editor.
In my case I am directly setting an document object in treeviewer input like below.
IFileEditorInput editorInput = (IFileEditorInput) getEditorInput();
IFile inputIFile = editorInput.getFile();
File f = new File(inputIFile.getLocation().toString());
try {
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(f);
}
catch (SAXException | IOException | ParserConfigurationException e) {
e.printStackTrace();
}
//setting root element of doc as input
treeViewer.setInput(doc.getDocumentElement());
Now on what object should I implement an IPropertySource interface to contribute properties?
Let me know if I am going in right direction or missing something or doing it completely wrong.
Hope this make sense !!
When your selection provider fires a selection changed event the properties page will look at the new selection. If you are using a tree viewer as the provider the selection will be the current object from your tree content provider.
The properties view will try to get an IPropertySourceProvider from the selection. Your object can implement IPropertySourceProvider directly, or provide it view the IAdaptable interface or by using IAdapterFactory.
Once the view has the IPropertySourceProvier it will call the getPropertySource method. Your code must return an IPropertySource object - it is up to you to write this class.
So I've used FCKeditor for TinyMCE. This integrated easily and gave my customers a nice way to upload files while selecting them. To integrate this I used the following code:
function fileBrowserCallBack(field_name, url, type, win) {
var connector = ROOT + "path/to/tiny_mce/filemanager/browser.html?Connector=connectors/php/connector.php";
connector += "&Type=" + type;
browserField = field_name;
browserWin = win;
window.open(connector, "browserWindow", "modal,width=600,height=400");
}
And file_browser_callback: "fileBrowserCallBack" in the TinyMCE call.
Now I want to use this same function to fill a simple input-tag so my users can select an image for a custom background.
Now I created an onClick event on this input field that opens the file-browser. But when I select a file I get the following javascript error:
TypeError: window.top.opener.tinyfck is undefined
So how can I use this same plug-in as a regular file-browser making it return the selected file?
Edit: The actual name of the plug-in I used is TinyFCK
Unfortuanatly, this is not possible. The tinymce image uploader needs the tinymce document structure which is not present when you use another kind of editor.