def on_colorbar(self): #print 'QWSpectrum.on_colorbar' ctab_ind = popup_select_color_table(None) if ctab_ind is None: return self.ctab = ct.next_color_table(ctab_ind) arr = ct.array_for_color_bar(self.ctab, orient='H') self.cbar.set_pixmap_from_arr(arr) self.emit(QtCore.SIGNAL('color_table_is_changed()'))
def __init__(self, parent=None, arr=None,\ coltab=ct.color_table_rainbow(ncolors=1000, hang1=250, hang2=-20),\ origin='UL', scale_ctl='HV', rulers='TBLR',\ margl=None, margr=None, margt=None, margb=None) : if arr is None: import numpy as np arr = np.arange(100) arr.shape = (10, 10) #import pyimgalgos.NDArrGenerators as ag #arr = ag.random_standard((10,10), mu=0, sigma=10) h, w = arr.shape rectax = QtCore.QRectF(0, 0, w, h) GUViewAxes.__init__(self, parent, rectax, origin, scale_ctl, rulers, margl, margr, margt, margb) self._name = self.__class__.__name__ #self.scene().removeItem(self.raxi) self.pmi = None self.arr = None mean, std = arr.mean(), arr.std() amin, amax = mean - 2 * std, mean + 10 * std # None, None self.set_intensity_limits(amin, amax) self.set_color_table(coltab) self.set_pixmap_from_arr(arr)
def set_pixmap_from_arr(self, arr=None) : if arr is not None: self.arr = arr anorm = self.arr if self.coltab is None else\ ct.apply_color_table(self.arr, self.coltab, self.amin, self.amax) h, w = self.arr.shape image = QtGui.QImage(anorm, w, h, QtGui.QImage.Format_ARGB32) pixmap = QtGui.QPixmap.fromImage(image) self.add_pixmap_to_scene(pixmap) self.emit(QtCore.SIGNAL('pixmap_is_updated()'))
def __init__(self, parent=None, arr=None,\ coltab=ct.color_table_rainbow(ncolors=1000, hang1=250, hang2=-20),\ origin='UL', scale_ctl='HV', rulers='UDLR',\ margl=None, margr=None, margt=None, margb=None) : GUViewImage.__init__(self, parent, arr, coltab, origin, scale_ctl, rulers, margl, margr, margt, margb) self.add_request = None self.lst_drag_items = []
def __init__(self, parser=None): # **dict_opts) : #Frame.__init__(self, parent=None, mlw=1) QtGui.QWidget.__init__(self, parent=None) #self._name = self.__class__.__name__ self.proc_parser(parser) self.main_win_width = cp.main_win_width self.main_win_height = cp.main_win_height self.main_win_pos_x = cp.main_win_pos_x self.main_win_pos_y = cp.main_win_pos_y self.arr = self.get_image_array() ctab = ct.color_table_rainbow(ncolors=1000, hang1=250, hang2=-20) self.wimg = GUViewImage(None, self.arr, coltab=ctab, origin='UL', scale_ctl='HV', rulers='DL',\ margl=0.09, margr=0.0, margt=0.0, margb=0.04) self.wspe = QWSpectrum(None, self.arr, show_buts=False) #icon.set_icons() self.wtab = IVMainTabs() self.wbut = IVMainButtons() self.wcur = IVImageCursorInfo() self.wlog = QWLogger(log, cp, show_buttons=False) self.vbox = QtGui.QVBoxLayout() self.vbox.addWidget(self.wtab) self.vbox.addStretch(1) self.vbox.addWidget(self.wbut) self.vbox.addWidget(self.wcur) self.wrig = QtGui.QWidget() self.wrig.setLayout(self.vbox) self.vspl = QtGui.QSplitter(QtCore.Qt.Vertical) self.vspl.addWidget(self.wrig) self.vspl.addWidget(self.wspe) self.vspl.addWidget(self.wlog) self.hspl = QtGui.QSplitter(QtCore.Qt.Horizontal) self.hspl.addWidget(self.wimg) self.hspl.addWidget(self.vspl) #self.hspl.addWidget(self.wrig) self.mbox = QtGui.QHBoxLayout() self.mbox.addWidget(self.hspl) self.setLayout(self.mbox) self.set_style() #self.set_tool_tips() self.connect_signals_to_slots() #self.spectrum_show(self.arr) self.move(self.pos()) # + QtCore.QPoint(self.width()+5, 0))
def test_guiviewfwimage(tname): print '%s:' % sys._getframe().f_code.co_name #import numpy as np #arr = np.random.random((1000, 1000)) arr = image_with_random_peaks((1000, 1000)) #ctab = ct.color_table_rainbow(ncolors=1000, hang1=250, hang2=-20) ctab = ct.color_table_monochr256() #ctab = ct.color_table_interpolated() app = QtGui.QApplication(sys.argv) w = None if tname == '0': w = GUViewFWImage(None, arr, coltab=ctab, origin='UL', scale_ctl='HV') elif tname == '1': w = GUViewFWImage(None, arr, coltab=ctab, origin='UL', scale_ctl='H') elif tname == '2': w = GUViewFWImage(None, arr, coltab=ctab, origin='UL', scale_ctl='V') elif tname == '3': w = GUViewFWImage(None, arr, coltab=ctab, origin='UL', scale_ctl='') elif tname == '4': arrct = ct.array_for_color_bar(orient='H') w = GUViewFWImage(None, arrct, coltab=None, origin='UL', scale_ctl='H') w.setGeometry(50, 50, 500, 40) elif tname == '5': arrct = ct.array_for_color_bar(orient='V') w = GUViewFWImage(None, arrct, coltab=None, origin='UL', scale_ctl='V') w.setGeometry(50, 50, 40, 500) elif tname == '6': #ctab= ct.color_table_rainbow(ncolors=1000, hang1=0, hang2=360) #ctab = ct.color_table_rainbow(ncolors=1000, hang1=250, hang2=-20) #ctab = ct.color_table_monochr256() ctab = ct.color_table_interpolated() arrct = ct.array_for_color_bar(ctab, orient='H') w = GUViewFWImage(None, arrct, coltab=None, origin='UL', scale_ctl='H') w.setGeometry(50, 50, 500, 40) elif tname == '7': a = np.arange(15).reshape((5, 3)) w = GUViewFWImage(None, a, coltab=ctab, origin='UL', scale_ctl='HV') else: print 'test %s is not implemented' % tname return w.show() app.exec_()
def fill_list(self): for i in range(1, 9): item = QtGui.QListWidgetItem('%02d' % i, self.list) item.setSizeHint(QtCore.QSize(200, 30)) item._coltab_index = i #item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) lab = QtGui.QLabel(parent=None) lab.setPixmap(ct.get_pixmap(i, size=(200, 30))) self.list.setItemWidget(item, lab) item = QtGui.QListWidgetItem('cancel', self.list) self.list.setItemWidget(item, self.but_cancel)
def __init__(self, parent=None, arr=None,\ coltab=ct.color_table_rainbow(ncolors=1000, hang1=250, hang2=-20),\ origin='UL', scale_ctl='HV') : h, w = arr.shape rectax = QtCore.QRectF(0, 0, w, h) GUViewFW.__init__(self, parent, rectax, origin, scale_ctl) self._name = self.__class__.__name__ #self.scene().removeItem(self.raxi) self.coltab = coltab self.pmi = None self.set_pixmap_from_arr(arr)
def set_pixmap_from_arr(self, arr): """Input array is scailed by color table. If color table is None arr set as is. """ self.arr = arr anorm = arr if self.coltab is None else\ ct.apply_color_table(arr, ctable=self.coltab) h, w = arr.shape #print 'GUViewFWImage.set_pixmap_from_arr shape=', arr.shape self.raxes = QtCore.QRectF(0, 0, w, h) image = QtGui.QImage(anorm, w, h, QtGui.QImage.Format_ARGB32) pixmap = QtGui.QPixmap.fromImage(image) self.add_pixmap_to_scene(pixmap) self.set_view()
def test_guiviewimage(tname): print '%s:' % sys._getframe().f_code.co_name #import numpy as np #arr = np.random.random((1000, 1000)) arr = image_with_random_peaks((1000, 1000)) ctab = ct.color_table_monochr256() app = QtGui.QApplication(sys.argv) w = None if tname == '0': w = GUViewImage(None, arr, coltab=ctab, origin='UL', scale_ctl='HV', rulers='UDLR',\ margl=0.12, margr=0.10, margt=0.06, margb=0.06) elif tname == '1': w = GUViewImage(None, arr, coltab=ctab, origin='UL', scale_ctl='HV', rulers='DL',\ margl=0.12, margr=0.02, margt=0.02, margb=0.06) elif tname == '2': w = GUViewImage(None, arr, coltab=ctab, origin='UL', scale_ctl='HV', rulers='',\ margl=0, margr=0, margt=0, margb=0) elif tname == '3': ctab = ct.color_table_rainbow(ncolors=1000, hang1=250, hang2=-20) w = GUViewImage(None, arr, coltab=ctab, origin='UL', scale_ctl='HV', rulers='UL',\ margl=0.12, margr=0.02, margt=0.02, margb=0.06) else: print 'test %s is not implemented' % tname return w.connect_axes_limits_changed_to(w.test_axes_limits_changed_reception) #w.disconnect_axes_limits_changed_from(w.test_axes_limits_changed_reception) w.connect_pixmap_is_updated_to(w.test_pixmap_is_updated_reception) #w.disconnect_pixmap_is_updated_from(w.test_pixmap_is_updated_reception) w.connect_cursor_pos_value_to(w.test_cursor_pos_value_reception) #w.disconnect_cursor_pos_value_from(w.test_cursor_pos_value_reception) w.show() app.exec_()
def __init__V0(self, parent=None): QtGui.QDialog.__init__(self, parent) self.ctab_selected = None #self.list = QtGui.QListWidget(parent) #self.fill_list(lst) #self.fill_list_icons(lst_icons) # Confirmation buttons self.but_cancel = QtGui.QPushButton('&Cancel') #self.but_apply = QtGui.QPushButton('&Apply') #self.but_create = QtGui.QPushButton('&Create') #cp.setIcons() #self.but_cancel.setIcon(cp.icon_button_cancel) #self.but_apply .setIcon(cp.icon_button_ok) #self.connect(self.but_cancel, QtCore.SIGNAL('clicked()'), self.onCancel) #self.connect(self.but_apply, QtCore.SIGNAL('clicked()'), self.onApply) #self.hbox = QtGui.QVBoxLayout() #self.hbox.addWidget(self.but_cancel) #self.hbox.addWidget(self.but_apply) ##self.hbox.addStretch(1) vbox = QtGui.QVBoxLayout() for i in range(1, 9): lab = QtGui.QLabel(parent=None) lab.setPixmap(ct.get_pixmap(i, size=(200, 30))) #lab.setText('%02d'%i) # set text !!!OR!!! pixmam #lab.setContentsMargins(QtCore.QMargins(-5,-5,-5,-5)) #lab.setFixedSize(200,10) lab._coltab_index = i vbox.addWidget(lab) vbox.addStretch() vbox.addWidget(self.but_cancel) self.setLayout(vbox) self.connect(self.but_cancel, QtCore.SIGNAL('clicked()'), self.onCancel) self.showToolTips() self.setStyle()
def set_pixmap_from_arr(self, arr=None): #print 'XXXX: set_pixmap_from_arr'#, arr need_to_update_rectax = False if arr is not None: if self.arr is not None and arr.shape != self.arr.shape: need_to_update_rectax = True self.arr = arr anorm = self.arr if self.coltab is None else\ ct.apply_color_table(self.arr, self.coltab, self.amin, self.amax) h, w = self.arr.shape image = QtGui.QImage(anorm, w, h, QtGui.QImage.Format_ARGB32) pixmap = QtGui.QPixmap.fromImage(image) self.add_pixmap_to_scene(pixmap) if need_to_update_rectax: self.set_rect_axes_default(QtCore.QRectF(0, 0, w, h)) self.reset_original_image_size() #self.set_view() #self.update_my_scene() #self.check_axes_limits_changed() self.emit(QtCore.SIGNAL('pixmap_is_updated()'))
def __init__(self, parent=None, arr=None,\ coltab=ct.color_table_rainbow(ncolors=1000, hang1=250, hang2=-20),\ origin='UL', scale_ctl='HV', rulers='TBLR',\ margl=None, margr=None, margt=None, margb=None) : h, w = arr.shape rectax = QtCore.QRectF(0, 0, w, h) GUViewAxes.__init__(self, parent, rectax, origin, scale_ctl, rulers, margl, margr, margt, margb) self._name = self.__class__.__name__ #self.scene().removeItem(self.raxi) self.pmi = None mean, std = arr.mean(), arr.std() amin, amax = mean-2*std, mean+10*std # None, None self.set_intensity_limits(amin, amax) self.set_color_table(coltab) self.set_pixmap_from_arr(arr)
def test_guiviewcolorbar(tname): print '%s:' % sys._getframe().f_code.co_name #import numpy as np #arr = np.random.random((1000, 1000)) #arr = image_with_random_peaks((1000, 1000)) #ctab = ct.color_table_monochr256() ctab = ct.color_table_rainbow(ncolors=1000, hang1=250, hang2=-20) app = QtGui.QApplication(sys.argv) w = None if tname == '0': w = GUViewColorBar(None, coltab=ctab, rulers='R', margl=0, margr=0.5, margt=0.03, margb=0.03) else: print 'test %s is not implemented' % tname return w.show() app.exec_()
def __init__(self, parent=None, arr=None,\ coltab = ct.color_table_rainbow(ncolors=1000, hang1=250, hang2=-20), show_frame=True, show_buts=True) : QtGui.QWidget.__init__(self, parent) #Frame.__init__(self, parent, mlw=1, vis=show_frame) self._name = self.__class__.__name__ self.show_frame = show_frame self.show_buts = show_buts self.but_save = QtGui.QPushButton('&Save') self.but_reset = QtGui.QPushButton('&Reset') self.lab_stat = QtGui.QLabel(' Histogram\n statistics') self.lab_ibin = QtGui.QLabel('Bin info') #amin, amax, nbins, values = image_to_hist_arr(arr) #vmin, vmax = values.min(), values.max() #rectax=QtCore.QRectF(amin, vmin, amax-amin, vmax-vmin) rectax = QtCore.QRectF(0, 0, 1, 1) self.hist = GUViewHist(None, rectax, origin='DL', scale_ctl='H', rulers='DL', margl=0.12, margr=0.01, margt=0.01, margb=0.15) self.hist.connect_mean_std_updated_to(self.draw_mean_std) self.hist.connect_statistics_updated_to(self.draw_stat) self.hist.connect_cursor_bin_changed_to(self.draw_cursor_locator) self.hist._ymin = None #self.hist._ymax = 1.5 hcolor = Qt.yellow # Qt.green Qt.yellow Qt.blue #self.hist.add_hist(values, (amin,amax), pen=QtGui.QPen(hcolor, 0), brush=QtGui.QBrush(hcolor)) # vtype=np.float self.hist.add_array_as_hist(arr, pen=QtGui.QPen(hcolor, 0), brush=QtGui.QBrush(hcolor)) #self.ctab = ct.color_table_monochr256() #self.ctab = ct.color_table_rainbow(ncolors=1000, hang1=250, hang2=-20) #self.ctab = ct.color_table_interpolated() self.ctab = coltab arrct = ct.array_for_color_bar(self.ctab, orient='H') self.cbar = GUViewFWImage(None, arrct, coltab=None, origin='UL', scale_ctl='') # 'H' #self.hist.move(10,10) #self.cbar.move(50,200) #self.label = QtGui.QLineEdit(self) #self.label.move(130, 22) #self.vbox = QtGui.QVBoxLayout() #self.vbox.addWidget(self.cbar) #self.vbox.addWidget(self.hist) #self.vbox.addStretch(1) #self.setLayout(self.vbox) grid = QtGui.QGridLayout() grid.addWidget(self.hist, 0, 0, 100, 100) grid.addWidget(self.cbar, 96, 12, 4, 88) grid.addWidget(self.lab_stat, 0, 80, 10, 20) grid.addWidget(self.lab_ibin, 0, 12, 5, 20) grid.addWidget(self.but_reset, 92, 0, 4, 10) grid.addWidget(self.but_save, 96, 0, 4, 10) #grid.addWidget(self.cbar, 0, 13, 4, 86) self.setLayout(grid) self.set_tool_tips() self.set_style() self.cbar.connect_click_on_color_bar_to(self.on_colorbar) #self.hist.disconnect_mean_std_updated_from(self.draw_stat) #self.hist.disconnect_statistics_updated_from(self.draw_stat) #self.cbar.disconnect_click_on_color_bar_from(self.on_colorbar) #self.connect_color_table_is_changed_to(self.test_color_table_is_changed_reception) if self.show_buts: self.connect(self.but_save, QtCore.SIGNAL('clicked()'), self.on_but_save) self.connect(self.but_reset, QtCore.SIGNAL('clicked()'), self.on_but_reset)
def keyPressEvent(self, e): #print 'keyPressEvent, key=', e.key() if e.key() == Qt.Key_Escape: self.close() elif e.key() == Qt.Key_R: print '%s: Reset original size' % self._name self.reset_original_image_size() # see GUViewAxes elif e.key() == Qt.Key_N: print '%s: Set new pixel map of the same shape' % self._name s = self.pmi.pixmap().size() #self.set_pixmap_random((s.width(), s.height())) img = image_with_random_peaks((s.height(), s.width())) self.set_pixmap_from_arr(img) elif e.key() == Qt.Key_S: print '%s: Set new pixel map of different shape' % self._name #s = self.pmi.pixmap().size() #self.set_pixmap_random((s.width(), s.height())) sh_new = ag.random_standard((2, ), mu=1000, sigma=200, dtype=np.int) #sh_new = [(int(v) if v>100 else 100) for v in s_newh] print '%s: Set image with new shape %s' % (self._name, str(sh_new)) img = image_with_random_peaks(sh_new) self.set_pixmap_from_arr(img) elif e.key() == Qt.Key_C: print 'Reset color table' ctab = ct.next_color_table() self.set_color_table(coltab=ctab) self.set_pixmap_from_arr() elif e.key() == Qt.Key_L: nsigma = ag.random_standard((2, ), mu=3, sigma=1, dtype=np.float) arr = self.arr mean, std = arr.mean(), arr.std() amin, amax = mean - nsigma[0] * std, mean + nsigma[ 1] * std # None, None print '%s: Set intensity min=%.1f max=%.1f' % (self._name, amin, amax) #------------------------------------ self.set_intensity_limits(amin, amax) self.set_pixmap_from_arr() elif e.key() == Qt.Key_W: print '%s: change axes rect, do not change default)' % self._name v = ag.random_standard((4, ), mu=0, sigma=200, dtype=np.int) rax = QtCore.QRectF(v[0], v[1], v[2] + 1000, v[3] + 1000) print 'Set new axes rect: %s' % str(rax) self.set_rect_axes(rax, set_def=False) # def in GUView elif e.key() == Qt.Key_D: print '%s: change default axes rect, set new default' % self._name v = ag.random_standard((4, ), mu=0, sigma=200, dtype=np.int) rax = QtCore.QRectF(v[0], v[1], v[2] + 1000, v[3] + 1000) print 'Set new default axes rect: %s' % str(rax) self.set_rect_axes(rax) # def in GUView else: print self.key_usage()