DrawingArea Probleme

Programmierung für GNOME und GTK+, GUI-Erstellung mit Glade.
Antworten
Clython
User
Beiträge: 151
Registriert: Samstag 21. August 2004, 13:58
Wohnort: Schweiz, BE-2500

Hallo Leute

ich versuche gerade ein GUI für eine Anwendung zu basteln und habe bisher folgenden Code:

Code: Alles auswählen

#!/usr/bin/env python
# -*- coding: UTF8 -*-

# Python module can.py
# Autogenerated from can.glade
# Generated on Sun Feb 25 14:52:56 2007

# Warning: Do not modify any context comment such as #--
# They are required to keep user's code

import os, codecs

import gtk, pango

from SimpleGladeApp import SimpleGladeApp
from SimpleGladeApp import bindtextdomain
from article import ArticleNavigator
from xmlparser import parseCAN
from helper import sortid

app_name = "can"
app_version = "0.0.1"

glade_dir = ""
locale_dir = ""

bindtextdomain(app_name, locale_dir)


class Can(SimpleGladeApp):

    def __init__(self, path="can.glade",
                 root="CAN",
                 domain=app_name, **kwargs):
        path = os.path.join(glade_dir, path)
        SimpleGladeApp.__init__(self, path, root, domain, **kwargs)
        self.navigator = None

    #-- Can.new {
    def new(self):
        print "A new %s has been created" % self.__class__.__name__
    #-- Can.new }

    #-- Can custom methods {
    def show_editor(self):
        editor = self.RightAnnoField
        x, y, width, height = editor.get_allocation()
        editor.set_size_request(width, height)
        color = gtk.gdk.Color(red=50, green=50, blue=50, pixel=0)
        bcolor = gtk.gdk.Color(red=1000, green=1000, blue=1000, pixel=0)
        gc = editor.window.new_gc(foreground=color, background=bcolor, font=None, 
                     function=-1, fill=-1, tile=None,
                     stipple=None, clip_mask=None, subwindow_mode=-1,
                     ts_x_origin=-1, ts_y_origin=-1, clip_x_origin=-1,
                     clip_y_origin=-1, graphics_exposures=-1,
                     line_width=-1, line_style=-1, cap_style=-1,
                     join_style=-1)
        editor.window.draw_point(gc, 10, 10)
##        editor.realize()
##        print dir(editor)
        print "Editor Drawn"
    def show_sentence(self):
        # Create Tags
        highlight_tag = gtk.TextTag("highlight")
        highlight_tag.set_property("foreground", "red")
        title_tag = gtk.TextTag("title")
        title_tag.set_property("weight", pango.WEIGHT_BOLD)
        both_tag = gtk.TextTag("both")
        both_tag.set_property("weight", pango.WEIGHT_BOLD)
        both_tag.set_property("foreground", "red")
        # Create Buffer
        buf = gtk.TextBuffer()
        tag_table = buf.get_tag_table()
        tag_table.add(highlight_tag)
        tag_table.add(title_tag)
        tag_table.add(both_tag)
        # Create Tags done
        senIDs = sortid(self.navigator.senindex)
        # Compute Text Buf
        for x in xrange(0, len(senIDs)):
            sen = senIDs[x]
            type, text = self.navigator.getText(sen)
            if type == "title" and self.navigator.current == x and x == 0:
                text = text + "\n"
                sob, eob = buf.get_bounds()
                buf.insert_with_tags_by_name(eob, text, "both")
            elif type == "title" and x == self.navigator.current:
                text = "\n" + text + "\n"
                sob, eob = buf.get_bounds()
                buf.insert_with_tags_by_name(eob, text, "both")
            elif type == "title":
                text = "\n" + text + "\n"
                sob, eob = buf.get_bounds()
                buf.insert_with_tags_by_name(eob, text, "title")
            elif self.navigator.current == x:
                text = " " + text + " "
                sob, eob = buf.get_bounds()
                buf.insert_with_tags_by_name(eob, text, "highlight")
            else:
                sob, eob = buf.get_bounds()
                buf.insert(eob, text)
        # Compute Text Buf done
        # Display Text
        self.RightTextDisplay.set_buffer(buf)
    def set_navigator(self, navigator):
        print "Set Navigator"
        self.navigator = navigator
        self.set_meta()
        self.show_sentence()
        self.show_editor()
    def sen_nr(self):
        length = len(self.navigator.article.sentences)
        pos = self.navigator.current +1
        nr = str(pos) + " / " + str(length)
        return nr
    def nuc_nr(self):
        buf = self.navigator.article.sentences
        buf.sort()
        senID = buf[self.navigator.current]
        sen = self.navigator.article[senID]
        length = len(sen["nuclei"])
        if length == 0:
            return "0 / 0"
        else:
            pos = self.navigator.currnuc +1
            nr = str(pos) + " / " + str(length)
            return nr
        
    def set_meta(self):
        print "set_meta"
        root = self.navigator.article.root
        meta = self.navigator.article[root]
