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="fontchooserwidget.py" xml:lang="ko">
  <info>
    <title type="text">FontChooserWidget (Python)</title>
    <link type="guide" xref="beginner.py#font-selectors"/>
    <link type="seealso" xref="signals-callbacks.py"/>
    <link type="next" xref="filechooserdialog.py"/>    
    <revision version="0.2" date="2012-05-05" 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>FontChooserWidget</title>

  <media type="image" mime="image/png" src="media/fontchooserwidget.png"/>
  <p>콜백 함수와 사용하는 FontChooserWidget입니다.</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="FontChooserWidget", application=app)

        # a font chooser
        self.font_chooser = Gtk.FontChooserWidget()
        # a default font
        self.font_chooser.set_font("Sans")
        # a text to preview the font
        self.font_chooser.set_preview_text(
            "This is an example of preview text!")

        # connect signal from the font chooser to the callback function
        self.font_chooser.connect("notify::font", self.font_cb)

        # add the font chooser to the window
        self.add(self.font_chooser)

    # callback function:
    def font_cb(self, event, user_data):
        # print in the terminal
        print("You chose the font " + self.font_chooser.get_font())


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>FontChooserWidget에 쓸만한 메서드</title>
    <p>16번째 줄에서, <code><var>widget</var>.connect(<var>signal</var>, <var>callback function</var>)</code> 코드로 <code>"notify::font"</code> 시그널을 <code>font_cb()</code> 콜백 함수에 연결했습니다. 더 자세한 설명은 <link xref="signals-callbacks.py"/>를 참조하십시오.</p>
    <list>
      <item><p>초기에 선택하는 글꼴을 설정하려면 <code>set_font(font)</code> (<code>font</code> 는 글꼴 이름) 또는 <code>set_font_desc(font)</code> (<code>font</code> 는 PangoFontDescription 객체) 함수를 사용하십시오.</p></item>
      <item><p>선택한 글꼴을 가져오려면 <code>get_font()</code> 또는 <code>get_font_desc()</code> 함수를 사용하십시오.</p></item>
      <item><p>미리 보기 화면에 나타난 텍스트를 바꾸려면 <code>set_preview_text()</code> 함수를 사용하십시오.</p></item>
    </list>
  </section>
  <section id="references">
    <title>API 참고서</title>
    <p>이 예제는 다음 참고자료가 필요합니다:</p>
    <list>
      <item><p><link href="http://developer.gnome.org/gtk3/unstable/GtkFontChooserWidget.html">GtkFontChooserWidget</link></p></item>
    </list>
  </section>
</page>