Blob Blame History Raw
<?xml version="1.0" encoding="utf-8"?>
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" type="guide" style="task" id="statusbar.py" xml:lang="ko">
  <info>
    <title type="text">Statusbar (Python)</title>
    <link type="guide" xref="beginner.py#display-widgets"/>
    <link type="seealso" xref="signals-callbacks.py"/>
    <link type="next" xref="spinner.py"/>    
    <revision version="0.2" date="2012-06-12" status="draft"/>

    <credit type="author copyright">
      <name>Marta Maria Casetti</name>
      <email its:translate="no">mmcasetti@gmail.com</email>
      <years>2012</years>
    </credit>

    <desc>별로 중요하지 않은 메시지를 사용자에게 알립니다</desc>
  
    <mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
      <mal:name>조성호</mal:name>
      <mal:email>shcho@gnome.org</mal:email>
      <mal:years>2017</mal:years>
    </mal:credit>
  </info>

  <title>Statusbar</title>
  <media type="image" mime="image/png" src="media/statusbar.png"/>
  <p>이 상태 표시줄은 단추를 누르거나 아무 키(어떤 키)를 눌렀을 때 알려줍니다.</p>

  <links type="section"/>

  <section id="code">
  <title>예제 결과를 만드는 코드</title>

  <code mime="text/x-python" style="numbered">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)
</code>

  <note><p><code>Gdk.keyval_name(event.keyval)</code>은  <code>event.keyval</code> 키 값을 심볼릭 이름으로 변환합니다. 이름과 관련 키 값은 <link href="http://git.gnome.org/browse/gtk+/tree/gdk/gdkkeysyms.h">여기</link>에서 알아볼 수 있지만, 예를 들어 <code>GDK_KEY_BackSpace</code> 인스턴스는 <code>"BackSpace"</code> 문자열입니다.</p></note>
  </section>

  <section id="methods">
  <title>Statusbar 위젯에 쓸만한 메서드</title>
    <p>17번째 줄에서 <code>"clicked"</code> 시그널은 <code><var>widget</var>.connect(<var>signal</var>, <var>callback function</var>)</code> 함수로  <code>button_clicked_cb()</code> 콜백 함수에 연결했습니다. 더 자세한 설명은 <link xref="signals-callbacks.py"/>를 참조하십시오.</p>
  <list>
    <item><p><code>pop(context_id)</code> 함수는 상태 표시줄 스택에서 <code>context_id</code>가 주어진 처음 메시지를 제거합니다.</p></item>
    <item><p><code>remove_all(context_id)</code> 함수는 상태 표시줄 스택에서 <code>context_id</code>가 주어진 모든 메시지를 제거합니다.</p></item>
    <item><p><code>remove(context_id, message_id)</code> 함수는 상태 표시줄 스택에서 <code>message_id</code>가 주어진 메시지를 제거합니다. <code>message_id</code>는 <code>push(context_id, "the message")</code> 함수로 상태 표시줄에 메시지를 밀어넣을 때 반환합니다.</p></item>
  </list>
  </section>

  <section id="references">
  <title>API 참고서</title>
  <p>이 예제는 다음 참고자료가 필요합니다:</p>
  <list>
    <item><p><link href="http://developer.gnome.org/gtk3/unstable/GtkStatusbar.html">GtkStatusbar</link></p></item>
    <item><p><link href="http://developer.gnome.org/gdk/stable/gdk-Keyboard-Handling.html">Gdk - 키 값</link></p></item>
  </list>
  </section>
</page>