def setColorColumn(self): self.color_list = self.color_list[0:self.num_buckets] for i in range(self.num_buckets): colorPB = QPushButton() colorPB.setStyleSheet("QPushButton { background-color: %s; margin: 1px; border: 0px; }" % self.color_list[i]) colorPB.connect(colorPB, SIGNAL('clicked()'), self.makeChooseColor(colorPB,i)) self.tbl_Colors.setCellWidget(i,0,colorPB)
def _get_label(self): try: icon = QIcon(':/icons/users_deconnection.png') widget = QPushButton(icon, '') if self.fetcher.canKill(): widget.connect(widget, SIGNAL('clicked(bool)'), lambda b: ArgDataKill.kill(self.fetcher, self.value, widget)) else: widget.setEnabled(False) return widget except AttributeError: return self.value
def buildInterface(self, config): #<server uri> self.uri = QLineEdit() self.texts.add(self.uri) self.connect(self.uri, SIGNAL('textChanged(QString)'), self.setUri) self.connect(self.uri, SIGNAL('textChanged(QString)'), self.signalModified) self.connect(self.uri, SIGNAL('textEdited(QString)'), self.helpURI) self.connect(self.uri, SIGNAL('editingFinished()'), self.noHelpURI) self.connect(self.uri, SIGNAL('editingFinished()'), self.updateUri) self.form.addRow(tr('LDAP Server(s) uri'), self.uri) self.uri.setToolTip(help_uri_tooltip) self.connect(self.uri, SIGNAL('returnPressed()'), self.signalModified) self.uri_message_area = MessageArea() self.empty_uri_label = QLabel() self.form.addRow(self.empty_uri_label, self.uri_message_area) self.empty_uri_label.hide() self.uri_message_area.hide() self.uri_message_area.setMessage(help_uri_title, help_uri_message_area) self.numeric_uri_warning = MessageArea() empty = QLabel() self.form.addRow(empty, self.numeric_uri_warning) empty.hide() self.numeric_uri_warning.hide() self.numeric_uri_warning.warning(numeric_warning_title, numeric_warning) self.numeric_uri_warning.setWidth(60) #</server uri> #<other fields> for args in self._genTextFieldsData(): text_input = self.addTextInput(*args[1:]) setattr(self, args[0], text_input) self.connect(text_input, SIGNAL('editingFinished(QString)'), self.valid) #</other fields> self.ssl_box = self.mkSslBox() self.connect(self.ssl_box, SIGNAL('toggled(bool)'), self.toggleSsl) self.form.addRow(self.ssl_box) self.form.addRow(separator()) test_widget = QPushButton(tr("Test this configuration")) self.form.addRow("", test_widget) test_widget.connect(test_widget, SIGNAL('clicked()'), self.test_ldap)
def __init__(self, ingredient, parent=None): QtGui.QWidget.__init__(self, parent) self.ingredient = ingredient layout = QVBoxLayout() self.setLayout(layout) formlayout = QtGui.QFormLayout() layout.addLayout(formlayout) layout.addWidget(QLabel("Changes to Current Amount \nwill not be reflected in graphs.")) self.inputs = {} self.fields = ('name', 'barcode', 'size', 'current_amount', 'threshold', 'potency', 'note', 'hidden') for a in self.fields: value = getattr(ingredient, a) vt = type(value) if vt in (str, unicode): i = QLineEdit(text=value) elif vt in (int, float, long): i = QDoubleSpinBox() i.setDecimals(0) i.setRange(0, 10000) i.setSuffix(" mL") i.setValue(value) if a == "potency": i.setDecimals(2) i.setSuffix("%") if a == "hidden": i = QtGui.QCheckBox("Hidden from shopping list") i.setChecked(value) label = a.replace("_", " ").title()+":" formlayout.addRow(label, i) self.inputs.update({a:i}) save = QPushButton("Save") save.connect(save, SIGNAL("clicked()"), self.save_data) layout.addWidget(save)
"programming, with high-quality technical articles " "written by Qt experts.") textWindow = mdiArea.addSubWindow(textEdit) textWindow.setWindowTitle("A Text Editor") label = QLabel() label.setPixmap(QPixmap("../../images/qt-logo.png")) labelWindow = mdiArea.addSubWindow(label) labelWindow.setWindowTitle("A Label") items = (("Henry", 23), ("Bill", 56), ("Susan", 19), ("Jane", 47)) table = QTableWidget(len(items), 2) for i in range(len(items)): name, age = items[i] item = QTableWidgetItem(name) table.setItem(i, 0, item) item = QTableWidgetItem(str(age)) table.setItem(i, 1, item) tableWindow = mdiArea.addSubWindow(table) tableWindow.setWindowTitle("A Table Widget") mdiArea.show() changer = Changer(mdiArea) button = QPushButton("Cascade") button.connect(button, SIGNAL("clicked()"), changer.change) button.show() sys.exit(app.exec_())
def makeColorButton(self, row, color=None): colorPB = QPushButton() if (not color is None): colorPB.setStyleSheet("QPushButton { background-color: %s; margin: 1px; border: 0px; }" % color) colorPB.connect(colorPB, SIGNAL('clicked()'), self.makeChooseColor(colorPB,row)) self.tbl_Colors.setCellWidget(row,0,colorPB)
class OptionsLayout(QTabWidget): ''' Manages right panel. Provides general informations, navigation and timestamp selection. Navigation allow user to zoom in timeline. Timestamp selection allow user to select which timestamp to display with which color. ''' def __init__(self, parent): QTabWidget.__init__(self) self.setTabPosition(QTabWidget.East) self.init(parent) self.initShape() def init(self, parent): self.VFS = libvfs.VFS.Get() self.timeline = parent self.swapIndex = -1 self.swapColor = '' self.metricIndex = -1 self.configuration = [] self.zoom = False self.exportedNode = None def initShape(self): self.h = QHBoxLayout() self.vbox = QVBoxLayout() self.vbox.setMargin(0) self.vbox.setSpacing(0) self.vbox.setAlignment(Qt.AlignTop) self.setLayout(self.vbox) self.infoBox = QGroupBox('Global information') # self.infoBox.setFlat(True) self.totalNodes = QLabel('No time found in nodes') self.startTime = QLabel('No start time') self.endTime = QLabel('No end time') self.navBox = QGroupBox('Navigation') self.selStartTime = QLabel('No selection start time') self.selEndTime = QLabel('No selection end time') self.buttonLayout = QHBoxLayout() self.zoomButton = QPushButton('Zoom') self.zoomButton.setEnabled(False) self.zoomButton.connect(self.zoomButton, SIGNAL("clicked(bool)"), self.zoomClick) self.dezoomButton = QPushButton('Original Size') self.dezoomButton.setEnabled(False) self.dezoomButton.connect(self.dezoomButton, SIGNAL("clicked(bool)"), self.dezoomClick) self.exportButton = QPushButton('Export') self.exportButton.setEnabled(False) self.exportButton.connect(self.exportButton, SIGNAL("clicked(bool)"), self.exportClick) self.buttonLayout.setAlignment(Qt.AlignLeft) self.buttonLayout.addWidget(self.zoomButton) self.buttonLayout.addWidget(self.dezoomButton) self.selectedNodes = QLabel('Nothing selected') self.infoLayout = QVBoxLayout() self.infoLayout.setAlignment(Qt.AlignTop) self.infoLayout.addWidget(self.totalNodes) self.infoLayout.addWidget(self.startTime) self.infoLayout.addWidget(self.endTime) self.infoBox.setLayout(self.infoLayout) self.navLayout = QVBoxLayout() self.navLayout.setAlignment(Qt.AlignTop) self.navLayout.addWidget(self.selStartTime) self.navLayout.addWidget(self.selEndTime) self.navLayout.addLayout(self.buttonLayout) self.navLayout.addWidget(self.selectedNodes) self.navLayout.addWidget(self.exportButton) self.navBox.setLayout(self.navLayout) self.familyLayout = QVBoxLayout() self.familyLayout.setMargin(0) self.familyLayout.setSpacing(0) self.familyWidget = QWidget() self.familyWidget.setLayout(self.familyLayout) self.familyScroll = QScrollArea() self.insertTab(0, self.infoBox, 'Global') self.insertTab(1, self.navBox, 'Navigation') self.insertTab(2, self.familyScroll, 'Display') def newInformations(self): if self.timeline.timesCount > 1: sTimes = str(self.timeline.timesCount) + ' time values' else: sTimes = 'One time value' if self.timeline.nodeCount > 1: sNodes = str(self.timeline.nodeCount) + ' nodes' else: sNodes = 'one node' self.totalNodes.setText(sTimes + '\n' + sNodes) if self.timeline.baseDateMin != self.timeline.dateMin: self.startTime.setText('From ' + str(self.timeline.fromUSec(self.timeline.baseDateMin).strftime('%d.%m.%Y %H:%M:%S'))) if self.timeline.selDateMin: self.selStartTime.setText('From ' + str(self.timeline.fromUSec(self.timeline.selDateMin).strftime('%d.%m.%Y %H:%M:%S'))) else: self.selStartTime.setText('No selection start time') if self.timeline.baseDateMax != self.timeline.dateMax: self.endTime.setText('To ' + str(self.timeline.fromUSec(self.timeline.baseDateMax).strftime('%d.%m.%Y %H:%M:%S'))) if self.timeline.selDateMax: self.selEndTime.setText('To ' + str(self.timeline.fromUSec(self.timeline.selDateMax).strftime('%d.%m.%Y %H:%M:%S'))) else: self.selEndTime.setText('No selection end time') def dumpOptionsConf(self): for family in self.configuration: if not family[1]: print family[0] + ': empty' else: print family[0] + ':' for time in family[1]: print '\t' + time[0] + ':' for param in time[1]: print '\t\t' + param[0] + ':', param[1] def createMetricTools(self): ''' Called once countThread is over. ''' if not self.configuration: # First, create configuration dictionary i = 0 for timeFamily, timeList in self.timeline.timeMap.items(): if len(timeList): # One sub dictionary per time family self.configuration.append([timeFamily, []]) for oneMetric in timeList: # One sub sub dictionary per family sub time # checked indicate if item is displayed # color indicate which color to use if i < len(self.timeline.colors): self.configuration[-1][1].append([oneMetric, [['checked', True], ['color', self.timeline.colors[i][0]], ['checkBox', None], ['colorWidget', None], ['colorWidgetIndex', -1], ['orderedNodeList', {'dates':None, 'nodes':None}], ['dateLimits', [long(0), long(0xffffffffffffffff)]], ['mainPixmap', [True, None]], ['zoomPixmap', [True, None]]]]) else: self.configuration[-1][1].append([oneMetric, [['checked', False], ['color', ''], ['checkBox', None], ['colorWidget', None], ['colorWidgetIndex', -1], ['orderedNodeList', {'dates':None, 'nodes':None}], ['dateLimits', [long(0), long(0xffffffffffffffff)]], ['mainPixmap', [True, None]], ['zoomPixmap', [True, None]]]]) i += 1 else: self.configuration.append([timeFamily, []]) # Configuration object created, now create graphical view of it # self.dumpOptionsConf() i = 0 for family in self.configuration: if family[1]: box = QGroupBox(family[0]) oneTime = QVBoxLayout() for time in family[1]: hbox = QHBoxLayout() time[1][2][1] = QCheckBox(':'.join(time[0])) self.connect(time[1][2][1], SIGNAL("stateChanged(int)"), self.checkboxClick) time[1][3][1] = QComboBox() for color in self.timeline.colors: time[1][3][1].addItem(color[0]) palette = time[1][2][1].palette() if i < len(self.timeline.colors): time[1][2][1].setChecked(time[1][0][1]) # Colorize foreground palette.setColor(QPalette.WindowText, self.timeline.colors[i][1]) time[1][3][1].setCurrentIndex(i) time[1][4][1] = i else: # In case every colors are already used, don't check time (default) and don't select any color palette.setColor(QPalette.WindowText, Qt.gray) time[1][0][1] = False time[1][3][1].setEnabled(False) time[1][2][1].setPalette(palette) self.connect(time[1][3][1], SIGNAL("currentIndexChanged(const QString&)"), self.colorChange) hbox.addWidget(time[1][2][1]) hbox.addWidget(time[1][3][1]) oneTime.addLayout(hbox) i += 1 box.setLayout(oneTime) optimum = box.minimumSizeHint() box.setFixedSize(optimum) if optimum.width() > self.familyLayout.sizeHint().width(): geom = QRect(0, 0, optimum.width(), self.familyLayout.sizeHint().height() + optimum.height()) else: geom = QRect(0, 0, self.familyLayout.sizeHint().width(), self.familyLayout.sizeHint().height() + optimum.height()) self.familyLayout.addWidget(box) self.familyLayout.setGeometry(geom) self.familyWidget.setFixedSize(geom.width(), geom.height()) self.familyScroll.setWidget(self.familyWidget) else: # Configuration object already created, we are called because am item has been # unchecked or its color has changed. pass def colorChange(self, colorText): loop = 2 while loop: i = 0 for family in self.configuration: for time in family[1]: if time[1][3][1]: if QString(time[1][1][1]) != time[1][3][1].currentText() and self.swapIndex == -1 and self.metricIndex == -1 and time[1][3][1].isEnabled(): # This selection has just been changed self.swapColor = time[1][1][1] self.swapIndex = time[1][4][1] time[1][1][1] = str(colorText) #Color palette = time[1][2][1].palette() palette.setColor(QPalette.WindowText, self.timeline.colors[time[1][3][1].currentIndex()][1]) time[1][2][1].setPalette(palette) time[1][4][1] = time[1][3][1].currentIndex() time[1][7][1][0] = True time[1][8][1][0] = True self.metricIndex = i if QString(time[1][1][1]) == colorText and self.swapIndex != -1 and self.metricIndex != i and time[1][3][1].isEnabled(): # This selection is impacted because color is the same as the one just selected # Changing color relaunch another signal. time[1][1][1] = self.swapColor time[1][4][1] = self.swapIndex time[1][3][1].setCurrentIndex(self.swapIndex) time[1][7][1][0] = True time[1][8][1][0] = True #Color palette = time[1][2][1].palette() palette.setColor(QPalette.WindowText, self.timeline.colors[time[1][3][1].currentIndex()][1]) time[1][2][1].setPalette(palette) self.metricIndex = -1 i += 1 loop -= 1 # if self.swapColor == '': # Swap already done ; redraw self.timeline.updatePaintingArea() self.swapIndex = -1 self.swapColor = '' self.metricIndex = -1 def checkboxClick(self, newState): self.selectedNodes.setText('Nothing selected') self.zoomButton.setEnabled(False) self.exportButton.setEnabled(False) for family in self.configuration: for time in family[1]: if time[1][2][1]: palette = time[1][2][1].palette() if not time[1][2][1].checkState() and time[1][0][1]: # This box has just been unchecked time[1][0][1] = False time[1][3][1].setEnabled(False) palette.setColor(QPalette.WindowText, Qt.gray) elif time[1][2][1].checkState() and not time[1][0][1]: # This box has just been checked time[1][0][1] = True time[1][3][1].setEnabled(True) # Deactivate color already used palette.setColor(QPalette.WindowText, self.timeline.colors[time[1][3][1].currentIndex()][1]) time[1][1][1] = self.timeline.colors[time[1][3][1].currentIndex()][0] time[1][4][1] = time[1][3][1].currentIndex() time[1][7][1][0] = True time[1][8][1][0] = True for family2 in self.configuration: # sure, 2 is ugly, it is used to search color to remove for time2 in family2[1]: if time2[1][3][1] and time2[1][3][1].isEnabled(): if self.timeline.colors[time2[1][3][1].currentIndex()][0] == self.timeline.colors[time[1][3][1].currentIndex()][0] and time2[1][3][1] != time[1][3][1]: palette2 = time2[1][2][1].palette() time2[1][0][1] = False time2[1][2][1].setChecked(False) time2[1][3][1].setEnabled(False) palette2.setColor(QPalette.WindowText, Qt.gray) time2[1][2][1].setPalette(palette2) time[1][2][1].setPalette(palette) self.timeline.updatePaintingArea() def zoomClick(self, clickState): self.timeline.maxOccZoom = 0 rect = self.timeline.ploter.selectionRect.rect() newSelDateMin = self.timeline.draw.findXTime(rect.x()) newSelDateMax = self.timeline.draw.findXTime(rect.x() + rect.width()) self.timeline.selDateMin = self.timeline.toUSec(newSelDateMin) self.timeline.selDateMax = self.timeline.toUSec(newSelDateMax) self.newInformations() self.dezoomButton.setEnabled(True) self.zoomButton.setEnabled(False) self.exportButton.setEnabled(False) txt = self.selectedNodes.text().__str__() self.selectedNodes.setText(txt[:txt.rfind(' ')] + ' displayed') self.zoom = True self.timeline.updatePaintingArea(True) def dezoomClick(self, clickState): self.dezoomButton.setEnabled(False) self.zoomButton.setEnabled(False) self.exportButton.setEnabled(False) self.zoom = False self.timeline.selDateMin = None self.timeline.selDateMax = None self.timeline.maxOccZoom = 0 self.newInformations() for family in self.configuration: for time in family[1]: if time[1][8][1]: time[1][8][1][0] = True time[1][8][1][1] = None self.timeline.updatePaintingArea() def exportClick(self, clickState): rect = self.timeline.ploter.selectionRect.rect() exportSelDateMin = self.timeline.draw.findXTime(rect.x()) exportSelDateMax = self.timeline.draw.findXTime(rect.x() + rect.width()) for family in self.configuration: for time in family[1]: if time[1][0][1]: nodes = [] everyNodes = self.timeline.elementsInRangeToNodeList(time[1][5][1], self.timeline.toUSec(exportSelDateMin), self.timeline.toUSec(exportSelDateMax)) for oneGroupNode in everyNodes: for node in oneGroupNode: nodes.append(node) if len(nodes): if not self.exportedNode: # Create /timeline if needed root = vfs.vfs().getnode('/Bookmarks') baseNode = Node('timeline', 0, root) baseNode.__disown__() baseNode.setDir() e = event() e.thisown = False e.value = RCVariant(Variant(baseNode)) self.VFS.notify(e) # Create /timeline/<ParentName> self.exportedNode = Node(self.timeline.node.name(), 0, baseNode) self.exportedNode.__disown__() self.exportedNode.setDir() timeBaseName = self.exportedNode.absolute() + '/' + str(exportSelDateMin.strftime('%d.%m.%Y %H:%M:%S')) + ' to ' + str(exportSelDateMax.strftime('%d.%m.%Y %H:%M:%S')) timeBaseNode = vfs.vfs().getnode(timeBaseName) if not timeBaseNode: # Create /timeline/<ParentName>/dateStart to dateEnd/<Module:FullTimestampAttributePath>/ timeBaseNode = Node(str(exportSelDateMin.strftime('%d.%m.%Y %H:%M:%S')) + ' to ' + str(exportSelDateMax.strftime('%d.%m.%Y %H:%M:%S')), 0, self.exportedNode) timeBaseNode.__disown__() timeBaseNode.setDir() baseFamilyName = timeBaseNode.absolute() + '/' + ':'.join([family[0]] + time[0]) baseFamilyNode = vfs.vfs().getnode(baseFamilyName) if not baseFamilyNode: # Create /timeline/<ParentName>/dateStart to dateEnd//<Module:FullTimestampAttributePath> if needed baseFamilyNode = Node(':'.join([family[0]] + time[0]), 0, timeBaseNode) baseFamilyNode.__disown__() baseFamilyNode.setDir() for node in nodes: # Add each node in array as child l = VLink(node, baseFamilyNode) l.__disown__()
# lw.addItems(['a', '1', '2', 'a(1,2)', 'a(1.2)', 'a(2,1)', '2,1']) items = ['a(1,2)', '(0,2)e', 'b(1,1)', 'a(2,1)', '(99,100)', '(100,99)'] # lw.addItems(items) for item in items: QListWidgetItem(item, lw) l = QVBoxLayout() l.addWidget(lw) l.addWidget(lw.filter_line_edit_factory()) l.addWidget(lw.all_selected_check_box_factory()) l.addWidget(lw.invert_selection_push_button_factory('&Invert Selection')) l.addWidget(lw.sort_check_box_factory()) import random button = QPushButton('add random') button.connect(button, SIGNAL('clicked(bool)'), lambda: lw.addItem(random.choice(['x','y','z']), True)) l.addWidget(button) button2 = QPushButton('remove random') button2.connect(button2, SIGNAL('clicked(bool)'), lambda: lw.pop(random.randint(0, lw.count()-1))) l.addWidget(button2) self = QWidget() self.setLayout(l) self.setGeometry(600, 400, 200, 480) self.setWindowTitle(lw.__class__.__name__) self.show() # lw.select(-2) # lw.select(9) exit(app.exec_())
class OptionsLayout(QTabWidget): ''' Manages right panel. Provides general informations, navigation and timestamp selection. Navigation allow user to zoom in timeline. Timestamp selection allow user to select which timestamp to display with which color. ''' def __init__(self, parent): QTabWidget.__init__(self) self.setTabPosition(QTabWidget.East) self.init(parent) self.initShape() def init(self, parent): self.VFS = libvfs.VFS.Get() self.timeline = parent self.swapIndex = -1 self.swapColor = '' self.metricIndex = -1 self.configuration = [] self.zoom = False self.exportedNode = None def initShape(self): self.h = QHBoxLayout() self.vbox = QVBoxLayout() self.vbox.setMargin(0) self.vbox.setSpacing(0) self.vbox.setAlignment(Qt.AlignTop) self.setLayout(self.vbox) self.infoBox = QGroupBox('Global information') # self.infoBox.setFlat(True) self.totalNodes = QLabel('No time found in nodes') self.startTime = QLabel('No start time') self.endTime = QLabel('No end time') self.navBox = QGroupBox('Navigation') self.selStartTime = QLabel('No selection start time') self.selEndTime = QLabel('No selection end time') self.buttonLayout = QHBoxLayout() self.zoomButton = QPushButton('Zoom') self.zoomButton.setEnabled(False) self.zoomButton.connect(self.zoomButton, SIGNAL("clicked(bool)"), self.zoomClick) self.dezoomButton = QPushButton('Original Size') self.dezoomButton.setEnabled(False) self.dezoomButton.connect(self.dezoomButton, SIGNAL("clicked(bool)"), self.dezoomClick) self.exportButton = QPushButton('Export') self.exportButton.setEnabled(False) self.exportButton.connect(self.exportButton, SIGNAL("clicked(bool)"), self.exportClick) self.buttonLayout.setAlignment(Qt.AlignLeft) self.buttonLayout.addWidget(self.zoomButton) self.buttonLayout.addWidget(self.dezoomButton) self.selectedNodes = QLabel('Nothing selected') self.infoLayout = QVBoxLayout() self.infoLayout.setAlignment(Qt.AlignTop) self.infoLayout.addWidget(self.totalNodes) self.infoLayout.addWidget(self.startTime) self.infoLayout.addWidget(self.endTime) self.infoBox.setLayout(self.infoLayout) self.navLayout = QVBoxLayout() self.navLayout.setAlignment(Qt.AlignTop) self.navLayout.addWidget(self.selStartTime) self.navLayout.addWidget(self.selEndTime) self.navLayout.addLayout(self.buttonLayout) self.navLayout.addWidget(self.selectedNodes) self.navLayout.addWidget(self.exportButton) self.navBox.setLayout(self.navLayout) self.familyLayout = QVBoxLayout() self.familyLayout.setMargin(0) self.familyLayout.setSpacing(0) self.familyWidget = QWidget() self.familyWidget.setLayout(self.familyLayout) self.familyScroll = QScrollArea() self.insertTab(0, self.infoBox, 'Global') self.insertTab(1, self.navBox, 'Navigation') self.insertTab(2, self.familyScroll, 'Display') def newInformations(self): if self.timeline.timesCount > 1: sTimes = str(self.timeline.timesCount) + ' time values' else: sTimes = 'One time value' if self.timeline.nodeCount > 1: sNodes = str(self.timeline.nodeCount) + ' nodes' else: sNodes = 'one node' self.totalNodes.setText(sTimes + '\n' + sNodes) if self.timeline.baseDateMin != self.timeline.dateMin: self.startTime.setText('From ' + str( self.timeline.fromUSec(self.timeline.baseDateMin).strftime( '%d.%m.%Y %H:%M:%S'))) if self.timeline.selDateMin: self.selStartTime.setText('From ' + str( self.timeline.fromUSec(self.timeline.selDateMin).strftime( '%d.%m.%Y %H:%M:%S'))) else: self.selStartTime.setText('No selection start time') if self.timeline.baseDateMax != self.timeline.dateMax: self.endTime.setText('To ' + str( self.timeline.fromUSec(self.timeline.baseDateMax).strftime( '%d.%m.%Y %H:%M:%S'))) if self.timeline.selDateMax: self.selEndTime.setText('To ' + str( self.timeline.fromUSec(self.timeline.selDateMax).strftime( '%d.%m.%Y %H:%M:%S'))) else: self.selEndTime.setText('No selection end time') def dumpOptionsConf(self): for family in self.configuration: if not family[1]: print family[0] + ': empty' else: print family[0] + ':' for time in family[1]: print '\t' + time[0] + ':' for param in time[1]: print '\t\t' + param[0] + ':', param[1] def createMetricTools(self): ''' Called once countThread is over. ''' if not self.configuration: # First, create configuration dictionary i = 0 for timeFamily, timeList in self.timeline.timeMap.items(): if len(timeList): # One sub dictionary per time family self.configuration.append([timeFamily, []]) for oneMetric in timeList: # One sub sub dictionary per family sub time # checked indicate if item is displayed # color indicate which color to use if i < len(self.timeline.colors): self.configuration[-1][1].append([ oneMetric, [['checked', True], ['color', self.timeline.colors[i][0]], ['checkBox', None], ['colorWidget', None], ['colorWidgetIndex', -1], [ 'orderedNodeList', { 'dates': None, 'nodes': None } ], [ 'dateLimits', [long(0), long(0xffffffffffffffff)] ], ['mainPixmap', [True, None]], ['zoomPixmap', [True, None]]] ]) else: self.configuration[-1][1].append([ oneMetric, [['checked', False], ['color', ''], ['checkBox', None], ['colorWidget', None], ['colorWidgetIndex', -1], [ 'orderedNodeList', { 'dates': None, 'nodes': None } ], [ 'dateLimits', [long(0), long(0xffffffffffffffff)] ], ['mainPixmap', [True, None]], ['zoomPixmap', [True, None]]] ]) i += 1 else: self.configuration.append([timeFamily, []]) # Configuration object created, now create graphical view of it # self.dumpOptionsConf() i = 0 for family in self.configuration: if family[1]: box = QGroupBox(family[0]) oneTime = QVBoxLayout() for time in family[1]: hbox = QHBoxLayout() time[1][2][1] = QCheckBox(':'.join(time[0])) self.connect(time[1][2][1], SIGNAL("stateChanged(int)"), self.checkboxClick) time[1][3][1] = QComboBox() for color in self.timeline.colors: time[1][3][1].addItem(color[0]) palette = time[1][2][1].palette() if i < len(self.timeline.colors): time[1][2][1].setChecked(time[1][0][1]) # Colorize foreground palette.setColor(QPalette.WindowText, self.timeline.colors[i][1]) time[1][3][1].setCurrentIndex(i) time[1][4][1] = i else: # In case every colors are already used, don't check time (default) and don't select any color palette.setColor(QPalette.WindowText, Qt.gray) time[1][0][1] = False time[1][3][1].setEnabled(False) time[1][2][1].setPalette(palette) self.connect( time[1][3][1], SIGNAL("currentIndexChanged(const QString&)"), self.colorChange) hbox.addWidget(time[1][2][1]) hbox.addWidget(time[1][3][1]) oneTime.addLayout(hbox) i += 1 box.setLayout(oneTime) optimum = box.minimumSizeHint() box.setFixedSize(optimum) if optimum.width() > self.familyLayout.sizeHint().width(): geom = QRect( 0, 0, optimum.width(), self.familyLayout.sizeHint().height() + optimum.height()) else: geom = QRect( 0, 0, self.familyLayout.sizeHint().width(), self.familyLayout.sizeHint().height() + optimum.height()) self.familyLayout.addWidget(box) self.familyLayout.setGeometry(geom) self.familyWidget.setFixedSize(geom.width(), geom.height()) self.familyScroll.setWidget(self.familyWidget) else: # Configuration object already created, we are called because am item has been # unchecked or its color has changed. pass def colorChange(self, colorText): loop = 2 while loop: i = 0 for family in self.configuration: for time in family[1]: if time[1][3][1]: if QString(time[1][1][1]) != time[1][3][1].currentText( ) and self.swapIndex == -1 and self.metricIndex == -1 and time[ 1][3][1].isEnabled(): # This selection has just been changed self.swapColor = time[1][1][1] self.swapIndex = time[1][4][1] time[1][1][1] = str(colorText) #Color palette = time[1][2][1].palette() palette.setColor( QPalette.WindowText, self.timeline.colors[ time[1][3][1].currentIndex()][1]) time[1][2][1].setPalette(palette) time[1][4][1] = time[1][3][1].currentIndex() time[1][7][1][0] = True time[1][8][1][0] = True self.metricIndex = i if QString( time[1][1][1] ) == colorText and self.swapIndex != -1 and self.metricIndex != i and time[ 1][3][1].isEnabled(): # This selection is impacted because color is the same as the one just selected # Changing color relaunch another signal. time[1][1][1] = self.swapColor time[1][4][1] = self.swapIndex time[1][3][1].setCurrentIndex(self.swapIndex) time[1][7][1][0] = True time[1][8][1][0] = True #Color palette = time[1][2][1].palette() palette.setColor( QPalette.WindowText, self.timeline.colors[ time[1][3][1].currentIndex()][1]) time[1][2][1].setPalette(palette) self.metricIndex = -1 i += 1 loop -= 1 # if self.swapColor == '': # Swap already done ; redraw self.timeline.updatePaintingArea() self.swapIndex = -1 self.swapColor = '' self.metricIndex = -1 def checkboxClick(self, newState): self.selectedNodes.setText('Nothing selected') self.zoomButton.setEnabled(False) self.exportButton.setEnabled(False) for family in self.configuration: for time in family[1]: if time[1][2][1]: palette = time[1][2][1].palette() if not time[1][2][1].checkState() and time[1][0][1]: # This box has just been unchecked time[1][0][1] = False time[1][3][1].setEnabled(False) palette.setColor(QPalette.WindowText, Qt.gray) elif time[1][2][1].checkState() and not time[1][0][1]: # This box has just been checked time[1][0][1] = True time[1][3][1].setEnabled(True) # Deactivate color already used palette.setColor( QPalette.WindowText, self.timeline.colors[ time[1][3][1].currentIndex()][1]) time[1][1][1] = self.timeline.colors[ time[1][3][1].currentIndex()][0] time[1][4][1] = time[1][3][1].currentIndex() time[1][7][1][0] = True time[1][8][1][0] = True for family2 in self.configuration: # sure, 2 is ugly, it is used to search color to remove for time2 in family2[1]: if time2[1][3][1] and time2[1][3][1].isEnabled( ): if self.timeline.colors[ time2[1][3][1].currentIndex( )][0] == self.timeline.colors[ time[1][3][1].currentIndex( )][0] and time2[1][3][ 1] != time[1][3][1]: palette2 = time2[1][2][1].palette() time2[1][0][1] = False time2[1][2][1].setChecked(False) time2[1][3][1].setEnabled(False) palette2.setColor( QPalette.WindowText, Qt.gray) time2[1][2][1].setPalette(palette2) time[1][2][1].setPalette(palette) self.timeline.updatePaintingArea() def zoomClick(self, clickState): self.timeline.maxOccZoom = 0 rect = self.timeline.ploter.selectionRect.rect() newSelDateMin = self.timeline.draw.findXTime(rect.x()) newSelDateMax = self.timeline.draw.findXTime(rect.x() + rect.width()) self.timeline.selDateMin = self.timeline.toUSec(newSelDateMin) self.timeline.selDateMax = self.timeline.toUSec(newSelDateMax) self.newInformations() self.dezoomButton.setEnabled(True) self.zoomButton.setEnabled(False) self.exportButton.setEnabled(False) txt = self.selectedNodes.text().__str__() self.selectedNodes.setText(txt[:txt.rfind(' ')] + ' displayed') self.zoom = True self.timeline.updatePaintingArea(True) def dezoomClick(self, clickState): self.dezoomButton.setEnabled(False) self.zoomButton.setEnabled(False) self.exportButton.setEnabled(False) self.zoom = False self.timeline.selDateMin = None self.timeline.selDateMax = None self.timeline.maxOccZoom = 0 self.newInformations() for family in self.configuration: for time in family[1]: if time[1][8][1]: time[1][8][1][0] = True time[1][8][1][1] = None self.timeline.updatePaintingArea() def exportClick(self, clickState): rect = self.timeline.ploter.selectionRect.rect() exportSelDateMin = self.timeline.draw.findXTime(rect.x()) exportSelDateMax = self.timeline.draw.findXTime(rect.x() + rect.width()) for family in self.configuration: for time in family[1]: if time[1][0][1]: nodes = [] everyNodes = self.timeline.elementsInRangeToNodeList( time[1][5][1], self.timeline.toUSec(exportSelDateMin), self.timeline.toUSec(exportSelDateMax)) for oneGroupNode in everyNodes: for node in oneGroupNode: nodes.append(node) if len(nodes): if not self.exportedNode: # Create /timeline if needed root = vfs.vfs().getnode('/Bookmarks') baseNode = Node('timeline', 0, root) baseNode.__disown__() baseNode.setDir() e = event() e.thisown = False e.value = RCVariant(Variant(baseNode)) self.VFS.notify(e) # Create /timeline/<ParentName> self.exportedNode = Node(self.timeline.node.name(), 0, baseNode) self.exportedNode.__disown__() self.exportedNode.setDir() timeBaseName = self.exportedNode.absolute( ) + '/' + str( exportSelDateMin.strftime('%d.%m.%Y %H:%M:%S') ) + ' to ' + str( exportSelDateMax.strftime('%d.%m.%Y %H:%M:%S')) timeBaseNode = vfs.vfs().getnode(timeBaseName) if not timeBaseNode: # Create /timeline/<ParentName>/dateStart to dateEnd/<Module:FullTimestampAttributePath>/ timeBaseNode = Node( str( exportSelDateMin.strftime( '%d.%m.%Y %H:%M:%S')) + ' to ' + str( exportSelDateMax.strftime( '%d.%m.%Y %H:%M:%S')), 0, self.exportedNode) timeBaseNode.__disown__() timeBaseNode.setDir() baseFamilyName = timeBaseNode.absolute( ) + '/' + ':'.join([family[0]] + time[0]) baseFamilyNode = vfs.vfs().getnode(baseFamilyName) if not baseFamilyNode: # Create /timeline/<ParentName>/dateStart to dateEnd//<Module:FullTimestampAttributePath> if needed baseFamilyNode = Node( ':'.join([family[0]] + time[0]), 0, timeBaseNode) baseFamilyNode.__disown__() baseFamilyNode.setDir() for node in nodes: # Add each node in array as child l = VLink(node, baseFamilyNode) l.__disown__()
class IngredientsEditor(QtGui.QWidget): '''Shows a list of Ingredients and an IngredientEditorPane when one is selected. When it becomes visible, it loads the list of ingredients from the database. It selects either the first item or the last one selected. It then displays a viewer pane on the right which shows you information about the ''' def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) layout = QHBoxLayout() self.setLayout(layout) self.ingredients = client.get_ingredients() self.ingredict = {} for v in self.ingredients: self.ingredict.update({v.name:v}) self.last_selection = "" self.leftcol = QVBoxLayout() #TODO: Use a QSplitter to let people resize their things. self.listwidget = QtGui.QListWidget() self.listwidget.setFixedWidth(self.width()/3.0) self.leftcol.addWidget(self.listwidget) self.listwidget.connect(self.listwidget, SIGNAL("itemSelectionChanged()"), self.show_edit_pane) self.addbutton = QtGui.QPushButton("Add Ingredient") self.addbutton.connect(self.addbutton, SIGNAL("clicked()"), self.add_new_ingredient) self.leftcol.addWidget(self.addbutton) self.layout().addLayout(self.leftcol) self.evcontainer = QtGui.QWidget() self.evcontainer.setLayout(QVBoxLayout()) self.layout().addWidget(self.evcontainer) self.evpane = None #TODO: Add a toggle button to hide or show hidden Ingredients. self.editbutton = QPushButton("Enable Editing") self.editbutton.connect(self.editbutton, SIGNAL("clicked()"), self.toggle_editmode) self.editing = False for a in (LCSIGNAL.doBuyAction, LCSIGNAL.doDrinkAction): a.connect(self.showEvent) self.update_listwidget() LCSIGNAL.doNewIngredient.connect(self.add_new_ingredient) def add_new_ingredient(self): i = models.Ingredient('New Ingredient', '', 0) client.try_add(i) client.commit() self.showEvent(None) for i in xrange(self.listwidget.count()): if self.listwidget.item(i).text() == "New Ingredient": self.listwidget.setCurrentItem(self.listwidget.item(i)) break self.toggle_editmode() def toggle_editmode(self): self.editing = not self.editing if self.editing: self.editbutton.setText("Disable Editing") else: self.editbutton.setText("Enable Editing") self.update_listwidget() self.add_viewpane() def update_listwidget(self): self.ingredients = client.get_ingredients() self.listwidget.clear() for i in self.ingredients: self.ingredict.update({i.name:i}) newitem = QtGui.QListWidgetItem(i.name) if i.hidden: newitem.setTextColor(Qt.darkGray) self.listwidget.addItem(newitem) items = self.listwidget.findItems(self.last_selection, Qt.MatchExactly) if items != []: self.listwidget.setCurrentItem(items[0]) else: self.listwidget.setCurrentItem(self.listwidget.item(0)) def show_edit_pane(self): if self.listwidget.selectedItems() != []: self.last_selection = str(self.listwidget.selectedItems()[0].text()) self.add_viewpane() def add_viewpane(self): self.evcontainer.layout().removeWidget(self.evpane) if self.evpane is not None: self.evpane.setParent(None) if self.last_selection in self.ingredict: if self.editing: self.evpane = IngredientEditorPane(self.ingredict[self.last_selection]) else: self.evpane = IngredientViewerPane(self.ingredict[self.last_selection]) self.evcontainer.layout().addWidget(self.evpane) self.evcontainer.layout().addWidget(self.editbutton) else: print "Last selection not in ingredients!" def showEvent(self, event=None): self.update_listwidget() try: event.ignore() except(AttributeError): pass
def login(video): if gui is "PyQt4": #A login with Qt4 GUI global mail, passw #Objects login = QDialog() login_mailtext = QLabel("Email:") login_mail = QLineEdit(mail) login_passtext = QLabel("Password:"******"Ok") login_cancel = QPushButton("Cancel") login_grid = QGridLayout() #Connection to grid login_grid.addWidget(login_mailtext,0,0) login_grid.addWidget(login_mail,0,1) login_grid.addWidget(login_passtext,1,0) login_grid.addWidget(login_passw,1,1) login_grid.addWidget(login_Ok,2,0) login_grid.addWidget(login_cancel,2,1) login.setLayout(login_grid) #Method def accept(): global mail, passw mail = login_mail.text() passw = login_passw.text() if mail != "" and passw != "": login.close() return work(video) #Signals login.connect(login_Ok, SIGNAL("clicked()"), accept) login.connect(login_cancel, SIGNAL("clicked()"), SLOT("close()") ) #Options and execution login_passw.setEchoMode(2) login.setWindowTitle("NicoLogin") login.show() login.exec_() elif gui is "Gtk": #A login with GTK GUI #Method def accept(widget): global mail, passw mail = login_mail.get_text() passw = login_passw.get_text() if mail != "" and passw != "": login.destroy() return work(video) def close(widget): login.destroy() #Objects login = gtk.Window() layout = gtk.Table(2,3,True) login_mailtext = gtk.Label() login_mail = gtk.Entry() login_passtext = gtk.Label() login_passw = gtk.Entry() login_Ok = gtk.Button("Ok") login_cancel = gtk.Button("Cancel") #Grid layout.attach(login_mailtext,0,1,0,1) layout.attach(login_mail,1,2,0,1) layout.attach(login_passtext,0,1,1,2) layout.attach(login_passw,1,2,1,2) layout.attach(login_Ok,0,1,2,3) layout.attach(login_cancel,1,2,2,3) #Options and Run login_Ok.connect("clicked",accept) login_cancel.connect("clicked",close) login.connect("destroy", gtk.main_quit) login_mailtext.set_text("Email:") login_mail.set_text(mail) login_passtext.set_text("Password:"******"Tk": #A login with Tk GUI #Method def accept(*args): global mail, passw mail = login_mail.get() passw = login_passw.get() if mail != "" and passw != "": login.destroy() return work(video) #Objects login = Tk.Toplevel() login_mailtext = Tk.Label(login, text="Email:") login_passtext = Tk.Label(login, text="Password:"******"*") login_Ok = Tk.Button(login, text="Ok", command=accept) login_cancel = Tk.Button(login, text="Cancel", command=login.destroy) #Connection to grid login_mailtext.grid(row=0) login_passtext.grid(row=1) login_mail.grid(row=0, column=1) login_passw.grid(row=1, column=1) login_Ok.grid(row=2) login_cancel.grid(row=2, column=1) #Options and execution login_mail.focus() login.bind("<Return>", accept) login.mainloop() else: #A login without GUI while mail == "" or passw == "": mail = raw_input("\nEmail: ") passw = getpass.getpass(prompt="Password: ") return work(video) return False