Exemplo n.º 1
0
    def update(self):
        """overwrite superclass's method
        updates this window and property window
        Returns None
        """
        if self.theSession.theSession is not self.theAssociatedSession:
            self.reconstructSystemTree()
            self.theQueue = FullPNQueue(
                (self["backbutton"], self["forwardbutton"]))
            self.theQueue.registerCallback(self.doSelection)
            self.theQueue.pushFullPNList(
                [convertFullIDToFullPN(createFullID('System::/'))])
            self.updateButtons()

        # updates this window
        if not self.exists():
            return
        OsogoWindow.update(self)

        # updates property window
        self.thePropertyWindow.update()

        # update PluginInstanceSelectionWindow
        if self.thePluginInstanceSelection != None:
            self.thePluginInstanceSelection.update()

        self.updateLists()
        self.theAssociatedSession = self.theSession.theSession
Exemplo n.º 2
0
    def update( self ):
        """overwrite superclass's method
        updates this window and property window
        Returns None
        """
        if self.theSession.theSession is not self.theAssociatedSession:
            self.reconstructSystemTree()
            self.theQueue = FullPNQueue( ( self[ "backbutton" ], self[ "forwardbutton" ] ) )
            self.theQueue.registerCallback( self.doSelection )
            self.theQueue.pushFullPNList( [ convertFullIDToFullPN( createFullID ( 'System::/' ) ) ] )
            self.updateButtons()

        # updates this window
        if not self.exists():
            return
        OsogoWindow.update(self)

        # updates property window
        self.thePropertyWindow.update()

        # update PluginInstanceSelectionWindow
        if self.thePluginInstanceSelection != None:
            self.thePluginInstanceSelection.update()

        self.updateLists()
        self.theAssociatedSession = self.theSession.theSession
Exemplo n.º 3
0
class EntityListWindow(OsogoWindow):
    '''EntityListWindow
    '''

    DEFAULT_PLUGIN = 'TracerWindow'

    DEFAULT_VARIABLE_PROPERTY = 'Value'
    DEFAULT_PROCESS_PROPERTY = 'Activity'

    COMMON_COLUMN_INFO_MAP = {
        'ID': gobject.TYPE_STRING,
        'Classname': gobject.TYPE_STRING,
        'Path': gobject.TYPE_STRING
    }

    VARIABLE_COLUMN_INFO_MAP = {
        # Name:      Type
        'Value': gobject.TYPE_STRING
    }

    PROCESS_COLUMN_INFO_MAP = {'Activity': gobject.TYPE_STRING}

    VARIABLE_COLUMN_LIST = ['ID', 'Value', 'Classname', 'Path']
    PROCESS_COLUMN_LIST = ['ID', 'Activity', 'Classname', 'Path']

    def __init__(self, session, rootWidget, aStatusbar):
        '''Constructor
        session   --   a reference to GtkSessionMonitor
        '''

        # call superclass's constructor
        OsogoWindow.__init__(self, session, rootWidget=rootWidget)

        # initialize parameters
        self.theSelectedFullPNList = []

        self.searchString = ''

        # set status bar
        self.theStatusbar = aStatusbar

        # fix me
        self.thePluginManager = session.thePluginManager
        self.thePropertyWindow = None
        self.thePluginInstanceSelection = None

        self.theAssociatedSession = None

    def openWindow(self):

        # call superclass's openWindow
        OsogoWindow.openWindow(self)

        self['search_method'].set_property('active', 0)
        self['search_scope'].set_property('active', 0)

        # add handers
        self.addHandlers({
            'on_system_tree_button_press_event': self.popupMenu,
            'on_view_button_clicked': self.createPluginWindow,
            'on_variable_tree_button_press_event': self.popupMenu,
            'on_process_tree_button_press_event': self.popupMenu,
            # search
            'on_search_button_clicked': self.pushSearchButton,
            'on_search_entry_key_press_event': self.keypressOnSearchEntry,
            'on_clear_button_clicked': self.pushClearButton,
            'on_search_scope_changed': self.searchScopeChanged
        })

        self.entitySelected = False
        self.theLastSelectedWindow = None
        self.thePopupMenu = gtk.Menu()
        self.donotHandle = False
        self.systemTree = self['system_tree']
        self.processTree = self['process_tree']
        self.variableTree = self['variable_tree']

        # --------------------------------------------
        # initialize components
        # --------------------------------------------
        self.__initializeSystemTree()
        self.__initializeProcessTree()
        self.__initializeVariableTree()
        self.__initializeSelection()
        self.__initializePluginWindowOptionMenu()

        self.theQueue = None
        self.__initializePropertyWindow()
        self.__initializePopupMenu()

        self.theSelectedEntityList = []
        self.theSelectedPluginInstanceList = []

        self.CloseOrder = False
        self.updateButtons()

    def updateButtons(self):
        if self.theSession.theSession is not None:
            self['search_button'].set_sensitive(True)
            self['view_button'].set_sensitive(True)
            self['search_entry'].set_sensitive(True)
            self['plugin_optionmenu'].set_sensitive(True)
            self['backbutton'].set_sensitive(False)
            self['forwardbutton'].set_sensitive(False)
        else:
            self['search_button'].set_sensitive(False)
            self['view_button'].set_sensitive(False)
            self['search_entry'].set_sensitive(False)
            self['plugin_optionmenu'].set_sensitive(False)
            self['backbutton'].set_sensitive(False)
            self['forwardbutton'].set_sensitive(False)

    def getQueue(self):
        return self.theQueue

    def deleted(self, *arg):
        self.close()

    def close(self):
        if self.CloseOrder:
            return
        self.CloseOrder = True

        if self.thePluginInstanceSelection != None:
            self.thePluginInstanceSelection.deleted()
            self.thePluginInstanceSelection = None

        if self.theSession != None:
            self.theSession.deleteEntityListWindow(self)
            OsogoWindow.close(self)

    def deletePluginInstanceSelection(self, *arg):
        """sets 'delete_event' as 'hide_event'
        """

        # hide this window
        self['PluginInstanceSelection'].hide_all()

        # set 'delete_event' uneffective
        return True

    def __initializeSystemTree(self):
        """initialize SystemTree
        """
        self.lastSelectedSystem = ""
        treeStore = gtk.TreeStore(gobject.TYPE_STRING)
        self.theSysTreeStore = treeStore
        column = gtk.TreeViewColumn('System Tree',
                                    gtk.CellRendererText(),
                                    text=0)
        column.set_visible(True)
        self.systemTree.append_column(column)

        self.systemTree.set_model(treeStore)

        self.processTree.set_search_column(0)
        self.theSysSelection = self.systemTree.get_selection()

    def __initializeSelection(self):
        selection = self.systemTree.get_selection()
        selection.set_mode(gtk.SELECTION_MULTIPLE)
        selection.connect('changed', self.selectSystem)
        selection = self.processTree.get_selection()
        selection.set_mode(gtk.SELECTION_MULTIPLE)
        selection.connect('changed', self.selectProcess)
        selection = self.variableTree.get_selection()
        selection.set_mode(gtk.SELECTION_MULTIPLE)
        selection.connect('changed', self.selectVariable)

    def __initializeProcessTree(self):
        """initialize ProcessTree
        """

        columnTypeList = []

        for i in range(len(self.PROCESS_COLUMN_LIST)):
            title = self.PROCESS_COLUMN_LIST[i]

            try:
                type = self.PROCESS_COLUMN_INFO_MAP[title]
            except:
                type = self.COMMON_COLUMN_INFO_MAP[title]

            column = gtk.TreeViewColumn(title, gtk.CellRendererText(), text=i)
            column.set_reorderable(True)
            column.set_sort_column_id(i)
            self.processTree.append_column(column)
            columnTypeList.append(type)
            if type == gobject.TYPE_FLOAT:
                column.set_alignment(1.0)
                column.get_cell_renderers()[0].set_property('xalign', 1.0)

        self.processTree.set_search_column(0)

        model = gtk.ListStore(*columnTypeList)
        self.processTree.set_model(model)

    def __initializeVariableTree(self):
        """initializes VariableTree
        """

        columnTypeList = []

        for i in range(len(self.VARIABLE_COLUMN_LIST)):
            title = self.VARIABLE_COLUMN_LIST[i]

            try:
                type = self.VARIABLE_COLUMN_INFO_MAP[title]
            except:
                type = self.COMMON_COLUMN_INFO_MAP[title]

            column = gtk.TreeViewColumn(title, gtk.CellRendererText(), text=i)
            column.set_reorderable(True)
            column.set_sort_column_id(i)
            self.variableTree.append_column(column)
            columnTypeList.append(type)
            if type == gobject.TYPE_FLOAT:
                column.set_alignment(1.0)
                column.get_cell_renderers()[0].set_property('xalign', 1.0)

        self.variableTree.set_search_column(0)

        model = gtk.ListStore(*columnTypeList)
        self.variableTree.set_model(model)

    def __initializePluginWindowOptionMenu(self):
        """initializes PluginWindowOptionMenu
        """

        aPluginWindowNameList = []
        aMenu = gtk.Menu()

        for aPluginWindowName in self.thePluginManager.thePluginMap.keys():

            aButton = gtk.Button()
            aMenuItem = gtk.MenuItem(aPluginWindowName)

            if aPluginWindowName == self.DEFAULT_PLUGIN:
                aMenu.prepend(aMenuItem)
            else:
                aMenu.append(aMenuItem)

        self['plugin_optionmenu'].set_menu(aMenu)
        self['plugin_optionmenu'].show_all()

    def __initializePropertyWindow(self):
        if self.thePropertyWindow != None:
            return
        self.thePropertyWindow = self.thePluginManager.createInstance(
            'PropertyWindow', [], rootWidget='top_frame', parent=self)
        if self.theStatusbar is not None:
            self.thePropertyWindow.setStatusBar(self.theStatusbar)

        aPropertyWindowTopVBox = self.thePropertyWindow['top_frame']
        self['property_area'].add(aPropertyWindowTopVBox)
        self.thePropertyWindow.setParent(self)

    def __initializePopupMenu(self):
        """Initialize popup menu
        Returns None
        [Note]:In this method, only 'PluginWindow type' menus, 'Create 
        Logger' menu and 'Add to Board' menu are created. 
        The menus of PluginWindow instances are appended
        dinamically in self.popupMenu() method.
        """

        # ------------------------------------------
        # menus for PluginWindow
        # ------------------------------------------

        # creaets menus of PluginWindow
        for aPluginWindowType in self.thePluginManager.thePluginMap.keys():
            aMenuItem = gtk.MenuItem(aPluginWindowType)
            aMenuItem.connect('activate', self.createPluginWindow)
            aMenuItem.set_name(aPluginWindowType)
            if aPluginWindowType == self.DEFAULT_PLUGIN:
                self.thePopupMenu.prepend(aMenuItem)
            else:
                self.thePopupMenu.append(aMenuItem)

        # appends separator
        self.thePopupMenu.append(gtk.MenuItem())

        # ------------------------------------------
        # menus for Logger
        # ------------------------------------------
        # creates menu of Logger
        aLogMenuString = "Create Logger"
        aMenuItem = gtk.MenuItem(aLogMenuString)
        aMenuItem.connect('activate', self.createLogger)
        aMenuItem.set_name(aLogMenuString)
        self.thePopupMenu.append(aMenuItem)

        # appends separator
        self.thePopupMenu.append(gtk.MenuItem())

        # ------------------------------------------
        # menus for Bord
        # ------------------------------------------
        # creates menu of Board
        aSubMenu = gtk.Menu()

        for aPluginWindowType in self.thePluginManager.thePluginMap.keys():
            aMenuItem = gtk.MenuItem(aPluginWindowType)
            aMenuItem.connect('activate', self.addToBoard)
            aMenuItem.set_name(aPluginWindowType)
            if aPluginWindowType == self.DEFAULT_PLUGIN:
                aSubMenu.prepend(aMenuItem)
            else:
                aSubMenu.append(aMenuItem)

        aMenuString = "Add to Board"
        aMenuItem = gtk.MenuItem(aMenuString)
        aMenuItem.set_name(aLogMenuString)
        aMenuItem.set_submenu(aSubMenu)
        self.thePopupMenu.append(aMenuItem)
        self.theBoardMenu = aMenuItem

        # appends separator
        self.thePopupMenu.append(gtk.MenuItem())

        # ------------------------------------------
        # menus for submenu
        # ------------------------------------------
        self.thePopupSubMenu = None

    def __openPluginInstanceSelectionWindow(self, *arg):
        """open PluginInstanceSelectionWindow
        Returns None
        """

        if self.thePluginInstanceSelection != None:
            self.thePluginInstanceSelection.present()

        else:

            self.thePluginInstanceSelection = \
            PluginInstanceSelection( self.theSession, self )
            self.thePluginInstanceSelection.openWindow()

            # updates list of PluginInstance
            self.thePluginInstanceSelection.update()

    def __updatePluginInstanceSelectionWindow2(self):
        """updates list of PluginInstanceSelectionWindow
        Returns None
        """

        self.thePluginInstanceListStore.clear()
        aPluginInstanceList = self.thePluginManager.thePluginTitleDict.keys()

        for aPluginInstance in aPluginInstanceList:
            if aPluginInstance.theViewType == MULTIPLE:
                aPluginInstanceTitle = self.thePluginManager.thePluginTitleDict[
                    aPluginInstance]
                iter = self.thePluginInstanceListStore.append()
                self.thePluginInstanceListStore.set_value(
                    iter, 0, aPluginInstanceTitle)
                self.thePluginInstanceListStore.set_data(
                    aPluginInstanceTitle, aPluginInstanceTitle)

    def closePluginInstanceSelectionWindow(self, *arg):
        """closes PluginInstanceSelectionWindow
        Returns None
        """

        if self.thePluginInstanceSelection != None:
            #self.thePluginInstanceSelection['PluginInstanceSelection'].hide_all()
            self.thePluginInstanceSelection.deleted()
            self.thePluginInstanceSelection = None

    def popupMenu(self, aWidget, anEvent):
        """displays popup menu only when right button is pressed.
        aWidget   --  EntityListWindow
        anEvent   --  an event
        Returns None
        [Note]:creates and adds submenu that includes menus of PluginWindow instances
        """
        # When left button is pressed
        if anEvent.type == gtk.gdk._2BUTTON_PRESS:
            aSelectedRawFullPNList = self.__getSelectedRawFullPNList()
            aPluginWindowType = self['plugin_optionmenu'].get_children(
            )[0].get()

            # When no FullPN is selected, displays error message.
            if aSelectedRawFullPNList != None:
                if len(aSelectedRawFullPNList) == 0:
                    aMessage = 'No entity is selected.'
                    aDialog = ConfirmWindow(OK_MODE, aMessage, 'Error!')
                    self.thePropertyWindow.showMessageOnStatusBar(aMessage)
                    return False

            #self.theQueue.pushFullPNList( aSelectedRawFullPNList )
            self.thePluginManager.createInstance(
                aPluginWindowType, self.thePropertyWindow.getFullPNList())

        # When right button is pressed
        if anEvent.type == gtk.gdk.BUTTON_PRESS and anEvent.button == 3:

            if self.theSession.getWindow('BoardWindow').exists():
                self.theBoardMenu.set_sensitive(True)
            else:
                self.theBoardMenu.set_sensitive(False)

            # removes previous sub menu
            # When PopupMenu was displayed last time without PluginWindows'
            # menus, the buffer (self.thePopupSubMenu) is None.
            if self.thePopupSubMenu != None:
                self.thePopupMenu.remove(self.thePopupSubMenu)

            if len(self.thePluginManager.theInstanceList) != 0:

                # creates submenu
                aSubMenu = gtk.Menu()

                # creaets menus of PluginWindow instances
                aMenuItemFlag = False
                for aPluginInstance in self.thePluginManager.theInstanceList:

                    if aPluginInstance.theViewType == MULTIPLE:
                        aTitle = aPluginInstance.getTitle()
                        aMenuItem = gtk.MenuItem(aTitle)
                        aMenuItem.connect('activate', self.appendData)
                        aMenuItem.set_name(aTitle)
                        aSubMenu.append(aMenuItem)
                        aMenuItemFlag = True

                if aMenuItemFlag:
                    # creates parent MenuItem attached created submenu.
                    aMenuString = "Append data to"
                    aMenuItem = gtk.MenuItem(aMenuString)
                    aMenuItem.set_submenu(aSubMenu)

                    # appends parent MenuItem to PopupMenu
                    self.thePopupMenu.append(aMenuItem)

                    # saves this submenu set to buffer (self.thePopupSubMenu)
                    self.thePopupSubMenu = aMenuItem

            # displays all items on PopupMenu
            self.thePopupMenu.show_all()

            # displays popup menu
            self.thePopupMenu.popup(None, None, None, anEvent.button,
                                    anEvent.time)

    def update(self):
        """overwrite superclass's method
        updates this window and property window
        Returns None
        """
        if self.theSession.theSession is not self.theAssociatedSession:
            self.reconstructSystemTree()
            self.theQueue = FullPNQueue(
                (self["backbutton"], self["forwardbutton"]))
            self.theQueue.registerCallback(self.doSelection)
            self.theQueue.pushFullPNList(
                [convertFullIDToFullPN(createFullID('System::/'))])
            self.updateButtons()

        # updates this window
        if not self.exists():
            return
        OsogoWindow.update(self)

        # updates property window
        self.thePropertyWindow.update()

        # update PluginInstanceSelectionWindow
        if self.thePluginInstanceSelection != None:
            self.thePluginInstanceSelection.update()

        self.updateLists()
        self.theAssociatedSession = self.theSession.theSession

    def constructSystemTree(self, parent, fullID):
        # System tree
        newlabel = fullID[ID]

        systemStore = self.systemTree.get_model()
        iter = systemStore.append(parent)
        systemStore.set_value(iter, 0, newlabel)
        key = str(systemStore.get_path(iter))
        systemStore.set_data(key, fullID)

        systemPath = createSystemPathFromFullID(fullID)
        systemList = self.theSession.getEntityList('System', systemPath)
        systemListLength = len(systemList)

        if systemListLength == 0:
            return

        for systemID in systemList:
            newSystemFullID = (SYSTEM, systemPath, systemID)
            self.constructSystemTree(iter, newSystemFullID)

            path = systemStore.get_path(iter)
            if systemListLength < 6 and len(path) < 6:
                self.systemTree.expand_row(path, True)

    def reconstructSystemTree(self):
        rootSystemFullID = createFullID('System::/')
        self.donotHandle = True
        self.theSysTreeStore.clear()
        self.donotHandle = False
        if self.theSession.theSession:
            self.constructSystemTree(None, rootSystemFullID)
        self.reconstructLists()

    def reconstructLists(self):
        selectedSystemList = self.getSelectedSystemList()
        if self.entitySelected:
            return
        # Variable list
        self.reconstructEntityList( 'Variable', self.variableTree,\
                                    selectedSystemList,\
                                    self.VARIABLE_COLUMN_LIST,\
                                    self.VARIABLE_COLUMN_INFO_MAP )

        # Process list
        self.reconstructEntityList( 'Process', self.processTree,\
                                    selectedSystemList,\
                                    self.PROCESS_COLUMN_LIST,\
                                    self.PROCESS_COLUMN_INFO_MAP )
        self.updateListLabels()



    def reconstructEntityList( self, type, view, systemList, columnList,\
                               columnInfoList ):
        # get the entity list in the selected system(s)
        typeID = ENTITYTYPE_DICT[type]

        fullIDList = []
        if self.theSession.theSession is not None:
            for systemFullID in systemList:
                systemPath = createSystemPathFromFullID(systemFullID)

                idList = self.theSession.getEntityList(type, systemPath)
                fullIDList += [(typeID, systemPath, id) for id in idList]

        entityStore = view.get_model()

        # clear the store
        donotHandle = self.donotHandle
        self.donotHandle = True
        entityStore.clear()
        self.donotHandle = donotHandle

        #        columnList = view.get_columns()
        # re-create the list
        for fullID in fullIDList:

            ID = fullID[2]
            # temporary hack for the entity searching.
            # this can be like this in python 2.3 or above:
            #    if not self.searchString in ID:
            if ID.find(self.searchString) < 0:
                continue

            fullIDString = createFullIDString(fullID)

            stub = self.theSession.createEntityStub(fullIDString)

            valueList = []

            for title in columnList:

                if title in self.COMMON_COLUMN_INFO_MAP.keys():
                    if title == 'ID':
                        value = ID
                    elif title == 'Classname':
                        value = stub.getClassname()
                    elif title == 'Path':
                        value = fullID[SYSTEMPATH]
                    else:
                        raise "Unexpected error: invalid column title."
                else:
                    value = stub[title]  # if not common, it's entity property

                valueList.append(value)

            iter = entityStore.append(valueList)
            iterString = entityStore.get_string_from_iter(iter)
            entityStore.set_data(iterString, fullIDString)

    def doSelection(self, aFullPNList):
        self.doSelectSystem(aFullPNList)
        self.doSelectProcess(aFullPNList)
        self.doSelectVariable(aFullPNList)

    def doSelectSystem(self, aFullPNList):
        targetFullIDList = []
        if aFullPNList[0][TYPE] != SYSTEM:
            targetFullIDList += [
                createFullIDFromSystemPath(aFullPN[SYSTEMPATH])
                for aFullPN in aFullPNList
            ]
        else:
            for aFullPN in aFullPNList:
                aFullID, _ = convertFullPNToFullID(aFullPN)
                targetFullIDList.append(aFullID)

        # if to slow there should be a check whether this is needed in all cases
        donotHandle = self.donotHandle
        self.donotHandle = True
        self.theSysSelection.unselect_all()
        self.theSysSelection.set_mode(gtk.SELECTION_MULTIPLE)

        for targetFullID in targetFullIDList:
            #doselection
            targetPath = createSystemPathFromFullID(targetFullID)
            anIter = self.getSysTreeIter(targetPath)
            if anIter is not None:
                aPath = self.theSysTreeStore.get_path(anIter)
                self.__expandRow(aPath)
                self.theSysSelection.select_iter(anIter)

        self.donotHandle = donotHandle

        self.reconstructLists()

    def getSysTreeIter(self, aSysPath, anIter=None):
        """
        returns iter of string aSysPath or None if not available
        """
        systemStore = self.systemTree.get_model()
        if anIter == None:
            anIter = systemStore.get_iter_first()
            if aSysPath == '/':
                return anIter
            else:
                aSysPath = aSysPath.strip('/')

        # get first path string
        anIndex = aSysPath.find('/')
        if anIndex == -1:
            anIndex = len(aSysPath)
        firstTag = aSysPath[0:anIndex]

        # create remaining path string
        aRemainder = aSysPath[anIndex + 1:len(aSysPath)]

        # find iter of first path string
        numChildren = systemStore.iter_n_children(anIter)
        isFound = False
        for i in range(0, numChildren):
            childIter = systemStore.iter_nth_child(anIter, i)

            if systemStore.get_value(childIter, 0) == firstTag:
                isFound = True
                break

        # if not found return None
        if not isFound:
            return None

        # if remainder is '' return iter
        if aRemainder == '':
            return childIter

        # return recursive remainder with iter
        return self.getSysTreeIter(aRemainder, childIter)

    def __expandRow(self, aPath):
        """
        in: gtktreePath aPath
        """
        if not self.systemTree.row_expanded(aPath):

            # get iter
            anIter = self.theSysTreeStore.get_iter(aPath)

            # get parent iter
            parentIter = self.theSysTreeStore.iter_parent(anIter)

            # if iter is root expand
            if parentIter != None:

                # if not get parent path
                parentPath = self.theSysTreeStore.get_path(parentIter)

                # expand parentpath
                self.__expandRow(parentPath)

            # expand this path
            self.systemTree.expand_row(aPath, False)

    def selectListIter(self, aListStore, aSelection, anIDList):

        anIter = aListStore.get_iter_first()
        while anIter != None:
            if aListStore.get_value(anIter, 0) in anIDList:
                donotHandle = self.donotHandle
                self.donotHandle = True
                aSelection.select_iter(anIter)
                self.donotHandle = donotHandle

            anIter = aListStore.iter_next(anIter)

    def doSelectProcess(self, aFullPNList):
        #unselect all

        selection = self.processTree.get_selection()
        listStore = self.processTree.get_model()
        selection.unselect_all()
        selection.set_mode(gtk.SELECTION_MULTIPLE)

        if aFullPNList[0][TYPE] == PROCESS:
            # do select
            self.selectListIter(listStore, selection,
                                self.__createIDList(aFullPNList))

    def __createIDList(self, aFullPNList):
        anIDList = []
        for aFullPN in aFullPNList:
            anIDList.append(aFullPN[ID])
        return anIDList

    def doSelectVariable(self, aFullPNList):
        #unselect all
        selection = self.variableTree.get_selection()
        listStore = self.variableTree.get_model()
        selection.unselect_all()
        selection.set_mode(gtk.SELECTION_MULTIPLE)

        if aFullPNList[0][TYPE] == VARIABLE:
            # do select
            self.selectListIter(listStore, selection,
                                self.__createIDList(aFullPNList))

    def selectSystem(self, obj):
        if self.donotHandle:
            return

        # select the first selected System in the PropertyWindow
        systemFullIDList = self.getSelectedSystemList()
        fullPNList = []
        for systemFullID in systemFullIDList:
            fullPNList.append(convertFullIDToFullPN(systemFullID))
        self.donotHandle = True
        self.theQueue.pushFullPNList(fullPNList)
        self.donotHandle = False

    def getSelectedSystemList(self):
        '''
        Return - a list of FullIDs of the currently selected Systems.
        '''

        # get system ID from selected items of system tree,
        # and get entity list from session

        systemList = []

        selection = self.systemTree.get_selection()
        selectedSystemTreePathList = selection.get_selected_rows()
        if selectedSystemTreePathList == None:
            return []
        selectedSystemTreePathList = selectedSystemTreePathList[1]

        systemStore = self.systemTree.get_model()

        for treePath in selectedSystemTreePathList:

            systemFullID = systemStore.get_data(str(treePath))
            systemList.append(systemFullID)

        return systemList

    def updateLists(self):
        '''
        This method updates property values shown in the list of
        Variables and Processes.
        '''
        if self.theSession.theSession is None:
            return

        self.updateEntityList( 'Process', self.processTree.get_model(),\
                               self.PROCESS_COLUMN_LIST,\
                               self.PROCESS_COLUMN_INFO_MAP )

        self.updateEntityList( 'Variable', self.variableTree.get_model(),\
                               self.VARIABLE_COLUMN_LIST,\
                               self.VARIABLE_COLUMN_INFO_MAP )

    def updateEntityList(self, type, model, columnList, columnInfoMap):

        propertyColumnList= [ ( columnList.index( i ), i )\
                              for i in columnInfoMap.keys() ]

        for row in model:

            iter = row.iter
            fullID = model.get_data(model.get_string_from_iter(iter))

            stub = self.theSession.createEntityStub(fullID)

            columnList = []
            for propertyColumn in propertyColumnList:
                newValue = stub[propertyColumn[1]]
                columnList += [propertyColumn[0], "%g" % (newValue)]

            model.set(iter, *columnList)

    def updateListLabels(self):
        self.__updateViewLabel( 'Variable', self['variable_label'],\
                                self.variableTree )
        self.__updateViewLabel( 'Process', self['process_label'],\
                                self.processTree )
        self.__updateViewLabel( 'System', self['system_label'],\
                                self.systemTree )

    def __updateViewLabel(self, type, label, view):
        shownCount = len(view.get_model())
        selectedCount = view.get_selection().count_selected_rows()
        labelText = '<b>%s</b> (%d / %d)' % (type, selectedCount, shownCount)
        label.set_markup(labelText)

    def selectProcess(self, selection):
        if self.donotHandle:
            return
        self.entitySelected = True
        self.theLastSelectedWindow = "Process"

        # clear fullPN list
        self.theSelectedFullPNList = []

        # get selected items
        selection.selected_foreach(self.process_select_func)

        if len(self.theSelectedFullPNList) > 0:
            self.donotHandle = True
            self.theQueue.pushFullPNList(self.theSelectedFullPNList)
            self.donotHandle = False
        # clear selection of variable list
