Statusbar (Python) Marta Maria Casetti mmcasetti@gmail.com 2012 별로 중요하지 않은 메시지를 사용자에게 알립니다 조성호 shcho@gnome.org 2017 Statusbar

이 상태 표시줄은 단추를 누르거나 아무 키(어떤 키)를 눌렀을 때 알려줍니다.

예제 결과를 만드는 코드 from gi.repository import Gtk from gi.repository import Gdk import sys class MyWindow(Gtk.ApplicationWindow): # a window def __init__(self, app): Gtk.Window.__init__(self, title="StatusBar Example", application=app) self.set_default_size(200, 100) # a label label = Gtk.Label(label="Press any key or ") # a button button = Gtk.Button(label="click me.") # connected to a callback button.connect("clicked", self.button_clicked_cb) # the statusbar self.statusbar = Gtk.Statusbar() # its context_id - not shown in the UI but needed to uniquely identify # the source of a message self.context_id = self.statusbar.get_context_id("example") # we push a message onto the statusbar's stack self.statusbar.push( self.context_id, "Waiting for you to do something...") # a grid to attach the widgets grid = Gtk.Grid() grid.set_column_spacing(5) grid.set_column_homogeneous(True) grid.set_row_homogeneous(True) grid.attach(label, 0, 0, 1, 1) grid.attach_next_to(button, label, Gtk.PositionType.RIGHT, 1, 1) grid.attach(self.statusbar, 0, 1, 2, 1) # add the grid to the window self.add(grid) # callback function for the button clicked # if the button is clicked the event is signaled to the statusbar # onto which we push a new status def button_clicked_cb(self, button): self.statusbar.push(self.context_id, "You clicked the button.") # event handler def do_key_press_event(self, event): # any signal from the keyboard is signaled to the statusbar # onto which we push a new status with the symbolic name # of the key pressed self.statusbar.push(self.context_id, Gdk.keyval_name(event.keyval) + " key was pressed.") # stop the signal emission return True class MyApplication(Gtk.Application): def __init__(self): Gtk.Application.__init__(self) def do_activate(self): win = MyWindow(self) win.show_all() def do_startup(self): Gtk.Application.do_startup(self) app = MyApplication() exit_status = app.run(sys.argv) sys.exit(exit_status)

Gdk.keyval_name(event.keyval)event.keyval 키 값을 심볼릭 이름으로 변환합니다. 이름과 관련 키 값은 여기에서 알아볼 수 있지만, 예를 들어 GDK_KEY_BackSpace 인스턴스는 "BackSpace" 문자열입니다.

Statusbar 위젯에 쓸만한 메서드

17번째 줄에서 "clicked" 시그널은 widget.connect(signal, callback function) 함수로 button_clicked_cb() 콜백 함수에 연결했습니다. 더 자세한 설명은 를 참조하십시오.

pop(context_id) 함수는 상태 표시줄 스택에서 context_id가 주어진 처음 메시지를 제거합니다.

remove_all(context_id) 함수는 상태 표시줄 스택에서 context_id가 주어진 모든 메시지를 제거합니다.

remove(context_id, message_id) 함수는 상태 표시줄 스택에서 message_id가 주어진 메시지를 제거합니다. message_idpush(context_id, "the message") 함수로 상태 표시줄에 메시지를 밀어넣을 때 반환합니다.

API 참고서

이 예제는 다음 참고자료가 필요합니다:

GtkStatusbar

Gdk - 키 값