#!/usr/bin/env python


from contextlib import contextmanager

from PyQt4.QtGui import *
from PyQt4.QtCore import *

from structdata import g_project

from roomlistwidget import RoomListWidget

@contextmanager
def blockedSignals(widget):
    widget.blockSignals(True)
    try:
        yield
    finally:
        widget.blockSignals(False)

class RoomManager(RoomListWidget):

    def sizeHint(self):
        return QSize(400, 800)

    def getIconSize(self):
        return QSize(150, 150)

    def __init__(self, event=None, item=None, parent=None):
        self.start_room = g_project.data['rooms']\
                          [g_project.data['world'].start]
        self.selected_room = self.start_room.id
        super(RoomManager, self).__init__(event, item, parent)
        g_project.subscribe(self)
        self.highlightStartRoom()

    def setRowSelected(self, id_room):
        item = self.table.findItems(self.selected_room, Qt.MatchExactly)
        if item:
            self.table.selectRow(item[0].row())

    def highlightStartRoom(self):
        item = self.table.findItems(self.start_room.id, Qt.MatchExactly)
        if item:
            row = item[0].row()
            item[0].setBackground(Qt.yellow)
            item = self.table.item(row, 1)
            item.setBackground(Qt.yellow)

    def signal(self, row, col):
        self.emit(SIGNAL("currentRoomChanged(const QString &)"),
                  self.table.item(row, 0).text())

    def changeCurrentRoomName(self, new_name):
        self.selected_room = new_name

    def updateData(self):
        with blockedSignals(self.table):
            self.table.clear()
            self.table.setRowCount(0)
            self.createTable()
        self.highlightStartRoom()
        self.setRowSelected("")


@@ -369,16 +369,172 @@
 dget):%0A%0A
+    %22%22%22%0A    classe utilizzata per visualizzare la lista di tutte le room del modello%0A    deriva da RoomListWidget, reimplementa la funzione signal%0A    %22%22%22%0A%0A
     def 
@@ -541,32 +541,32 @@
 sizeHint(self):%0A
-
         return Q
@@ -1645,24 +1645,163 @@
  new_name):%0A
+        %22%22%22%0A        funzione per settare il nome della room correntemente selezionata%0A        qualora il nome venga modificato%0A        %22%22%22%0A
         self
@@ -2028,16 +2028,16 @@
 tRoom()%0A
-
         
@@ -2061,8 +2061,637 @@
 ed(%22%22)%0A%0A
+    def contextMenuEvent(self, event=None):%0A        %22%22%22%0A        gestione dell'evento di pressione del tasto destro del mouse. Quando%0A        viene premuto si cambia la room di partenza del progetto%0A        %22%22%22%0A        self.changeStartRoom()%0A%0A    def changeStartRoom(self):%0A        %22%22%22%0A        funzione per il cambio della room di partenza del progetto%0A        %22%22%22%0A        selected_item = self.table.selectedIndexes()%5B0%5D%0A        item = self.table.item(selected_item.row(), 0)%0A        g_project.data%5B'world'%5D.start = str(item.text())%0A        self.start_room = g_project.data%5B'rooms'%5D%5Bstr(item.text())%5D%0A        g_project.notify()%0A%0A%0A

add right click event, in this case the start room is update. Add docstrings