Esempio n. 1
0
    def make_button(self, name, wtyp, icon=None, tooltip=None):
        picon = None
        if icon:
            iconfile = os.path.join(self.iconpath, '%s.png' % icon)
            try:
                image = QImage(iconfile)
                pixmap = QPixmap.fromImage(image)
                picon = QIcon(pixmap)
                qsize = QtCore.QSize(24, 24)
            except Exception as e:
                self.logger.error("Error loading icon '%s': %s" %
                                  (iconfile, str(e)))

        if wtyp == 'button':
            if picon:
                w = Widgets.Button()
                _w = w.get_widget()
                _w.setIconSize(qsize)
                _w.setIcon(picon)
            else:
                w = Widgets.Button(name)
        elif wtyp == 'toggle':
            if picon:
                w = Widgets.ToggleButton()
                _w = w.get_widget()
                _w.setIconSize(qsize)
                _w.setIcon(picon)
            else:
                w = Widgets.ToggleButton()

        return w
Esempio n. 2
0
    def make_button(self, name, wtyp, icon=None, tooltip=None):
        picon = None
        if icon:
            iconfile = os.path.join(self.iconpath, '%s.png' % icon)
            try:
                image = QImage(iconfile)
                pixmap = QPixmap.fromImage(image)
                picon = QIcon(pixmap)
                qsize = QtCore.QSize(24, 24)
            except Exception as e:
                self.logger.error("Error loading icon '%s': %s" % (
                    iconfile, str(e)))

        if wtyp == 'button':
            if picon:
                w = Widgets.Button()
                _w = w.get_widget()
                _w.setIconSize(qsize)
                _w.setIcon(picon)
            else:
                w = Widgets.Button(name)
        elif wtyp == 'toggle':
            if picon:
                w = Widgets.ToggleButton()
                _w = w.get_widget()
                _w.setIconSize(qsize)
                _w.setIcon(picon)
            else:
                w = Widgets.ToggleButton()

        return w
Esempio n. 3
0
    def insert_thumbnail(self, imgwin, thumbkey, thumbname, chname, name, path,
                         thumbpath, metadata, image_future):
        pixmap = QPixmap.fromImage(imgwin)
        imglbl = MyLabel()
        imglbl.setPixmap(pixmap)
        # set the load callback
        imglbl.thumbs_cb = lambda: self.load_file(thumbkey, chname, name, path,
                                                  image_future)
        # make a context menu
        self._mk_context_menu(imglbl, thumbkey, chname, name, path,
                              image_future)
        # make a tool tip
        text = self.query_thumb(thumbkey, name, metadata)
        imglbl.setToolTip(text)

        widget = QtGui.QWidget()
        #vbox = QtGui.QGridLayout()
        vbox = QtGui.QVBoxLayout()
        vbox.setContentsMargins(0, 0, 0, 0)
        vbox.setSpacing(0)
        widget.setLayout(vbox)
        namelbl = QtGui.QLabel(thumbname)
        namelbl.setAlignment(QtCore.Qt.AlignLeft)
        namelbl.setAlignment(QtCore.Qt.AlignHCenter)
        ## vbox.addWidget(namelbl, 0, 0)
        ## vbox.addWidget(imglbl,  1, 0)
        vbox.addWidget(namelbl, stretch=0)
        vbox.addWidget(imglbl,  stretch=0)
        widget.setSizePolicy(QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed,
                                               QtGui.QSizePolicy.Fixed))
        bnch = Bunch.Bunch(widget=widget, image=imgwin, layout=vbox,
                           imglbl=imglbl, name=name, imname=name,
                           chname=chname, path=path, thumbpath=thumbpath,
                           pixmap=pixmap, image_future=image_future)

        with self.thmblock:
            self.thumbDict[thumbkey] = bnch
            self.thumbList.append(thumbkey)

            sort_order = self.settings.get('sort_order', None)
            if sort_order:
                self.thumbList.sort()
                self.reorder_thumbs()
                return
            
            self.w.thumbs.addWidget(widget,
                                    self.thumbRowCount, self.thumbColCount)
            self.thumbColCount = (self.thumbColCount + 1) % self.thumbNumCols
            if self.thumbColCount == 0:
                self.thumbRowCount += 1

        #self.w.thumbs.show()
        
        # force scroll to bottom of thumbs, if checkbox is set
        scrollp = self.w.auto_scroll.isChecked()
        if scrollp:
            self.fv.update_pending()
            area = self.w.thumbs_scroll
            area.verticalScrollBar().setValue(area.verticalScrollBar().maximum())
        self.logger.debug("added thumb for %s" % (name))