#        self.variableTree.get_selection().unselect_all()

        self.updateListLabels()
        self.entitySelected = False

    def selectVariable(self, selection):
        if self.donotHandle:
            return
        self.entitySelected = True
        self.theLastSelectedWindow = "Variable"

        # clear fullPN list
        self.theSelectedFullPNList = []

        # get selected items
        selection.selected_foreach(self.variable_select_func)

        if len(self.theSelectedFullPNList) > 0:
            self.donotHandle = True
            self.theQueue.pushFullPNList(self.theSelectedFullPNList)
            self.donotHandle = False

        # clear selection of process list
#        self.processTree.get_selection().unselect_all()

        self.updateListLabels()
        self.entitySelected = False

    def variable_select_func(self, tree, path, iter):
        '''function for variable list selection

        Return None
        '''

        model = self.variableTree.get_model()
        data = model.get_data(model.get_string_from_iter(iter))
        entityFullID = createFullID(data)
        entityFullPN = entityFullID + (self.DEFAULT_VARIABLE_PROPERTY, )
        self.theSelectedFullPNList.append(entityFullPN)

    def process_select_func(self, tree, path, iter):
        '''function for process list selection

        Return None
        '''

        model = self.processTree.get_model()
        data = model.get_data(model.get_string_from_iter(iter))
        entityFullID = createFullID(data)
        entityFullPN = entityFullID + (self.DEFAULT_PROCESS_PROPERTY, )
        self.theSelectedFullPNList.append(entityFullPN)

    def createPluginWindow(self, *obj):
        """creates new PluginWindow instance(s)
        *obj   --  gtk.MenuItem on popupMenu or gtk.Button
        Returns None
        """

        self.thePropertyWindow.clearStatusBar()

        if len(obj) == 0:
            return None

        aPluginWindowType = self.DEFAULT_PLUGIN
        aSetFlag = False

        # When this method is cadef doSeleclled by popup menu
        if type(obj[0]) == gtk.MenuItem:
            aPluginWindowType = obj[0].get_name()

        # When this method is called by 'CreateWindow' button
        elif type(obj[0]) == gtk.Button:
            aPluginWindowType = self['plugin_optionmenu'].get_children(
            )[0].get()

        else:
            raise TypeErrir("%s must be gtk.MenuItem or gtk.Button" %
                            str(type(obj[0])))

        aSelectedRawFullPNList = self.__getSelectedRawFullPNList()

        # When no FullPN is selected, displays error message.
        if aSelectedRawFullPNList == None or len(aSelectedRawFullPNList) == 0:

            aMessage = 'No entity is selected.'
            aDialog = ConfirmWindow(OK_MODE, aMessage, 'Error!')
            self.thePropertyWindow.showMessageOnStatusBar(aMessage)
            return False

        #self.theQueue.pushFullPNList( aSelectedRawFullPNList )
        self.thePluginManager.createInstance(
            aPluginWindowType, self.thePropertyWindow.getFullPNList())

    def appendData(self, *obj):
        """appends RawFullPN to PluginWindow instance
        Returns True(when appened) / False(when not appened)
        """

        # clear status bar
        self.thePropertyWindow.clearStatusBar()

        if len(obj) == 0:
            return None

        # Only when at least one menu is selected.

        # ----------------------------------------------------
        # When this method is called by popup menu
        # ----------------------------------------------------
        if type(obj[0]) == gtk.MenuItem:
            aSetFlag = True
            aPluginWindowTitle = obj[0].get_name()

            for anInstance in self.thePluginManager.theInstanceList:
                if anInstance.getTitle() == aPluginWindowTitle:

                    try:
                        anInstance.appendRawFullPNList(
                            self.__getSelectedRawFullPNList())
                    except TypeError:
                        anErrorFlag = True
                        aMessage = "Can't append data to %s" % str(
                            anInstance.getTitle())
                        self.thePropertyWindow.showMessageOnStatusBar(aMessage)
                    else:
                        aMessage = "Selected Data are added to %s" % aPluginWindowTitle
                        self.thePropertyWindow.showMessageOnStatusBar(aMessage)
                    break

            return True

        # ----------------------------------------------------
        # When this method is called by PluginInstanceWindow
        # ----------------------------------------------------
        elif type(obj[0]) == gtk.Button:

            self.theSelectedPluginInstanceList = []
            selection = self.thePluginInstanceSelection[
                'plugin_tree'].get_selection()
            selection.selected_foreach(
                self.thePluginInstanceSelection.plugin_select_func)

            # When no FullPN is selected, displays error message.
            if self.__getSelectedRawFullPNList() == None or len(
                    self.__getSelectedRawFullPNList()) == 0:

                aMessage = 'No entity is selected.'
                aDialog = ConfirmWindow(OK_MODE, aMessage, 'Error!')
                self.thePropertyWindow.showMessageOnStatusBar(aMessage)
                return False

            # When no plugin instance is selected, displays error message.
            if len(self.theSelectedPluginInstanceList) == 0:

                aMessage = 'No Plugin Instance is selected.'
                aDialog = ConfirmWindow(OK_MODE, aMessage, 'Error!')
                self.thePropertyWindow.showMessageOnStatusBar(aMessage)
                return False

            # buffer of appended instance's title
            anAppendedTitle = []

            anErrorFlag = False

            # appneds data
            for aPluginWindowTitle in self.theSelectedPluginInstanceList:
                for anInstance in self.thePluginManager.theInstanceList:
                    if anInstance.getTitle() == aPluginWindowTitle:
                        try:
                            anInstance.appendRawFullPNList(
                                self.__getSelectedRawFullPNList())
                        except TypeError:
                            anErrorFlag = True
                            aMessage = "Can't append data to %s" % str(
                                anInstance.getTitle())
                            self.thePropertyWindow.showMessageOnStatusBar(
                                aMessage)
                        else:
                            anAppendedTitle.append(anInstance.getTitle())
                        break

            # When at least one instance is appended
            if len(anAppendedTitle) > 0 and anErrorFlag == False:
                # displays message
                aMessage = "Selected Data are added to %s" % str(
                    anAppendedTitle)
                self.theSession.message(aMessage)
                self.thePropertyWindow.showMessageOnStatusBar(aMessage)

                # closes PluginInstanceSelectionWindow
                #self.__closePluginInstanceSelectionWindow()
                self.closePluginInstanceSelectionWindow()
                return True

            # When no instance is appended
            else:

                return None

    def __getSelectedRawFullPNList(self):
        """
        Return a list of selected FullPNs
        """
        return self.theQueue.getActualFullPNList()

    def addToBoard(self, *arg):
        """add plugin window to board
        """

        self.thePropertyWindow.clearStatusBar()

        if len(arg) == 0:
            return None

        aPluginWindowType = self.DEFAULT_PLUGIN
        aSetFlag = False

        # When this method is called by popup menu
        if type(arg[0]) == gtk.MenuItem:
            aPluginWindowType = arg[0].get_name()

        # When this method is called by 'CreateWindow' button
        elif type(arg[0]) == gtk.Button:
            aPluginWindowType = self['plugin_optionmenu'].get_children(
            )[0].get()

        else:
            raise TypeError("%s must be gtk.MenuItem or gtk.Button" %
                            str(type(arg[0])))

        aSelectedRawFullPNList = self.__getSelectedRawFullPNList()

        # When no FullPN is selected, displays error message.
        if aSelectedRawFullPNList == None or len(aSelectedRawFullPNList) == 0:

            aMessage = 'No entity is selected.'
            aDialog = ConfirmWindow(OK_MODE, aMessage, 'Error!')
            self.thePropertyWindow.showMessageOnStatusBar(aMessage)
            return False

        self.theSession.getWindow('BoardWindow').addPluginWindows( aPluginWindowType, \
        self.__getSelectedRawFullPNList() )

    def createLogger(self, *arg):
        """creates Logger about all FullPN selected on EntityTreeView
        Returns None
        """

        # clear status bar
        self.thePropertyWindow.clearStatusBar()

        # gets selected RawFullPNList
        aSelectedRawFullPNList = self.__getSelectedRawFullPNList()

        # When no entity is selected, displays confirm window.
        if len(aSelectedRawFullPNList) == 0:

            aMessage = 'No Entity is selected.'
            self.thePropertyWindow.showMessageOnStatusBar(aMessage)
            aDialog = ConfirmWindow(OK_MODE, aMessage, 'Error!')
            return None

        # creates Logger using PropertyWindow
        #self.theQueue.pushFullPNList( aSelectedRawFullPNList )
        aLogPolicy = self.theSession.getLogPolicyParameters()
        try:
            for aFullPN in self.getFullPNList():
                # creates loggerstub and call its create method.
                aLoggerStub = self.theSession.createLoggerStub(
                    createFullPNString(aFullPN))
                if not aLoggerStub.exists():
                    aLoggerStub.setLoggerPolicy(aLogPolicy)
                    aLoggerStub.create()
        except:
            # When to create log is failed, display error message on MessageWindow.
            anErrorMessage = traceback.format_exception(
                sys.exc_type, sys.exc_value, sys.exc_traceback)
            self.thePluginManager.printMessage(anErrorMessage)
            return

        # updates fandamental windows.
        self.thePluginManager.updateFundamentalWindows()

        # display message on status bar
        if len(aSelectedRawFullPNList) == 1:
            aMessage = 'Logger was created.'
        else:
            aMessage = 'Loggers were created.'
        self.thePropertyWindow.showMessageOnStatusBar(aMessage)
        #self.checkCreateLoggerButton()

    def searchEntity(self):
        """search Entities
        Returns None
        """
        searchString = self['search_entry'].get_text()
        # set modelwalker to current selection
        aFullPNList = []

        modelWalker = self.theSession.theModelWalker

        modelWalker.reset()

        nextFullID = modelWalker.getCurrentFullID()

        while nextFullID != None:
            if nextFullID[TYPE] == SYSTEM:
                currentSystemID = nextFullID
                currentSystemSelected = False

            elif not currentSystemSelected and nextFullID[ID].find(
                    searchString) != -1:
                # select
                aFullPNList += [convertFullIDToFullPN(currentSystemID)]
                currentSystemSelected = True

            nextFullID = modelWalker.getNextFullID()

        if len(aFullPNList) == 0:
            aDialog = ConfirmWindow(
                OK_MODE, "Search string %s not found." % searchString,
                "Search failed")
            return
        self.searchString = searchString
        self.theQueue.pushFullPNList(aFullPNList)
        self['search_button'].set_sensitive(False)
        if self.searchString != '':
            self['clear_button'].set_sensitive(True)

    def filterSelectedSystems(self):

        self.searchString = self['search_entry'].get_text()
        self.reconstructLists()
        self['search_button'].set_sensitive(False)
        if self.searchString != '':
            self['clear_button'].set_sensitive(True)
        else:
            self['clear_button'].set_sensitive(False)

    def pushSearchButton(self, *arg):
        searchScope = self['search_scope'].get_property('active')
        if searchScope == 0:
            self.searchEntity()
        else:
            self.filterSelectedSystems()

    def keypressOnSearchEntry(self, *arg):

        if (arg[1].keyval == 65293):

            self.pushSearchButton(None)
        else:
            self['search_button'].set_sensitive(True)

    def pushClearButton(self, *args):
        self['search_entry'].set_text('')
        self.filterSelectedSystems()

    def searchScopeChanged(self, *args):
        searchString = self['search_entry'].get_text()
        if self.searchString != '':
            self['search_button'].set_sensitive(True)
        else:
            self['search_button'].set_sensitive(False)
