Hello everybody,

I just started recently to work with paraview. It looks great. I installed the latest version (3.98) on a windows 7 64 bit machine. I faced troubles when trying to use the wxpython backend. You will find enclosed the scripts that triggered the troubles:

Here they are:

- wxpython is not shipped by default with paraview (an import wx in the python shell failed). So, I had to install it by myself in C:\Program Files (x86)\ParaView 3.98.0\lib\paraview-3.98\site-packages. Is this normal ?

- the standard wxpython installation process with the creation of a wx.pth file in the aformentionned directory seems to be broken. Indeed, an import wx still failed. To make it work, I had to add the following awful hack at the beginning of my script:

      ##################################
      import os
      import sys
      if os.name == 'nt':
sys.path.append(os.path.join(os.path.dirname(sys.exec_prefix),'lib','paraview-3.98','site-packages','wx-2.8-msw-unicode'))
      ##################################

This hack does more or less doing what is normally done with the standard .pth files process. Is this also something known ?

- when ran in command line with the python console shipped with paraview (pvpython.exe) the script works. When ran in paraview through the macros process, the contents of the ellipsoids.txt file is not flushed on the listbox. The problem seems to be related with the opening of the 'ellipsoids.txt' file and also occured on an ubuntu machine ? Very weird.

    - when I used the docstring with the following format:
          '''blablabla
          '''
the script can not be executed from paraview. I have to format them as they are in the enclosed scripts ?

for all these reasons, I have the feeling that the python shipped with paraview is not a standard one or something is done on top of it.
Am I right ?

Would you have any idea of what is going wrong with my script (or with paraview) ?

thank you very much

555771    0    0    0    1    2    3    1    0    0    0    1    0    0    0    
1
555772    0    0    0    1    2    3    1    0    0    0    1    0    0    0    
1
555773    0    0    0    1    2    3    1    0    0    0    1    0    0    0    
1
555774    0    0    0    1    2    3    1    0    0    0    1    0    0    0    
1
555775    0    0    0    1    2    3    1    0    0    0    1    0    0    0    
1
# The standard imports.
import os
import sys

# Awful hack to make wx importable on paraview/windows. To be solved.
if os.name == 'nt':
    sys.path.append(os.path.join(os.path.dirname(sys.exec_prefix),'lib','paraview-3.98','site-packages','wx-2.8-msw-unicode'))

# The wx import.
import wx

from wx.lib.filebrowsebutton import DirBrowseButton, FileBrowseButton

