Sep 24, 2009

Navigate Faster with your Keyboard

Hope some of these will help you to navigate faster in typed text. (Thanks to Eugene Isack and Lydia. ^ ^)

Moving Cursor
Home................ = to the beginning of line
End................... = to the end of line
Ctrl + Home..... = to the beginning of page
Ctrl + End........ = to the end of page

Deleting
Ctrl + Backspace......= word to the left
Ctrl + Delete.............= word to the right

Selecting
Shift + left arrow...........................= one character to the left
Ctrl + Shift + left/right arrow......= word to the left/right
Shift + Home/End.........................= Select all till Start/Finish

Internet Browser
Ctrl + Enter..................= when entering URLs automatically adds www & .com
Ctrl + w.........................= close window/tab
Alt + Tab.......................= next tab
Alt + Shift + Tab...........= previous tab
Alt + d.........................= Go to url box
Alt + g..........................=Go to search box



Windows
Windows + D.........= minimises all windows
Windows + E.........= brings up my computer

Sep 15, 2009

Python loop and modify list

When working with lists, don't modify them as you iterate through.
For example, if you need to remove empty strings in your list, don't delete the strings as you find them, as your loop is still iterating, and some items might be looped through twice, or not at all.

Solution:
Write out another list, or another variable to keep track of what your loop is trying to achieve.

Extra Tags:
Remove whitespace empty string list iterate modify for loop

Sep 10, 2009

Picking actors

I met spent a couple of hours on this picking problem.

Problem:
My pointPicker is giving strange values. Values that are obviously greater than the number of points I have.

Solution:
I had more than one actor in my Render Window Interactor, and the picker was accessing them.
All I had to do was
myActor.PickableOff()
This made my other actors unpickable, so that the picker could do its job of picking my main actor.

Sep 3, 2009

-1 is true (if loops)

In programming (at least in python), all values except 0, empty strings, etc is true.
That is, if your expression returns something like '-1', your code inside the if loop is still run.

E.g.
myString = 'Hello World'
if myString.find('bye'):
print('I found bye.')

Output:
> I found bye.

This is because the .find command returns '-1', which is 'true'.

Instead, you need to replace the if statement to something like so:
if (myString.find('bye') != -1):

(Thanks to Stephen Hansen.)

QStrings and Strings

In Qt, QFileDialog can be used to open up a filedialog window. QFileDialog's static methods allows the GUI to capture the directory/file name that the user chooses. From that, a QString is returned.

My problem was that I wanted to find a certain string in the filename, but it was a QString, and not a string. I found that...

to convert a qstring to string, use the str function.

stringB = str(stringA)

In this situation, stringB will be the string version of stringA, which is of type QString. By the way, str works on integers as well.

PyQt Documentation on Qfiledialog

Sep 2, 2009

Backslashes and Forward slashes

Windows requires that paths are written with backslashes (\). If your path is currently forward slashed (/), you just need to use:
path_better = path.replace('/','\\')
To convert the forward slashes to backward ones. Note that the reason why I used TWO backslashes is because the single backslash escapes special characters (except in raw strings).
Of course, if what you need is to convert from backward to forward slash, just swap the order in the brackets. That is --> ('\\','/')

Tags: Converting Convert backward forward slash slashes

Sep 1, 2009

Embedding vtk into a pyqt GUI

Now that vtk is installed with python bindings, all you need to do is to let your GUI find these bindings, then import them into your GUI. Let's jump right into the code. I have skipped some bits that are general for vtk, and have mainly included bits that are directly relevant to the QVTKRenderWindowInteractor.

import sys
// Now append the path of the python wrapping, which comes in the source code.
// Alter the path according to your own path.
sys.path.append("C:\Qt\vtk-5.4.2\Wrapping\Python")
//Import the vtk module
import vtk

class StartMain(QtGui.QMainWindow):
# no parent, i.e. is top level widget
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_main()
self.ui.setupUi(self)
self.ui.meshDisplayWidget = QVTKRenderWindowInteractor(self.ui.meshDisplay) self.ui.meshDisplayWidget.Initialize()

//Set actors and mappers, then instead of creating a renderwindowinteractor,
// use the self.ui.meshDisplayWidget to display the mesh. Also define picker, and
// set data source (for code about displaying a mesh from coordinates, as
// an unstructured grid.
ren = vtk.vtkRenderer()
ren.AddActor(aMeshActor)
ren.AddActor2D(textActor)
ren.AddActor(dotActor)

ren.ResetCamera()
cam1 = ren.GetActiveCamera()
self.ui.meshDisplayWidget.GetRenderWindow().AddRenderer(ren)
self.ui.meshDisplayWidget.SetPicker(picker_point)
self.ui.meshDisplayWidget.show()