Exemplo n.º 4
0
class PropertyWindow(OsogoPluginWindow):

    # ---------------------------------------------------------------
    # constructor
    #
    # return -> None
    # This method is throwable exception.
    # ---------------------------------------------------------------
    def __init__( self, aDirName, aData, aPluginManager, rootWidget=None ):
        
        # calls superclass's constructor
        OsogoPluginWindow.__init__( self, aDirName, aData,
                                   aPluginManager, rootWidget=rootWidget )
        self.theStatusBarWidget = None
        self.theQueue = None
        self.theAssociatedSession = None

    # end of __init__

    def setParent ( self, aParent ):
        self.theParent = aParent


    def openWindow( self ):
        #self.openWindow()
        OsogoPluginWindow.openWindow(self)
        
        # add handers
        self.addHandlers( { 'on_checkViewAll_toggled' : self.updateViewAllProperties } )

        # initializes buffer
        self.thePreFullID = None
        self.thePrePropertyMap = {}
       
        # initializes ListStore
        self.theListStore=gtk.ListStore(
                                        GETABLE_COL_TYPE,
                                        SETTABLE_COL_TYPE,
                                        PROPERTY_COL_TYPE,
                                        VALUE_COL_TYPE )
        self.lockCursor = False
        self.cursorHandler = self['theTreeView'].connect('cursor_changed', self.__cursorChanged)
        self['theTreeView'].connect('button_press_event', self.__popupMenu)
        
        self['theTreeView'].set_model(self.theListStore)
        
        renderer=gtk.CellRendererToggle()
        column=gtk.TreeViewColumn( "R", renderer, active = GETABLE_COL )
        column.set_visible( True )
        column.set_resizable( True )
        column.set_sort_column_id( GETABLE_COL )
        column.set_reorderable( True )
        self['theTreeView'].append_column(column)

        renderer=gtk.CellRendererToggle()
        column=gtk.TreeViewColumn( "W", renderer, active = SETTABLE_COL )
        column.set_visible( True )
        column.set_reorderable( True )
        column.set_sort_column_id( SETTABLE_COL )
        column.set_resizable( True )
        self['theTreeView'].append_column(column)

        renderer=gtk.CellRendererText()
        column=gtk.TreeViewColumn( "Property", renderer, text=PROPERTY_COL)
        column.set_visible( True )
        column.set_resizable( True )
        column.set_reorderable( True )
        column.set_sort_column_id( PROPERTY_COL )
        self['theTreeView'].append_column(column)

        renderer = gtk.CellRendererText()
        renderer.connect('edited', self.__valueEdited)
        column=gtk.TreeViewColumn( "Value", renderer, text=VALUE_COL,
                                  editable=SETTABLE_COL )
        column.set_visible( True )
        column.set_sizing( 1 ) # auto sizing
        self['theTreeView'].append_column(column)
        column.set_sort_column_id( VALUE_COL )
        column.set_reorderable( True )
        self.theValueColumn = column

        # creates popu menu
        self.thePopupMenu = PropertyWindowPopupMenu( self.thePluginManager, self )
        # initializes statusbar
        self.theStatusBarWidget = self['statusbar']
        self.theVarrefTabNumber  = -1
        self.theNoteBook = self['notebookProperty']
        self.theVarrefEditor = None

        self['entrySystemSubsystems'].set_property( 'xalign', 1 )
        self['entrySystemProcesses'].set_property( 'xalign', 1 )
        self['entrySystemVariables'].set_property( 'xalign', 1 )

        self['entryProcessVarRefTotal'].set_property( 'xalign', 1 )
        self['entryProcessVarRefPositive'].set_property( 'xalign', 1 )
        self['entryProcessVarRefZero'].set_property( 'xalign', 1 )
        self['entryProcessVarRefNegative'].set_property( 'xalign', 1 )

        self['entryVariableValue'].set_property( 'xalign', 1 )
        self['entryVariableVelocity'].set_property( 'xalign', 1 )
        self['entryVariableMolar'].set_property( 'xalign', 1 )
        self['entryVariableNumber'].set_property( 'xalign', 1 )

        if len( self.theRawFullPNList ) == 0:
            return
        # set default as not to view all properties
        self['checkViewAll'].set_active( False )

        self.setIconList(
            os.path.join( config.GLADEFILE_PATH, "ecell.png" ),
            os.path.join( config.GLADEFILE_PATH, "ecell32.png" ) )
        #self.__setFullPNList()
        self.update()

        if ( len( self.getFullPNList() ) > 1 ) and ( rootWidget !=
                                                    'EntityWindow' ):
            self.thePreFullID, _ = convertFullPNToFullID( self.getFullPN() )
            aClassName = self.__class__.__name__

        # registers myself to PluginManager
        self.thePluginManager.appendInstance( self ) 
        



    # =====================================================================
    def setStatusBar( self, aStatusBarWidget ):
        """sets a status bar to this window. 
        This method is used when this window is displayed on other window.
        aStatusBarWidget  --  a status bar (gtk.StatusBar)
        Returns None
        [Note]:The type of aStatusBarWidget is wrong, throws exception.
        """

        if type(aStatusBarWidget) != gtk.Statusbar:
            raise TypeError("%s must be gtk.StatusBar.")

        self.theStatusBarWidget = aStatusBarWidget


    # =====================================================================
    def clearStatusBar( self ):
        """clear messaeg of statusbar
        """

        self.theStatusBarWidget.push(1,'')


    # =====================================================================
    def showMessageOnStatusBar( self, aMessage ):
        """show messaegs on statusbar
        aMessage   --  a message to be displayed on statusbar (str)
        [Note]:message on statusbar should be 1 line. If the line aMessage is
               more than 2 lines, connects them as one line.
        """

        aMessage = ', '.join( aMessage.split( '\n' ) )

        self.theStatusBarWidget.push(1,aMessage)


    # ---------------------------------------------------------------
    # Overwrite Window.__getitem__
    # When this instance is on EntityListWindow,
    # self['statusbar'] returns the statusbar of EntityListWindow
    #
    # aKey  : a key to access widget
    # return -> a widget
    # ---------------------------------------------------------------
    def __getitem__( self, aKey ):

        # When key is not statusbar, return default widget
        if aKey != 'statusbar':
                return self.widgets.get_widget( aKey )

        # When is 'statusbar' and self.setStatusBar method has already called,
        # returns, the statusbar of EntityWindow.
        else:
            if self.theStatusBarWidget != None:
                return self.theStatusBarWidget
            else:
                return None

    # end of __getitem__

    # ---------------------------------------------------------------
    # Overwrite Window.setRawFullPNList
    # This method is used by EntityListWindow
    # change RawFullPNList
    #
    # aRawFullPNList  : a RawFullPNList
    # return -> None
    # ---------------------------------------------------------------
    def setRawFullPNList( self, aRawFullPNList ):
        # When aRawFullPNList is not changed, does nothing.
        if self.theRawFullPNList == aRawFullPNList:
            # do nothing
            pass

        # When aRawFullPNList is changed, updates its and call self.update().
        else:
            self['theTreeView'].disconnect( self.cursorHandler )
            OsogoPluginWindow.setRawFullPNList( self, aRawFullPNList )
            self.update()
            self.cursorHandler = self['theTreeView'].connect('cursor_changed', self.__cursorChanged)



       
    # end of setRawFullPNList

    # ---------------------------------------------------------------
    # update (overwrite the method of superclass)
    #
    # return -> None
    # This method is throwable exception.
    # ---------------------------------------------------------------
    def update( self ):
        aFullID = None
        aFullPN = None
        fullUpdate = False

        if self.theSession.theSession is not self.theAssociatedSession:
            self.theRawFullPNList = []
            if self.theSession.theSession is not None:
                if self.theParent != None:
                    if self.theParent.__class__.__name__ == "EntityListWindow":
                        self.theQueue = self.theParent.getQueue()
                    else:
                        self['navigation'].visible = True
                        self.theQueue = FullPNQueue( ( self['backbutton'], self['forwardbutton'] ), self.theRawFullPNList )
                else:
                    self['navigation'].visible = True
                    self.theQueue = FullPNQueue( ( self['backbutton'], self['forwardbutton'] ), self.theRawFullPNList )
                self.theAssociatedSession = self.theSession.theSession
                self.theQueue.registerCallback( self.setRawFullPNList )
            else:
                self.theQueue = None
        else:
            aFullPN = self.getFullPN()
            if aFullPN is not None:
                aFullID, _ = convertFullPNToFullID( self.getFullPN() )
        if self.thePreFullID != aFullID:
            fullUpdate = True

        # ----------------------------------------------------
        # updates widgets
        # ----------------------------------------------------
        # creates EntityStub
        if aFullID is not None:
            anEntityStub = self.theSession.createEntityStub( createFullIDString( aFullID ) )
        else:
            anEntityStub = None
            fullUpdate = True

        if not fullUpdate:
            # gets propery values for thePreProperyMap in case value is not tuple
            for aPropertyName in self.thePrePropertyMap.keys():
                aProperty = self.thePrePropertyMap[aPropertyName]
                if type( aProperty[0] ) not in ( tuple, list ):
                    aProperty[0] = anEntityStub.getProperty( aPropertyName )
            if self.theVarrefEditor != None:
                self.theVarrefEditor.update()
        else:
            self.theSelectedFullPN = ''

            # -----------------------------------------------
            # updates each widget
            # Type, ID, Path, Classname
            # -----------------------------------------------
            if anEntityStub is not None:
                anEntityType = ENTITYTYPE_STRING_LIST[aFullPN[TYPE]]
                anID = aFullPN[ID]
                aSystemPath = str( aFullPN[SYSTEMPATH] )

                self['entryClassName'].set_text( anEntityStub.getClassname() )
                self['entryFullID'].set_text( ':'.join( [ anEntityType,
                                                          aSystemPath,
                                                          anID ] ) )
                # saves properties to buffer
                self.thePrePropertyMap = {}
                for aProperty in anEntityStub.getPropertyList():
                    self.thePrePropertyMap[str(aProperty)] = [None, None]
                    self.thePrePropertyMap[str(aProperty)][0] =\
                            anEntityStub.getProperty(aProperty)
                    self.thePrePropertyMap[str(aProperty)][1] =\
                            anEntityStub.getPropertyAttributes(aProperty)

                self['entryName'].set_text( str(
                                     self.thePrePropertyMap[ 'Name' ][0] )  )

                # save current full id to previous full id.
                self.thePreFullID = aFullID
                self.setSelectedFullPN( aFullPN )
            else:
                self['entryClassName'].set_text( "" )
                self['entryFullID'].set_text( "" )
                self['entryName'].set_text( "" )

            # update Summary tab for unique fields of each entity type
            # update the respective Entity's PropertyList
            if aFullPN is not None:
                self.__setDiscardList()
                if aFullPN[TYPE] == PROCESS:
                    self.__createVariableReferenceListTab()
                    self.__updateProcess()
                elif aFullPN[TYPE] == VARIABLE:
                    self.__deleteVariableReferenceListTab()
                    self.__updateVariable()
                elif aFullPN[TYPE] == SYSTEM:
                    self.__deleteVariableReferenceListTab()
                    self.__updateSystem()

        # updates status bar
        if self['statusbar'] != None:
            self['statusbar'].push(1,'')

                
    def __updatePropertyList( self ):
        self.theList = []
        aPropertyList = self.thePrePropertyMap.keys()

        # do nothing for following properties
        try:
            aPropertyList.remove( 'FullID' )
            aPropertyList.remove( 'Name' )
        except:
            pass

        for aPropertyName in aPropertyList: # for (1)
            if aPropertyName not in self.theDiscardList:
                aProperty = self.thePrePropertyMap[aPropertyName]
                anAttribute = aProperty[1]

                # When the getable attribute is false, value is ''
                if anAttribute[GETABLE] == False:
                    aValue = ''
                else:
                    aValue = str( aProperty[0] )


                self.theList.append( [
                                      anAttribute[GETABLE],
                                      anAttribute[SETTABLE],
                                      aPropertyName,
                                      aValue ] )
        lockCursor = self.lockCursor
        self.lockCursor = True
        self['theTreeView'].get_selection().unselect_all()

