/usr/share/pyshared/guidata/tests/editgroupbox.py is in python-guidata 1.6.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | # -*- coding: utf-8 -*-
#
# Copyright © 2009-2010 CEA
# Pierre Raybaut
# Licensed under the terms of the CECILL License
# (see guidata/__init__.py for details)
"""
DataSetEditGroupBox and DataSetShowGroupBox demo
These group box widgets are intended to be integrated in a GUI application
layout, showing read-only parameter sets or allowing to edit parameter values.
"""
SHOW = True # Show test in GUI-based test launcher
from guidata.qt.QtGui import QMainWindow, QSplitter
from guidata.qt.QtCore import SIGNAL
from guidata.dataset.datatypes import (DataSet, BeginGroup, EndGroup,
BeginTabGroup, EndTabGroup)
from guidata.dataset.dataitems import (ChoiceItem, FloatItem, StringItem,
DirectoryItem, FileOpenItem)
from guidata.dataset.qtwidgets import DataSetShowGroupBox, DataSetEditGroupBox
from guidata.configtools import get_icon
from guidata.qthelpers import create_action, add_actions, get_std_icon
# Local test import:
from guidata.tests.activable_dataset import ExampleDataSet
class AnotherDataSet(DataSet):
"""
Example 2
<b>Simple dataset example</b>
"""
param0 = ChoiceItem("Choice", ['deazdazk', 'aeazee', '87575757'])
param1 = FloatItem("Foobar 1", default=0, min=0)
a_group = BeginGroup("A group")
param2 = FloatItem("Foobar 2", default=.93)
param3 = FloatItem("Foobar 3", default=123)
_a_group = EndGroup("A group")
class ExampleMultiGroupDataSet(DataSet):
param0 = ChoiceItem("Choice", ['deazdazk', 'aeazee', '87575757'])
param1 = FloatItem("Foobar 1", default=0, min=0)
t_group = BeginTabGroup("T group")
a_group = BeginGroup("A group")
param2 = FloatItem("Foobar 2", default=.93)
dir1 = DirectoryItem("Directory 1")
file1 = FileOpenItem("File 1")
_a_group = EndGroup("A group")
b_group = BeginGroup("B group")
param3 = FloatItem("Foobar 3", default=123)
_b_group = EndGroup("B group")
c_group = BeginGroup("C group")
param4 = FloatItem("Foobar 4", default=250)
_c_group = EndGroup("C group")
_t_group = EndTabGroup("T group")
class OtherDataSet(DataSet):
title = StringItem("Title", default="Title")
icon = ChoiceItem("Icon", (("python.png", "Python"),
("guidata.svg", "guidata"),
("settings.png", "Settings")))
opacity = FloatItem("Opacity", default=1., min=.1, max=1)
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setWindowIcon(get_icon('python.png'))
self.setWindowTitle("Application example")
# Instantiate dataset-related widgets:
self.groupbox1 = DataSetShowGroupBox("Activable dataset",
ExampleDataSet, comment='')
self.groupbox2 = DataSetShowGroupBox("Standard dataset",
AnotherDataSet, comment='')
self.groupbox3 = DataSetEditGroupBox("Standard dataset",
OtherDataSet, comment='')
self.groupbox4 = DataSetEditGroupBox("Standard dataset",
ExampleMultiGroupDataSet, comment='')
self.connect(self.groupbox3, SIGNAL("apply_button_clicked()"),
self.update_window)
self.update_groupboxes()
splitter = QSplitter(self)
splitter.addWidget(self.groupbox1)
splitter.addWidget(self.groupbox2)
splitter.addWidget(self.groupbox3)
splitter.addWidget(self.groupbox4)
self.setCentralWidget(splitter)
self.setContentsMargins(10, 5, 10, 5)
# File menu
file_menu = self.menuBar().addMenu("File")
quit_action = create_action(self, "Quit",
shortcut="Ctrl+Q",
icon=get_std_icon("DialogCloseButton"),
tip="Quit application",
triggered=self.close)
add_actions(file_menu, (quit_action, ))
# Edit menu
edit_menu = self.menuBar().addMenu("Edit")
editparam1_action = create_action(self, "Edit dataset 1",
triggered=self.edit_dataset1)
editparam2_action = create_action(self, "Edit dataset 2",
triggered=self.edit_dataset2)
editparam4_action = create_action(self, "Edit dataset 4",
triggered=self.edit_dataset4)
add_actions(edit_menu, (editparam1_action,
editparam2_action,
editparam4_action))
def update_window(self):
dataset = self.groupbox3.dataset
self.setWindowTitle(dataset.title)
self.setWindowIcon(get_icon(dataset.icon))
self.setWindowOpacity(dataset.opacity)
def update_groupboxes(self):
self.groupbox1.dataset.set_readonly() # This is an activable dataset
self.groupbox1.get()
self.groupbox2.get()
self.groupbox4.get()
def edit_dataset1(self):
self.groupbox1.dataset.set_writeable() # This is an activable dataset
if self.groupbox1.dataset.edit():
self.update_groupboxes()
def edit_dataset2(self):
if self.groupbox2.dataset.edit():
self.update_groupboxes()
def edit_dataset4(self):
if self.groupbox4.dataset.edit():
self.update_groupboxes()
if __name__ == '__main__':
from guidata.qt.QtGui import QApplication
import sys
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
|