##        print self.navigator.article.terminals
##        print dir(self.RightMetaLandValue)
        ID = u"Artikel-ID: " + root
        self.RightArtlIDLabl.set_label(ID)
        senID = "Satz-ID: " + root + "-" + str(self.navigator.current + 1)
        self.RightSentIDLabl.set_label(senID)
        
        self.RightMetaLandValue.set_label(meta["countrycode"])
        self.RightMetaRubrValue.set_label(meta["rubric"].encode("utf8"))
        self.RightMetaDateValue.set_label(meta["published"])
        self.RightMetaSiteValu.set_label(meta["page"])
        self.RightMetaPaprValue.set_label(meta["paper"])
        self.RightMetaLengValue.set_label(meta["length"])
        
        self.RightSentCounter.set_label(self.sen_nr())
        self.RightAnnoNuclValue.set_label(self.nuc_nr())
    #-- Can custom methods }

    #-- Can.on_MenuFileNew_activate {
    def on_MenuFileNew_activate(self, widget, *args):
        print "on_MenuFileNew_activate called with self.%s" % widget.get_name()
    #-- Can.on_MenuFileNew_activate }

    #-- Can.on_MenuFileOpen_activate {
    def on_MenuFileOpen_activate(self, widget, *args):
        print "on_MenuFileOpen_activate called with self.%s" % widget.get_name()
        self.open_file = Openfile(self.set_navigator)
##        self.open_file.run()
    #-- Can.on_MenuFileOpen_activate }

    #-- Can.on_MenuFileSave_activate {
    def on_MenuFileSave_activate(self, widget, *args):
        print "on_MenuFileSave_activate called with self.%s" % widget.get_name()
    #-- Can.on_MenuFileSave_activate }

    #-- Can.on_MenuFileSaveas_activate {
    def on_MenuFileSaveas_activate(self, widget, *args):
        print "on_MenuFileSaveas_activate called with self.%s" % widget.get_name()
    #-- Can.on_MenuFileSaveas_activate }

    #-- Can.on_MenuFileQuit_activate {
    def on_MenuFileQuit_activate(self, widget, *args):
        print "on_MenuFileQuit_activate called with self.%s" % widget.get_name()
        self.quit()
    #-- Can.on_MenuFileQuit_activate }

    #-- Can.on_MenuEditCut_activate {
    def on_MenuEditCut_activate(self, widget, *args):
        print "on_MenuEditCut_activate called with self.%s" % widget.get_name()
    #-- Can.on_MenuEditCut_activate }

    #-- Can.on_MenuEditCopy_activate {
    def on_MenuEditCopy_activate(self, widget, *args):
        print "on_MenuEditCopy_activate called with self.%s" % widget.get_name()
    #-- Can.on_MenuEditCopy_activate }

    #-- Can.on_MenuEditPaste_activate {
    def on_MenuEditPaste_activate(self, widget, *args):
        print "on_MenuEditPaste_activate called with self.%s" % widget.get_name()
    #-- Can.on_MenuEditPaste_activate }

    #-- Can.on_MenuEditDel_activate {
    def on_MenuEditDel_activate(self, widget, *args):
        print "on_MenuEditDel_activate called with self.%s" % widget.get_name()
    #-- Can.on_MenuEditDel_activate }

    #-- Can.on_MenuHelpAbout_activate {
    def on_MenuHelpAbout_activate(self, widget, *args):
        print "on_MenuHelpAbout_activate called with self.%s" % widget.get_name()
    #-- Can.on_MenuHelpAbout_activate }

    #-- Can.on_Connect_clicked {
    def on_Connect_clicked(self, widget, *args):
        print "on_Connect_clicked called with self.%s" % widget.get_name()
    #-- Can.on_Connect_clicked }

    #-- Can.on_Disconnect_clicked {
    def on_Disconnect_clicked(self, widget, *args):
        print "on_Disconnect_clicked called with self.%s" % widget.get_name()
    #-- Can.on_Disconnect_clicked }

    #-- Can.on_Help_clicked {
    def on_Help_clicked(self, widget, *args):
        print "on_Help_clicked called with self.%s" % widget.get_name()
    #-- Can.on_Help_clicked }

    #-- Can.on_LeftTextBackButt_clicked {
    def on_LeftTextBackButt_clicked(self, widget, *args):
        print "on_LeftTextBackButt_clicked called with self.%s" % widget.get_name()
    #-- Can.on_LeftTextBackButt_clicked }

    #-- Can.on_LeftTextForwButt_clicked {
    def on_LeftTextForwButt_clicked(self, widget, *args):
        print "on_LeftTextForwButt_clicked called with self.%s" % widget.get_name()
    #-- Can.on_LeftTextForwButt_clicked }

    #-- Can.on_LeftSentBackButt_clicked {
    def on_LeftSentBackButt_clicked(self, widget, *args):
        print "on_LeftSentBackButt_clicked called with self.%s" % widget.get_name()
        self.navigator.prevsen()
        self.set_meta()
        self.show_sentence()
    #-- Can.on_LeftSentBackButt_clicked }

    #-- Can.on_LeftSentForwButt_clicked {
    def on_LeftSentForwButt_clicked(self, widget, *args):
        print "on_LeftSentForwButt_clicked called with self.%s" % widget.get_name()
        self.navigator.nextsen()
        self.set_meta()
        self.show_sentence()
    #-- Can.on_LeftSentForwButt_clicked }

    #-- Can.on_LeftNuclBackButt_clicked {
    def on_LeftNuclBackButt_clicked(self, widget, *args):
        print "on_LeftNuclBackButt_clicked called with self.%s" % widget.get_name()
    #-- Can.on_LeftNuclBackButt_clicked }

    #-- Can.on_LeftNuclForwButt_clicked {
    def on_LeftNuclForwButt_clicked(self, widget, *args):
        print "on_LeftNuclForwButt_clicked called with self.%s" % widget.get_name()
    #-- Can.on_LeftNuclForwButt_clicked }

    #-- Can.on_LeftNuclNew_clicked {
    def on_LeftNuclNew_clicked(self, widget, *args):
        print "on_LeftNuclNew_clicked called with self.%s" % widget.get_name()
    #-- Can.on_LeftNuclNew_clicked }


