def __init__(self, parent, accelerator = None): QAction.__init__(self, parent) self.name=None self.dlgSearch=None self.dlgForm=None self.connect(self, SIGNAL("activated()"), self.slotActivatedName) if accelerator: QAction.setAccel(self, QAccel.stringToKey(accelerator))
def __actualizar_recientes(self): """Actualiza la lista de ficheros recientemente abiertos""" self.PopupMenuEditor_3.clear() for i in range(len(self.__config.configuracion["lfichero"]) - 1): self.__colectorfunciones.append(lambda nombre=self.__config.configuracion["lfichero"][i]: self.abrir_proyecto(self, nombre)) accion = QAction(self, self.__config.configuracion["lfichero"][i]) accion.setText(self.__config.configuracion["lfichero"][i]) accion.addTo(self.PopupMenuEditor_3) self.connect(accion, SIGNAL("activated()"), self.__colectorfunciones[-1])
def __atajos(self): """Establece los atajos""" self.ayudaAyudaAction.setAccel("F1") self.acciontab1 = QAction(self, "tabcasos") self.connect(self.acciontab1, SIGNAL("activated()"), self.grid.mostrar_t_reg) self.acciontab1.setAccel("F2") self.acciontab2 = QAction(self, "tabvars") self.connect(self.acciontab2, SIGNAL("activated()"), self.grid.mostrar_t_var) self.acciontab2.setAccel("F3") if self.__diccionarioacciones.has_key("Descriptivo"): self.__diccionarioacciones["Descriptivo"].setAccel("F4") self.__boton3.setAccel("F5") #Ventana salida self.archivoConfiguracinAction.setAccel("F10") self.acerca_deAcerca_deAction.setAccel("F12") self.archivoSalirAction.setAccel("Ctrl+Q")
def kajonggAction(self, name, icon, slot=None, shortcut=None, actionData=None): """simplify defining actions""" res = QAction(self) if icon: res.setIcon(KIcon(icon)) if slot: res.triggered.connect(slot) self.actionCollection().addAction(name, res) if shortcut: res.setShortcut(Qt.CTRL + shortcut) res.setShortcutContext(Qt.ApplicationShortcut) if actionData is not None: res.setData(actionData) return res
def __init__(self, parent, config, portero, idu, gestorproyectos, gestortemas, gestoroperaciones): """Inicializador de la ventana principal""" vprincipal.__init__(self, None) #VARIABLES PUBLICAS self.parent = parent self.__config = config self.__gestortemas = gestortemas self.__idu = idu #Bloque de inicialización de dialogos self.__dbuscar = DBuscar(self, "busqueda") self.__dconfig = DConfig(config, self) self.__dfiltro = DFiltrado(self, self.__idu) self.__dayuda = DAyuda(self) self.__portero = portero self.__gestorproyectos = gestorproyectos self.grid = Grid(self, self.__idu, self.__portero) self.widgetStack1.addWidget(self.grid) self.widgetStack1.raiseWidget(self.grid) # Funciones de inicializacion de componentes self.__init_toolbar() self.mostrar_undo_redo() self.setIcon(self.__gestortemas.icono_programa()) self.__diccionarioarbolmenu = {} self.__diccionarioacciones = {} self.__colectorfunciones = [] listalistasetiquetas = [operacion.etiquetas for operacion in gestoroperaciones.values()] from Driza import categorias arbol = categorias.conv_categorias_arbol("Raiz", listalistasetiquetas) self.__conv_arbol_menu(self.Analizar, arbol, self.__diccionarioarbolmenu) listaelementosmenu = self.__lista_etiquetas_menu(self.__diccionarioarbolmenu, []) from sets import Set for operacion in gestoroperaciones.values(): for elementofinal in listaelementosmenu: if Set(operacion.etiquetas) == Set(elementofinal[1]): accion = QAction(self, "") accion.setText(unicode(operacion.nombre)) accion.addTo(elementofinal[0]) self.__diccionarioacciones[operacion.nombre] = accion self.__atajos()
def initContextMenu(self, context): """ Initiates the popup menu depending on the context and adds appropriate menu items. """ #ACTION TO ARRANGE THE ICONS IN A LINE arrangeIcons01Action = QAction("Lines", QKeySequence(), self, "arrangeIcons01Actions") arrangeIcons01Action.setIconSet(QIconSet()) self.connect(arrangeIcons01Action, SIGNAL("activated()"), self.parent().arrangeIconsInLines) #ACTION TO ARRANGE THE ICONS IN A CIRCLE arrangeIcons02Action = QAction("Circle", QKeySequence(), self, "arrangeIcons02Actions") arrangeIcons02Action.setIconSet(QIconSet()) self.connect(arrangeIcons02Action, SIGNAL("activated()"), self.parent().arrangeIconsInCircle) #SUBMENU TO CHOOSE THE WAY OF ARRANGEMENT #---------------------------------------- subMenu01 = QPopupMenu(self, "Arrange Icons") arrangeIcons01Action.addTo(subMenu01) arrangeIcons02Action.addTo(subMenu01) #ACTION TO UPDATE THE SCREEN updateCanvasViewAction = QAction("Update Screen", QKeySequence(), self, "updateCanvasViewAction") updateCanvasViewAction.setIconSet(QIconSet()) self.connect(updateCanvasViewAction, SIGNAL("activated()"), self.parent().updateCanvasView) #ACTION TO ADD A NEW DATATYPE newDataTypeAction = QAction("New Data Type...", QKeySequence(), self, "newDataTypeAction") newDataTypeAction.setIconSet(QIconSet(QPixmap.fromMimeSource("newDataType16.png"))) self.connect(newDataTypeAction, SIGNAL("activated()"), self.myFrame.addDataTypeSlot) #ACTION TO ADD A NEW RELATIONTYPE newRelationTypeAction = QAction("New Relation Type...", QKeySequence(), self, "newRelationTypeAction") newRelationTypeAction.setIconSet(QIconSet(QPixmap.fromMimeSource("newRelationType16.png"))) self.connect(newRelationTypeAction, SIGNAL("activated()"), self.myFrame.addRelationTypeSlot) #ACTION TO EDIT THE MARKED DATATYPE editDataTypeAction = QAction("Edit Data Type...", QKeySequence(), self, "editDataTypeAction") editDataTypeAction.setIconSet(QIconSet(QPixmap.fromMimeSource("edit16.png"))) #ACTION TO EDIT THE MARKED RELATIONTYPE editRelationTypeAction = QAction("Edit Relation Type...", QKeySequence(), self, "editRelationTypeAction") editRelationTypeAction.setIconSet(QIconSet(QPixmap.fromMimeSource("edit16.png"))) #ACTION TO REMOVE THE MARKED ICON FROM SCREEN removeIconAction = QAction("Remove Icon", QKeySequence(), self, "removeIconAction") removeIconAction.setIconSet(QIconSet(QPixmap.fromMimeSource("delete16.png"))) self.connect(removeIconAction, SIGNAL("activated()"), self.parent().removeIcon) #ACTION TO DELETE THE MARKED DATATYPEICON deleteDataTypeAction = QAction("Delete Data Type", QKeySequence(), self, "deleteDataTypeAction") deleteDataTypeAction.setIconSet(QIconSet(QPixmap.fromMimeSource("delete16.png"))) self.connect(deleteDataTypeAction, SIGNAL("activated()"), self.myFrame.deleteSelectedDataType) #ACTION TO DELETE THE MARKED RELATIONTYPE deleteRelationTypeAction = QAction("Delete Relation Type", QKeySequence(), self, "deleteRelationTypeAction") deleteRelationTypeAction.setIconSet(QIconSet(QPixmap.fromMimeSource("delete16.png"))) self.connect(deleteRelationTypeAction, SIGNAL("activated()"), self.myFrame.deleteSelectedRelationType) #CONTEXT-MENU IF NOTHING IS MARKED if context == 0: newDataTypeAction.addTo(self) newRelationTypeAction.addTo(self) self.insertSeparator() self.insertItem("Arrange Icons...", subMenu01) updateCanvasViewAction.addTo(self) else: #CONTEXT-MENU IF A DATATYPE IS MARKED if context.iconType == 1: dataTypeController = data_type_dialog.DataTypeController(self.myFrame, context.iconLabel, self.myFrame.repositoryConfiguration) self.connect(editDataTypeAction, SIGNAL("activated()"), dataTypeController.show) editDataTypeAction.addTo(self) deleteDataTypeAction.addTo(self) self.insertSeparator() newDataTypeAction.addTo(self) newRelationTypeAction.addTo(self) self.insertSeparator() removeIconAction.addTo(self) self.insertItem("Arrange Icons...", subMenu01) updateCanvasViewAction.addTo(self) #CONTEXT-MENU IF A RELATIONTYPE IS MARKED if context.iconType == 2: relationTypeController = relation_type_dialog.RelationTypeController(self.myFrame, context.iconLabel, self.myFrame.repositoryConfiguration) self.connect(editRelationTypeAction, SIGNAL("activated()"), relationTypeController.show) editRelationTypeAction.addTo(self) deleteRelationTypeAction.addTo(self) self.insertSeparator() newDataTypeAction.addTo(self) newRelationTypeAction.addTo(self) self.insertSeparator() removeIconAction.addTo(self) self.insertItem("Arrange Icons...", subMenu01) updateCanvasViewAction.addTo(self)
def initContextMenu(self, context): """ Initiates the popup menu depending on the context and adds appropriate menu items. """ #ACTION TO ARRANGE THE ICONS IN A LINE arrangeIcons01Action = QAction("Lines", QKeySequence(), self, "arrangeIcons01Actions") arrangeIcons01Action.setIconSet(QIconSet()) self.connect(arrangeIcons01Action, SIGNAL("activated()"), self.parent().arrangeIconsInLines) #ACTION TO ARRANGE THE ICONS IN A CIRCLE arrangeIcons02Action = QAction("Circle", QKeySequence(), self, "arrangeIcons02Actions") arrangeIcons02Action.setIconSet(QIconSet()) self.connect(arrangeIcons02Action, SIGNAL("activated()"), self.parent().arrangeIconsInCircle) #SUBMENU TO CHOOSE THE WAY OF ARRANGEMENT #---------------------------------------- subMenu01 = QPopupMenu(self, "Arrange Icons") arrangeIcons01Action.addTo(subMenu01) arrangeIcons02Action.addTo(subMenu01) #ACTION TO UPDATE THE SCREEN updateCanvasViewAction = QAction("Update Screen", QKeySequence(), self, "updateCanvasViewAction") updateCanvasViewAction.setIconSet(QIconSet()) self.connect(updateCanvasViewAction, SIGNAL("activated()"), self.parent().updateCanvasView) #ACTION TO ADD A NEW DATATYPE newDataTypeAction = QAction("New Data Type...", QKeySequence(), self, "newDataTypeAction") newDataTypeAction.setIconSet( QIconSet(QPixmap.fromMimeSource("newDataType16.png"))) self.connect(newDataTypeAction, SIGNAL("activated()"), self.myFrame.addDataTypeSlot) #ACTION TO ADD A NEW RELATIONTYPE newRelationTypeAction = QAction("New Relation Type...", QKeySequence(), self, "newRelationTypeAction") newRelationTypeAction.setIconSet( QIconSet(QPixmap.fromMimeSource("newRelationType16.png"))) self.connect(newRelationTypeAction, SIGNAL("activated()"), self.myFrame.addRelationTypeSlot) #ACTION TO EDIT THE MARKED DATATYPE editDataTypeAction = QAction("Edit Data Type...", QKeySequence(), self, "editDataTypeAction") editDataTypeAction.setIconSet( QIconSet(QPixmap.fromMimeSource("edit16.png"))) #ACTION TO EDIT THE MARKED RELATIONTYPE editRelationTypeAction = QAction("Edit Relation Type...", QKeySequence(), self, "editRelationTypeAction") editRelationTypeAction.setIconSet( QIconSet(QPixmap.fromMimeSource("edit16.png"))) #ACTION TO REMOVE THE MARKED ICON FROM SCREEN removeIconAction = QAction("Remove Icon", QKeySequence(), self, "removeIconAction") removeIconAction.setIconSet( QIconSet(QPixmap.fromMimeSource("delete16.png"))) self.connect(removeIconAction, SIGNAL("activated()"), self.parent().removeIcon) #ACTION TO DELETE THE MARKED DATATYPEICON deleteDataTypeAction = QAction("Delete Data Type", QKeySequence(), self, "deleteDataTypeAction") deleteDataTypeAction.setIconSet( QIconSet(QPixmap.fromMimeSource("delete16.png"))) self.connect(deleteDataTypeAction, SIGNAL("activated()"), self.myFrame.deleteSelectedDataType) #ACTION TO DELETE THE MARKED RELATIONTYPE deleteRelationTypeAction = QAction("Delete Relation Type", QKeySequence(), self, "deleteRelationTypeAction") deleteRelationTypeAction.setIconSet( QIconSet(QPixmap.fromMimeSource("delete16.png"))) self.connect(deleteRelationTypeAction, SIGNAL("activated()"), self.myFrame.deleteSelectedRelationType) #CONTEXT-MENU IF NOTHING IS MARKED if context == 0: newDataTypeAction.addTo(self) newRelationTypeAction.addTo(self) self.insertSeparator() self.insertItem("Arrange Icons...", subMenu01) updateCanvasViewAction.addTo(self) else: #CONTEXT-MENU IF A DATATYPE IS MARKED if context.iconType == 1: dataTypeController = data_type_dialog.DataTypeController( self.myFrame, context.iconLabel, self.myFrame.repositoryConfiguration) self.connect(editDataTypeAction, SIGNAL("activated()"), dataTypeController.show) editDataTypeAction.addTo(self) deleteDataTypeAction.addTo(self) self.insertSeparator() newDataTypeAction.addTo(self) newRelationTypeAction.addTo(self) self.insertSeparator() removeIconAction.addTo(self) self.insertItem("Arrange Icons...", subMenu01) updateCanvasViewAction.addTo(self) #CONTEXT-MENU IF A RELATIONTYPE IS MARKED if context.iconType == 2: relationTypeController = relation_type_dialog.RelationTypeController( self.myFrame, context.iconLabel, self.myFrame.repositoryConfiguration) self.connect(editRelationTypeAction, SIGNAL("activated()"), relationTypeController.show) editRelationTypeAction.addTo(self) deleteRelationTypeAction.addTo(self) self.insertSeparator() newDataTypeAction.addTo(self) newRelationTypeAction.addTo(self) self.insertSeparator() removeIconAction.addTo(self) self.insertItem("Arrange Icons...", subMenu01) updateCanvasViewAction.addTo(self)
class VPrincipal(vprincipal): """Ventana principal, hereda de vprincipal, que esta generado por el designer. Esta clase es padre de la mayoria de los dialogos, y es la que permite introducir los datos a el usuario""" def __init__(self, parent, config, portero, idu, gestorproyectos, gestortemas, gestoroperaciones): """Inicializador de la ventana principal""" vprincipal.__init__(self, None) #VARIABLES PUBLICAS self.parent = parent self.__config = config self.__gestortemas = gestortemas self.__idu = idu #Bloque de inicialización de dialogos self.__dbuscar = DBuscar(self, "busqueda") self.__dconfig = DConfig(config, self) self.__dfiltro = DFiltrado(self, self.__idu) self.__dayuda = DAyuda(self) self.__portero = portero self.__gestorproyectos = gestorproyectos self.grid = Grid(self, self.__idu, self.__portero) self.widgetStack1.addWidget(self.grid) self.widgetStack1.raiseWidget(self.grid) # Funciones de inicializacion de componentes self.__init_toolbar() self.mostrar_undo_redo() self.setIcon(self.__gestortemas.icono_programa()) self.__diccionarioarbolmenu = {} self.__diccionarioacciones = {} self.__colectorfunciones = [] listalistasetiquetas = [operacion.etiquetas for operacion in gestoroperaciones.values()] from Driza import categorias arbol = categorias.conv_categorias_arbol("Raiz", listalistasetiquetas) self.__conv_arbol_menu(self.Analizar, arbol, self.__diccionarioarbolmenu) listaelementosmenu = self.__lista_etiquetas_menu(self.__diccionarioarbolmenu, []) from sets import Set for operacion in gestoroperaciones.values(): for elementofinal in listaelementosmenu: if Set(operacion.etiquetas) == Set(elementofinal[1]): accion = QAction(self, "") accion.setText(unicode(operacion.nombre)) accion.addTo(elementofinal[0]) self.__diccionarioacciones[operacion.nombre] = accion self.__atajos() #FUNCIONES PUBLICAS def abrir_proyecto(self, parent = None, filename = None): """ Lanza el diálogo de apertura de fichero """ from Driza.excepciones import FicheroNoExisteException, FicheroErroneoException, FicheroTipoDesconocidoException if not parent: parent = self if not self.__dproyecto_modificado(): return if not filename: filtro = "" for fmt in SL.extensiones_fichero: filtro = filtro + "%s files (*.%s);;" % (fmt, fmt.lower()) filename = QFileDialog.getOpenFileName(QString.null, filtro, self, None, "Dialogo abrir fichero", "") filename = str(filename) if filename: try: self.__gestorproyectos.cargar(filename) except FicheroErroneoException: QMessageBox.warning(parent, u'Atención', 'El fichero no ha podido ser leido') except FicheroTipoDesconocidoException: QMessageBox.warning(parent, u'Atención', 'El fichero no ha podido ser leido') except FicheroNoExisteException: QMessageBox.warning(parent, u'Atención', 'El fichero no ha podido ser leido') except AttributeError: QErrorMessage(parent, "Error").message(u"Parece que ha intentado cargar un fichero de una versión anterior. Lo siento") LOG.exception("excepcion capturada") else: self.__myUpdate() self.grid.myUpdate() return True return False def __myUpdate(self): """Acciones de actualizacion""" from Driza import VERSION if self.__gestorproyectos.fichero: nfichero = self.__gestorproyectos.fichero else: nfichero = "Nuevo fichero" self.setCaption("Driza " + VERSION + " - " + nfichero) def showEvent(self, event): self.__myUpdate() vprincipal.showEvent(self, event) def closeEvent(self, event): """Acciones que se realizaran cuando el usuario cierre la ventana. Guarda el estado de la configuración, incluyendo los ficheros recientemente abiertos""" if not self.__dproyecto_modificado(): return QWidget.closeEvent(self, event) if not self.parent.vsalida.isVisible(): self.__config.guardar() qApp.exit(0) else: self.hide() def mostrar_undo_redo(self): """Determina que botones estan activados y cuales no del submenu de edición""" if self.__portero.puedo_undo(): self.editUndoAction.setEnabled(True) else: self.editUndoAction.setEnabled(False) if self.__portero.puedo_redo(): self.editRedoAction.setEnabled(True) else: self.editRedoAction.setEnabled(False) #FUNCIONES PRIVADAS def __importar(self): """Importa los datos de un fichero""" if not self.__dproyecto_modificado(): return self.parent.dimportartexto.show() def __dproyecto_modificado(self): """Pregunta en caso de que haya sido modificado el proyecto si desea ser guardado""" if not self.__idu.original(): returncode = QMessageBox.information(self, 'Atencion:', 'El proyecto actual ha sido modificado, desea guardarlo?', 'Guardarlo', 'No guardarlo', 'Volver', 0, 1) if returncode == 0: self.__guardar() elif returncode == 2: return False return True def __dacerca_de(self): """Mensaje acerca de""" from Driza import VERSION separador = "\n----------------------------------\n" betatesters = u"Carlos Mestre Gonzalez\n Luis de Bethencourt Guimerá" iconos = "Iconos del Tango Desktop Project: http://tango.freedesktop.org/" ristra = u"Driza %s es una interfaz estadística\n (C) Néstor Arocha Rodríguez - Tutorizado por Inmaculada luengo Merino\n Distribuido bajo licencia GPL" +\ separador + "Betatesters:\n" + betatesters + separador +\ u" Mantenedor del paquete .deb:\n Luis de Bethencourt Guimerá"+ separador + iconos QMessageBox.about(self, "Acerca de Driza", ristra % (VERSION)) def __undo(self): """Deshace el último cambio""" self.__portero.undo() self.grid.myUpdate() self.mostrar_undo_redo() def __redo(self): """Rehace el último cambio""" self.__portero.redo() self.grid.myUpdate() self.mostrar_undo_redo() def __init_toolbar(self): """Inicializa la toolbar""" self.__boton1 = QToolButton(self.Toolbar) self.__boton1.setTextLabel("ABRIR") iconos = QIconSet() iconos.setIconSize(QIconSet.Small, QSize(100, 100)) iconos.setPixmap(self.__gestortemas.icono_abrir(), QIconSet.Small) # iconos.setPixmap("images/flechaabajo.png", QIconSet.Automatic, QIconSet.Normal, QIconSet.Off) self.__boton1.setOn(True) self.__boton1.setIconSet(iconos) self.__boton2 = QToolButton(self.Toolbar) self.__boton2.setTextLabel("GUARDAR") iconos = QIconSet() iconos.setIconSize(QIconSet.Small, QSize(100, 100)) iconos.setPixmap(self.__gestortemas.icono_guardar(), QIconSet.Small) self.__boton2.setOn(True) self.__boton2.setIconSet(iconos) self.__boton3 = QToolButton(self.Toolbar) self.__boton3.setTextLabel("Ventana Salida") iconos = QIconSet() iconos.setIconSize(QIconSet.Small, QSize(100, 100)) iconos.setPixmap(self.__gestortemas.icono_nueva_ventana(), QIconSet.Small) self.__boton3.setOn(True) self.__boton3.setIconSet(iconos) self.__boton4 = QToolButton(self.Toolbar) self.__boton4.setTextLabel("Mostrar etiquetas") self.__boton4.setToggleButton(True) iconos = QIconSet() iconos.setIconSize(QIconSet.Small, QSize(100, 100)) iconos.setPixmap(self.__gestortemas.icono_etiquetas(), QIconSet.Small) self.__boton4.setIconSet(iconos) def conexiones(self): """Funcion llamada en el constructor que almacena todas las conexiones accion-funcion""" self.connect(self.archivoSalirAction, SIGNAL("activated()"), self.__salir_programa) self.connect(self.fileNewAction, SIGNAL("activated()"), self.__nuevo) self.connect(self.fileOpenAction, SIGNAL("activated()"), self.abrir_proyecto) self.connect(self.fileSaveAsAction, SIGNAL("activated()"), self.__guardar_como) self.connect(self.fileSaveAction, SIGNAL("activated()"), self.__guardar) self.connect(self.archivoImportarAction, SIGNAL("activated()"), self.__importar) self.connect(self.archivoConfiguracinAction, SIGNAL("activated()"), self.__dconfig.show) self.connect(self.datosFiltrarAction, SIGNAL("activated()"), self.__dfiltro.show) self.connect(self.modificarCrear_nuevas_variablesAction, SIGNAL("activated()"), self.parent.dcrevar.show) self.connect(self.editFindAction, SIGNAL("activated()"), self.__dbuscar.show) self.connect(self.editCopyAction, SIGNAL("activated()"), self.__copiar) self.connect(self.editCutAction, SIGNAL("activated()"), self.__cortar) self.connect(self.editPasteAction, SIGNAL("activated()"), self.__pegar) self.connect(self.editUndoAction, SIGNAL("activated()"), self.__undo) self.connect(self.editRedoAction, SIGNAL("activated()"), self.__redo) self.connect(self.edicinBorrarAction, SIGNAL("activated()"), self.__borrar) self.connect(self.edicinInsertarAction, SIGNAL("activated()"), self.__insertar_registro) self.connect(self.acerca_deAcerca_deAction, SIGNAL("activated()"), self.__dacerca_de) self.connect(self.__boton1, SIGNAL("clicked()"), self.abrir_proyecto) self.connect(self.__boton2, SIGNAL("clicked()"), self.__guardar) self.connect(self.__boton3, SIGNAL("clicked()"), self.parent.vsalida.show) self.connect(self.__boton4, SIGNAL("clicked()"), self.__alternar_etiquetas) self.connect(self.ayudaAyudaAction, SIGNAL("activated()"), self.__mostrar_dayuda) self.connect(self.PopupMenuEditor_3, SIGNAL("aboutToShow()"), self.__actualizar_recientes) for (key, valor) in self.__diccionarioacciones.items(): self.__colectorfunciones.append(lambda k=key: self.parent.doperaciones.mostrar(k)) self.connect(valor, SIGNAL("activated()"), self.__colectorfunciones[-1]) def __atajos(self): """Establece los atajos""" self.ayudaAyudaAction.setAccel("F1") self.acciontab1 = QAction(self, "tabcasos") self.connect(self.acciontab1, SIGNAL("activated()"), self.grid.mostrar_t_reg) self.acciontab1.setAccel("F2") self.acciontab2 = QAction(self, "tabvars") self.connect(self.acciontab2, SIGNAL("activated()"), self.grid.mostrar_t_var) self.acciontab2.setAccel("F3") if self.__diccionarioacciones.has_key("Descriptivo"): self.__diccionarioacciones["Descriptivo"].setAccel("F4") self.__boton3.setAccel("F5") #Ventana salida self.archivoConfiguracinAction.setAccel("F10") self.acerca_deAcerca_deAction.setAccel("F12") self.archivoSalirAction.setAccel("Ctrl+Q") def __copiar(self): """Funcion que copia y borra la seleccion""" try: self.__copiar_privado() except AssertionError: QMessageBox.warning(self, u'Atención', 'Las operaciones de copiado, cortado y pegado no han sido implementadas') else: self.grid.borrar_seleccion() #http://www.google.com/codesearch?hl=en&q=+%22qtable%22+%22cut%22+%22paste%22+show:z9otKZeV6U8:R6dK3Cx-dYg:Gh37-3Ie27E&sa=N&cd=48&ct=rc&cs_p=http://mde.abo.fi/confluence/download/attachments/1011/coral-0.9.1.tar.gz&cs_f=coral-0.9.1/coral/modeler/property/propertyeditor.py#a0 def __cortar(self): """Copia, borra la seleccion y su contenido""" from Driza.excepciones import SeleccionIncorrectaException try: self.grid.verificar_seleccion_registros() self.__portero.guardar_estado() self.__copiar_privado() except SeleccionIncorrectaException: QMessageBox.warning(self, u'Atención', 'Solo se permite cortar registros') except AssertionError: QMessageBox.warning(self, u'Atención', 'Las operaciones de copiado, cortado y pegado no han sido implementadas') else: self.grid.borrar_seleccion(borrardatos=True) self.grid.myUpdate() def __pegar(self): """Funcion que envuelve a __pegar recogiendo sus excepciones""" #TODO Capturar otras excepciones try: self.__pegar_privado() except AssertionError: QErrorMessage(self, "Error").message(u"Error desconocido") LOG.exception("excepcion capturada en el pegado") def __pegar_privado(self): """Pega lo que haya sido copiado""" clipboard = QApplication.clipboard() registro = clipboard.text().latin1() lista = eval(registro) posrow = self.grid.table1.currentRow() poscol = self.grid.table1.currentColumn() if len(lista[0]) == self.__idu.n_var(): poscol = 0 #Copia de registro completo else: #No permitimos pegar si el pegado implica variables nuevas assert(poscol + len(lista[0]) <= self.__idu.n_var()) self.__portero.guardar_estado() #Guardamos el estado #Creamos nuevos registros hasta la posicion del cursor if posrow > self.__idu.n_reg(): for _ in range(self.__idu.n_reg(), posrow): self.__idu.ana_reg() #Hacemos el pegado efectivo i = posrow for registro in lista: if i >= self.__idu.n_reg(): self.__idu.ana_reg() j = poscol for campo in registro: if campo != None: self.__idu[i][j] = campo j += 1 i += 1 self.grid.myUpdate() def __salir_programa(self): """Funcion de salida del programa. Guarda la configuracion""" if not self.__dproyecto_modificado(): return self.__config.guardar() qApp.exit(0) def __nuevo(self): """Accion realizada cuando el usuario clickea en Nuevo""" if not self.__dproyecto_modificado(): return self.__idu.borrar_todo() self.__gestorproyectos.fichero = None self.__myUpdate() self.grid.myUpdate() def __guardar(self): """Funcion de guardado del fichero. Si el fichero no es conocido se llama a guardarcomo""" if self.__gestorproyectos.fichero: self.__gestorproyectos.guardar(sobreescribir = True) self.__idu.establecer_original() else: self.__guardar_como() def __guardar_como(self): """Abre un diálogo pidiendo el nombre de archivo y guarda en dicho archivo""" filtro = "" for fmt in SL.extensiones_fichero: filtro = filtro+ "%s files (*.%s);;" % (fmt, fmt.lower()) filename = QFileDialog.getSaveFileName(QString.null, filtro, self) filename = str(filename) if filename: from Driza.excepciones import FicheroExisteException, FicheroTipoDesconocidoException import re extension = re.compile('.*\..*') if not extension.match(filename): filename += ".driza" try: self.__gestorproyectos.guardar(filename) except FicheroExisteException, fichero: returncode = QMessageBox.information(self, 'Atencion:', 'El fichero' + fichero.fichero + ' ya existe' , 'Sobreescribir', 'Otro nombre', 'Cancelar', 0, 1) if returncode == 0: self.__gestorproyectos.guardar(filename, True) self.__idu.establecer_original() self.__myUpdate() elif returncode == 1: self.__guardarcomo() except FicheroTipoDesconocidoException: QMessageBox.warning(self, u'Atención', u'La extensión del fichero es incorrecta.\nPruebe con otra extensión') self.__gestorproyectos.fichero = None else:
def __init__(self, itemdata, name, slot, parent): QAction.__init__(self, parent, name) self.setMenuText(itemdata['text']) self.setToolTip(itemdata['ttip']) self.setWhatsThis(itemdata['whatsit']) self.connect(self, SIGNAL('activated()'), slot)
class BlogWin(QMainWindow): def __init__(self): QMainWindow.__init__(self) global server self.server = server self.filename = "" self.inEdit = False self.inPreview = False self.w = BlogWidget(self) self.setCentralWidget(self.w) self.connect(self.w.publish_b, SIGNAL("clicked()"), self.slotPublish) self.connect(self.w.entryList, SIGNAL("selected(int)"), self.slotEdit) if not password: self.slotGetPassword() self._setupMenus() self._fillEntryList() self.resize(550, 400) self.show() def _setupMenus(self): self._setupActions() self.fileMenu = QPopupMenu(self) self.menuBar().insertItem("&Dosya", self.fileMenu) self.newAction.addTo(self.fileMenu) self.deleteAction.addTo(self.fileMenu) self.quitAction.addTo(self.fileMenu) self.editMenu = QPopupMenu(self) self.menuBar().insertItem(u"&Düzenle", self.editMenu) self.imgAction.addTo(self.editMenu) self.previewAction.addTo(self.editMenu) def _setupActions(self): self.imgAction = QAction(self) self.imgAction.setAccel(QAccel.stringToKey("CTRL+ALT+R")) self.imgAction.setMenuText(u"Resim Ekle") self.connect(self.imgAction, SIGNAL("activated()"), self.slotInsertImage) self.passAction = QAction(self) self.passAction.setAccel(QAccel.stringToKey("CTRL+ALT+P")) self.connect(self.passAction, SIGNAL("activated()"), self.slotGetPassword) self.previewAction = QAction(self) self.previewAction.setAccel(QAccel.stringToKey("CTRL+ALT+O")) self.previewAction.setMenuText(u"Düzenleme/Önizleme modu") self.connect(self.previewAction, SIGNAL("activated()"), self.slotPreviewText) self.newAction = QAction(self) self.newAction.setAccel(QAccel.stringToKey("CTRL+ALT+Y")) self.newAction.setMenuText(u"Yeni") self.connect(self.newAction, SIGNAL("activated()"), self.slotNewEntry) self.deleteAction = QAction(self) self.deleteAction.setMenuText(u"Seçili olan gidiyi Sil") self.connect(self.deleteAction, SIGNAL("activated()"), self.slotDeleteEntry) self.quitAction = QAction(self) self.quitAction.setAccel(QAccel.stringToKey("CTRL+Q")) self.quitAction.setMenuText(u"Çık") self.connect(self.quitAction, SIGNAL("activated()"), self.slotQuit) def _fillEntryList(self): self.w.entryList.clear() logs = self.server.getLogs() for e in logs: self.w.entryList.insertItem(e) self.w.textLabel1.setText("Eski Girdiler (" + str(len(logs)) + "):") def _genFilename(self, line): self.filename = "" for c in range(line.length()): t = line[c] if t == u"ı" or t == u"İ": t = "i" elif t == u"ş" or t == u"Ş": t = "s" elif t == u"ü" or t == u"Ü": t = "u" elif t == u"ğ" or t == u"Ğ": t = "g" elif t == u"ö" or t == u"Ö": t = "o" elif t == u"ç" or t == u"Ç": t = "c" elif t == " " or t == "\t": t = "-" else: t = line[c].ascii() self.filename += t if not self.filename[-4] == ".txt": self.filename += ".txt" def slotGetPassword(self): askPass = PassDialog() askPass.exec_loop() def slotNewEntry(self): if self.inEdit: self.setEditMode(False) self.setPreviewMode(False) self.w.entryText.clear() def slotDeleteEntry(self): item = self.w.entryList.selectedItem() if not item: QMessageBox.critical( self, "HATA", u"Eski girdilerden hiçbiri seçili durumda değil!") return warnmsg = u"\"" + str(item.text().utf8( )) + u"\" isimli iletiyi gerçekten silmek istiyor musunuz?" ret = QMessageBox.question(self, "Dikkat!", warnmsg, u"Evet", u"Hayır") if ret != 0: return ret = self.server.deleteEntry(username, password, item.text().ascii()) if not ret: QMessageBox.critical(self, "HATA", u"Girdi silme başarısız!") else: QMessageBox.information(self, "Bitti", u"Girdi başarı ile silindi!") self._fillEntryList() def slotEdit(self, index): self.setEditMode(True) self.setPreviewMode(True) entry = self.w.entryList.item(index).text().ascii() self.filename = entry text = self.server.getText(entry) self.w.entryText.setText(text) def setEditMode(self, mode): if not mode: self.w.publish_b.setText(u"Yeni Girdiyi Yayınla") else: self.w.publish_b.setText(u"Eski Girdiyi Güncelle") self.w.entryText.clear() self.inEdit = mode def slotInsertImage(self): dlg = ImgSelectionDialog() if dlg.exec_loop() == QDialog.Accepted: filename = dlg.getSelectedImage() self.w.entryText.insert("<img src=\"" + blog_url + "/" + img_dir + "/" + filename + "\">") def slotPreviewText(self): if self.inPreview: self.setPreviewMode(False) else: self.setPreviewMode(True) def setPreviewMode(self, mode): self.w.entryText.setTextFormat(QTextEdit.PlainText) text = self.w.entryText.text() self.w.entryText.clear() if mode: self.w.entryText.setTextFormat(QTextEdit.RichText) self.w.textLabel2.setText(u"<b>** Önizleme **</b>") text.replace("\n", "<br>\n") else: self.w.textLabel2.setText("<b>Metin:</b>") text.replace("<br>\n", "\n") self.inPreview = mode self.w.entryText.setText(text) self.w.entryText.setReadOnly(mode) #preview mode'dayken yayınlama düğmesi kullanılamamalı. self.w.publish_b.setEnabled(not mode) #preview mode'dayken resim eklenemez.. self.imgAction.setEnabled(not mode) del text def slotPublish(self): global password text = self.w.entryText.text() firstline = text.left(text.find("\n")) if not firstline: QMessageBox.critical(self, "HATA", u"Bir metin girmediniz!") return # eğer EditMode içerisindeysek dosya adı liste kutusundan alınıyor # yeni bir dosya adı oluşturmaya gerek yok! if not self.inEdit: # dosya adını oluştur. self._genFilename(firstline) # her \n bir <br>\n ile değiştirilsin. text.replace("\n", "<br>\n") ret = QMessageBox.question( self, "Dikkat!", u"İçeriği gerçekten yayınlamak istiyor musun?", u"Evet", u"Hayır") if ret != 0: return # girdiyi gönder. ret = self.server.addEntry(username, password, str(self.filename), str(text.utf8()), self.inEdit) if not ret: QMessageBox.critical(self, "HATA", u"Girdi yayınlanamadı!") else: QMessageBox.information(self, "Bitti", u"Girdi başarı ile yayınlandı!") self._fillEntryList() # yayınladıktan sonra eğer içindeysek, EditMode'dan # çıkalım. Ve metin girişini temizleyelim. if self.inEdit: self.setEditMode(False) self.w.entryText.clear() def slotQuit(self): self.close()
def _setupActions(self): self.imgAction = QAction(self) self.imgAction.setAccel(QAccel.stringToKey("CTRL+ALT+R")) self.imgAction.setMenuText(u"Resim Ekle") self.connect(self.imgAction, SIGNAL("activated()"), self.slotInsertImage) self.passAction = QAction(self) self.passAction.setAccel(QAccel.stringToKey("CTRL+ALT+P")) self.connect(self.passAction, SIGNAL("activated()"), self.slotGetPassword) self.previewAction = QAction(self) self.previewAction.setAccel(QAccel.stringToKey("CTRL+ALT+O")) self.previewAction.setMenuText(u"Düzenleme/Önizleme modu") self.connect(self.previewAction, SIGNAL("activated()"), self.slotPreviewText) self.newAction = QAction(self) self.newAction.setAccel(QAccel.stringToKey("CTRL+ALT+Y")) self.newAction.setMenuText(u"Yeni") self.connect(self.newAction, SIGNAL("activated()"), self.slotNewEntry) self.deleteAction = QAction(self) self.deleteAction.setMenuText(u"Seçili olan gidiyi Sil") self.connect(self.deleteAction, SIGNAL("activated()"), self.slotDeleteEntry) self.quitAction = QAction(self) self.quitAction.setAccel(QAccel.stringToKey("CTRL+Q")) self.quitAction.setMenuText(u"Çık") self.connect(self.quitAction, SIGNAL("activated()"), self.slotQuit)