2011-10-09 8 views
1

別のウィンドウに表示されるカスタムウィジェットに問題があります。ウィンドウ内にあるすべてのウィジェットの意味ではなく、ウィンドウを別々にしてください。しかし、それらはすべて独自のウィンドウ装飾で個別に表示されます。私はどこに問題があるのか​​は分かりませんが、私はそれが次のいずれかにあるかもしれないと推測しました。 do_realizeはのinitで呼び出されています(下にも表示されています)。私はdo_expose_eventがgtkによって呼び出されると思っていますが、本当にわかりません。私はdo_expose_eventにprintステートメントを入れ、ウィジェットを作るプログラムのgtk mainに入る直前に置いたprintステートメントの後にそれぞれ呼び出されます。すべてのコードがGPLされています。pygtkカスタムウィジェットが別ウィンドウで表示

他のコードが必要な場合は、リクエストに応じて利用できます。

def do_realize(self): 
    """Makes a window on which we draw""" 

    #set a flag to say we are realised 
    self.set_flags(self.flags() | gtk.REALIZED) 

    #make a gdk window to draw on 
    self.window = gtk.gdk.Window(self.get_parent_window(), width=self.allocation.width, 
        height=self.allocation.height, window_type=gtk.gdk.WINDOW_CHILD, 
        wclass=gtk.gdk.INPUT_OUTPUT, event_mask=self.get_events() | gtk.gdk.EXPOSURE_MASK) 

    #associate the window with the widget 
    self.window.set_user_data(self) 

    #attach a style 
    self.style.attach(self.window) 

    #set the default background colour to whatever the theme says, and the state 
    self.style.set_background(self.window, gtk.STATE_NORMAL) 
    self.window.move_resize(*self.allocation) 

def do_expose_event(self, event): 
    """Called when the widget is asked to draw itself""" 
    #put the allocation in some variables 
    x, y, w, h = self.allocation 
    cr = self.window.cairo_create() 


    #if height is greater than width 
    if (h > w): 
     scale = h/float(BASE_SIZE) 
    else: 
     scale = w/float(BASE_SIZE) 

    #set the scale 
    cr.scale(scale,scale) 

    #put in the colour 
    self.draw_background_color(cr) 

    #draw the highlight if necessary 
    if self.is_focus(): 
     self.draw_highlight_box(cr) 

    self.draw_normal_box(cr) 
    self.draw_text(cr) 
    if self.draw_boxes and self.is_focus(): 
     self.draw_note_area_highlight_box(cr) 

def __init__(self, upper=9, text=''): 
    """initialise it""" 
    gtk.Widget.__init__(self)  #init the super class 
    self.upper = upper 
    self.font = self.style.font_desc 
    self.font.set_size(pango.SCALE*13) 
    self.note_font = self.font.copy() 
    self.note_font.set_size(pango.SCALE*6) 

    #set properties-can focus and grab all events 
    self.set_property('can-focus',True) 
    self.set_property('events',gtk.gdk.ALL_EVENTS_MASK) 

    #connect the events to functions 
    self.connect('button-press-event',self.button_press)  #box is clicked on 
    self.connect('key-release-event',self.key_press)   #release of key when inputting 
    self.connect('enter-notify-event',self.pointer_enter)  #pointer enters 
    self.connect('leave-notify-event',self.pointer_leave)  #pointer leaves 
    self.connect('focus-in-event',self.focus_in)    #goes into focus 
    self.connect('focus-out-event',self.focus_out)    #goes out of focus 
    self.connect('motion-notify-event',self.motion_notify)  #poniter is in the window 

    #debugging info 
    #print type(self) 

    self.set_text(text) 
    self.do_realize() 
+0

ここから2つの方法がありますか? – Louis

+0

彼らはどちらも__init__から呼び出されています。私は質問をより明確にするように変更しました。 – Harpy

答えて

1

の代わりに "__ initを"でdo_realizeを呼び出す("" と "初期化" の間にスペースを入れず、それがテキストを太字)、私はqueue_drawを呼び出す必要があります。私はpygtk ircの助けを得ました。

+0

なぜ私はdo_realizeがそこにあったのだろうと思っていましたが、解決策を見つけられませんでした。投稿していただきありがとうございます。私はこの有益なメッセージの両方のエントリをupvote。 – Louis

関連する問題