Braindump

Just a Braindump for various useful things, mostly concerning Programming Languages!

This makes a nice, embedded matplotlib Plot in a GTK app

        if self.canvas1 != None:
            self.axis1.clear()
            self.figure1.clear()
            self.canvas1.hide()
            self.canvas1.destroy()

        self.figure1 = Figure()
        self.axis1 = self.figure1.add_subplot(111)
        self.axis1.set_xlabel('Bins')
        self.axis1.set_ylabel('Percentage')
        self.axis1.set_title('Histogram')
        self.axis1.grid(True)
        self.canvas1 = FigureCanvasGTK(self.figure1)
        self.canvas1.show()
        self.graphview = self.xml.get_widget('graphbox')
        self.graphview.pack_start(self.canvas1, True, True)

        pl1 = self.axis1.bar(numpy.arange(0, int(self.db["nbin"]*self.db["binw"]), int(self.db["binw"])), histlist1, width=self.db["binw"], color='red')
        self.axis1.set_xlim(xmin=0, xmax=int(self.db["nbin"] * self.db["binw"]))
        self.axis1.set_ylim(ymin=0, ymax=100)
        self.figure1.legend((pl1[0], pl2[0]), ('CW', 'CCW'), loc='upper left')

Sort a TreeView with a custom sort-func

        liststore.set_sort_func(2, self.sort_float, 2)
        liststore.set_sort_func(3, self.sort_float, 3)
    def sort_float(self, treemodel, iter1, iter2, column):
        iter1 = treemodel.get_value(iter1, column)
        iter2 = treemodel.get_value(iter2, column)
        if float(iter1) < float(iter2):
            return -1
        elif float(iter1) > float(iter2):
            return 1
        else:
            return 0

Python & gettext on Windows

First Time Run:

perl gettext\bin\intltool-extract --type=gettext/glae hit_gui.glade
gettext\bin\xgettext.exe --language=Python --keyword=_ --keyword=N_ --output=hit.pot hit_gui.glade.h hit.py
gettext\bin\msginit --input=hit.pot --locale=de_DE
gettext\bin\msginit --input=hit.pot --locale=it_IT
md locale
md locale\de_DE
md locale\de_DE\LC_MESSAGES
md locale\it_IT
md locale\it_IT\LC_MESSAGES

*** Create Translation in de.po/it.po/... ***

gettext\bin\msgfmt --output-file=locale\de_DE\LC_MESSAGES\hit.mo de.po
gettext\bin\msgfmt --output-file=locale\it_IT\LC_MESSAGES\hit.mo it.po

Code Change:
perl gettext\bin\intltool-extract --type=gettext/glade hit_gui.glade
gettext\bin\xgettext.exe --language=Python --keyword=_ --keyword=N_ --output=hit.pot hit_gui.glade.h hit.py
gettext\bin\msgmerge -U de.po hit.pot
gettext\bin\msgmerge -U it.po hit.pot

*** Create Translation in de.po/it.po/... ***

gettext\bin\msgfmt --output-file=locale\de_DE\LC_MESSAGES\hit.mo de.po
gettext\bin\msgfmt --output-file=locale\it_IT\LC_MESSAGES\hit.mo it.po

To avoid problems with UTF8 and ISO conversions, I usually run the program via a batch file, setting the language explicitly (set lang=de_DE).

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies