|
Packit |
1470ea |
|
|
Packit |
1470ea |
<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="dialog.py" xml:lang="ko">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">Dialog(Python)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.py#windows"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="signals-callbacks.py"/>
|
|
Packit |
1470ea |
<link type="next" xref="aboutdialog.py"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-06-11" status="draft"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Marta Maria Casetti</name>
|
|
Packit |
1470ea |
<email its:translate="no">mmcasetti@gmail.com</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>뜨는 창</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>조성호</mal:name>
|
|
Packit |
1470ea |
<mal:email>shcho@gnome.org</mal:email>
|
|
Packit |
1470ea |
<mal:years>2017</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>Dialog</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/dialog.png"/>
|
|
Packit |
1470ea |
콜백 함수에 응답 시그널을 연결한 대화상자입니다.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<links type="section"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="code">
|
|
Packit |
1470ea |
<title>예제 결과를 만드는 코드</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
from gi.repository import Gtk
|
|
Packit |
1470ea |
import sys
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyWindow(Gtk.ApplicationWindow):
|
|
Packit |
1470ea |
# construct a window (the parent window)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self, app):
|
|
Packit |
1470ea |
Gtk.Window.__init__(self, title="GNOME Button", application=app)
|
|
Packit |
1470ea |
self.set_default_size(250, 50)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# a button on the parent window
|
|
Packit |
1470ea |
button = Gtk.Button("Click me")
|
|
Packit |
1470ea |
# connect the signal "clicked" of the button with the function
|
|
Packit |
1470ea |
# on_button_click()
|
|
Packit |
1470ea |
button.connect("clicked", self.on_button_click)
|
|
Packit |
1470ea |
# add the button to the window
|
|
Packit |
1470ea |
self.add(button)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# callback function for the signal "clicked" of the button in the parent
|
|
Packit |
1470ea |
# window
|
|
Packit |
1470ea |
def on_button_click(self, widget):
|
|
Packit |
1470ea |
# create a Gtk.Dialog
|
|
Packit |
1470ea |
dialog = Gtk.Dialog()
|
|
Packit |
1470ea |
dialog.set_title("A Gtk+ Dialog")
|
|
Packit |
1470ea |
# The window defined in the constructor (self) is the parent of the dialog.
|
|
Packit |
1470ea |
# Furthermore, the dialog is on top of the parent window
|
|
Packit |
1470ea |
dialog.set_transient_for(self)
|
|
Packit |
1470ea |
# set modal true: no interaction with other windows of the application
|
|
Packit |
1470ea |
dialog.set_modal(True)
|
|
Packit |
1470ea |
# add a button to the dialog window
|
|
Packit |
1470ea |
dialog.add_button(button_text="OK", response_id=Gtk.ResponseType.OK)
|
|
Packit |
1470ea |
# connect the "response" signal (the button has been clicked) to the
|
|
Packit |
1470ea |
# function on_response()
|
|
Packit |
1470ea |
dialog.connect("response", self.on_response)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# get the content area of the dialog, add a label to it
|
|
Packit |
1470ea |
content_area = dialog.get_content_area()
|
|
Packit |
1470ea |
label = Gtk.Label("This demonstrates a dialog with a label")
|
|
Packit |
1470ea |
content_area.add(label)
|
|
Packit |
1470ea |
# show the dialog
|
|
Packit |
1470ea |
dialog.show_all()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def on_response(self, widget, response_id):
|
|
Packit |
1470ea |
print("response_id is", response_id)
|
|
Packit |
1470ea |
# destroy the widget (the dialog) when the function on_response() is called
|
|
Packit |
1470ea |
# (that is, when the button of the dialog has been clicked)
|
|
Packit |
1470ea |
widget.destroy()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyApplication(Gtk.Application):
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def __init__(self):
|
|
Packit |
1470ea |
Gtk.Application.__init__(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def do_activate(self):
|
|
Packit |
1470ea |
win = MyWindow(self)
|
|
Packit |
1470ea |
win.show_all()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def do_startup(self):
|
|
Packit |
1470ea |
Gtk.Application.do_startup(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
app = MyApplication()
|
|
Packit |
1470ea |
exit_status = app.run(sys.argv)
|
|
Packit |
1470ea |
sys.exit(exit_status)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="methods">
|
|
Packit |
1470ea |
<title>Dialog 위젯에 쓸만한 메서드</title>
|
|
Packit |
1470ea |
16번째 줄에서, widget.connect(signal, callback function) 코드로 "clicked" 시그널을 on_button_click() 콜백 함수에 연결했습니다. 더 자세한 설명은 <link xref="signals-callbacks.py"/>를 참조하십시오.
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item>set_modal(True) 대신 set_modal(False) 로 호출하고, 그 뒤에 set_destroy_with_parent(True) 함수를 호출해서 메인 창을 닫으면 대화상자 창을 닫을 수 있게 할 수 있습니다. </item>
|
|
Packit |
1470ea |
<item>임의의 정수 값 42 를 갖는 add_button(button_text="The Answer", response_id=42) 대신, RESPONSE 자리에 -5, -6,..., -11 정수형 값에 해당하는 OK, CANCEL, CLOSE, YES, NO, APPLY, HELP 중 하나가 오는 add_button(button_text="text", response_id=Gtk.ResponseType.RESPONSE) 호출 방식을 쓸 수 있습니다. </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<section id="references">
|
|
Packit |
1470ea |
<title>API 참고서</title>
|
|
Packit |
1470ea |
이 예제는 다음 참고자료가 필요합니다:
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/GtkDialog.html">GtkDialog</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/GtkWindow.html">GtkWindow</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
</page>
|