def qt_container(container, **kwargs): widget = QtGui.QWidget() layout = QtGui.QFormLayout(widget) widget.editor = {} widget.control = {} for control in container.controls(): editor = qt_editor(control, 'hline') if editor: widget.editor[control] = weakref.ref(editor) widget.control[control.name] = control layout.addRow(control.alias, editor) return widget
def password(): _widget = QtGui.QWidget() _layout = QtGui.QVBoxLayout(_widget) _password = QtGui.QLineEdit() _password.setEchoMode(QtGui.QLineEdit.Password) _layout.addWidget(QtGui.QLabel("Password ?")) _layout.addWidget(_password) dialog = ModalDialog(_widget) if dialog.exec_(): return _password.text()
def setTheme(self,theme = BLACK_THEME): self.curveMaterial = Material(theme['Curve'],1) self.defaultColor = QtGui.QColor(*theme['BackGround']) self.disabledBGColor = QtGui.QColor(*theme['DisabledBackGround']) self.textColor = [v/255. for v in theme['Text']]+[1.0] self.ctrlCurveColor = [v/255. for v in theme['CtrlCurve']]+[0.0] self.gridColor = [v/255. for v in theme['GridStrong']]+[0.0] self.gridColor2 = [v/255. for v in theme['GridFade']]+[0.0] self.pointColor = Material(theme['Points'],1) self.firstPointColor = Material(theme['FirstPoint'],1) self.selectedPointColor = Material(theme['SelectedPoint'],1) self.curveshape.appearance = self.curveMaterial
def __init__(self): AbstractListener.__init__(self) super(WorldBrowser, self).__init__() self.world = None QtCore.QObject.connect(self.tree, QtCore.SIGNAL('doubleClicked(const QModelIndex&)'), self.show_world_object) actionClearWorld = QtGui.QAction(QtGui.QIcon(":/images/resources/plant.png"), "Clear World", self) actionClearWorld.triggered.connect(self.clear) self._actions = [["Project", "World", actionClearWorld, 0]] add_drop_callback(self, 'openalea/interface.IImage', self.drop_object)
def __init__(self, project, parent=None): super(Preview, self).__init__(parent) wanted_size = 50 self.project = project layout = QtGui.QGridLayout() icon_name = ":/images/resources/openalea_icon2.png" if len(project.icon): if project.icon[0] is not ":": # local icon icon_name = project.path / project.icon # else native icon from oalab.gui.resources image = QtGui.QImage(icon_name) label = QtGui.QLabel() label.setPixmap(QtGui.QPixmap(image)) size = image.size() if size.height() > wanted_size or size.width() > wanted_size: # Auto-rescale if image is bigger than wanted_size x wanted_size label.setScaledContents(True) label.setMinimumSize(wanted_size, wanted_size) label.setMaximumSize(wanted_size, wanted_size) layout.addWidget(label, 0, 0) layout.addWidget( QtGui.QLabel("<b><FONT SIZE = 40>" + pretty_print(project.name) + "<\b>"), 0, 1) i = 1 for label in Project.DEFAULT_METADATA: layout.addWidget(QtGui.QLabel(label), i, 0) # GBY Review: # QLabel expects a QString and QString is equivalent to unicode # so you must convert str to unicode to support non ASCII characters correctly (for example accent in author's name) # If project meta-info encoding is utf-8, you can write projet.author.decode('utf-8') # Just put accents or greek characters in test data to check such problems # GBY Review: if amount of metainfo grows, QTextEdit can be more convenient layout.addWidget( QtGui.QLabel(pretty_print(getattr(project, label))), i, 1) i += 1 layout.addWidget(QtGui.QLabel("Items:"), i, 0, 1, 2) model_list = QtGui.QTextEdit() layout.addWidget(model_list, i + 1, 0, 1, 2) model_list.setText(html_item_summary(project)) open_button = QtGui.QPushButton("Open this project") open_button.clicked.connect(self.on_project_opened) layout.addWidget(open_button, i + 2, 0) self.setLayout(layout)
def __init__(self): QtGui.QWidget.__init__(self) self.colormap_bar = QColormapBar() self.colormap_bar.setMinimumHeight(20) self.colormap_bar.setMinimumWidth(120) self.colormap_name = "grey" # self.label = QtGui.QLabel(self) # self.label.setText("Colormap") self.combobox = QtGui.QComboBox(self) # self.setMinimumHeight(50) colormap_names = [] # colormaps_path = Path(shared_data(tissuelab, 'colormaps/grey.lut')).parent colormaps_path = shared_data(tissuelab) / 'colormaps' for colormap_file in colormaps_path.walkfiles('*.lut'): colormap_name = str(colormap_file.name[:-4]) colormap_names.append(colormap_name) colormap_names.sort() # map between string and combobox index self.map_index = {} for s in colormap_names: self.combobox.addItem(s) self.map_index[s] = self.combobox.count() - 1 self.combobox.setCurrentIndex(self.map_index[self.colormap_name]) # Fill background to avoid to see text or widget behind self.setAutoFillBackground(True) AbstractQtControlWidget.__init__(self) self.combobox.currentIndexChanged.connect(self.updateColormap) self.colormap_bar.valueChanged.connect(self.valueChanged) layout = QtGui.QHBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) # line = QtGui.QHBoxLayout(self) # line.setContentsMargins(0, 0, 0, 0) # line.addWidget(self.label) # line.addWidget(self.combobox) # layout.addLayout(line) layout.addWidget(self.combobox) layout.addWidget(self.colormap_bar) self.value_changed_signal = self.valueChanged
def __init__(self, parent=None): super(HistoryWidget, self).__init__(parent=parent) Highlighter(self) self.setAccessibleName("HistoryWidget") self.setText("") self.setLineWrapMode(QtGui.QTextEdit.NoWrap) clear_action = QtGui.QAction( QtGui.QIcon(":/images/resources/editraise.png"), "Clear History", self) QtCore.QObject.connect(clear_action, QtCore.SIGNAL('triggered(bool)'), self.clear) self._actions = [["Edit", "History", clear_action, 0]]
def raw_input_dialog(prompt=None, size=None): _widget = QtGui.QWidget() _layout = QtGui.QVBoxLayout(_widget) _line = QtGui.QLineEdit() _layout.addWidget(QtGui.QLabel("Input ?")) _layout.addWidget(_line) dialog = ModalDialog(_widget) if dialog.exec_() and _line.text(): return _line.text() else: return u'\n'
def show_splash_screen(): """Show a small splash screen to make people wait for OpenAleaLab to startup""" pix = QtGui.QPixmap(":/images/resources/splash.png") splash = QtGui.QSplashScreen(pix, QtCore.Qt.WindowStaysOnTopHint) splash.show() message = "" + metainfo.get_copyright() + \ "Version : %s\n" % (metainfo.get_version(),) + \ "Loading modules..." splash.showMessage(message, QtCore.Qt.AlignCenter | QtCore.Qt.AlignBottom) # -- make sure qt really display the message before importing the modules.-- QtGui.QApplication.processEvents() return splash
def __init__(self): QtGui.QWidget.__init__(self) layout = QtGui.QFormLayout(self) self.e_min = QtGui.QLineEdit('0') self.e_max = QtGui.QLineEdit('100') text = 'Can be an int (for instance -5) or empty (no limits)' self.e_min.setToolTip(text) self.e_min.setWhatsThis(text) self.e_max.setToolTip(text) self.e_max.setWhatsThis(text) layout.addRow(QtGui.QLabel('Minimum'), self.e_min) layout.addRow(QtGui.QLabel('Maximum'), self.e_max)
def actions(self): minilab = QtGui.QAction( QtGui.QIcon(":/images/resources/openalealogo.png"), "MiniLab", self.mainwindow) lab3d = QtGui.QAction( QtGui.QIcon(":/images/resources/openalealogo.png"), "3DLab", self.mainwindow) plantlab = QtGui.QAction( QtGui.QIcon(":/images/resources/openalealogo.png"), "PlantLab", self.mainwindow) tissuelab = QtGui.QAction( QtGui.QIcon(":/images/resources/openalealogo.png"), "TissueLab", self.mainwindow) QtCore.QObject.connect(minilab, QtCore.SIGNAL('triggered(bool)'), self.mainwindow._mini) QtCore.QObject.connect(lab3d, QtCore.SIGNAL('triggered(bool)'), self.mainwindow._lab3d) QtCore.QObject.connect(plantlab, QtCore.SIGNAL('triggered(bool)'), self.mainwindow._plant) QtCore.QObject.connect(tissuelab, QtCore.SIGNAL('triggered(bool)'), self.mainwindow._tissue) _actions = [["Extension", "Select an Extension", minilab, 0], ["Extension", "Select an Extension", lab3d, 0], ["Extension", "Select an Extension", plantlab, 0], ["Extension", "Select an Extension", tissuelab, 0]] return None
def project_icon(self, project): # Propose icon by default. # If project have another one, use it icon_project = QtGui.QIcon(":/images/resources/openalea_icon2.png") icon = icon_project if hasattr(project, "icon"): icon_name = project.icon if len(icon_name): if icon_name[0] is not ":": # local icon icon_name = project.path / icon_name # else native icon from oalab.gui.resources icon = QtGui.QIcon(icon_name) return icon
def __init__(self, session=None, controller=None, parent=None): super(HelpWidget, self).__init__(parent=parent) self.setAccessibleName("HelpWidget") actionHelpOpenAlea = QtGui.QAction( QtGui.QIcon(":/images/resources/openalealogo.png"), "OpenAlea WebSite", self) actionHelpGForge = QtGui.QAction( QtGui.QIcon(":/images/resources/git.png"), "Submit Issues", self) actionHelpTasks = QtGui.QAction( QtGui.QIcon(":/images/resources/gforge.png"), "See Tasks", self) actionEditPref = QtGui.QAction( QtGui.QIcon(":/images/resources/node.png"), "Preferences", self) self.connect(actionHelpOpenAlea, QtCore.SIGNAL('triggered(bool)'), self.openWebsiteOpenalea) self.connect(actionHelpGForge, QtCore.SIGNAL('triggered(bool)'), self.openOALabIssues) self.connect(actionHelpTasks, QtCore.SIGNAL('triggered(bool)'), self.openOALabTasks) actionEditPref.triggered.connect(self.open_preferences) self._actions = [ ["Help", "Website", actionHelpOpenAlea, 0], ["Help", "Website", actionHelpGForge, 0], ["Help", "Settings", actionEditPref, 0], ] self.setText(default_text) register_helper(self)
def __init__(self, items, parent=None): QtGui.QDialog.__init__(self, parent, QtCore.Qt.WindowOkButtonHint| QtCore.Qt.WindowCancelButtonHint) self.setWindowTitle("Select a tool") self.__l = QtGui.QVBoxLayout() self.__itemList = QtGui.QListWidget() self.__buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok| QtGui.QDialogButtonBox.Cancel) self.__l.addWidget(self.__itemList) self.__l.addWidget(self.__buttons) self.setLayout(self.__l) self.__itemList.addItems(items) self.__buttons.accepted.connect(self.accept) self.__buttons.rejected.connect(self.reject)
def __init__(self, lst, labels=None): QtGui.QWidget.__init__(self) if labels is None: labels = {} self._layout = QtGui.QVBoxLayout(self) self._cb = QtGui.QComboBox() self._lst = lst for i, mimetype in enumerate(self._lst): self._cb.addItem(labels.get(mimetype, mimetype)) self._layout.addWidget(QtGui.QLabel("Drop as ...")) self._layout.addWidget(self._cb)
def __init__(self, vertex, graph, parent=None): QtGui.QGraphicsEllipseItem.__init__(self, 0.0, 0.0, self.__vertex_size__.width(), self.__vertex_size__.height(), parent) Vertex.__init__(self, vertex, graph) self.setZValue(1.0) #we choose the avocado colors self.setBrush(QtGui.QBrush(QtCore.Qt.yellow)) pen = QtGui.QPen(QtCore.Qt.darkGreen) pen.setWidth(self.__border_size__ - 2) self.setPen(pen) self.initialise_from_model()
def get_icon2(item): """ Return Icon object depending of the type of item """ if(isinstance(item, Package)): # Try to load package specific icon icon = item.metainfo.get("icon", None) if(icon): icon = os.path.join(item.path, icon) return QtGui.QIcon(icon) # Standard icon return icon_dict[type(item)] # Get icon from dictionary elif(icon_dict.has_key(type(item))): return icon_dict[type(item)] else: return QtGui.QIcon(":/icons/pseudopkg.png")
def __init__(self, world={}, parent=None): super(InAndOutModel, self).__init__(parent=parent) self.world = world layout = QtGui.QGridLayout(self) self.inp = InputsModel(self.world) self.outp = OutputsModel() layout.addWidget(self.inp) layout.addWidget(self.outp) self.ok_button = QtGui.QPushButton("Ok") self.ok_button.clicked.connect(self.print_current) layout.addWidget(self.ok_button) self.setLayout(layout)
def __set_curves(self): self.__refreshTimout.stop() crvs = self.__crvs if len(crvs) == len(self.__curveViews): #refresh the existing views for i in range(len(crvs)): pos, c = crvs[i] v = self.__curveViews[i] v.setCurve(c) v.pos = pos self.__curveLabels[i].setValue(pos) else: #recreate them del self.__curveViews[:] del self.__curveLabels[:] scrolledWidget = QtGui.QWidget(self) layout = QtGui.QBoxLayout(self.orientation) scrolledWidget.setLayout(layout) # -- used to lock the bounding cross section line edits -- minPos = min(crvs, key=lambda x: x[0])[0] maxPos = max(crvs, key=lambda x: x[0])[0] for pos, c in crvs: frame = QtGui.QFrame(scrolledWidget) frame.setFrameShape(QtGui.QFrame.Panel) frame.setFrameShadow(QtGui.QFrame.Raised) subLay = QtGui.QBoxLayout(QtGui.QBoxLayout.TopToBottom) frame.setLayout(subLay) w = CurvePanel.SimpleCurve2DView(pos, c, frame) w.clicked.connect(self.curveEditRequested) w.deleteRequested.connect(self.curveDeleteRequested) label = QtGui.QDoubleSpinBox() label.setRange(-100000., 100000.) label.setValue(pos) label.setAlignment(QtCore.Qt.AlignHCenter) sender = SenderWidget(label, float, self) if pos in [minPos, maxPos]: label.setEnabled(False) else: sender.valueChanged.connect(self.__on_label_changed) subLay.addWidget(w, QtCore.Qt.AlignHCenter) subLay.addWidget(label, QtCore.Qt.AlignHCenter) layout.addWidget(frame) self.__curveViews.append(w) self.__curveLabels.append(label) self.setWidget(scrolledWidget)
def draw(self): self.setBackgroundColor(QtGui.QColor(0, 0, 0)) glDisable(GL_LIGHTING) glEnable(GL_LINE_SMOOTH) glEnable(GL_BLEND) glEnable(GL_ALPHA_TEST) glAlphaFunc(GL_GREATER, 0.1) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glHint(GL_LINE_SMOOTH_HINT, GL_NICEST) glMatrixMode(GL_MODELVIEW) glPushMatrix() mat = 16 * [0] mat[0] = self.factor[0] mat[5] = self.factor[1] mat[10] = self.factor[2] mat[15] = 1. glMultMatrixd(mat) if self.__profile is not None: self.discretizer.clear() if self.__positionCurve: for addon in self._addons: addon._draw(self.renderer) glColor4f(0.0, 1.0, 0.0, 1.0) glDisable(GL_DEPTH_TEST) self.__positionCurve.apply(self.renderer) glEnable(GL_DEPTH_TEST) glPopMatrix()
def _get_color(self, color): """ Returns a QColor built from a Pygments color string. """ qcolor = QtGui.QColor() qcolor.setRgb(int(color[:2], base=16), int(color[2:4], base=16), int(color[4:6], base=16)) return qcolor
def __init__(self, parent=None): # TODO : scroll doesn't work yet super(Pane, self).__init__() self.setObjectName('Pane') self.group_name = list() self._layout = QtGui.QGridLayout(self) self.fine_tune()
def menus(self): actions = [action[2] for action in self.toolbar_actions()] menu = QtGui.QMenu('File', self) menu.addActions(actions) menu.addSeparator() menu.addMenu(self.menu_available_projects) return [menu]
def get_path(self, p1, p2): self.p1 = p1 self.p2 = p2 path = QtGui.QPainterPath(self.p1) points = [] sd = self.p2 - self.p1 if abs(sd.x()) <= self.WIDTH: # draw a line pass elif sd.y() < 2 * self.WIDTH: s1 = self.p1 + QtCore.QPointF(0, self.WIDTH) d1 = self.p2 - QtCore.QPointF(0, self.WIDTH) s1d1 = d1 - s1 s2 = s1 + QtCore.QPointF(s1d1.x() / 2., 0) d2 = s2 + QtCore.QPointF(0, s1d1.y()) points.extend([s1, s2, d2, d1]) else: s1 = self.p1 + QtCore.QPointF(0, sd.y() / 2.) d1 = self.p2 - QtCore.QPointF(0, sd.y() / 2.) points.extend([s1, d1]) points.append(self.p2) for pt in points: path.lineTo(pt) return path
def main(): import sys app = QtGui.QApplication(sys.argv) from openalea.oalab.world import World world = World() world["obj1"] = "plop" world["obj2"] = "plop2" obj1 = world["obj1"] obj2 = world["obj2"] obj1.set_attribute('a1', 1, 'IInt') obj1.set_attribute('a2', True, 'IBool') obj2.set_attribute('b1', 2.34, 'IFloat') wid1 = WorldControlPanel(style=WorldControlPanel.StylePanel) wid1.set_world(world) wid1.show() wid2 = WorldControlPanel(style=WorldControlPanel.StyleTableView) wid2.set_world(world) wid2.show() app.exec_()
class Data(HasName): """""" # -- PROPERTIES -- obj = property(lambda x:x.__obj) registerable = property(lambda x:True) mimetype = property(lambda x:x.__mimetype) icon = property(lambda x:x.__dt.icon if x.__dt else QtGui.QIcon()) factory_name = property(lambda x:x.__dt.name) type = property(lambda x:"b") hidden = property(lambda x:x.__dt.hidden) def __init__(self, name, obj, **kwargs): HasName.__init__(self, name) self.__obj = obj self.__mimetype = None self.__props = kwargs.copy() self.__dt = None def get_inner_property(self, key): return self.__props.get(key) def __set_data_type(self, dt, mimetype): assert isinstance(dt, DataFactory) self.__dt = dt self.__mimetype = mimetype def to_stream(self, stream): self.__dt.data_to_stream(self, stream)
def main(): import sys app = QtGui.QApplication(sys.argv) selector = ProjectExplorer() selector.show() app.exec_()
def doit(self): app = QtGui.QApplication([]) # self.widget = MyWidget() # self.widget.show() pgl.Viewer.start() self.start() app.exec_()
def mouseMoveEvent(self, event): if self.lowerPressed != QtGui.QStyle.SC_SliderHandle and self.upperPressed != QtGui.QStyle.SC_SliderHandle: event.ignore() return opt = QtGui.QStyleOptionSlider() self.initStyleOption(opt) m = self.style().pixelMetric(QtGui.QStyle.PM_MaximumDragDistance, opt, self) newPosition = self.pixelPosToRangeValue(self.pick(event.pos()) - self.offset) if m >= 0: r = self.rect().adjusted(-m, -m, m, m) if not r.contains(event.pos()): newPosition = self.position # pick the preferred handle on the first movement if self.firstMovement: # if self.lower == self.upper: # if newPosition < self.lowerValue(): # self.swapControls() # self.firstMovement = False # else: self.firstMovement = False if self.lowerPressed == QtGui.QStyle.SC_SliderHandle: newPosition = min(newPosition, self.upper) self.setLowerPosition(newPosition) elif self.upperPressed == QtGui.QStyle.SC_SliderHandle: newPosition = max(newPosition, self.lower) self.setUpperPosition(newPosition) event.accept()
def qicon(filename): if filename is None: return QtGui.QIcon(get_shared_data('icons/oxygen_application-x-desktop.png')) if filename.startswith(':/'): return QtGui.QIcon(filename) else: path = Path(filename) if not path.isfile(): path = get_shared_data(filename) if path is None: path = get_shared_data('icons/%s' % filename) if path: return QtGui.QIcon(path) else: return QtGui.QIcon(":/images/resources/%s" % filename)
def open_color_dialog(self): old_color = self.color() color = None if len(old_color) == 3: col = QtGui.QColorDialog.getColor(QtGui.QColor(*old_color), self) if col.isValid(): color = (col.red(), col.green(), col.blue()) elif len(old_color) == 4: col, ok = QtGui.QColorDialog.getRgba(QtGui.qRgba(*old_color), self) if ok: col = QtGui.QColor.fromRgba(col) color = (col.red(), col.green(), col.blue(), col.alpha()) else: msg = "unable to display this color: %s" % str(self._color) raise ValueError(msg) if color is not None: self.set_value(color)