Example #1
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.ui = Ui_ViewerMainWindow()
        self.ui.setupUi(self)

        self.item_to_filenames = {}
        self.filenames_to_items = {}

        self.main_browser = BrowserStack(self)
        self.ui.verticalLayout.addWidget(self.main_browser)

        self.pack_actions()

        self.ui.item_list.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.ui.item_list.customContextMenuRequested.connect(self.item_list_popup)
Example #2
0
class ViewerMainWindow(QtGui.QMainWindow):

    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.ui = Ui_ViewerMainWindow()
        self.ui.setupUi(self)

        self.item_to_filenames = {}
        self.filenames_to_items = {}

        self.main_browser = BrowserStack(self)
        self.ui.verticalLayout.addWidget(self.main_browser)

        self.pack_actions()

        self.ui.item_list.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.ui.item_list.customContextMenuRequested.connect(self.item_list_popup)

    def item_list_popup(self, pos):

        sel_indexes = self.ui.item_list.selectionModel().selection().indexes()
        if len(sel_indexes) > 0:
            menu = QtGui.QMenu(self.ui.item_list)
            reloadAction = menu.addAction("Reload")
            action = menu.exec_(self.ui.item_list.mapToGlobal(pos))
            if action == reloadAction:
                fn_to_cuboid = {}
                for i in sel_indexes:
                    r, c = i.row(), i.column()
                    item = str(self.ui.item_list.itemAt(r, c).text())
                    # only load cuboids once
                    fn = self.item_to_filenames[item]
                    if not fn_to_cuboid.has_key(fn):
                        fn_to_cuboid[fn] = xndarray.load(fn)
                    self.main_browser.set_new_cuboid(fn_to_cuboid[fn], item)
                    fn_to_cuboid = None #garbage collect

    def pack_actions(self):
        """
        Associate actions trigger to functions for:
        - Open -> display file chooser, load xndarray and open new view
        - Quit -> quit the application
        """
        self.ui.actionOpen.triggered.connect(self.ask_and_load_file)
        self.ui.actionQuit.triggered.connect(QtGui.qApp.quit)

    def ask_and_load_file(self):
        """
        Display file chooser, load xndarray and open new view
        """
        # ask for file names to open:
        
        fns = QtGui.QFileDialog.getOpenFileNames(self, "Open MRI data", './',
                                                 "MRI volume (*.img | *.img.gz"\
                                                 "| *.nii | *.nii.gz)")
        # convert QStringList to list of str:
        fns = [str(fn) for fn in fns]

        for fn in fns:
            self.add_file(fn)


    def get_unique_item_id(self, name, suffix_nb=0):
        print 'name:', name
        if suffix_nb != 0:
            suffix = '(%d)' %suffix_nb
        else:
            suffix = ''
        candidate = add_suffix(name, suffix)
        print 'candidate:', candidate
        print [str(self.ui.item_list.item(i)) \
               for i in range(self.ui.item_list.count())]