C:/mesDocs/QT_confDbVis_canvas/helper.py

Go to the documentation of this file.
00001 ###################################################################################################################
00002 # This module is a container class for functions that does not belong to any particular module. A collection of ###
00003 # useful functions that can be used in any module.                                                              ###
00004 ###################################################################################################################
00005 
00006 #from wxPython.wx import *
00007 
00008 OC = __import__('objectclasses') # We have to import the objectclasses module this way (using the load module function)
00009                                  # because or else we will get a recursive including/importing of objectclasses and helper
00010 
00011 
00012 ##
00013 #  Flattens a list. If we f.ex. have a list like [[[2],2],[[[3,3],4],4],5,6], 
00014 #       then this function will convert it to [2,2,3,3,4,4,5,5] recursively. Because 
00015 #       it is done recursively the list shouldn't have too many levels.
00016 #       
00017 def flatten(my_list):
00018 
00019         if type(my_list) != type([]): 
00020                 return [my_list]
00021         if my_list == []: 
00022                 return my_list
00023 
00024         return flatten(my_list[0]) + flatten(my_list[1:])
00025 
00026 ##
00027 #  prepends and appends a quote sign to a string, and returns it.
00028 # 
00029 #       @string - the string that will be quoted
00030 # 
00031 #       !return - the quoted string
00032 #       
00033 def prepostquotes(thestring):
00034 
00035         return '"' + thestring + '"'
00036 '''
00037 ##
00038 #  Drag and drop text functionality class.
00039 #       
00040 #           Here we define what that should be done on drop
00041 #       
00042 class TextDropTarget(wxTextDropTarget):
00043 
00044         ##
00045         #  Constructor.
00046         # 
00047         #                   Parameters:
00048         #                   @obj     - The object associated with the drop
00049         #                   @mainwin - The MainWindow instance (for communication)
00050         #               
00051         def __init__(self,obj,mainwin):
00052                 
00053                 wxTextDropTarget.__init__(self)
00054 
00055                 self.obj = obj
00056                 self.appwin = mainwin
00057 
00058         ##
00059         #  Method that is invoked on the drop of an object.
00060         # 
00061         #                   Parameters:
00062         #                   @x - x position (coord) of the dropped object
00063         #                   @y - y position (coord) of the dropped object
00064         #                   @data - data (string) set to the dropped object
00065         #               
00066         def OnDropText(self,x,y,data):
00067                 
00068                 tmp_info = data.split("|") # We have defined a string to be associated with every drag and drop object
00069                                            # First part is the systemname, second part the name of the object type dropped
00070                                            # They are separated by a '|'.
00071 
00072                 if tmp_info[2] == "Device":
00073                         tmp_devices = self.appwin.CreateDeviceClick(None) # Open Create Device Window
00074 
00075                         if tmp_devices != False and len(tmp_devices) > 0: # If we created one or more devices...
00076                                 i = 0
00077                                 for tmp_device in tmp_devices: # Lay them out nicely in the visual window
00078                                         x_offset,y_offset = self.appwin.GetVisWindow().CalcUnscrolledPosition(x,y+i)
00079                                         self.appwin.GetVisWindow().CreateNode(x_offset,y_offset,tmp_device)
00080                                         i += 5
00081 
00082                 else: #So far, only support for Devices...
00083                         print "Dropped an unknown object type"
00084                                 
00085 '''
00086 

Generated on Fri Aug 31 11:11:14 2007 for CDBVis by  doxygen 1.5.3