Esempio n. 4
0
    def insert_thumbnail(self, imgwin, thumbkey, thumbname, chname, name, path,
                         thumbpath, metadata, image_loader):
        pixmap = QPixmap.fromImage(imgwin)
        imglbl = MyLabel()
        imglbl.setPixmap(pixmap)
        imglbl.thumbs_cb = lambda: self.load_file(thumbkey, chname, name, path,
                                                  image_loader)

        text = self.query_thumb(thumbkey, name, metadata)
        imglbl.setToolTip(text)

        widget = QtGui.QWidget()
        #vbox = QtGui.QGridLayout()
        vbox = QtGui.QVBoxLayout()
        vbox.setContentsMargins(0, 0, 0, 0)
        vbox.setSpacing(0)
        widget.setLayout(vbox)
        namelbl = QtGui.QLabel(thumbname)
        namelbl.setAlignment(QtCore.Qt.AlignLeft)
        namelbl.setAlignment(QtCore.Qt.AlignHCenter)
        ## vbox.addWidget(namelbl, 0, 0)
        ## vbox.addWidget(imglbl,  1, 0)
        vbox.addWidget(namelbl, stretch=0)
        vbox.addWidget(imglbl, stretch=0)
        widget.setSizePolicy(
            QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed,
                              QtGui.QSizePolicy.Fixed))
        bnch = Bunch.Bunch(widget=widget,
                           image=imgwin,
                           layout=vbox,
                           imglbl=imglbl,
                           name=name,
                           imname=name,
                           chname=chname,
                           path=path,
                           thumbpath=thumbpath,
                           pixmap=pixmap)

        with self.thmblock:
            self.thumbDict[thumbkey] = bnch
            self.thumbList.append(thumbkey)

            self.w.thumbs.addWidget(widget, self.thumbRowCount,
                                    self.thumbColCount)
            self.thumbColCount = (self.thumbColCount + 1) % self.thumbNumCols
            if self.thumbColCount == 0:
                self.thumbRowCount += 1

        #self.w.thumbs.show()

        # force scroll to bottom of thumbs, if checkbox is set
        scrollp = self.w.auto_scroll.isChecked()
        if scrollp:
            self.fv.update_pending()
            area = self.w.thumbs_scroll
            area.verticalScrollBar().setValue(
                area.verticalScrollBar().maximum())
        self.logger.debug("added thumb for %s" % (thumbname))
Esempio n. 5
0
    def __init__(self, fv, fitsimage):
        # superclass is common subset outside of toolkits
        super(FBrowser, self).__init__(fv, fitsimage)

        # Make icons
        icondir = self.fv.iconpath
        foldericon = os.path.join(icondir, 'folder.png')
        image = QImage(foldericon)
        pixmap = QPixmap.fromImage(image)
        self.folderpb = QIcon(pixmap)
        fileicon = os.path.join(icondir, 'file.png')
        image = QImage(fileicon)
        pixmap = QPixmap.fromImage(image)
        self.filepb = QIcon(pixmap)
        fitsicon = os.path.join(icondir, 'fits.png')
        image = QImage(fitsicon)
        pixmap = QPixmap.fromImage(image)

        self.fitspb = QIcon(pixmap)