#        self.theListStore.clear()
        anIter = self.theListStore.get_iter_first()
        #first rewrite properties

        for aValue in self.theList:
            if anIter == None:
                anIter=self.theListStore.append( )
            cntr = 0
            for valueitem in aValue:
                self.theListStore.set_value(anIter,cntr,valueitem)
                cntr += 1
            anIter = self.theListStore.iter_next( anIter )
        while anIter != None:
            nextIter = self.theListStore.iter_next(anIter)
            self.theListStore.remove( anIter )
            anIter = nextIter

        if len( self.theRawFullPNList ) > 0:
            self.setSelectedFullPN( self.theRawFullPNList[0] )

        self.lockCursor = lockCursor


    def __updateProcess( self ):
        self.__updatePropertyList() 
        aVariableReferenceList = self.thePrePropertyMap[
                                       'VariableReferenceList'][0]
        aPositiveCoeff = 0
        aZeroCoeff = 0
        aNegativeCoeff = 0
        for aVariableReference in aVariableReferenceList:
            if aVariableReference[2] == 0:
                aZeroCoeff = aZeroCoeff + 1
            elif aVariableReference[2] > 0:
                aPositiveCoeff = aPositiveCoeff + 1
            elif aVariableReference[2] < 0:
                aNegativeCoeff = aNegativeCoeff + 1

        aStepperID = str( self.thePrePropertyMap[ 'StepperID' ][0] )
        anActivity = str( self.thePrePropertyMap[ 'Activity' ][0] )
        isContinuous = bool( self.thePrePropertyMap[ 'IsContinuous'][0] )
        aPriority = str( self.thePrePropertyMap[ 'Priority'][0] )

        self['entryProcessVarRefTotal'].set_text(
                                         str( len( aVariableReferenceList ) ) )
        self['entryProcessVarRefPositive'].set_text( str( aPositiveCoeff ) )
        self['entryProcessVarRefZero'].set_text( str( aZeroCoeff ) )
        self['entryProcessVarRefNegative'].set_text( str( aNegativeCoeff ) )
        self['entryProcessStepper'].set_text( aStepperID )
        self['entryProcessActivity'].set_text( anActivity )
        self['entryProcessIsContinuous'].set_text( str( isContinuous ) )
        self['entryProcessPriority'].set_text( aPriority )

        self['systemFrame'].hide()
        self['processFrame'].show()
        self['variableFrame'].hide()


        

    def __updateVariable( self ):
        self.__updatePropertyList()
        aMolarConc = str( self.thePrePropertyMap[ 'MolarConc' ][0] )
        aValue = str( self.thePrePropertyMap[ 'Value' ][0] )
        aNumberConc = str( self.thePrePropertyMap[ 'NumberConc' ][0] )
        aVelocity = str( self.thePrePropertyMap[ 'Velocity' ][0] )
        if self.thePrePropertyMap[ 'Fixed'][0]  == 1:
            aFixed = '<b>Fixed</b>'
        else:
            aFixed = ''
        
        self['entryVariableValue'].set_text( aValue )
        self['entryVariableMolar'].set_text( aMolarConc )
        self['entryVariableNumber'].set_text( aNumberConc )
        self['labelVariableQuantities'].set_markup( 'Quantities / Concentration %s' % aFixed )
        self['entryVariableVelocity'].set_text( aVelocity )

        self['systemFrame'].hide()
        self['processFrame'].hide()
        self['variableFrame'].show()

    def __updateSystem( self ):
        self.__updatePropertyList()
        aFullID, _ = convertFullPNToFullID( self.getFullPN() )
        aSystemPath = createSystemPathFromFullID( aFullID )
        aProcessList = self.theSession.getEntityList( 'Process', aSystemPath )
        aVariableList = self.theSession.getEntityList( 'Variable', aSystemPath )
        aSystemList = self.theSession.getEntityList( 'System', aSystemPath ) 
        aStepperID = str( self.thePrePropertyMap[ 'StepperID' ][0] )
        aSize = str( self.thePrePropertyMap[ 'Size' ][0] )

        self['entrySystemSubsystems'].set_text( str( len( aSystemList ) ) )
        self['entrySystemProcesses'].set_text( str( len( aProcessList ) ) )
        self['entrySystemVariables'].set_text( str( len( aVariableList ) ) )
        self['entrySystemStepper'].set_text( aStepperID )
        self['entrySystemSize'].set_text( aSize )
       
        self['systemFrame'].show()
        self['processFrame'].hide()
        self['variableFrame'].hide()

    def updateViewAllProperties( self, *anObject ):
        self.__setDiscardList()
        self.__updatePropertyList()


    def __setDiscardList( self ):
        aFullPN = self.getFullPN()
        if aFullPN is None:
            return
        isViewAll = self['checkViewAll'].get_active()
        if isViewAll:
            self.theDiscardList = []
        else:
            if aFullPN[TYPE] == PROCESS:
                self.theDiscardList = PROCESS_DISCARD_LIST 
            elif aFullPN[TYPE] == VARIABLE:
                self.theDiscardList = VARIABLE_DISCARD_LIST 
            elif aFullPN[TYPE] == SYSTEM:
                self.theDiscardList = SYSTEM_DISCARD_LIST 
        

    def __valueEdited( self, *args ):
        """
        args[0]: cellrenderer
        args[1]: path
        args[2]: newstring
        """
        
        aNewValue = args[2]
        aPath = args[1]
        anIter = self.theListStore.get_iter_from_string( aPath )
        aSelectedProperty = self.theListStore.get_value( anIter, PROPERTY_COL )
        aFullID, _ = convertFullPNToFullID( self.getFullPN() )
        self.theSelectedFullPN = convertFullIDToFullPN( aFullID, aSelectedProperty )
        
        # disable VariableReferenceList editing because of a bug when
        # saving changes
        if aSelectedProperty != 'VariableReferenceList':
            self.__updateValue( aNewValue, anIter, VALUE_COL )

    

    # ---------------------------------------------------------------
    # updateValue
    #   - sets inputted value to the simulator
    #
    # return -> None
    # This method is throwable exception.
    # ---------------------------------------------------------------
    def __updateValue( self, aValue, anIter, aColumn ):


        # ------------------------------------
        # gets getable status
        # ------------------------------------
        aGetable = self.theListStore.get_value( anIter, GETABLE_COL )

        # ------------------------------------
        # checks the type of inputted value 
        # ------------------------------------
        if aGetable:
            aPreValue = self.theListStore.get_value( anIter, aColumn )

            # ------------------------------------
            # when type is integer
            # ------------------------------------
            if type(aPreValue) == type(0):
                try:
                    aValue = int(aValue)
                except:
                    import sys
                    import traceback
                    anErrorMessage = '\n'.join(
                        traceback.format_exception( 
                            sys.exc_type,sys.exc_value,sys.exc_traceback ) )
                    self.theSession.message("-----An error happens.-----")
                    self.theSession.message(anErrorMessage)
                    self.theSession.message("---------------------------")

                    # creates and display error message dialog.
                    anErrorMessage = "Input an integer!"
                    anErrorTitle = "The type error!"
                    if self['statusbar'] != None:
                        self['statusbar'].push(1,anErrorMessage)
                    anErrorWindow = ConfirmWindow(OK_MODE,anErrorMessage,anErrorTitle)
                    return None

            # ------------------------------------
            # when type is float
            # ------------------------------------
            elif type(aPreValue) == type(0.0):
                try:
                    aValue = float(aValue)
                except:
                    import sys
                    import traceback
                    anErrorMessage = '\n'.join( traceback.format_exception(  sys.exc_type,sys.exc_value,sys.exc_traceback ) )
                    self.theSession.message("-----An error happened.-----")
                    self.theSession.message(anErrorMessage)
                    self.theSession.message("---------------------------")

                    # creates and display error message dialog.
                    anErrorMessage = "Input a float!"
                    anErrorTitle = "The type error!"
                    if self['statusbar'] != None:
                        self['statusbar'].push(1,anErrorMessage)
                    anErrorWindow = ConfirmWindow(OK_MODE,anErrorMessage,anErrorTitle)
                    return None

            # ------------------------------------
            # when type is tuple
            # ------------------------------------
            elif type(aPreValue) == type(()):
                try:
                    aValue = convertStringToTuple( aValue )

                except:
                    import sys
                    import traceback
                    anErrorMessage = '\n'.join( traceback.format_exception( sys.exc_type,sys.exc_value,sys.exc_traceback ) )
                    self.theSession.message("-----An error happens.-----")
                    self.theSession.message(anErrorMessage)
                    self.theSession.message("---------------------------")

                    # creates and display error message dialog.
                    anErrorMessage = "Input a tuple!"
                    anErrorTitle = "The type error!"
                    if self['statusbar'] != None:
                        self['statusbar'].push(1,anErrorMessage)
                    anErrorWindow = ConfirmWindow(OK_MODE,anErrorMessage,anErrorTitle)
                    return None


        aFullPNString = createFullPNString(self.theSelectedFullPN)

        try:
            self.theSession.setEntityProperty( self.theSelectedFullPN, aValue ) 
            lockCursor = self.lockCursor
            self.lockCursor = True
            self['theTreeView'].get_selection().select_iter( anIter )
            self.lockCursor = False
        except:


            import sys
            import traceback
            anErrorMessage = '\n'.join( traceback.format_exception( sys.exc_type,sys.exc_value,sys.exc_traceback ) )
            self.theSession.message("-----An error happens.-----")
            self.theSession.message(anErrorMessage)
            self.theSession.message("---------------------------")

            # creates and display error message dialog.
            anErrorMessage = "An error happened! See MessageWindow."
            anErrorTitle = "An error happened!"
            if self['statusbar'] != None:
                self['statusbar'].push(1,anErrorMessage)
            anErrorWindow = ConfirmWindow(OK_MODE,anErrorMessage,anErrorTitle)
        else:

            self.__updatePropertyList()
            #self.thePluginManager.updateAllPluginWindow() 

    # end of updateValue


    def getSelectedFullPN( self ):

        anIter = self['theTreeView'].get_selection().get_selected()[1]
        if anIter == None:
			self.theSelectedFullPN = ''
        else:
            aSelectedProperty = self.theListStore.get_value( anIter,
                                                            PROPERTY_COL )
            aFullID, _ = convertFullPNToFullID( self.getFullPN() )
            self.theSelectedFullPN = convertFullIDToFullPN( aFullID, aSelectedProperty )
        return self.theSelectedFullPN

    def setSelectedFullPN( self, aFullPN ):

        aPropertyName = aFullPN[3]
        anIter = self.theListStore.get_iter_first()
        while anIter != None:
            if self.theListStore.get_value( anIter, PROPERTY_COL ) == aPropertyName:
                lockCursor = self.lockCursor
                self.lockCursor = True
                self['theTreeView'].get_selection().select_iter( anIter )
                self.lockCursor = lockCursor
                break
            anIter = self.theListStore.iter_next( anIter ) 
                
    def __cursorChanged( self, *args ):

        if self.lockCursor:
            return

        aFullPNList = [ self.getSelectedFullPN() ]
        self.lockCursor = True
        self.theQueue.pushFullPNList( aFullPNList )
        self.lockCursor = False

    # ---------------------------------------------------------------
    # popupMenu
    #   - show popup menu
    #
    # aWidget         : widget
    # anEvent          : an event
    # return -> None
    # This method is throwable exception.
    # ---------------------------------------------------------------
    def __popupMenu( self, aWidget, anEvent ):

        if anEvent.button == 3:  # 3 means right

            if self['theTreeView'].get_selection().get_selected()[1]==None :
                return None

            self.thePopupMenu.popup( None, None, None, 1, 0 )

    # end of poppuMenu

    def createNewPluginWindow( self, anObject ):

        # gets PluginWindowName from selected MenuItem
        aPluginWindowName = anObject.get_name()

        # creates PluginWindow
        self.thePluginManager.createInstance( aPluginWindowName, self.theRawFullPNList )

    # end of createNewPluginWindow

    def __createVariableReferenceListTab( self ):
        aFullID, _ = convertFullPNToFullID( self.getFullPN() )
        if self.theVarrefTabNumber  != -1:
            if self.theVarrefEditor.getProcessFullID() == aFullID:
                return
            else:
                self.theVarrefEditor.setDisplayedFullID( aFullID )
        else:
            aFrame = gtk.Frame()
            aFrame.show()
            aLabel = gtk.Label("Variable References")
            aLabel.show()
            self.theNoteBook.append_page(  aFrame, aLabel )
            self.theVarrefTabNumber = 2
            self.theVarrefEditor = VariableReferenceEditor( self, aFrame )


    def __deleteVariableReferenceListTab( self ):
        if self.theVarrefTabNumber  == -1:
            return
        curPage = self.theNoteBook.get_current_page()
        if  curPage == self.theVarrefTabNumber:
            curPage = 0

        self.theNoteBook.remove_page( self.theVarrefTabNumber )
        self.theNoteBook.set_current_page( curPage )
        self.theVarrefTabNumber  = -1
        self.theVarrefEditor = None
Exemplo n.º 5
0
    def update( self ):
        aFullID = None
        aFullPN = None
        fullUpdate = False

        if self.theSession.theSession is not self.theAssociatedSession:
            self.theRawFullPNList = []
            if self.theSession.theSession is not None:
                if self.theParent != None:
                    if self.theParent.__class__.__name__ == "EntityListWindow":
                        self.theQueue = self.theParent.getQueue()
                    else:
                        self['navigation'].visible = True
                        self.theQueue = FullPNQueue( ( self['backbutton'], self['forwardbutton'] ), self.theRawFullPNList )
                else:
                    self['navigation'].visible = True
                    self.theQueue = FullPNQueue( ( self['backbutton'], self['forwardbutton'] ), self.theRawFullPNList )
                self.theAssociatedSession = self.theSession.theSession
                self.theQueue.registerCallback( self.setRawFullPNList )
            else:
                self.theQueue = None
        else:
            aFullPN = self.getFullPN()
            if aFullPN is not None:
                aFullID, _ = convertFullPNToFullID( self.getFullPN() )
        if self.thePreFullID != aFullID:
            fullUpdate = True

        # ----------------------------------------------------
        # updates widgets
        # ----------------------------------------------------
        # creates EntityStub
        if aFullID is not None:
            anEntityStub = self.theSession.createEntityStub( createFullIDString( aFullID ) )
        else:
            anEntityStub = None
            fullUpdate = True

        if not fullUpdate:
            # gets propery values for thePreProperyMap in case value is not tuple
            for aPropertyName in self.thePrePropertyMap.keys():
                aProperty = self.thePrePropertyMap[aPropertyName]
                if type( aProperty[0] ) not in ( tuple, list ):
                    aProperty[0] = anEntityStub.getProperty( aPropertyName )
            if self.theVarrefEditor != None:
                self.theVarrefEditor.update()
        else:
            self.theSelectedFullPN = ''

            # -----------------------------------------------
            # updates each widget
            # Type, ID, Path, Classname
            # -----------------------------------------------
            if anEntityStub is not None:
                anEntityType = ENTITYTYPE_STRING_LIST[aFullPN[TYPE]]
                anID = aFullPN[ID]
                aSystemPath = str( aFullPN[SYSTEMPATH] )

                self['entryClassName'].set_text( anEntityStub.getClassname() )
                self['entryFullID'].set_text( ':'.join( [ anEntityType,
                                                          aSystemPath,
                                                          anID ] ) )
                # saves properties to buffer
                self.thePrePropertyMap = {}
                for aProperty in anEntityStub.getPropertyList():
                    self.thePrePropertyMap[str(aProperty)] = [None, None]
                    self.thePrePropertyMap[str(aProperty)][0] =\
                            anEntityStub.getProperty(aProperty)
                    self.thePrePropertyMap[str(aProperty)][1] =\
                            anEntityStub.getPropertyAttributes(aProperty)

                self['entryName'].set_text( str(
                                     self.thePrePropertyMap[ 'Name' ][0] )  )

                # save current full id to previous full id.
                self.thePreFullID = aFullID
                self.setSelectedFullPN( aFullPN )
            else:
                self['entryClassName'].set_text( "" )
                self['entryFullID'].set_text( "" )
                self['entryName'].set_text( "" )

            # update Summary tab for unique fields of each entity type
            # update the respective Entity's PropertyList
            if aFullPN is not None:
                self.__setDiscardList()
                if aFullPN[TYPE] == PROCESS:
                    self.__createVariableReferenceListTab()
                    self.__updateProcess()
                elif aFullPN[TYPE] == VARIABLE:
                    self.__deleteVariableReferenceListTab()
                    self.__updateVariable()
                elif aFullPN[TYPE] == SYSTEM:
                    self.__deleteVariableReferenceListTab()
                    self.__updateSystem()

        # updates status bar
        if self['statusbar'] != None:
            self['statusbar'].push(1,'')
