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="spinbutton.py" xml:lang="ko">
  <info>
    <title type="text">SpinButton (Python)</title>
    <link type="guide" xref="beginner.py#entry"/>
    <link type="seealso" xref="signals-callbacks.py"/>
    <link type="next" xref="entry.py"/>    
    <revision version="0.2" date="2012-06-23" 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>SpinButton</title>
  <media type="image" mime="image/png" src="media/spinbutton.png"/>
  <p>숫자를 입력하거나 -/+ 단추를 눌러 입력 숫자를 선택합니다!</p>

  <links type="section"/>

  <section id="code">
    <title>예제 결과를 만드는 코드</title>
    <code mime="text/x-python" style="numbered">from gi.repository import Gtk
import sys


class MyWindow(Gtk.ApplicationWindow):

    def __init__(self, app):
        Gtk.Window.__init__(self, title="SpinButton Example", application=app)
        self.set_default_size(210, 70)
        self.set_border_width(5)

        # an adjustment (initial value, min value, max value,
        # step increment - press cursor keys or +/- buttons to see!,
        # page increment - not used here,
        # page size - not used here)
        ad = Gtk.Adjustment(0, 0, 100, 1, 0, 0)

        # a spin button for integers (digits=0)
        self.spin = Gtk.SpinButton(adjustment=ad, climb_rate=1, digits=0)
        # as wide as possible
        self.spin.set_hexpand(True)

        # we connect the signal "value-changed" emitted by the spinbutton with the callback
        # function spin_selected
        self.spin.connect("value-changed", self.spin_selected)

        # a label
        self.label = Gtk.Label()
        self.label.set_text("Choose a number")

        # a grid to attach the widgets
        grid = Gtk.Grid()
        grid.attach(self.spin, 0, 0, 1, 1)
        grid.attach(self.label, 0, 1, 2, 1)

        self.add(grid)

    # callback function: the signal of the spinbutton is used to change the
    # text of the label
    def spin_selected(self, event):
        self.label.set_text(
            "The number you selected is " + str(self.spin.get_value_as_int()) + ".")


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>
  </section>

  <section id="methods">
    <title>SpinButton 위젯에 쓸만한 메서드</title>
    <p>Gtk.Adjustment는 Gtk.SpinButton을 만들떄 씁니다. 이 객체는 상한값, 하한값, 단계값, 페이지 증가 값, 페이지 크기를 나타내며 <code>Gtk.Adjustment(value, lower, upper, step_increment, page_increment, page_size)</code>  생성자로 만듭니다. 여기서 필드 값은 <code>float</code>입니다. <code>step_increment</code> 은 커서 키를 사용할 떄 또는 SpinButton의 증감 단추를 사용할 때 가져올 증가 감소 값입니다. 참고로,  <code>page_increment</code>와 <code>page_size</code>는 이 상황에 활용하지 않으므로 <code>0</code> 값으로 설정해야합니다.</p>
    <p>23번째 줄에서 <code>"value-changed"</code> 시그널은 <code><var>widget</var>.connect(<var>signal</var>, <var>callback function</var>)</code> 함수로  <code>spin_selected()</code> 콜백 함수에 연결했습니다. 더 자세한 설명은 <link xref="signals-callbacks.py"/>를 참조하십시오.</p>
    <list>
      <item><p>SpinButton 값이 최대 최소 값을 넘어설 경우 시작 값 내지는 끝 값으로 돌아가게 하려면 <code>set_wrap(True)</code> 함수를 설정하십시오. 이 상황이 일어나면 <code>"wrapped"</code> 시그널을 내보냅니다.</p></item>
      <item><p><code>set_digits(digits)</code> 함수는 SpinButton에 나타낼 수 있는 자리수를 최대 20자리까지 설정합니다.</p></item>
      <item><p>SpinButton에서 정수 값을 받으려면 <code>get_value_as_int()</code> 함수를 사용하십시오.</p></item>
    </list>
  </section>

  <section id="references">
    <title>API 참고서</title>
    <p>이 예제는 다음 참고자료가 필요합니다:</p>
    <list>
      <item><p><link href="http://developer.gnome.org/gtk3/unstable/GtkSpinButton.html">GtkSpinButton</link></p></item>
      <item><p><link href="http://developer.gnome.org/gtk3/unstable/GtkAdjustment.html">GtkAdjustment</link></p></item>
    </list>
  </section>
</page>