Esempio n. 6
0
    def __init__(self, fv, fitsimage):
        # superclass is common subset outside of toolkits
        super(FBrowser, self).__init__(fv, fitsimage)

        # Make icons
        icondir = self.fv.iconpath
        foldericon = os.path.join(icondir, 'folder.png')
        image = QImage(foldericon)
        pixmap = QPixmap.fromImage(image)
        self.folderpb = QIcon(pixmap)
        fileicon = os.path.join(icondir, 'file.png')
        image = QImage(fileicon)
        pixmap = QPixmap.fromImage(image)
        self.filepb = QIcon(pixmap)
        fitsicon = os.path.join(icondir, 'fits.png')
        image = QImage(fitsicon)
        pixmap = QPixmap.fromImage(image)

        self.fitspb = QIcon(pixmap)
Esempio n. 7
0
 def make_button(self, name, wtyp, icon=None, tooltip=None):
     picon = None
     if icon:
         iconfile = os.path.join(self.iconpath, '%s.png' % icon)
         try:
             image = QImage(iconfile)
             pixmap = QPixmap.fromImage(image)
             picon = QIcon(pixmap)
             qsize = QtCore.QSize(24, 24)
         except Exception, e:
             self.logger.error("Error loading icon '%s': %s" % (
                 iconfile, str(e)))
Esempio n. 8
0
    def update_thumbnail(self, thumbkey, imgwin, name, metadata):
        with self.thmblock:
            try:
                bnch = self.thumbDict[thumbkey]
            except KeyError:
                return

            self.logger.debug("generating pixmap.")
            pixmap = QPixmap.fromImage(imgwin)
            bnch.imgwin = imgwin
            bnch.pixmap = pixmap
            bnch.imglbl.setPixmap(pixmap)
            bnch.imglbl.repaint()
            self.w.thumbs_w.update()
        self.logger.debug("update finished.")
Esempio n. 9
0
    def update_thumbnail(self, thumbkey, imgwin, name, metadata):
        with self.thmblock:
            try:
                bnch = self.thumbDict[thumbkey]
            except KeyError:
                return

            self.logger.debug("generating pixmap.")
            pixmap = QPixmap.fromImage(imgwin)
            bnch.imgwin = imgwin
            bnch.pixmap = pixmap
            bnch.imglbl.setPixmap(pixmap)
            bnch.imglbl.repaint()
            self.w.thumbs_w.update()
        self.logger.debug("update finished.")
Esempio n. 10
0
 def add_action(self, text, toggle=False, iconpath=None):
     child = ToolbarAction()
     if iconpath:
         image = QImage(iconpath)
         qsize = QtCore.QSize(24, 24)
         image = image.scaled(qsize)
         pixmap = QPixmap.fromImage(image)
         iconw = QIcon(pixmap)
         action = self.widget.addAction(iconw, text, child._cb_redirect)
     else:
         action = self.widget.addAction(text, child._cb_redirect)
     action.setCheckable(toggle)
     child.widget = action
     self.add_ref(child)
     return child
Esempio n. 11
0
 def add_action(self, text, toggle=False, iconpath=None):
     child = ToolbarAction()
     if iconpath:
         image = QImage(iconpath)
         qsize = QtCore.QSize(24, 24)
         image = image.scaled(qsize)
         pixmap = QPixmap.fromImage(image)
         iconw = QIcon(pixmap)
         action = self.widget.addAction(iconw, text,
                                        child._cb_redirect)
     else:
         action = self.widget.addAction(text, child._cb_redirect)
     action.setCheckable(toggle)
     child.widget = action
     self.add_ref(child)
     return child
Esempio n. 12
0
 def _set_image(self, native_image):
     pixmap = QPixmap.fromImage(native_image)
     self.widget.setPixmap(pixmap)
Esempio n. 13
0
 def get_icon(self, icondir, filename):
     iconpath = os.path.join(icondir, filename)
     image = QImage(iconpath)
     pixmap = QPixmap.fromImage(image)
     icon = QIcon(pixmap)
     return icon