Exemplo n.º 6
0
class PropertyWindow(OsogoPluginWindow):

    # ---------------------------------------------------------------
    # constructor
    #
    # return -> None
    # This method is throwable exception.
    # ---------------------------------------------------------------
    def __init__(self, aDirName, aData, aPluginManager, rootWidget=None):

        # calls superclass's constructor
        OsogoPluginWindow.__init__(self,
                                   aDirName,
                                   aData,
                                   aPluginManager,
                                   rootWidget=rootWidget)
        self.theStatusBarWidget = None
        self.theQueue = None
        self.theAssociatedSession = None

    # end of __init__

    def setParent(self, aParent):
        self.theParent = aParent

    def openWindow(self):
        #self.openWindow()
        OsogoPluginWindow.openWindow(self)

        # add handers
        self.addHandlers(
            {'on_checkViewAll_toggled': self.updateViewAllProperties})

        # initializes buffer
        self.thePreFullID = None
        self.thePrePropertyMap = {}

        # initializes ListStore
        self.theListStore = gtk.ListStore(GETABLE_COL_TYPE, SETTABLE_COL_TYPE,
                                          PROPERTY_COL_TYPE, VALUE_COL_TYPE)
        self.lockCursor = False
        self.cursorHandler = self['theTreeView'].connect(
            'cursor_changed', self.__cursorChanged)
        self['theTreeView'].connect('button_press_event', self.__popupMenu)

        self['theTreeView'].set_model(self.theListStore)

        renderer = gtk.CellRendererToggle()
        column = gtk.TreeViewColumn("R", renderer, active=GETABLE_COL)
        column.set_visible(True)
        column.set_resizable(True)
        column.set_sort_column_id(GETABLE_COL)
        column.set_reorderable(True)
        self['theTreeView'].append_column(column)

        renderer = gtk.CellRendererToggle()
        column = gtk.TreeViewColumn("W", renderer, active=SETTABLE_COL)
        column.set_visible(True)
        column.set_reorderable(True)
        column.set_sort_column_id(SETTABLE_COL)
        column.set_resizable(True)
        self['theTreeView'].append_column(column)

        renderer = gtk.CellRendererText()
        column = gtk.TreeViewColumn("Property", renderer, text=PROPERTY_COL)
        column.set_visible(True)
        column.set_resizable(True)
        column.set_reorderable(True)
        column.set_sort_column_id(PROPERTY_COL)
        self['theTreeView'].append_column(column)

        renderer = gtk.CellRendererText()
        renderer.connect('edited', self.__valueEdited)
        column = gtk.TreeViewColumn("Value",
                                    renderer,
                                    text=VALUE_COL,
                                    editable=SETTABLE_COL)
        column.set_visible(True)
        column.set_sizing(1)  # auto sizing
        self['theTreeView'].append_column(column)
        column.set_sort_column_id(VALUE_COL)
        column.set_reorderable(True)
        self.theValueColumn = column

        # creates popu menu
        self.thePopupMenu = PropertyWindowPopupMenu(self.thePluginManager,
                                                    self)
        # initializes statusbar
        self.theStatusBarWidget = self['statusbar']
        self.theVarrefTabNumber = -1
        self.theNoteBook = self['notebookProperty']
        self.theVarrefEditor = None

        self['entrySystemSubsystems'].set_property('xalign', 1)
        self['entrySystemProcesses'].set_property('xalign', 1)
        self['entrySystemVariables'].set_property('xalign', 1)

        self['entryProcessVarRefTotal'].set_property('xalign', 1)
        self['entryProcessVarRefPositive'].set_property('xalign', 1)
        self['entryProcessVarRefZero'].set_property('xalign', 1)
        self['entryProcessVarRefNegative'].set_property('xalign', 1)

        self['entryVariableValue'].set_property('xalign', 1)
        self['entryVariableVelocity'].set_property('xalign', 1)
        self['entryVariableMolar'].set_property('xalign', 1)
        self['entryVariableNumber'].set_property('xalign', 1)

        if len(self.theRawFullPNList) == 0:
            return
        # set default as not to view all properties
        self['checkViewAll'].set_active(False)

        self.setIconList(os.path.join(config.GLADEFILE_PATH, "ecell.png"),
                         os.path.join(config.GLADEFILE_PATH, "ecell32.png"))
        #self.__setFullPNList()
        self.update()

        if (len(self.getFullPNList()) > 1) and (rootWidget != 'EntityWindow'):
            self.thePreFullID, _ = convertFullPNToFullID(self.getFullPN())
            aClassName = self.__class__.__name__

        # registers myself to PluginManager
        self.thePluginManager.appendInstance(self)

    # =====================================================================
    def setStatusBar(self, aStatusBarWidget):
        """sets a status bar to this window. 
        This method is used when this window is displayed on other window.
        aStatusBarWidget  --  a status bar (gtk.StatusBar)
        Returns None
        [Note]:The type of aStatusBarWidget is wrong, throws exception.
        """

        if type(aStatusBarWidget) != gtk.Statusbar:
            raise TypeError("%s must be gtk.StatusBar.")

        self.theStatusBarWidget = aStatusBarWidget

    # =====================================================================
    def clearStatusBar(self):
        """clear messaeg of statusbar
        """

        self.theStatusBarWidget.push(1, '')

    # =====================================================================
    def showMessageOnStatusBar(self, aMessage):
        """show messaegs on statusbar
        aMessage   --  a message to be displayed on statusbar (str)
        [Note]:message on statusbar should be 1 line. If the line aMessage is
               more than 2 lines, connects them as one line.
        """

        aMessage = ', '.join(aMessage.split('\n'))

        self.theStatusBarWidget.push(1, aMessage)

    # ---------------------------------------------------------------
    # Overwrite Window.__getitem__
    # When this instance is on EntityListWindow,
    # self['statusbar'] returns the statusbar of EntityListWindow
    #
    # aKey  : a key to access widget
    # return -> a widget
    # ---------------------------------------------------------------
    def __getitem__(self, aKey):

        # When key is not statusbar, return default widget
        if aKey != 'statusbar':
            return self.widgets.get_widget(aKey)

        # When is 'statusbar' and self.setStatusBar method has already called,
        # returns, the statusbar of EntityWindow.
        else:
            if self.theStatusBarWidget != None:
                return self.theStatusBarWidget
            else:
                return None

    # end of __getitem__

    # ---------------------------------------------------------------
    # Overwrite Window.setRawFullPNList
    # This method is used by EntityListWindow
    # change RawFullPNList
    #
    # aRawFullPNList  : a RawFullPNList
    # return -> None
    # ---------------------------------------------------------------
    def setRawFullPNList(self, aRawFullPNList):
        # When aRawFullPNList is not changed, does nothing.
        if self.theRawFullPNList == aRawFullPNList:
            # do nothing
            pass

        # When aRawFullPNList is changed, updates its and call self.update().
        else:
            self['theTreeView'].disconnect(self.cursorHandler)
            OsogoPluginWindow.setRawFullPNList(self, aRawFullPNList)
            self.update()
            self.cursorHandler = self['theTreeView'].connect(
                'cursor_changed', self.__cursorChanged)

    # end of setRawFullPNList

    # ---------------------------------------------------------------
    # update (overwrite the method of superclass)
    #
    # return -> None
    # This method is throwable exception.
    # ---------------------------------------------------------------
    def update(self):
        aFullID = None
        aFullPN = None
        fullUpdate = False

        if self.theSession.theSession is not self.theAssociatedSession:
            self.theRawFullPNList = []
            if self.theSession.theSession is not None:
                if self.theParent != None:
                    if self.theParent.__class__.__name__ == "EntityListWindow":
                        self.theQueue = self.theParent.getQueue()
                    else:
                        self['navigation'].visible = True
                        self.theQueue = FullPNQueue(
                            (self['backbutton'], self['forwardbutton']),
                            self.theRawFullPNList)
                else:
                    self['navigation'].visible = True
                    self.theQueue = FullPNQueue(
                        (self['backbutton'], self['forwardbutton']),
                        self.theRawFullPNList)
                self.theAssociatedSession = self.theSession.theSession
                self.theQueue.registerCallback(self.setRawFullPNList)
            else:
                self.theQueue = None
        else:
            aFullPN = self.getFullPN()
            if aFullPN is not None:
                aFullID, _ = convertFullPNToFullID(self.getFullPN())
        if self.thePreFullID != aFullID:
            fullUpdate = True

        # ----------------------------------------------------
        # updates widgets
        # ----------------------------------------------------
        # creates EntityStub
        if aFullID is not None:
            anEntityStub = self.theSession.createEntityStub(
                createFullIDString(aFullID))
        else:
            anEntityStub = None
            fullUpdate = True

        if not fullUpdate:
            # gets propery values for thePreProperyMap in case value is not tuple
            for aPropertyName in self.thePrePropertyMap.keys():
                aProperty = self.thePrePropertyMap[aPropertyName]
                if type(aProperty[0]) not in (tuple, list):
                    aProperty[0] = anEntityStub.getProperty(aPropertyName)
            if self.theVarrefEditor != None:
                self.theVarrefEditor.update()
        else:
            self.theSelectedFullPN = ''

            # -----------------------------------------------
            # updates each widget
            # Type, ID, Path, Classname
            # -----------------------------------------------
            if anEntityStub is not None:
                anEntityType = ENTITYTYPE_STRING_LIST[aFullPN[TYPE]]
                anID = aFullPN[ID]
                aSystemPath = str(aFullPN[SYSTEMPATH])

                self['entryClassName'].set_text(anEntityStub.getClassname())
                self['entryFullID'].set_text(':'.join(
                    [anEntityType, aSystemPath, anID]))
                # saves properties to buffer
                self.thePrePropertyMap = {}
                for aProperty in anEntityStub.getPropertyList():
                    self.thePrePropertyMap[str(aProperty)] = [None, None]
                    self.thePrePropertyMap[str(aProperty)][0] =\
                            anEntityStub.getProperty(aProperty)
                    self.thePrePropertyMap[str(aProperty)][1] =\
                            anEntityStub.getPropertyAttributes(aProperty)

                self['entryName'].set_text(
                    str(self.thePrePropertyMap['Name'][0]))

                # save current full id to previous full id.
                self.thePreFullID = aFullID
                self.setSelectedFullPN(aFullPN)
            else:
                self['entryClassName'].set_text("")
                self['entryClassName'].set_max_length(0)
                self['entryFullID'].set_text("")
                self['entryName'].set_text("")

            # update Summary tab for unique fields of each entity type
            # update the respective Entity's PropertyList
            if aFullPN is not None:
                self.__setDiscardList()
                if aFullPN[TYPE] == PROCESS:
                    self.__createVariableReferenceListTab()
                    self.__updateProcess()
                elif aFullPN[TYPE] == VARIABLE:
                    self.__deleteVariableReferenceListTab()
                    self.__updateVariable()
                elif aFullPN[TYPE] == SYSTEM:
                    self.__deleteVariableReferenceListTab()
                    self.__updateSystem()

        # updates status bar
        if self['statusbar'] != None:
            self['statusbar'].push(1, '')

    def __updatePropertyList(self):
        self.theList = []
        aPropertyList = self.thePrePropertyMap.keys()

        # do nothing for following properties
        try:
            aPropertyList.remove('FullID')
            aPropertyList.remove('Name')
        except:
            pass

        for aPropertyName in aPropertyList:  # for (1)
            if aPropertyName not in self.theDiscardList:
                aProperty = self.thePrePropertyMap[aPropertyName]
                anAttribute = aProperty[1]

                # When the getable attribute is false, value is ''
                if anAttribute[GETABLE] == False:
                    aValue = ''
                else:
                    aValue = str(aProperty[0])

                self.theList.append([
                    anAttribute[GETABLE], anAttribute[SETTABLE], aPropertyName,
                    aValue
                ])
        lockCursor = self.lockCursor
        self.lockCursor = True
        self['theTreeView'].get_selection().unselect_all()

        #        self.theListStore.clear()
        anIter = self.theListStore.get_iter_first()
        #first rewrite properties

        for aValue in self.theList:
            if anIter == None:
                anIter = self.theListStore.append()
            cntr = 0
            for valueitem in aValue:
                self.theListStore.set_value(anIter, cntr, valueitem)
                cntr += 1
            anIter = self.theListStore.iter_next(anIter)
        while anIter != None:
            nextIter = self.theListStore.iter_next(anIter)
            self.theListStore.remove(anIter)
            anIter = nextIter

        if len(self.theRawFullPNList) > 0:
            self.setSelectedFullPN(self.theRawFullPNList[0])

        self.lockCursor = lockCursor

    def __updateProcess(self):
        self.__updatePropertyList()
        aVariableReferenceList = self.thePrePropertyMap[
            'VariableReferenceList'][0]
        aPositiveCoeff = 0
        aZeroCoeff = 0
        aNegativeCoeff = 0
        for aVariableReference in aVariableReferenceList:
            if aVariableReference[2] == 0:
                aZeroCoeff = aZeroCoeff + 1
            elif aVariableReference[2] > 0:
                aPositiveCoeff = aPositiveCoeff + 1
            elif aVariableReference[2] < 0:
                aNegativeCoeff = aNegativeCoeff + 1

        aStepperID = str(self.thePrePropertyMap['StepperID'][0])
        anActivity = str(self.thePrePropertyMap['Activity'][0])
        isContinuous = bool(self.thePrePropertyMap['IsContinuous'][0])
        aPriority = str(self.thePrePropertyMap['Priority'][0])

        self['entryProcessVarRefTotal'].set_text(
            str(len(aVariableReferenceList)))
        self['entryProcessVarRefPositive'].set_text(str(aPositiveCoeff))
        self['entryProcessVarRefZero'].set_text(str(aZeroCoeff))
        self['entryProcessVarRefNegative'].set_text(str(aNegativeCoeff))
        self['entryProcessStepper'].set_text(aStepperID)
        self['entryProcessActivity'].set_text(anActivity)
        self['entryProcessIsContinuous'].set_text(str(isContinuous))
        self['entryProcessPriority'].set_text(aPriority)

        self['systemFrame'].hide()
        self['processFrame'].show()
        self['variableFrame'].hide()

    def __updateVariable(self):
        self.__updatePropertyList()
        aMolarConc = str(self.thePrePropertyMap['MolarConc'][0])
        aValue = str(self.thePrePropertyMap['Value'][0])
        aNumberConc = str(self.thePrePropertyMap['NumberConc'][0])
        aVelocity = str(self.thePrePropertyMap['Velocity'][0])
        if self.thePrePropertyMap['Fixed'][0] == 1:
            aFixed = '<b>Fixed</b>'
        else:
            aFixed = ''

        self['entryVariableValue'].set_text(aValue)
        self['entryVariableMolar'].set_text(aMolarConc)
        self['entryVariableNumber'].set_text(aNumberConc)
        self['labelVariableQuantities'].set_markup(
            'Quantities / Concentration %s' % aFixed)
        self['entryVariableVelocity'].set_text(aVelocity)

        self['systemFrame'].hide()
        self['processFrame'].hide()
        self['variableFrame'].show()

    def __updateSystem(self):
        self.__updatePropertyList()
        aFullID, _ = convertFullPNToFullID(self.getFullPN())
        aSystemPath = createSystemPathFromFullID(aFullID)
        aProcessList = self.theSession.getEntityList('Process', aSystemPath)
        aVariableList = self.theSession.getEntityList('Variable', aSystemPath)
        aSystemList = self.theSession.getEntityList('System', aSystemPath)
        aStepperID = str(self.thePrePropertyMap['StepperID'][0])
        aSize = str(self.thePrePropertyMap['Size'][0])

        self['entrySystemSubsystems'].set_text(str(len(aSystemList)))
        self['entrySystemProcesses'].set_text(str(len(aProcessList)))
        self['entrySystemVariables'].set_text(str(len(aVariableList)))
        self['entrySystemStepper'].set_text(aStepperID)
        self['entrySystemSize'].set_text(aSize)

        self['systemFrame'].show()
        self['processFrame'].hide()
        self['variableFrame'].hide()

    def updateViewAllProperties(self, *anObject):
        self.__setDiscardList()
        self.__updatePropertyList()

    def __setDiscardList(self):
        aFullPN = self.getFullPN()
        if aFullPN is None:
            return
        isViewAll = self['checkViewAll'].get_active()
        if isViewAll:
            self.theDiscardList = []
        else:
            if aFullPN[TYPE] == PROCESS:
                self.theDiscardList = PROCESS_DISCARD_LIST
            elif aFullPN[TYPE] == VARIABLE:
                self.theDiscardList = VARIABLE_DISCARD_LIST
            elif aFullPN[TYPE] == SYSTEM:
                self.theDiscardList = SYSTEM_DISCARD_LIST

    def __valueEdited(self, *args):
        """
        args[0]: cellrenderer
        args[1]: path
        args[2]: newstring
        """

        aNewValue = args[2]
        aPath = args[1]
        anIter = self.theListStore.get_iter_from_string(aPath)
        aSelectedProperty = self.theListStore.get_value(anIter, PROPERTY_COL)
        aFullID, _ = convertFullPNToFullID(self.getFullPN())
        self.theSelectedFullPN = convertFullIDToFullPN(aFullID,
                                                       aSelectedProperty)

        # disable VariableReferenceList editing because of a bug when
        # saving changes
        if aSelectedProperty != 'VariableReferenceList':
            self.__updateValue(aNewValue, anIter, VALUE_COL)

    # ---------------------------------------------------------------
    # updateValue
    #   - sets inputted value to the simulator
    #
    # return -> None
    # This method is throwable exception.
    # ---------------------------------------------------------------
    def __updateValue(self, aValue, anIter, aColumn):

        # ------------------------------------
        # gets getable status
        # ------------------------------------
        aGetable = self.theListStore.get_value(anIter, GETABLE_COL)

        # ------------------------------------
        # checks the type of inputted value
        # ------------------------------------
        if aGetable:
            aPreValue = self.theListStore.get_value(anIter, aColumn)

            # ------------------------------------
            # when type is integer
            # ------------------------------------
            if type(aPreValue) == type(0):
                try:
                    aValue = int(aValue)
                except:
                    import sys
                    import traceback
                    anErrorMessage = '\n'.join(
                        traceback.format_exception(sys.exc_type, sys.exc_value,
                                                   sys.exc_traceback))
                    self.theSession.message("-----An error happens.-----")
                    self.theSession.message(anErrorMessage)
                    self.theSession.message("---------------------------")

                    # creates and display error message dialog.
                    anErrorMessage = "Input an integer!"
                    anErrorTitle = "The type error!"
                    if self['statusbar'] != None:
                        self['statusbar'].push(1, anErrorMessage)
                    anErrorWindow = ConfirmWindow(OK_MODE, anErrorMessage,
                                                  anErrorTitle)
                    return None

            # ------------------------------------
            # when type is float
            # ------------------------------------
            elif type(aPreValue) == type(0.0):
                try:
                    aValue = float(aValue)
                except:
                    import sys
                    import traceback
                    anErrorMessage = '\n'.join(
                        traceback.format_exception(sys.exc_type, sys.exc_value,
                                                   sys.exc_traceback))
                    self.theSession.message("-----An error happened.-----")
                    self.theSession.message(anErrorMessage)
                    self.theSession.message("---------------------------")

                    # creates and display error message dialog.
                    anErrorMessage = "Input a float!"
                    anErrorTitle = "The type error!"
                    if self['statusbar'] != None:
                        self['statusbar'].push(1, anErrorMessage)
                    anErrorWindow = ConfirmWindow(OK_MODE, anErrorMessage,
                                                  anErrorTitle)
                    return None

            # ------------------------------------
            # when type is tuple
            # ------------------------------------
            elif type(aPreValue) == type(()):
                try:
                    aValue = convertStringToTuple(aValue)

                except:
                    import sys
                    import traceback
                    anErrorMessage = '\n'.join(
                        traceback.format_exception(sys.exc_type, sys.exc_value,
                                                   sys.exc_traceback))
                    self.theSession.message("-----An error happens.-----")
                    self.theSession.message(anErrorMessage)
                    self.theSession.message("---------------------------")

                    # creates and display error message dialog.
                    anErrorMessage = "Input a tuple!"
                    anErrorTitle = "The type error!"
                    if self['statusbar'] != None:
                        self['statusbar'].push(1, anErrorMessage)
                    anErrorWindow = ConfirmWindow(OK_MODE, anErrorMessage,
                                                  anErrorTitle)
                    return None

        try:
            self.theSession.setEntityProperty(self.theSelectedFullPN, aValue)
            self.theSession.updateWindows()
            self.lockCursor = True
            self['theTreeView'].get_selection().select_iter(anIter)
            self.lockCursor = False
        except:

            import sys
            import traceback
            anErrorMessage = '\n'.join(
                traceback.format_exception(sys.exc_type, sys.exc_value,
                                           sys.exc_traceback))
            self.theSession.message("-----An error happens.-----")
            self.theSession.message(anErrorMessage)
            self.theSession.message("---------------------------")

            # creates and display error message dialog.
            anErrorMessage = "An error happened! See MessageWindow."
            anErrorTitle = "An error happened!"
            if self['statusbar'] != None:
                self['statusbar'].push(1, anErrorMessage)
            anErrorWindow = ConfirmWindow(OK_MODE, anErrorMessage,
                                          anErrorTitle)
        else:

            self.__updatePropertyList()
            #self.thePluginManager.updateAllPluginWindow()

    # end of updateValue

    def getSelectedFullPN(self):

        anIter = self['theTreeView'].get_selection().get_selected()[1]
        if anIter == None:
            self.theSelectedFullPN = ''
        else:
            aSelectedProperty = self.theListStore.get_value(
                anIter, PROPERTY_COL)
            aFullID, _ = convertFullPNToFullID(self.getFullPN())
            self.theSelectedFullPN = convertFullIDToFullPN(
                aFullID, aSelectedProperty)
        return self.theSelectedFullPN

    def setSelectedFullPN(self, aFullPN):

        aPropertyName = aFullPN[3]
        anIter = self.theListStore.get_iter_first()
        while anIter != None:
            if self.theListStore.get_value(anIter,
                                           PROPERTY_COL) == aPropertyName:
                lockCursor = self.lockCursor
                self.lockCursor = True
                self['theTreeView'].get_selection().select_iter(anIter)
                self.lockCursor = lockCursor
                break
            anIter = self.theListStore.iter_next(anIter)

    def __cursorChanged(self, *args):

        if self.lockCursor:
            return

        aFullPNList = [self.getSelectedFullPN()]
        self.lockCursor = True
        self.theQueue.pushFullPNList(aFullPNList)
        self.lockCursor = False

    # ---------------------------------------------------------------
    # popupMenu
    #   - show popup menu
    #
    # aWidget         : widget
    # anEvent          : an event
    # return -> None
    # This method is throwable exception.
    # ---------------------------------------------------------------
    def __popupMenu(self, aWidget, anEvent):

        if anEvent.button == 3:  # 3 means right

            if self['theTreeView'].get_selection().get_selected()[1] == None:
                return None

            self.thePopupMenu.popup(None, None, None, 1, 0)

    # end of poppuMenu

    def createNewPluginWindow(self, anObject):

        # gets PluginWindowName from selected MenuItem
        aPluginWindowName = anObject.get_name()

        # creates PluginWindow
        self.thePluginManager.createInstance(aPluginWindowName,
                                             self.theRawFullPNList)

    # end of createNewPluginWindow

    def __createVariableReferenceListTab(self):
        aFullID, _ = convertFullPNToFullID(self.getFullPN())
        if self.theVarrefTabNumber != -1:
            if self.theVarrefEditor.getProcessFullID() == aFullID:
                return
            else:
                self.theVarrefEditor.setDisplayedFullID(aFullID)
        else:
            aFrame = gtk.Frame()
            aFrame.show()
            aLabel = gtk.Label("Variable References")
            aLabel.show()
            self.theNoteBook.append_page(aFrame, aLabel)
            self.theVarrefTabNumber = 2
            self.theVarrefEditor = VariableReferenceEditor(self, aFrame)

    def __deleteVariableReferenceListTab(self):
        if self.theVarrefTabNumber == -1:
            return
        curPage = self.theNoteBook.get_current_page()
        if curPage == self.theVarrefTabNumber:
            curPage = 0

        self.theNoteBook.remove_page(self.theVarrefTabNumber)
        self.theNoteBook.set_current_page(curPage)
        self.theVarrefTabNumber = -1
        self.theVarrefEditor = None