class Openfile(SimpleGladeApp):

    def __init__(self, set, path="can.glade",
                 root="openFile",
                 domain=app_name, **kwargs):
        path = os.path.join(glade_dir, path)
        SimpleGladeApp.__init__(self, path, root, domain, **kwargs)
        self.navigator = None
        self.set = set

    #-- Openfile.new {
    def new(self):
        print "A new %s has been created" % self.__class__.__name__
    #-- Openfile.new }

    #-- Openfile custom methods {
    def returnData(self):
        return self.navigator
    #-- Openfile custom methods }

    #-- Openfile.on_openFile_response {
    def on_openFile_response(self, widget, *args):
        print "on_openFile_response called with self.%s" % widget.get_name()
        g = parseCAN(widget.get_uri())
        self.navigator = ArticleNavigator(g)
        print "Generated Navigator"
    #-- Openfile.on_openFile_response }

    #-- Openfile.on_FileOpenCancel_clicked {
    def on_FileOpenCancel_clicked(self, widget, *args):
        print "on_FileOpenCancel_clicked called with self.%s" % widget.get_name()
        widget.window.destroy()
    #-- Openfile.on_FileOpenCancel_clicked }

    #-- Openfile.on_openFileButton_clicked {
    def on_openFileButton_clicked(self, widget, *args):
        print "on_openFileButton_clicked called with self.%s" % widget.get_name()
        self.set(self.navigator)
        widget.window.hide()
    #-- Openfile.on_openFileButton_clicked }


#-- main {

def main():
    c_aN = Can()
    c_aN.run()

if __name__ == "__main__":
    main()

#-- main }
Das Problem ist, dass wenn ich die Methode show_editor aufrufe, bekomme ich zwar keine Fehlermeldung, aber ich sehe auch nichts im Fenster. Ich hab mal versucht mit dem rumzuspielen http://www.python-forum.de/viewtopic.ph ... d7587b9d56, aber das hat auch nicht geholfen. Was mache ich falsch?

PS: Ich benutze Glade in Kombination mit SimpleGladeApp.py
Antworten