def __init__(self, mainWin): self.mainWin = mainWin self.mcal = mainWin.mcal qt.QFileDialog.__init__(self) self.setAcceptMode(qt.QFileDialog.AcceptSave) self.setFileMode(qt.QFileDialog.AnyFile)## FIXME self.setOption(qt.QFileDialog.HideNameFilterDetails) self.setWindowTitle(_('Export to %s')%'HTML') self.vbox = VBox() ######## hbox = HBox() hbox.addWidget(qt.QLabel(_('Month Range'))) combo = qt.QComboBox() for t in ('Current Month', 'Whole Current Year', 'Custom'): combo.addItem(_(t)) hbox.addWidget(combo) hbox.addWidget(qt.QLabel('')) self.combo = combo ### hbox2 = HBox() hbox2.addWidget(qt.QLabel(_('from month'))) self.ymBox0 = YearMonthBox() hbox2.addWidget(self.ymBox0) hbox2.addWidget(qt.QLabel('')) hbox2.addWidget(qt.QLabel(_('to month'))) self.ymBox1 = YearMonthBox() hbox2.addWidget(self.ymBox1) hbox.addWidget(hbox2) self.hbox2 = hbox2 combo.setCurrentIndex(0) self.vbox.addWidget(hbox) ######## self.layout().addWidget(self.vbox, 4, 0, 5, 2)## between rows 4 and 5, between columns 0 and 2 (before buttons) ######## self.connect(combo, qc.SIGNAL('currentIndexChanged (int)'), self.comboChanged) self.connect(self, qc.SIGNAL('fileSelected (const QString&)'), self.save) try: self.setDirectory(deskDir) except:## FIXME pass
def __init__(self, items=[], mainWin=None): qt.QDialog.__init__(self) self.setWindowTitle(_('Customize')) self.vbox = qt.QVBoxLayout() self.vbox.setMargin(0) self.setLayout(self.vbox)## FIXME self.optionBox = qt.QStackedLayout() self.optionBox.setMargin(0) #self.optionBox.setSizePolicy(qt.QSizePolicy.Minimum, qt.QSizePolicy.Minimum) self.nullWidget = qt.QLabel('') self.optionBox.addWidget(self.nullWidget) #if rtl: # self.setLayoutDirection(qt.QBoxLayout.RightToLeft) ### self.items = items self.mainWin = mainWin ### self.tree = qt.QTreeWidget(self) #self.tree.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Expanding) self.tree.setHeaderHidden(True) self.tree.setItemsExpandable(True) self.tree.setSelectionMode(qt.QAbstractItemView.SingleSelection) self.tree.setColumnCount(2) self.connect(self.tree, qc.SIGNAL('itemChanged (QTreeWidgetItem *,int)'), self.itemChanged) for item in items: qItem = qt.QTreeWidgetItem(['', item.desc]) qItem.setCheckState(0, qc.Qt.Checked if item.enable else qc.Qt.Unchecked) if item.optionsWidget: self.optionBox.addWidget(item.optionsWidget) #item.optionsWidget.setSizePolicy(qt.QSizePolicy.Minimum, qt.QSizePolicy.Minimum) for child in item.items: child.qItem = qt.QTreeWidgetItem(['', child.desc]) child.qItem.setCheckState(0, qc.Qt.Checked if child.enable else qc.Qt.Unchecked) qItem.addChild(child.qItem) if child.optionsWidget: self.optionBox.addWidget(child.optionsWidget) self.tree.addTopLevelItem(qItem) item.qItem = qItem ##### hbox = qt.QHBoxLayout() hbox.setMargin(0) vbox_l = qt.QVBoxLayout() vbox_l.setMargin(0) vbox_l.addWidget(self.tree) hbox.addLayout(vbox_l) ##### toolbar = qt.QToolBar(self) toolbar.setOrientation(qc.Qt.Vertical) ### action = qt.QAction(qt.QIcon(qpixDir+'/go-up.png'), '', self) action.connect(action, qc.SIGNAL('triggered()'), self.upClicked) action.setToolTip(_('Move up')) toolbar.addAction(action) ### action = qt.QAction(qt.QIcon(qpixDir+'/go-down.png'), '', self) action.connect(action, qc.SIGNAL('triggered()'), self.downClicked) action.setToolTip(_('Move down')) toolbar.addAction(action) ### hbox.addWidget(toolbar) self.vbox.addLayout(hbox) self.vbox_l = vbox_l ######## self.widget = VBox() for item in items: try: self.widget.addWidget(item.widget) except TypeError: print '\nERROR: the widget for item %s has wrong type %s'%(item._name, type(item.widget)) self.widget.setVisible(True) for item in items: if item.enable: for chItem in item.items: if not chItem.enable: chItem.widget.setVisible(False) else: item.widget.setVisible(False) ######## self.tree.selectionChanged = self.treevCursorChanged ### self.vbox.addLayout(self.optionBox) ######## bbox = qt.QDialogButtonBox(self) closeB = bbox.addButton(qt.QDialogButtonBox.Close) if ui.autoLocale: closeB.setText(_('_Close')) ## ??????????????? self.connect(closeB, qc.SIGNAL('clicked()'), self.closeEvent) self.vbox.addWidget(bbox)
class CustomizeDialog(qt.QWidget):## QDialog def __init__(self, items=[], mainWin=None): qt.QDialog.__init__(self) self.setWindowTitle(_('Customize')) self.vbox = qt.QVBoxLayout() self.vbox.setMargin(0) self.setLayout(self.vbox)## FIXME self.optionBox = qt.QStackedLayout() self.optionBox.setMargin(0) #self.optionBox.setSizePolicy(qt.QSizePolicy.Minimum, qt.QSizePolicy.Minimum) self.nullWidget = qt.QLabel('') self.optionBox.addWidget(self.nullWidget) #if rtl: # self.setLayoutDirection(qt.QBoxLayout.RightToLeft) ### self.items = items self.mainWin = mainWin ### self.tree = qt.QTreeWidget(self) #self.tree.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Expanding) self.tree.setHeaderHidden(True) self.tree.setItemsExpandable(True) self.tree.setSelectionMode(qt.QAbstractItemView.SingleSelection) self.tree.setColumnCount(2) self.connect(self.tree, qc.SIGNAL('itemChanged (QTreeWidgetItem *,int)'), self.itemChanged) for item in items: qItem = qt.QTreeWidgetItem(['', item.desc]) qItem.setCheckState(0, qc.Qt.Checked if item.enable else qc.Qt.Unchecked) if item.optionsWidget: self.optionBox.addWidget(item.optionsWidget) #item.optionsWidget.setSizePolicy(qt.QSizePolicy.Minimum, qt.QSizePolicy.Minimum) for child in item.items: child.qItem = qt.QTreeWidgetItem(['', child.desc]) child.qItem.setCheckState(0, qc.Qt.Checked if child.enable else qc.Qt.Unchecked) qItem.addChild(child.qItem) if child.optionsWidget: self.optionBox.addWidget(child.optionsWidget) self.tree.addTopLevelItem(qItem) item.qItem = qItem ##### hbox = qt.QHBoxLayout() hbox.setMargin(0) vbox_l = qt.QVBoxLayout() vbox_l.setMargin(0) vbox_l.addWidget(self.tree) hbox.addLayout(vbox_l) ##### toolbar = qt.QToolBar(self) toolbar.setOrientation(qc.Qt.Vertical) ### action = qt.QAction(qt.QIcon(qpixDir+'/go-up.png'), '', self) action.connect(action, qc.SIGNAL('triggered()'), self.upClicked) action.setToolTip(_('Move up')) toolbar.addAction(action) ### action = qt.QAction(qt.QIcon(qpixDir+'/go-down.png'), '', self) action.connect(action, qc.SIGNAL('triggered()'), self.downClicked) action.setToolTip(_('Move down')) toolbar.addAction(action) ### hbox.addWidget(toolbar) self.vbox.addLayout(hbox) self.vbox_l = vbox_l ######## self.widget = VBox() for item in items: try: self.widget.addWidget(item.widget) except TypeError: print '\nERROR: the widget for item %s has wrong type %s'%(item._name, type(item.widget)) self.widget.setVisible(True) for item in items: if item.enable: for chItem in item.items: if not chItem.enable: chItem.widget.setVisible(False) else: item.widget.setVisible(False) ######## self.tree.selectionChanged = self.treevCursorChanged ### self.vbox.addLayout(self.optionBox) ######## bbox = qt.QDialogButtonBox(self) closeB = bbox.addButton(qt.QDialogButtonBox.Close) if ui.autoLocale: closeB.setText(_('_Close')) ## ??????????????? self.connect(closeB, qc.SIGNAL('clicked()'), self.closeEvent) self.vbox.addWidget(bbox) def itemChanged(self, qItem, column_index):## enableCellToggled (index, parentIndex) = self.getSelectedIndex() item = self.getItemByIndex(index, parentIndex) item.enable = (qItem.checkState(0)==qc.Qt.Checked) item.widget.setVisible(item.enable) if item.enable: item.onDateChange() try: item.widget.repaint() except: pass elif self.mainWin: self.mainWin.setMinHeightLater() def getItemByIndex(self, index, parentIndex=-1): if parentIndex==-1: return self.items[index] else: return self.items[parentIndex].items[index] def getSelectedIndex(self): qIndexes = self.tree.selectedIndexes() if not qIndexes: return (-1, -1) qIndex = qIndexes[0] return (qIndex.row(), qIndex.parent().row()) def treevCursorChanged(self, selected, deselected): (index, parentIndex) = self.getSelectedIndex() if index==-1: return #print 'treevCursorChanged', index, parentIndex item = self.getItemByIndex(index, parentIndex) if item.optionsWidget: self.optionBox.setCurrentWidget(item.optionsWidget) pass else: self.optionBox.setCurrentWidget(self.nullWidget) def upClicked(self): (index, parentIndex) = self.getSelectedIndex() if index==-1: return #print 'upClicked', index, parentIndex #item = self.getItemByIndex(index, parentIndex) if index<=0: qt.QApplication.beep() return if parentIndex==-1: self.moveItemUp(index) qItem = self.tree.takeTopLevelItem(index) self.tree.insertTopLevelItem(index-1, qItem) self.tree.setCurrentItem(qItem) else: root = self.items[parentIndex] root.moveItemUp(index) qRootItem = self.tree.topLevelItem(parentIndex) qItem = qRootItem.takeChild(index) qRootItem.insertChild(index-1, qItem) self.tree.setCurrentItem(qItem) def downClicked(self): (index, parentIndex) = self.getSelectedIndex() if index==-1: return #print 'upClicked', index, parentIndex #item = self.getItemByIndex(index, parentIndex) if parentIndex==-1: if index>=len(self.items)-1: qt.QApplication.beep() return self.moveItemUp(index+1) qItem = self.tree.takeTopLevelItem(index+1) self.tree.insertTopLevelItem(index, qItem) self.tree.setCurrentItem(self.tree.topLevelItem(index+1)) else: root = self.items[parentIndex] if index>=len(root.items)-1: qt.QApplication.beep() return root.moveItemUp(index+1) qRootItem = self.tree.topLevelItem(parentIndex) qItem = qRootItem.takeChild(index+1) qRootItem.insertChild(index, qItem) self.tree.setCurrentItem(qRootItem.child(index+1)) def moveItemUp(self, i): self.widget.removeWidget(self.items[i].widget) self.widget.insertWidget(i-1, self.items[i].widget)## QBoxLayout.insertWidget self.items.insert(i-1, self.items.pop(i)) #def confStr(self):## FIXME def closeEvent(self, event=None): text = '' mainWinItems = [] for item in self.items: item.updateVars() text += item.confStr() mainWinItems.append((item._name, item.enable)) text += 'ui.mainWinItems=%r\n'%mainWinItems open(preferences.customizeConfPath, 'w').write(text) # FIXME self.hide() if event: event.ignore()
def __init__(self, maxResults=200): #qt.QWidget.__init__(self, None, qc.Qt.Tool)## FIXME qt.QDialog.__init__(self, None, qc.Qt.Tool)## FIXME self.maxResults = maxResults self.vbox = qt.QVBoxLayout() self.vbox.setMargin(0) self.setLayout(self.vbox) ############### hbox = HBox() hbox.addWidget(qt.QLabel(_('Search Cities:'))) entry = qt.QLineEdit() hbox.addWidget(entry) entry.changeEvent = self.entryChanged self.vbox.addWidget(hbox) ###################### treev = qt.QTreeWidget() treev.setColumnCount(2) treev.setHeaderLabels([_('Index'), _('City'),]) treev.hideColumn(0) #treev.set_headers_clickable(False) #treev.set_headers_visible(False) self.vbox.addWidget(treev) self.treev = treev treev.selectionChanged = self.treevSelectionChanged #treev.set_search_column(1) ######### lines = file(dataDir+'/locations.txt').read().split('\n') cityData = [] country = '' for l in lines: p = l.split('\t') if len(p)<2: #print p continue if p[0]=='': if p[1]=='': city, lat, lng = p[2:5] #if country=='Iran': # print city if len(p)>4: cityData.append(( country + '/' + city, _(country) + '/' + _(city), float(lat), float(lng) )) else: print country, p else: country = p[1] self.cityData = cityData self.updateList() ########### gbox = qt.QGroupBox(_('Edit Manually')) gboxLay = qt.QVBoxLayout() gboxLay.setMargin(0)## FIXME gbox.setLayout(gboxLay) gbox.setCheckable(True) self.connect(gbox, qc.SIGNAL('toggled (bool)'), self.editCheckbToggled) self.gboxEdit = gbox vbox = VBox() #group = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL) ##### hbox = HBox() label = qt.QLabel(_('Name:')) hbox.addWidget(label) #group.add_widget(label) #label.set_alignment(0, 0.5) entry = qt.QLineEdit() hbox.addWidget(entry) vbox.addWidget(hbox) self.entry_edit_name = entry #### hbox = HBox() label = qt.QLabel(_('Latitude:')) hbox.addWidget(label) #group.add_widget(label) #label.set_alignment(0, 0.5) #### spin = qt.QDoubleSpinBox() spin.setSingleStep(1) spin.setRange(-180, 180) spin.setDecimals(3) spin.setLayoutDirection(qc.Qt.LeftToRight) hbox.addWidget(spin) vbox.addWidget(hbox) self.spin_lat = spin #### hbox = HBox() label = qt.QLabel(_('Longitude:')) hbox.addWidget(label) #group.add_widget(label) spin = qt.QDoubleSpinBox() spin.setSingleStep(1) spin.setRange(-180, 180) spin.setDecimals(3) spin.setLayoutDirection(qc.Qt.LeftToRight) hbox.addWidget(spin) vbox.addWidget(hbox) self.spin_lng = spin #### hbox = HBox() self.lowerLabel = qt.QLabel('') # self.lowerLabel.setSizePolicy Expandig ## FIXME hbox.addWidget(self.lowerLabel) #self.lowerLabel.set_alignment(0, 0.5) button = qt.QPushButton(_('Calculate Nearest City')) self.connect(button, qc.SIGNAL('clicked ()'), self.calcClicked) hbox.addWidget(button) vbox.addWidget(hbox) #### vbox.setEnabled(False) gboxLay.addWidget(vbox) self.vbox_edit = vbox self.vbox.addWidget(gbox) ####### bbox = qt.QDialogButtonBox(qc.Qt.Horizontal) cancelB = bbox.addButton(qt.QDialogButtonBox.Cancel) okB = bbox.addButton(qt.QDialogButtonBox.Ok) if autoLocale: cancelB.setText(_('_Cancel')) #cancelB.setIcon(qt.QIcon('cancel.png')) okB.setText(_('_OK')) #okB.setIcon(qt.QIcon('ok.png')) #okB.grab_default()#????????? #okB.grab_focus()#????????? ## ??????????????? self.connect(bbox, qc.SIGNAL('rejected()'), lambda: self.reject()) self.connect(bbox, qc.SIGNAL('accepted()'), lambda: self.accept()) #self.connect(cancelB, qc.SIGNAL('clicked()'), self.reject) #self.connect(okB, qc.SIGNAL('clicked()'), self.accept) ''' cancelB = self.add_button(gtk.STOCK_CANCEL, self.EXIT_CANCEL) okB = self.add_button(gtk.STOCK_OK, self.EXIT_OK) #if autoLocale: cancelB.setText(_('_Cancel')) cancelB.set_image(gtk.image_new_from_stock(gtk.STOCK_CANCEL, gtk.ICON_SIZE_BUTTON)) okB.setText(_('_OK')) okB.set_image(gtk.image_new_from_stock(gtk.STOCK_OK, gtk.ICON_SIZE_BUTTON)) ''' self.vbox.addWidget(bbox)
class ExportDialog(qt.QFileDialog): def __init__(self, mainWin): self.mainWin = mainWin self.mcal = mainWin.mcal qt.QFileDialog.__init__(self) self.setAcceptMode(qt.QFileDialog.AcceptSave) self.setFileMode(qt.QFileDialog.AnyFile)## FIXME self.setOption(qt.QFileDialog.HideNameFilterDetails) self.setWindowTitle(_('Export to %s')%'HTML') self.vbox = VBox() ######## hbox = HBox() hbox.addWidget(qt.QLabel(_('Month Range'))) combo = qt.QComboBox() for t in ('Current Month', 'Whole Current Year', 'Custom'): combo.addItem(_(t)) hbox.addWidget(combo) hbox.addWidget(qt.QLabel('')) self.combo = combo ### hbox2 = HBox() hbox2.addWidget(qt.QLabel(_('from month'))) self.ymBox0 = YearMonthBox() hbox2.addWidget(self.ymBox0) hbox2.addWidget(qt.QLabel('')) hbox2.addWidget(qt.QLabel(_('to month'))) self.ymBox1 = YearMonthBox() hbox2.addWidget(self.ymBox1) hbox.addWidget(hbox2) self.hbox2 = hbox2 combo.setCurrentIndex(0) self.vbox.addWidget(hbox) ######## self.layout().addWidget(self.vbox, 4, 0, 5, 2)## between rows 4 and 5, between columns 0 and 2 (before buttons) ######## self.connect(combo, qc.SIGNAL('currentIndexChanged (int)'), self.comboChanged) self.connect(self, qc.SIGNAL('fileSelected (const QString&)'), self.save) try: self.setDirectory(deskDir) except:## FIXME pass def comboChanged(self, index=None, ym=None): if index is None: index = self.combo.currentIndex() if ym==None: ym = (ui.cell.year, ui.cell.month) if index==0: filename = 'calendar-%.4d-%.2d.html'%ym self.hbox2.hide() elif index==1: #self.fcw.set_current_name('calendar-%.4d.html'%ym[0]) filename = 'calendar-%.4d.html'%ym[0] self.hbox2.hide() else:#elif index==2 filename = 'calendar.html' self.hbox2.show() #self.fcw.set_current_name(filename) self.selectFile(filename)## FIXME ## select_region(0, -4) ## FIXME def closeEvent(self, event): self.hide() event.ignore() def done(self, i): self.hide() def save(self, path): print 'save', path self.setCursor(qc.Qt.WaitCursor) #while gtk.events_pending():## FIXME # gtk.main_iteration_do(False) if path in (None, ''): return print 'Exporting to html file "%s"'%path i = self.combo.currentIndex() months = [] module = core.modules[core.primaryMode] if i==0: s = getCurrentMonthStatus() months = [s] title = '%s %s'%(core.getMonthName(core.primaryMode, s.month, s.year), _(s.year)) elif i==1: for i in xrange(1, 13): months.append(getMonthStatus(ui.cell.year, i)) title = '%s %s'%(_('Calendar'), _(ui.cell.year)) elif i==2: y0, m0 = self.ymBox0.getYM() y1, m1 = self.ymBox1.getYM() for ym in xrange(y0*12+m0-1, y1*12+m1): y, m = divmod(ym, 12) m += 1 months.append(getMonthStatus(y, m)) title = _('Calendar') exportToHtml(path, months, title) self.setCursor(qc.Qt.ArrowCursor) self.hide() def showDialog(self, year, month): self.comboChanged(ym=(year, month)) self.ymBox0.setYM(year, month) self.ymBox1.setYM(year, month) self.resize(700, 400) self.show()## raise_()