Exemplo n.º 7
0
    def update(self):
        aFullID = None
        aFullPN = None
        fullUpdate = False

        if self.theSession.theSession is not self.theAssociatedSession:
            self.theRawFullPNList = []
            if self.theSession.theSession is not None:
                if self.theParent != None:
                    if self.theParent.__class__.__name__ == "EntityListWindow":
                        self.theQueue = self.theParent.getQueue()
                    else:
                        self['navigation'].visible = True
                        self.theQueue = FullPNQueue(
                            (self['backbutton'], self['forwardbutton']),
                            self.theRawFullPNList)
                else:
                    self['navigation'].visible = True
                    self.theQueue = FullPNQueue(
                        (self['backbutton'], self['forwardbutton']),
                        self.theRawFullPNList)
                self.theAssociatedSession = self.theSession.theSession
                self.theQueue.registerCallback(self.setRawFullPNList)
            else:
                self.theQueue = None
        else:
            aFullPN = self.getFullPN()
            if aFullPN is not None:
                aFullID, _ = convertFullPNToFullID(self.getFullPN())
        if self.thePreFullID != aFullID:
            fullUpdate = True

        # ----------------------------------------------------
        # updates widgets
        # ----------------------------------------------------
        # creates EntityStub
        if aFullID is not None:
            anEntityStub = self.theSession.createEntityStub(
                createFullIDString(aFullID))
        else:
            anEntityStub = None
            fullUpdate = True

        if not fullUpdate:
            # gets propery values for thePreProperyMap in case value is not tuple
            for aPropertyName in self.thePrePropertyMap.keys():
                aProperty = self.thePrePropertyMap[aPropertyName]
                if type(aProperty[0]) not in (tuple, list):
                    aProperty[0] = anEntityStub.getProperty(aPropertyName)
            if self.theVarrefEditor != None:
                self.theVarrefEditor.update()
        else:
            self.theSelectedFullPN = ''

            # -----------------------------------------------
            # updates each widget
            # Type, ID, Path, Classname
            # -----------------------------------------------
            if anEntityStub is not None:
                anEntityType = ENTITYTYPE_STRING_LIST[aFullPN[TYPE]]
                anID = aFullPN[ID]
                aSystemPath = str(aFullPN[SYSTEMPATH])

                self['entryClassName'].set_text(anEntityStub.getClassname())
                self['entryFullID'].set_text(':'.join(
                    [anEntityType, aSystemPath, anID]))
                # saves properties to buffer
                self.thePrePropertyMap = {}
                for aProperty in anEntityStub.getPropertyList():
                    self.thePrePropertyMap[str(aProperty)] = [None, None]
                    self.thePrePropertyMap[str(aProperty)][0] =\
                            anEntityStub.getProperty(aProperty)
                    self.thePrePropertyMap[str(aProperty)][1] =\
                            anEntityStub.getPropertyAttributes(aProperty)

                self['entryName'].set_text(
                    str(self.thePrePropertyMap['Name'][0]))

                # save current full id to previous full id.
                self.thePreFullID = aFullID
                self.setSelectedFullPN(aFullPN)
            else:
                self['entryClassName'].set_text("")
                self['entryClassName'].set_max_length(0)
                self['entryFullID'].set_text("")
                self['entryName'].set_text("")

            # update Summary tab for unique fields of each entity type
            # update the respective Entity's PropertyList
            if aFullPN is not None:
                self.__setDiscardList()
                if aFullPN[TYPE] == PROCESS:
                    self.__createVariableReferenceListTab()
                    self.__updateProcess()
                elif aFullPN[TYPE] == VARIABLE:
                    self.__deleteVariableReferenceListTab()
                    self.__updateVariable()
                elif aFullPN[TYPE] == SYSTEM:
                    self.__deleteVariableReferenceListTab()
                    self.__updateSystem()

        # updates status bar
        if self['statusbar'] != None:
            self['statusbar'].push(1, '')
