def __init__(self, parent_window=None, message=None, window_title=None): Dialog.__init__( self, unicode(StringType(window_title)).encode('utf-8'), parent_window, 0, (gtk.STOCK_NO, gtk.RESPONSE_NO, gtk.STOCK_YES, gtk.RESPONSE_YES)) hbox = gtk.HBox(False, 8) hbox.set_border_width(8) self.vbox.pack_start(hbox, False, False, 0) stock = gtk.image_new_from_stock(gtk.STOCK_DIALOG_QUESTION, gtk.ICON_SIZE_DIALOG) hbox.pack_start(stock, False, False, 0) label = gtk.Label(unicode(StringType(message)).encode('utf-8')) hbox.pack_start(label, True, True, 0) self.show_all() self.response = self.run() self.destroy()
def __init__(self, cnx=None, window=None): self.ventana = window self.cnx = cnx self.cod_empresa = None if cnx == None: dlgError(self.ventana, 'No hay una conexión activa.') return lbl = unicode("Selección de Empresa") Dialog.__init__(self, lbl.encode("utf-8"), window, 0, (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)) self.set_position(gtk.WIN_POS_CENTER_ALWAYS) hbox = gtk.HBox(False, 8) hbox.set_border_width(8) self.vbox.pack_start(hbox, 1, False, 0) stock = gtk.Image() stock.set_from_stock(gtk.STOCK_HOME, gtk.ICON_SIZE_DIALOG) hbox.pack_start(stock, False, False, 0) label = gtk.Label("Empresa") label.set_use_underline(True) hbox.pack_start(label, 0, 0, 0) try: r = cnx.cursor() r.execute( "select text(cod_empresa), descripcion_empresa from cc.empresa order by descripcion_empresa" ) l = r.fetchall() except: dlgError(self.ventana, StringType(sys.exc_info()[1])) return 0 self.modelo = gtk.ListStore(str, str) for i in l: self.modelo.append([i[0], unicode(i[1]).encode('utf-8')]) self.combo = gtk.ComboBox(self.modelo) cell = gtk.CellRendererText() self.combo.pack_start(cell, True) self.combo.add_attribute(cell, 'text', 0) cell = gtk.CellRendererText() self.combo.pack_start(cell, True) self.combo.add_attribute(cell, 'text', 1) self.combo.set_active(0) self.cod_empresa = l[0][0] self.combo.set_size_request(300, 25) hbox.pack_start(self.combo, True, True, 0) label.set_mnemonic_widget(self.combo) self.set_default_response(gtk.RESPONSE_OK) self.show_all()
def __init__(self, parent_window=None, message=""): MessageDialog.__init__( self, parent_window, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, unicode(StringType(message)).encode('utf-8')) self.set_default_response(gtk.BUTTONS_OK) self.connect('response', lambda dialog, response: dialog.destroy()) self.run()
def __new__(self, filename): rtf_name = filename[:-4] + '.rtf' try: z = ZipFile( filename ) files = z.namelist() content = z.read( files[0] ) z.close() except BadZipfile: return None return StringType.__new__(self, content )
def __init__(self, parent_window=None, message="", quit=None, trace=True): Dialog.__init__(self, unicode(StringType("Error")).encode('utf-8'), parent_window, 0, (gtk.STOCK_OK, gtk.RESPONSE_OK)) self.set_default_size(400, 150) hbox = gtk.HBox(False, 8) hbox.set_border_width(8) self.vbox.pack_start(hbox, False, False, 0) stock = gtk.image_new_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_DIALOG) hbox.pack_start(stock, False, False, 0) try: label = gtk.Label(unicode(StringType(message)).encode('utf-8')) except: label = gtk.Label("Ha ocurrido un error.") label.set_use_markup(True) hbox.pack_start(label, True, True, 0) if trace: sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) textview = gtk.TextView() textbuffer = textview.get_buffer() sw.add(textview) sw.show() textview.set_editable(False) textview.set_cursor_visible(False) textview.show() t = StringType(sys.exc_info()[0]) + "\n" t += StringType(sys.exc_info()[1]) + "\n" t += "Traza:\n" for i in traceback.format_tb(sys.exc_info()[2]): t += i + "\n" textbuffer.set_text(t) expander = gtk.Expander("Detalles") expander.add(sw) expander.set_expanded(True) self.vbox.pack_start(expander, True, True) self.show_all() self.response = self.run() self.destroy()
def str_message_repr(self): return '%s.%s(%s)' %( type(self).__module__, type(self).__name__, StringType.__repr__(self), )
def _compile(target, localfilename, fkt_name): """ Compiles a C++ function into a shared object library :param target: target folder where the .cpp file is located and where the output should be stored :param localfilename: name of file to be compiled without '.cpp' suffix :param fkt_name: name of the function to be compiled :raises Exception: An exception is raised if the file could be to compiled :return so_filename: The name of the .so file """ outfile, stdout, stderr, argv = None, None, None, sys.argv try: sys.stdout.flush(), sys.stderr.flush() outfile = open(os.path.join(target, "{0}.out".format(localfilename)), 'w') if sys.version_info[0] == 2 and isinstance( sys.stdout, file) and isinstance(sys.stdout, file): stdout, stderr = os.dup(sys.stdout.fileno()), os.dup( sys.stderr.fileno()) os.dup2(outfile.fileno(), sys.stdout.fileno()) os.dup2(outfile.fileno(), sys.stderr.fileno()) else: stdout, stderr = sys.stdout, sys.stderr sys.stdout, sys.stderr = outfile, outfile try: sources = os.path.join(target, "{0}.cpp".format(localfilename)) sys.argv = [ "", "build_ext", "-b", target, #--build-lib (-b) directory for compiled extension modules "-t", "/" #--build-temp - a rel path will result in a dir structure of -b at the cur position ] # setuptools have a problem with the unicode_literals in python 2 ... if sys.version_info[0] == 2: from types import StringType localfilename = StringType(localfilename) sources = StringType(sources) # avoid warning on linux + gcc cfg_vars = distutils.sysconfig.get_config_vars() if "CFLAGS" in cfg_vars: cfg_vars["CFLAGS"] = cfg_vars["CFLAGS"].replace( "-Wstrict-prototypes", "") if "OPT" in cfg_vars: cfg_vars["OPT"] = cfg_vars["OPT"].replace( "-Wstrict-prototypes", "") setuptools.setup( \ name = localfilename\ , ext_modules = [setuptools.Extension( \ localfilename \ , sources = [sources] \ , extra_compile_args = config.cxxflags \ )] \ , include_dirs = get_numpy_include_dirs() \ ) except SystemExit as e: print(sys.stderr.write(str(e))) sys.stdout.flush(), sys.stderr.flush() finally: if isinstance(stdout, int): os.dup2(stdout, sys.stdout.fileno()), os.close(stdout) elif not stdout is None: sys.stdout = stdout if isinstance(stderr, int): os.dup2(stderr, sys.stderr.fileno()), os.close(stderr) elif not stderr is None: sys.stderr = stderr if (sys.version_info[0] == 2 and isinstance(outfile, file))\ or (sys.version_info[0] == 3 and isinstance(outfile, io.TextIOWrapper) and not outfile.closed): outfile.close() sys.argv = argv with open(os.path.join(target, "{0}.out".format(localfilename))) as outfile: out = outfile.read() # on Travis CI & Py33 name contains additional suffix to .so so_filename = build_ext(Distribution()).get_ext_filename(localfilename) if not os.path.isfile(os.path.join( target, so_filename)) or out.find("error:") > -1: print(out) raise Exception( "Error compiling function {0} (compiled to {1})".format( fkt_name, target)) #TODO: add test case if out.find("warning:") > -1: try: #trying to encode utf-8 to support AstroPy warnings.warn( "A warning has been issued during compilation:\n{0}".format( out).encode('utf-8')) except UnicodeError: #encoding fails on Linux warnings.warn( "A warning has been issued during compilation:\n{0}".format( out)) if config.verbose: print(out) return so_filename