class RacerVisualization(wx.Frame):
    """
    This class implements a paraview dialog for displaying the numors treated with racer program.
    """

    def __init__(self, *args, **kwargs):
        """The constructor.
        """
    
        # The base class constructor.
        super(RacerVisualization,self).__init__(*args,**kwargs)

        # Will store the informations about the loaded numors.
        self.__numors = {}
        
        # Build the dialog.
        self.__build_dialog()
        
    def __build_dialog(self):
        """
        Builds the dialog.
        """
                        
        # The panel that will contains all the dialogs widgets.
        mainPanel = wx.Panel(self, wx.ID_ANY)
        
        # The widgets will be organized on a extensible grid.
        sizer = wx.GridBagSizer(5,5)
        sizer.AddGrowableCol(1)
        sizer.AddGrowableRow(4)
 
        # Some static texts.
        sText = wx.StaticText(mainPanel, wx.ID_ANY, "Working directory", style=wx.ALIGN_LEFT)
        sizer.Add(sText,(0,0), flag=wx.ALIGN_CENTER_VERTICAL)       

        sText = wx.StaticText(mainPanel, wx.ID_ANY, "Ellipsoid file", style=wx.ALIGN_LEFT)
        sizer.Add(sText,(2,0), flag=wx.ALIGN_CENTER_VERTICAL)       
        
        # The working directory entry and its associated browse button.
        self.workingDirectory = wx.TextCtrl(mainPanel, wx.ID_ANY)
        sizer.Add(self.workingDirectory,(0,1), flag=wx.EXPAND|wx.LEFT|wx.RIGHT, border=5)       
        button = wx.Button(mainPanel, wx.ID_ANY,label='Browse')
        sizer.Add(button,(0,2), flag=wx.EXPAND)
        # The event handler associated with the browse button.
        button.Bind(wx.EVT_BUTTON, self.on_browse_working_directory)                        

        # The ellipsoid file entry and its associated browse button.
        self.ellipsoidFile = wx.TextCtrl(mainPanel, wx.ID_ANY)
        sizer.Add(self.ellipsoidFile,(2,1), flag=wx.EXPAND|wx.LEFT|wx.RIGHT, border=5)       
        button = wx.Button(mainPanel, wx.ID_ANY,label='Browse')
        button.Bind(wx.EVT_BUTTON, self.on_browse_ellipsoid_file)
        sizer.Add(button,(2,2), flag=wx.EXPAND)       
        
        # The list box that contains the list of the loaded numors for which an ellipsoid could be defined.
        self.loadedEllipsoids = wx.ListBox(mainPanel, wx.ID_ANY, choices=['toto','titi','yaya'],style=wx.LB_SINGLE|wx.LB_SORT|wx.LB_ALWAYS_SB)
        sizer.Add(self.loadedEllipsoids,(4,0),(1,3), flag=wx.EXPAND)
        # The event handler bound to the selection of an item.
        self.loadedEllipsoids.Bind(wx.EVT_LISTBOX, self.on_select_ellipsoid)
                
        # The size is set.
        mainPanel.SetSizer(sizer)
        mainPanel.SetSizer(sizer)
        sizer.SetSizeHints(self)
        sizer.Fit(mainPanel)
   
        # A status bar is created.
        self.sb = self.CreateStatusBar()
                     
        # The dialog is showed.
        self.Show()
        
    
    def on_select_ellipsoid(self, event):
        """
        Called when the user select one numor from the ellipsoid listbox.
        """
    
        # Get the selected item.
        numor = event.GetString()
            
        # Format it to display for futher use.
        s = "numor: %s -- center: %8.3f %8.3f %8.3f -- a: %8.3f b:%8.3f c: %8.3f" % tuple([numor] + self.__numors[numor][0:6])
            
        # Update the status bar with the formatted text.
        self.sb.SetStatusText(s)
    
                
    def load_ellipsoid_file(self, filename):
        """
        Load an ellipsoiid file.
        """
                    
        # Clear the dictionary of the loaded ellipsoids.
        self.__numors.clear()
                                                   
        # Open the selected ellipsoid file for reading.
        with open(filename, 'r') as ellFile:
            for lines in ellFile:
                try:                
                    # Split the lines.
                    values = lines.split()
                    # A line of an ellipsoid file must contains 16 values.
                    if len(values) != 16:
                        raise
                    # If the current line is OK, update the loaded ellipsoids dictionary.
                    self.__numors[values[0]] = [float(v) for v in values[1:]]
                except:
                    continue
                                                            
    def on_browse_working_directory(self, event):
        """
        Called when the user browse for a working directory.
        """
                
        # Open a directory selection dialog.
        dlg = wx.DirDialog(self, "Select working directory", style=wx.DD_DIR_MUST_EXIST|wx.DD_CHANGE_DIR)
        
        if dlg.ShowModal() == wx.ID_OK:
            # Update the working directory entry with the directory browsed.
            self.workingDirectory.SetValue(dlg.GetPath())    
                    
            
    def on_browse_ellipsoid_file(self, event):
        """
        Called when the user browse for an ellipsoid file.
        """

        # Open a file selection dialog.
        dlg = wx.FileDialog(self, "Select ellipsoid file.", defaultDir=os.getcwd(), style=wx.FD_OPEN)

        if dlg.ShowModal() == wx.ID_OK:
        
            # Update the ellipsoid file entry with the browsed file.
            self.ellipsoidFile.SetValue(dlg.GetPath())
            
            # Load the browsed ellipsoid file.
            self.load_ellipsoid_file(dlg.GetPath())
            
            # Clear up the loaded ellipsoids listbox.
            self.loadedEllipsoids.Clear()
            
            # Update the loaded ellipsoid listbox with the ellipsoid file contents.
            self.loadedEllipsoids.Set(self.__numors.keys())
            

if __name__ == "__main__":
    
    app = wx.App(False)
    
    RacerVisualization(None, wx.ID_ANY, 'racer visualization')
    
    app.MainLoop()
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the ParaView Wiki at: 
http://paraview.org/Wiki/ParaView

Follow this link to subscribe/unsubscribe:
http://www.paraview.org/mailman/listinfo/paraview

Reply via email to