|
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="messagedialog.py" xml:lang="ko">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">MessageDialog(Python)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="beginner.py#windows"/>
|
|
Packit |
1470ea |
<link type="next" xref="gmenu.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>MessageDialog</title>
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/messagedialog.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 |
from gi.repository import Gio
|
|
Packit |
1470ea |
import sys
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
class MyWindow(Gtk.ApplicationWindow):
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# constructor for a window (the parent window) with a label
|
|
Packit |
1470ea |
def __init__(self, app):
|
|
Packit |
1470ea |
Gtk.Window.__init__(self, title="GMenu Example", application=app)
|
|
Packit |
1470ea |
self.set_default_size(400, 200)
|
|
Packit |
1470ea |
label = Gtk.Label()
|
|
Packit |
1470ea |
label.set_text("This application goes boom!")
|
|
Packit |
1470ea |
self.add(label)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# create the message_action (a Gio.SimpleAction) - for the window
|
|
Packit |
1470ea |
message_action = Gio.SimpleAction.new("message", None)
|
|
Packit |
1470ea |
# connect the signal from the action to the function message_cb()
|
|
Packit |
1470ea |
message_action.connect("activate", self.message_cb)
|
|
Packit |
1470ea |
# add the action to the application
|
|
Packit |
1470ea |
app.add_action(message_action)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# callback function for the signal "activate" from the message_action
|
|
Packit |
1470ea |
# in the menu of the parent window
|
|
Packit |
1470ea |
def message_cb(self, action, parameter):
|
|
Packit |
1470ea |
# a Gtk.MessageDialog
|
|
Packit |
1470ea |
messagedialog = Gtk.MessageDialog(parent=self,
|
|
Packit |
1470ea |
flags=Gtk.DialogFlags.MODAL,
|
|
Packit |
1470ea |
type=Gtk.MessageType.WARNING,
|
|
Packit |
1470ea |
buttons=Gtk.ButtonsType.OK_CANCEL,
|
|
Packit |
1470ea |
message_format="This action will cause the universe to stop existing.")
|
|
Packit |
1470ea |
# connect the response (of the button clicked) to the function
|
|
Packit |
1470ea |
# dialog_response()
|
|
Packit |
1470ea |
messagedialog.connect("response", self.dialog_response)
|
|
Packit |
1470ea |
# show the messagedialog
|
|
Packit |
1470ea |
messagedialog.show()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def dialog_response(self, widget, response_id):
|
|
Packit |
1470ea |
# if the button clicked gives response OK (-5)
|
|
Packit |
1470ea |
if response_id == Gtk.ResponseType.OK:
|
|
Packit |
1470ea |
print("*boom*")
|
|
Packit |
1470ea |
# if the button clicked gives response CANCEL (-6)
|
|
Packit |
1470ea |
elif response_id == Gtk.ResponseType.CANCEL:
|
|
Packit |
1470ea |
print("good choice")
|
|
Packit |
1470ea |
# if the messagedialog is destroyed (by pressing ESC)
|
|
Packit |
1470ea |
elif response_id == Gtk.ResponseType.DELETE_EVENT:
|
|
Packit |
1470ea |
print("dialog closed or cancelled")
|
|
Packit |
1470ea |
# finally, destroy the messagedialog
|
|
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 quit_cb(self, action, parameter):
|
|
Packit |
1470ea |
self.quit()
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
def do_startup(self):
|
|
Packit |
1470ea |
Gtk.Application.do_startup(self)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# create a menu (a Gio.Menu)
|
|
Packit |
1470ea |
menu = Gio.Menu()
|
|
Packit |
1470ea |
# append a menu item with label "Message" and action "app.message"
|
|
Packit |
1470ea |
menu.append("Message", "app.message")
|
|
Packit |
1470ea |
# append a menu item with label "Quit" and action "app.quit"
|
|
Packit |
1470ea |
menu.append("Quit", "app.quit")
|
|
Packit |
1470ea |
# set menu as the menu for the application
|
|
Packit |
1470ea |
self.set_app_menu(menu)
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
# a new simpleaction - for the application
|
|
Packit |
1470ea |
quit_action = Gio.SimpleAction.new("quit", None)
|
|
Packit |
1470ea |
quit_action.connect("activate", self.quit_cb)
|
|
Packit |
1470ea |
self.add_action(quit_action)
|
|
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>MessageDialog 위젯에 쓸만한 메서드</title>
|
|
Packit |
1470ea |
18번째 줄에서 "activate" 시그널은 widget.connect(signal, callback function) 함수로 message_cb() 콜백 함수에 연결했습니다. 더 자세한 설명은 <link xref="signals-callbacks.py"/>를 참조하십시오.
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item>MessageDialog 생성자에서 Gtk.DialogFlags.DESTROY_WITH_PARENT 플래그(상위 창을 해체할 때 messagedialog 창을 해체) 또는 Gtk.DialogFlags.MODAL 플래그(프로그램의 다른 창과 동작하지 않음)을 설정할 수 있습니다. </item>
|
|
Packit |
1470ea |
<item>MessageDialog 생성자에서 원하는 메시지 형식에 따라 Gtk.MessageType.INFO, Gtk.MessageType.WARNING, Gtk.MessageType.QUESTION, Gtk.MessageType.ERROR, Gtk.MessageType.OTHER 중 하나를 설정할 수 있습니다. </item>
|
|
Packit |
1470ea |
<item>MessageDialog 생성자에서 Gtk.ButtonsType.NONE, Gtk.ButtonsType.OK, Gtk.ButtonsType.CLOSE, Gtk.ButtonsType.CANCEL, Gtk.ButtonsType.YES_NO, Gtk.ButtonsType.OK_CANCEL 또는 Gtk.Dialog에서와 같이 add_button() 를 활용한 그 어떤 요소든 단추로 설정할 수 있습니다. </item>
|
|
Packit |
1470ea |
<item>다른 그림을 활용하여 MessageDialog의 기본 그림을 대신할 수 있습니다.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
image = Gtk.Image()
|
|
Packit |
1470ea |
image.set_from_stock(Gtk.STOCK_CAPS_LOCK_WARNING, Gtk.IconSize.DIALOG)
|
|
Packit |
1470ea |
image.show()
|
|
Packit |
1470ea |
messagedialog.set_image(image)
|
|
Packit |
1470ea |
Gtk.STOCK_CAPS_LOCK_WARNING 은 <link href="http://developer.gnome.org/gtk3/unstable/gtk3-Stock-Items.html">스톡 항목</link>의 그림입니다. image.set_from_file("filename.png") 코드로 그림 위젯처럼 어떤 그림이든 설정할 수 있습니다. </item>
|
|
Packit |
1470ea |
<item>format_secondary_text("some secondary message") 는 부차적인 메시지를 설정합니다. 주 텍스트는 굵은 글씨로 나타납니다. </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/GtkMessageDialog.html">GtkMessageDialog</link> </item>
|
|
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 |
<item><link href="http://developer.gnome.org/gio/stable/GSimpleAction.html">GSimpleAction</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gio/unstable/GActionMap.html">GActionMap</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gio/stable/GMenu.html">GMenu</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/unstable/GtkApplication.html">GtkApplication</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</section>
|
|
Packit |
1470ea |
</page>
|