Exemplo n.º 8
0
class EntityListWindow(OsogoWindow):
    '''EntityListWindow
    '''

    DEFAULT_PLUGIN = 'TracerWindow'

    DEFAULT_VARIABLE_PROPERTY = 'Value'
    DEFAULT_PROCESS_PROPERTY = 'Activity'

    COMMON_COLUMN_INFO_MAP= {
        'ID':        gobject.TYPE_STRING,
        'Classname': gobject.TYPE_STRING,
        'Path':      gobject.TYPE_STRING
        }

    VARIABLE_COLUMN_INFO_MAP= {
        # Name:      Type

        'Value':     gobject.TYPE_STRING
        }

    PROCESS_COLUMN_INFO_MAP= {
        'Activity':  gobject.TYPE_STRING
        }

    VARIABLE_COLUMN_LIST = [ 'ID', 'Value', 'Classname', 'Path' ]
    PROCESS_COLUMN_LIST = [ 'ID', 'Activity', 'Classname', 'Path' ]


    def __init__( self, session, rootWidget, aStatusbar ):
        '''Constructor
        session   --   a reference to GtkSessionMonitor
        '''

        # call superclass's constructor 
        OsogoWindow.__init__( self, session, rootWidget=rootWidget )

        # initialize parameters
        self.theSelectedFullPNList = []

        self.searchString = ''

        # set status bar
        self.theStatusbar = aStatusbar

        # fix me
        self.thePluginManager = session.thePluginManager
        self.thePropertyWindow = None
        self.thePluginInstanceSelection = None

        self.theAssociatedSession = None

        

    def openWindow( self ):

        # call superclass's openWindow
        OsogoWindow.openWindow( self )

        self['search_method'].set_property('active', 0)
        self['search_scope'].set_property('active', 0)
        
        # add handers
        self.addHandlers( { 
            'on_system_tree_button_press_event' : self.popupMenu,
            'on_view_button_clicked': self.createPluginWindow,
            'on_variable_tree_button_press_event': self.popupMenu,
            'on_process_tree_button_press_event': self.popupMenu,
            # search 
            'on_search_button_clicked': self.pushSearchButton,
            'on_search_entry_key_press_event': self.keypressOnSearchEntry,
            'on_clear_button_clicked': self.pushClearButton, 
            'on_search_scope_changed': self.searchScopeChanged
            } )

        self.entitySelected = False
        self.theLastSelectedWindow = None
        self.thePopupMenu = gtk.Menu()
        self.donotHandle = False
        self.systemTree   = self['system_tree']
        self.processTree  = self['process_tree']
        self.variableTree = self['variable_tree']

        # --------------------------------------------
        # initialize components
        # --------------------------------------------
        self.__initializeSystemTree()
        self.__initializeProcessTree()
        self.__initializeVariableTree()
        self.__initializeSelection()
        self.__initializePluginWindowOptionMenu()

        self.theQueue = None
        self.__initializePropertyWindow()
        self.__initializePopupMenu()

        self.theSelectedEntityList = []
        self.theSelectedPluginInstanceList = []

        self.CloseOrder = False
        self.updateButtons()

    def updateButtons( self ):
        if self.theSession.theSession is not None:
            self['search_button'].set_sensitive(True)
            self['view_button'].set_sensitive(True)
            self['search_entry'].set_sensitive(True)
            self['plugin_optionmenu'].set_sensitive(True)
            self['backbutton'].set_sensitive(False)
            self['forwardbutton'].set_sensitive(False)
        else:
            self['search_button'].set_sensitive(False)
            self['view_button'].set_sensitive(False)
            self['search_entry'].set_sensitive(False)
            self['plugin_optionmenu'].set_sensitive(False)
            self['backbutton'].set_sensitive(False)
            self['forwardbutton'].set_sensitive(False)
    

    def getQueue( self ):
        return self.theQueue


    def deleted( self, *arg ):
        self.close()


    def close( self ):
        if self.CloseOrder:
            return
        self.CloseOrder = True

        if self.thePluginInstanceSelection != None:
            self.thePluginInstanceSelection.deleted()
            self.thePluginInstanceSelection = None

        if self.theSession != None:
            self.theSession.deleteEntityListWindow( self )
            OsogoWindow.close(self)


    def deletePluginInstanceSelection( self, *arg ):
        """sets 'delete_event' as 'hide_event'
        """

        # hide this window
        self['PluginInstanceSelection'].hide_all()

        # set 'delete_event' uneffective
        return True


    def __initializeSystemTree( self ):
        """initialize SystemTree
        """
        self.lastSelectedSystem = ""
        treeStore = gtk.TreeStore( gobject.TYPE_STRING )
        self.theSysTreeStore = treeStore
        column = gtk.TreeViewColumn( 'System Tree',
                                     gtk.CellRendererText(),
                                     text=0 )
        column.set_visible( True )
        self.systemTree.append_column(column)

        self.systemTree.set_model( treeStore )

        self.processTree.set_search_column( 0 )
        self.theSysSelection =  self.systemTree.get_selection()

    def __initializeSelection( self ):
        selection = self.systemTree.get_selection()
        selection.set_mode( gtk.SELECTION_MULTIPLE )
        selection.connect( 'changed', self.selectSystem )
        selection = self.processTree.get_selection()
        selection.set_mode( gtk.SELECTION_MULTIPLE )
        selection.connect( 'changed', self.selectProcess )
        selection = self.variableTree.get_selection()
        selection.set_mode( gtk.SELECTION_MULTIPLE )
        selection.connect( 'changed', self.selectVariable )

    def __initializeProcessTree( self ):
        """initialize ProcessTree
        """

        columnTypeList = []

        for i in range( len( self.PROCESS_COLUMN_LIST ) ):
            title = self.PROCESS_COLUMN_LIST[i]

            try:
                type = self.PROCESS_COLUMN_INFO_MAP[ title ]
            except:
                type = self.COMMON_COLUMN_INFO_MAP[ title ]

            column = gtk.TreeViewColumn( title,
                                         gtk.CellRendererText(),
                                         text=i )
            column.set_reorderable( True )
            column.set_sort_column_id( i )
            self.processTree.append_column( column )
            columnTypeList.append( type )
            if type == gobject.TYPE_FLOAT:
                column.set_alignment( 1.0 )
                column.get_cell_renderers()[0].set_property( 'xalign', 1.0 )

        self.processTree.set_search_column( 0 )

        model = gtk.ListStore( *columnTypeList )
        self.processTree.set_model( model )


    def __initializeVariableTree( self ):
        """initializes VariableTree
        """

        columnTypeList = []

        for i in range( len( self.VARIABLE_COLUMN_LIST ) ):
            title = self.VARIABLE_COLUMN_LIST[i]

            try:
                type = self.VARIABLE_COLUMN_INFO_MAP[ title ]
            except:
                type = self.COMMON_COLUMN_INFO_MAP[ title ]

            column = gtk.TreeViewColumn( title,
                                         gtk.CellRendererText(),
                                         text=i )
            column.set_reorderable( True )
            column.set_sort_column_id( i )
            self.variableTree.append_column( column )
            columnTypeList.append( type )
            if type == gobject.TYPE_FLOAT:
                column.set_alignment( 1.0 )
                column.get_cell_renderers()[0].set_property( 'xalign', 1.0 )

        self.variableTree.set_search_column( 0 )

        model = gtk.ListStore( *columnTypeList )
        self.variableTree.set_model( model )




    def __initializePluginWindowOptionMenu( self ):
        """initializes PluginWindowOptionMenu
        """

        aPluginWindowNameList = []
        aMenu = gtk.Menu()

        for aPluginWindowName in self.thePluginManager.thePluginMap.keys():

            aButton = gtk.Button()
            aMenuItem = gtk.MenuItem(aPluginWindowName)

            if aPluginWindowName == self.DEFAULT_PLUGIN:
                aMenu.prepend( aMenuItem )
            else:
                aMenu.append( aMenuItem )

        self['plugin_optionmenu'].set_menu(aMenu)
        self['plugin_optionmenu'].show_all()





    def __initializePropertyWindow( self ):
        if self.thePropertyWindow != None:
            return
        self.thePropertyWindow = self.thePluginManager.createInstance(
            'PropertyWindow', [], rootWidget='top_frame', parent=self ) 
        if self.theStatusbar is not None:
            self.thePropertyWindow.setStatusBar( self.theStatusbar )

        aPropertyWindowTopVBox = self.thePropertyWindow['top_frame']
        self['property_area'].add( aPropertyWindowTopVBox )
        self.thePropertyWindow.setParent( self )



    def __initializePopupMenu( self ):
        """Initialize popup menu
        Returns None
        [Note]:In this method, only 'PluginWindow type' menus, 'Create 
        Logger' menu and 'Add to Board' menu are created. 
        The menus of PluginWindow instances are appended
        dinamically in self.popupMenu() method.
        """

        # ------------------------------------------
        # menus for PluginWindow
        # ------------------------------------------

        # creaets menus of PluginWindow
        for aPluginWindowType in self.thePluginManager.thePluginMap.keys(): 
            aMenuItem = gtk.MenuItem( aPluginWindowType )
            aMenuItem.connect('activate', self.createPluginWindow )
            aMenuItem.set_name( aPluginWindowType )
            if aPluginWindowType == self.DEFAULT_PLUGIN:
                self.thePopupMenu.prepend( aMenuItem )
            else:
                self.thePopupMenu.append( aMenuItem )

        # appends separator
        self.thePopupMenu.append( gtk.MenuItem() )

        # ------------------------------------------
        # menus for Logger
        # ------------------------------------------
        # creates menu of Logger
        aLogMenuString = "Create Logger"
        aMenuItem = gtk.MenuItem( aLogMenuString )
        aMenuItem.connect('activate', self.createLogger )
        aMenuItem.set_name( aLogMenuString )
        self.thePopupMenu.append( aMenuItem )

        # appends separator
        self.thePopupMenu.append( gtk.MenuItem() )

        # ------------------------------------------
        # menus for Bord
        # ------------------------------------------
        # creates menu of Board
        aSubMenu = gtk.Menu()

        for aPluginWindowType in self.thePluginManager.thePluginMap.keys(): 
            aMenuItem = gtk.MenuItem( aPluginWindowType )
            aMenuItem.connect('activate', self.addToBoard )
            aMenuItem.set_name( aPluginWindowType )
            if aPluginWindowType == self.DEFAULT_PLUGIN:
                aSubMenu.prepend( aMenuItem )
            else:
                aSubMenu.append( aMenuItem )

        aMenuString = "Add to Board"
        aMenuItem = gtk.MenuItem( aMenuString )
        aMenuItem.set_name( aLogMenuString )
        aMenuItem.set_submenu( aSubMenu )
        self.thePopupMenu.append( aMenuItem )
        self.theBoardMenu = aMenuItem

        # appends separator
        self.thePopupMenu.append( gtk.MenuItem() )

        # ------------------------------------------
        # menus for submenu
        # ------------------------------------------
        self.thePopupSubMenu = None  


    def __openPluginInstanceSelectionWindow( self, *arg ):
        """open PluginInstanceSelectionWindow
        Returns None
        """

        if self.thePluginInstanceSelection != None:
            self.thePluginInstanceSelection.present()

        else:

            self.thePluginInstanceSelection = \
            PluginInstanceSelection( self.theSession, self )
            self.thePluginInstanceSelection.openWindow()

            # updates list of PluginInstance
            self.thePluginInstanceSelection.update()




    def __updatePluginInstanceSelectionWindow2( self ):
        """updates list of PluginInstanceSelectionWindow
        Returns None
        """

        self.thePluginInstanceListStore.clear()
        aPluginInstanceList = self.thePluginManager.thePluginTitleDict.keys()

        for aPluginInstance in aPluginInstanceList:
            if aPluginInstance.theViewType == MULTIPLE:
                aPluginInstanceTitle = self.thePluginManager.thePluginTitleDict[aPluginInstance]
                iter = self.thePluginInstanceListStore.append()
                self.thePluginInstanceListStore.set_value( iter, 0, aPluginInstanceTitle )
                self.thePluginInstanceListStore.set_data( aPluginInstanceTitle, aPluginInstanceTitle )


    def closePluginInstanceSelectionWindow( self, *arg ):
        """closes PluginInstanceSelectionWindow
        Returns None
        """

        if self.thePluginInstanceSelection != None:
            #self.thePluginInstanceSelection['PluginInstanceSelection'].hide_all()
            self.thePluginInstanceSelection.deleted()
            self.thePluginInstanceSelection = None



    def popupMenu( self, aWidget, anEvent ):
        """displays popup menu only when right button is pressed.
        aWidget   --  EntityListWindow
        anEvent   --  an event
        Returns None
        [Note]:creates and adds submenu that includes menus of PluginWindow instances
        """
        # When left button is pressed
        if anEvent.type == gtk.gdk._2BUTTON_PRESS:
            aSelectedRawFullPNList = self.__getSelectedRawFullPNList()
            aPluginWindowType = self['plugin_optionmenu'].get_children()[0].get()

            # When no FullPN is selected, displays error message.
            if aSelectedRawFullPNList  != None:
                if len( aSelectedRawFullPNList ) == 0:
                    aMessage = 'No entity is selected.'
                    aDialog = ConfirmWindow(OK_MODE,aMessage,'Error!')
                    self.thePropertyWindow.showMessageOnStatusBar(aMessage)
                    return False

            #self.theQueue.pushFullPNList( aSelectedRawFullPNList )
            self.thePluginManager.createInstance( aPluginWindowType, self.thePropertyWindow.getFullPNList() )



        # When right button is pressed
        if anEvent.type == gtk.gdk.BUTTON_PRESS and anEvent.button == 3:

            if self.theSession.getWindow('BoardWindow').exists():
                self.theBoardMenu.set_sensitive( True )
            else:
                self.theBoardMenu.set_sensitive( False )

            # removes previous sub menu
            # When PopupMenu was displayed last time without PluginWindows'
            # menus, the buffer (self.thePopupSubMenu) is None.
            if self.thePopupSubMenu != None:
                self.thePopupMenu.remove( self.thePopupSubMenu )

            if len(self.thePluginManager.theInstanceList)!=0:

                # creates submenu
                aSubMenu = gtk.Menu()

                # creaets menus of PluginWindow instances
                aMenuItemFlag = False
                for aPluginInstance in self.thePluginManager.theInstanceList: 

                    if aPluginInstance.theViewType == MULTIPLE:
                        aTitle = aPluginInstance.getTitle()
                        aMenuItem = gtk.MenuItem( aTitle )
                        aMenuItem.connect('activate', self.appendData )
                        aMenuItem.set_name( aTitle )
                        aSubMenu.append( aMenuItem )
                        aMenuItemFlag = True

                if aMenuItemFlag:
                    # creates parent MenuItem attached created submenu.
                    aMenuString = "Append data to"
                    aMenuItem = gtk.MenuItem( aMenuString )
                    aMenuItem.set_submenu( aSubMenu )

                    # appends parent MenuItem to PopupMenu
                    self.thePopupMenu.append( aMenuItem )

                    # saves this submenu set to buffer (self.thePopupSubMenu)
                    self.thePopupSubMenu = aMenuItem


            # displays all items on PopupMenu
            self.thePopupMenu.show_all() 

            # displays popup menu
            self.thePopupMenu.popup(None,None,None,anEvent.button,anEvent.time)


    def update( self ):
        """overwrite superclass's method
        updates this window and property window
        Returns None
        """
        if self.theSession.theSession is not self.theAssociatedSession:
            self.reconstructSystemTree()
            self.theQueue = FullPNQueue( ( self[ "backbutton" ], self[ "forwardbutton" ] ) )
            self.theQueue.registerCallback( self.doSelection )
            self.theQueue.pushFullPNList( [ convertFullIDToFullPN( createFullID ( 'System::/' ) ) ] )
            self.updateButtons()

        # updates this window
        if not self.exists():
            return
        OsogoWindow.update(self)

        # updates property window
        self.thePropertyWindow.update()

        # update PluginInstanceSelectionWindow
        if self.thePluginInstanceSelection != None:
            self.thePluginInstanceSelection.update()

        self.updateLists()
        self.theAssociatedSession = self.theSession.theSession


    def constructSystemTree( self, parent, fullID ):
        # System tree
        newlabel = fullID[ID] 

        systemStore = self.systemTree.get_model()
        iter  = systemStore.append( parent )
        systemStore.set_value( iter, 0, newlabel )
        key = str( systemStore.get_path( iter ) )
        systemStore.set_data( key, fullID )

        systemPath = createSystemPathFromFullID( fullID )
        systemList = self.theSession.getEntityList( 'System', systemPath )
        systemListLength = len( systemList )

        if  systemListLength == 0:
            return

        for systemID in systemList:
            newSystemFullID = ( SYSTEM, systemPath, systemID )
            self.constructSystemTree( iter, newSystemFullID )

            path = systemStore.get_path( iter )
            if systemListLength < 6 and len( path ) < 6:
                self.systemTree.expand_row( path, True )


    def reconstructSystemTree( self ):
        rootSystemFullID = createFullID( 'System::/' )
        self.donotHandle = True
        self.theSysTreeStore.clear()
        self.donotHandle = False
        if self.theSession.theSession:
            self.constructSystemTree( None, rootSystemFullID )
        self.reconstructLists()


    def reconstructLists( self ):
        selectedSystemList = self.getSelectedSystemList()
        if self.entitySelected:
            return 
        # Variable list
        self.reconstructEntityList( 'Variable', self.variableTree,\
                                    selectedSystemList,\
                                    self.VARIABLE_COLUMN_LIST,\
                                    self.VARIABLE_COLUMN_INFO_MAP )

        # Process list
        self.reconstructEntityList( 'Process', self.processTree,\
                                    selectedSystemList,\
                                    self.PROCESS_COLUMN_LIST,\
                                    self.PROCESS_COLUMN_INFO_MAP )
        self.updateListLabels()

        

    def reconstructEntityList( self, type, view, systemList, columnList,\
                               columnInfoList ):
        # get the entity list in the selected system(s)
        typeID = ENTITYTYPE_DICT[ type ]

        fullIDList = []
        if self.theSession.theSession is not None:
            for systemFullID in systemList:
                systemPath = createSystemPathFromFullID( systemFullID )

                idList = self.theSession.getEntityList( type, systemPath )
                fullIDList += [ ( typeID, systemPath, id ) for id in idList ]

        entityStore = view.get_model()

        # clear the store
        donotHandle = self.donotHandle
        self.donotHandle = True
        entityStore.clear()
        self.donotHandle = donotHandle

        #        columnList = view.get_columns()
        # re-create the list
        for fullID in fullIDList:

            ID = fullID[2]
            # temporary hack for the entity searching.
            # this can be like this in python 2.3 or above:
            #    if not self.searchString in ID:
            if ID.find( self.searchString ) < 0:
                continue

            fullIDString = createFullIDString( fullID )

            stub = self.theSession.createEntityStub( fullIDString )

            valueList = []

            for title in columnList:

                if title in self.COMMON_COLUMN_INFO_MAP.keys():
                    if title == 'ID':
                        value = ID
                    elif title == 'Classname':
                        value = stub.getClassname()
                    elif title == 'Path':
                        value =  fullID [SYSTEMPATH]
                    else:
                        raise "Unexpected error: invalid column title."
                else:
                    value = stub[ title ] # if not common, it's entity property

                valueList.append( value )

            iter = entityStore.append( valueList )
            iterString = entityStore.get_string_from_iter( iter )
            entityStore.set_data( iterString, fullIDString )


    def doSelection( self, aFullPNList ):
        self.doSelectSystem( aFullPNList ) 
        self.doSelectProcess( aFullPNList )
        self.doSelectVariable( aFullPNList )


    def doSelectSystem( self, aFullPNList ):
        targetFullIDList = []
        if aFullPNList[0][TYPE] != SYSTEM:
            targetFullIDList += [ createFullIDFromSystemPath( aFullPN[SYSTEMPATH] )  for aFullPN in aFullPNList ]
        else:
            for aFullPN in aFullPNList:
                aFullID, _ = convertFullPNToFullID( aFullPN ) 
                targetFullIDList.append( aFullID )

        # if to slow there should be a check whether this is needed in all cases
        donotHandle = self.donotHandle
        self.donotHandle = True
        self.theSysSelection.unselect_all()
        self.theSysSelection.set_mode( gtk.SELECTION_MULTIPLE )

        for  targetFullID in targetFullIDList:
            #doselection
            targetPath = createSystemPathFromFullID( targetFullID )
            anIter = self.getSysTreeIter( targetPath )
            if anIter is not None:
                aPath = self.theSysTreeStore.get_path( anIter )
                self.__expandRow( aPath )
                self.theSysSelection.select_iter( anIter )

        self.donotHandle = donotHandle

        self.reconstructLists()


    def getSysTreeIter( self, aSysPath, anIter = None ):
        """
        returns iter of string aSysPath or None if not available
        """
        systemStore = self.systemTree.get_model()
        if anIter == None:
            anIter = systemStore.get_iter_first()
            if aSysPath == '/':
                return anIter
            else:
                aSysPath = aSysPath.strip ('/')

        # get first path string
        anIndex = aSysPath.find( '/' )
        if anIndex == -1:
            anIndex = len( aSysPath )
        firstTag = aSysPath[ 0 : anIndex ]

        # create remaining path string
        aRemainder = aSysPath[ anIndex + 1 : len( aSysPath ) ]

        # find iter of first path string
        numChildren = systemStore.iter_n_children( anIter )
        isFound = False
        for i in range( 0, numChildren):
            childIter = systemStore.iter_nth_child( anIter, i )

            if systemStore.get_value( childIter, 0) == firstTag:
                isFound = True
                break

        # if not found return None
        if not isFound:
            return None

        # if remainder is '' return iter
        if aRemainder == '':
            return childIter

        # return recursive remainder with iter
        return self.getSysTreeIter( aRemainder, childIter )


    def __expandRow( self, aPath ):
        """
        in: gtktreePath aPath
        """
        if not self.systemTree.row_expanded( aPath ):

            # get iter
            anIter = self.theSysTreeStore.get_iter( aPath)

            # get parent iter
            parentIter = self.theSysTreeStore.iter_parent( anIter )

            # if iter is root expand
            if parentIter != None:

                # if not get parent path
                parentPath = self.theSysTreeStore.get_path( parentIter )
                
                # expand parentpath
                self.__expandRow( parentPath )
                
            # expand this path
            self.systemTree.expand_row( aPath, False )


    def selectListIter( self, aListStore, aSelection, anIDList ):

        anIter = aListStore.get_iter_first()
        while anIter != None:
            if aListStore.get_value( anIter, 0 ) in anIDList:
                donotHandle = self.donotHandle
                self.donotHandle = True
                aSelection.select_iter( anIter )
                self.donotHandle = donotHandle

            anIter = aListStore.iter_next( anIter )

    
    def doSelectProcess( self, aFullPNList ):
        #unselect all

        selection = self.processTree.get_selection()
        listStore = self.processTree.get_model()
        selection.unselect_all()
        selection.set_mode(gtk.SELECTION_MULTIPLE )

        if aFullPNList[0][TYPE] == PROCESS:
            # do select
            self.selectListIter( listStore, selection, self.__createIDList( aFullPNList ) )

    
    def __createIDList( self, aFullPNList ):
        anIDList = []
        for aFullPN in aFullPNList:
            anIDList.append( aFullPN[ID] )
        return anIDList
    
    
    def doSelectVariable( self, aFullPNList ):
        #unselect all
        selection = self.variableTree.get_selection()
        listStore = self.variableTree.get_model()
        selection.unselect_all()
        selection.set_mode(gtk.SELECTION_MULTIPLE )

        if aFullPNList[0][TYPE] == VARIABLE:
            # do select
            self.selectListIter( listStore, selection, self.__createIDList( aFullPNList ) )

    def selectSystem( self, obj ):
        if self.donotHandle:
            return

        # select the first selected System in the PropertyWindow
        systemFullIDList = self.getSelectedSystemList()
        fullPNList = []
        for systemFullID in systemFullIDList:
            fullPNList.append( convertFullIDToFullPN( systemFullID ) )
        self.donotHandle = True
        self.theQueue.pushFullPNList( fullPNList )
        self.donotHandle = False




    def getSelectedSystemList( self ):
        '''
        Return - a list of FullIDs of the currently selected Systems.
        '''

        # get system ID from selected items of system tree,
        # and get entity list from session

        systemList = []

        selection = self.systemTree.get_selection()
        selectedSystemTreePathList = selection.get_selected_rows()
        if selectedSystemTreePathList == None:
            return []
        selectedSystemTreePathList = selectedSystemTreePathList[1]
        
        systemStore = self.systemTree.get_model()


        for treePath in selectedSystemTreePathList:

            systemFullID = systemStore.get_data( str( treePath ) )
            systemList.append( systemFullID )

        return systemList


    def updateLists( self ):
        '''
        This method updates property values shown in the list of
        Variables and Processes.
        '''
        if self.theSession.theSession is None:
            return

        self.updateEntityList( 'Process', self.processTree.get_model(),\
                               self.PROCESS_COLUMN_LIST,\
                               self.PROCESS_COLUMN_INFO_MAP )

        self.updateEntityList( 'Variable', self.variableTree.get_model(),\
                               self.VARIABLE_COLUMN_LIST,\
                               self.VARIABLE_COLUMN_INFO_MAP )
                               

    def updateEntityList( self, type, model, columnList, columnInfoMap ): 

        propertyColumnList= [ ( columnList.index( i ), i )\
                              for i in columnInfoMap.keys() ]

        for row in model:

            iter = row.iter
            fullID = model.get_data( model.get_string_from_iter( iter ) )

            stub = self.theSession.createEntityStub( fullID )

            columnList = []
            for propertyColumn in propertyColumnList:
                newValue = stub[ propertyColumn[1] ]
                columnList += [ propertyColumn[0], "%g"%(newValue) ] 

            model.set( iter, *columnList )


    def updateListLabels( self ):
        self.__updateViewLabel( 'Variable', self['variable_label'],\
                                self.variableTree )
        self.__updateViewLabel( 'Process', self['process_label'],\
                                self.processTree )
        self.__updateViewLabel( 'System', self['system_label'],\
                                self.systemTree )

    def __updateViewLabel( self, type, label, view ):
        shownCount    = len( view.get_model() )
        selectedCount = view.get_selection().count_selected_rows()
        labelText = '<b>%s</b> (%d / %d)' % (type, selectedCount, shownCount )
        label.set_markup( labelText )

    def selectProcess( self, selection ):
        if self.donotHandle:
            return
        self.entitySelected = True
        self.theLastSelectedWindow = "Process"

        # clear fullPN list
        self.theSelectedFullPNList = []

        # get selected items
        selection.selected_foreach(self.process_select_func)

        if len( self.theSelectedFullPNList ) > 0:
            self.donotHandle = True
            self.theQueue.pushFullPNList( self.theSelectedFullPNList )
            self.donotHandle = False
        # clear selection of variable list
#        self.variableTree.get_selection().unselect_all()

        self.updateListLabels()
        self.entitySelected = False
        
    def selectVariable( self, selection ):
        if self.donotHandle:
            return
        self.entitySelected = True
        self.theLastSelectedWindow = "Variable"

        # clear fullPN list
        self.theSelectedFullPNList = []

        # get selected items
        selection.selected_foreach(self.variable_select_func)

        if len( self.theSelectedFullPNList ) > 0:
            self.donotHandle = True
            self.theQueue.pushFullPNList( self.theSelectedFullPNList )
            self.donotHandle = False

        # clear selection of process list
#        self.processTree.get_selection().unselect_all()

        self.updateListLabels()
        self.entitySelected = False

    def variable_select_func(self,tree,path,iter):
        '''function for variable list selection

        Return None
        '''

        model = self.variableTree.get_model()
        data = model.get_data( model.get_string_from_iter( iter ) )
        entityFullID = createFullID( data )
        entityFullPN = entityFullID + ( self.DEFAULT_VARIABLE_PROPERTY, )
        self.theSelectedFullPNList.append( entityFullPN )


    def process_select_func(self,tree,path,iter):
        '''function for process list selection

        Return None
        '''
        
        model = self.processTree.get_model()
        data = model.get_data( model.get_string_from_iter( iter ) )
        entityFullID = createFullID( data )
        entityFullPN = entityFullID + ( self.DEFAULT_PROCESS_PROPERTY, )
        self.theSelectedFullPNList.append( entityFullPN )



    def createPluginWindow( self, *obj ) :
        """creates new PluginWindow instance(s)
        *obj   --  gtk.MenuItem on popupMenu or gtk.Button
        Returns None
        """

        self.thePropertyWindow.clearStatusBar()

        if len(obj) == 0:
            return None

        aPluginWindowType = self.DEFAULT_PLUGIN
        aSetFlag = False

        # When this method is cadef doSeleclled by popup menu
        if type( obj[0] ) == gtk.MenuItem:
            aPluginWindowType = obj[0].get_name()

        # When this method is called by 'CreateWindow' button
        elif type( obj[0] ) == gtk.Button:
            aPluginWindowType = self['plugin_optionmenu'].get_children()[0].get()

        else:
            raise TypeErrir("%s must be gtk.MenuItem or gtk.Button" %str(type(obj[0])))

        aSelectedRawFullPNList = self.__getSelectedRawFullPNList()

        # When no FullPN is selected, displays error message.
        if aSelectedRawFullPNList  == None or len( aSelectedRawFullPNList ) == 0:

            aMessage = 'No entity is selected.'
            aDialog = ConfirmWindow(OK_MODE,aMessage,'Error!')
            self.thePropertyWindow.showMessageOnStatusBar(aMessage)
            return False

        #self.theQueue.pushFullPNList( aSelectedRawFullPNList )
        self.thePluginManager.createInstance( aPluginWindowType, self.thePropertyWindow.getFullPNList() )



    def appendData( self, *obj ):
        """appends RawFullPN to PluginWindow instance
        Returns True(when appened) / False(when not appened)
        """

        # clear status bar
        self.thePropertyWindow.clearStatusBar()

        if len(obj) == 0:
            return None

        # Only when at least one menu is selected.

        # ----------------------------------------------------
        # When this method is called by popup menu
        # ----------------------------------------------------
        if type( obj[0] ) == gtk.MenuItem:
            aSetFlag = True
            aPluginWindowTitle = obj[0].get_name()

            for anInstance in self.thePluginManager.theInstanceList:
                if anInstance.getTitle() == aPluginWindowTitle:

                    try:
                        anInstance.appendRawFullPNList( self.__getSelectedRawFullPNList() )
                    except TypeError:
                        anErrorFlag = True
                        aMessage = "Can't append data to %s" %str(anInstance.getTitle())
                        self.thePropertyWindow.showMessageOnStatusBar(aMessage)
                    else:
                        aMessage = "Selected Data are added to %s" %aPluginWindowTitle
                        self.thePropertyWindow.showMessageOnStatusBar(aMessage)
                    break

            return True

        # ----------------------------------------------------
        # When this method is called by PluginInstanceWindow
        # ----------------------------------------------------
        elif type( obj[0] ) == gtk.Button:

            self.theSelectedPluginInstanceList = []
            selection=self.thePluginInstanceSelection['plugin_tree'].get_selection()
            selection.selected_foreach(self.thePluginInstanceSelection.plugin_select_func)

            # When no FullPN is selected, displays error message.
            if self.__getSelectedRawFullPNList() == None or len( self.__getSelectedRawFullPNList() ) == 0:

                aMessage = 'No entity is selected.'
                aDialog = ConfirmWindow(OK_MODE,aMessage,'Error!')
                self.thePropertyWindow.showMessageOnStatusBar(aMessage)
                return False

            # When no plugin instance is selected, displays error message.
            if len(self.theSelectedPluginInstanceList) == 0:

                aMessage = 'No Plugin Instance is selected.'
                aDialog = ConfirmWindow(OK_MODE,aMessage,'Error!')
                self.thePropertyWindow.showMessageOnStatusBar(aMessage)
                return False

            # buffer of appended instance's title
            anAppendedTitle = []

            anErrorFlag = False

            # appneds data
            for aPluginWindowTitle in self.theSelectedPluginInstanceList:
                for anInstance in self.thePluginManager.theInstanceList:
                    if anInstance.getTitle() == aPluginWindowTitle:
                        try:
                            anInstance.appendRawFullPNList( self.__getSelectedRawFullPNList() )
                        except TypeError:
                            anErrorFlag = True
                            aMessage = "Can't append data to %s" %str(anInstance.getTitle())
                            self.thePropertyWindow.showMessageOnStatusBar(aMessage)
                        else:
                            anAppendedTitle.append( anInstance.getTitle() )
                        break

            # When at least one instance is appended
            if len(anAppendedTitle) > 0 and anErrorFlag == False:
                # displays message
                aMessage = "Selected Data are added to %s" %str(anAppendedTitle)
                self.theSession.message(aMessage)
                self.thePropertyWindow.showMessageOnStatusBar(aMessage)

                # closes PluginInstanceSelectionWindow
                #self.__closePluginInstanceSelectionWindow()
                self.closePluginInstanceSelectionWindow()
                return True

            # When no instance is appended
            else:

                return None



    def __getSelectedRawFullPNList( self ):
        """
        Return a list of selected FullPNs
        """
        return self.theQueue.getActualFullPNList()


    def addToBoard( self, *arg ):
        """add plugin window to board
        """

        self.thePropertyWindow.clearStatusBar()

        if len(arg) == 0:
            return None

        aPluginWindowType = self.DEFAULT_PLUGIN
        aSetFlag = False

        # When this method is called by popup menu
        if type( arg[0] ) == gtk.MenuItem:
            aPluginWindowType = arg[0].get_name()

        # When this method is called by 'CreateWindow' button
        elif type( arg[0] ) == gtk.Button:
            aPluginWindowType = self['plugin_optionmenu'].get_children()[0].get()

        else:
            raise TypeError("%s must be gtk.MenuItem or gtk.Button" %str(type(arg[0])))

        aSelectedRawFullPNList = self.__getSelectedRawFullPNList()

        # When no FullPN is selected, displays error message.
        if aSelectedRawFullPNList  == None or len( aSelectedRawFullPNList ) == 0:

            aMessage = 'No entity is selected.'
            aDialog = ConfirmWindow(OK_MODE,aMessage,'Error!')
            self.thePropertyWindow.showMessageOnStatusBar(aMessage)
            return False

        self.theSession.getWindow('BoardWindow').addPluginWindows( aPluginWindowType, \
        self.__getSelectedRawFullPNList() )



    def createLogger( self, *arg ):
        """creates Logger about all FullPN selected on EntityTreeView
        Returns None
        """

        # clear status bar
        self.thePropertyWindow.clearStatusBar()

        # gets selected RawFullPNList
        aSelectedRawFullPNList = self.__getSelectedRawFullPNList()


        # When no entity is selected, displays confirm window.
        if len(aSelectedRawFullPNList) == 0:


            aMessage = 'No Entity is selected.'
            self.thePropertyWindow.showMessageOnStatusBar(aMessage)
            aDialog = ConfirmWindow(OK_MODE,aMessage,'Error!')
            return None

        # creates Logger using PropertyWindow
        #self.theQueue.pushFullPNList( aSelectedRawFullPNList )
        aLogPolicy = self.theSession.getLogPolicyParameters()
        try:
            for aFullPN in self.getFullPNList():
                # creates loggerstub and call its create method.
                aLoggerStub = self.theSession.createLoggerStub( createFullPNString( aFullPN ) )
                if not aLoggerStub.exists():
                    aLoggerStub.setLoggerPolicy( aLogPolicy )
                    aLoggerStub.create()
        except:
            # When to create log is failed, display error message on MessageWindow.
            anErrorMessage = traceback.format_exception(sys.exc_type,sys.exc_value,sys.exc_traceback)
            self.thePluginManager.printMessage( anErrorMessage )
            return

        # updates fandamental windows.
        self.thePluginManager.updateFundamentalWindows()

        # display message on status bar
        if len(aSelectedRawFullPNList) == 1:
            aMessage = 'Logger was created.'
        else:
            aMessage = 'Loggers were created.'
        self.thePropertyWindow.showMessageOnStatusBar(aMessage)
        #self.checkCreateLoggerButton()

    def searchEntity( self ):
        """search Entities
        Returns None
        """
        searchString = self['search_entry'].get_text()
        # set modelwalker to current selection
        aFullPNList = []

        modelWalker = self.theSession.theModelWalker

        modelWalker.reset()
        
        nextFullID = modelWalker.getCurrentFullID()

        while nextFullID != None:
            if nextFullID[TYPE] == SYSTEM:
                currentSystemID = nextFullID
                currentSystemSelected = False
                
            elif not currentSystemSelected and nextFullID[ID].find( searchString ) != -1:
                # select
                aFullPNList += [ convertFullIDToFullPN( currentSystemID ) ]
                currentSystemSelected = True
                
            nextFullID = modelWalker.getNextFullID()
            

        if len( aFullPNList ) == 0:
            aDialog = ConfirmWindow( OK_MODE, 
                                    "Search string %s not found."%searchString, 
                                    "Search failed" )
            return
        self.searchString = searchString
        self.theQueue.pushFullPNList( aFullPNList )
        self['search_button'].set_sensitive( False)
        if self.searchString != '':
            self['clear_button'].set_sensitive(True )


    def filterSelectedSystems( self ):
        
        self.searchString = self['search_entry'].get_text()
        self.reconstructLists()
        self['search_button'].set_sensitive( False)
        if self.searchString != '':
            self['clear_button'].set_sensitive(True )
        else:
            self['clear_button'].set_sensitive(False )


    def pushSearchButton( self, *arg ):
        searchScope = self['search_scope'].get_property( 'active' )
        if searchScope == 0:
            self.searchEntity()
        else:
            self.filterSelectedSystems()


    def keypressOnSearchEntry( self, *arg ):

        if( arg[1].keyval == 65293 ):

            self.pushSearchButton( None )
        else :
            self['search_button'].set_sensitive(True )

        
    def pushClearButton( self, *args ):
        self['search_entry'].set_text('')
        self.filterSelectedSystems()
        
    def searchScopeChanged( self, *args ):
        searchString = self['search_entry'].get_text()
        if self.searchString != '':
            self['search_button'].set_sensitive( True)
        else:
            self['search_button'].set_sensitive( False)