GNU Smalltalk 㧠GTK
GNU Smalltalk 3.2ç³»ã®ã¦ãªã¯ GTK ãªã®ã§ããããã¸ãã§éãã§ã¿ã¾ãããã¾ãã¯ä¸çªç°¡åãªã³ã¼ããGNU Smalltalk GTK 2.0 Tutorialãè¦ãªããä½æã
#!/usr/bin/env gst PackageLoader fileInPackage: 'GTK'. Object subclass: HelloWorld [ | button window | hello [ 'hello world' printNl ] delate [ 'delete event occured' printNl. ^false ] destroy [ GTK.Gtk mainQuit ] show [ window := GTK.GtkWindow new: GTK.Gtk gtkWindowToplevel. window connectSignal: 'delete_event' to: self selector: #delete userData: nil. window connectSignal: 'destroy' to: self selector: #destroy userData: nil. window setBorderWidth: 10. button := GTK.GtkButton newWithLabel: 'Hello World'. button connectSignal: 'clicked' to: self selector: #hello userData: nil. button connectSignal: 'clicked' to: self selector: #destroy userData: nil. window add: button. button show. window show. ] ]. Eval [ hello := HelloWorld new. hello show. GTK.Gtk main ]
Tk ã¨ãã«é¦´æãã§ããã°ãç¹ã«è§£èª¬ã¯è¦ããªãããæ®éãªæä½æããã ãGTK ããã±ã¼ã¸ã®é¨åã¯å§è²ã§ä½¿ã£ã¦ãã¤ã³ã¿ã¼ãã§ã¤ã¹ã¯ããã¯ã¿ã¤ãã³ã°ä»»ãã»ã»ã¨ããã®ãæ¨æºçãªã¹ã¿ã¤ã«ã®æ§åãªã®ã¯ãã¡ãã£ã¨ã ããããï¼ãã¨æããã¤ã³ãã§ãããããWindow ãç¶æ¿ããªãã®ã¯æ°é®®ã
ãã¨ãdetele_event ã¤ãã³ãã¯ä½ãã¨ããã¨ãã¦ã£ã³ãã¦ã®ãããã³ãã¿ã³ãæ¼ãããããã¨åºãã¤ãã³ãã§ãfalse ã§è¿ããã¨ã§ ããã«destroy ã¤ãã³ããçºçãããããªãtrueã§è¿ã㨠destroy ã¯çºçããªãããã§ããæ¬å½ã«çµäºãã¾ãã Y/Nãã¿ãããªã®ãåºãã¨ãã«ä½¿ãã¿ããã§ãã
ãããã³ã°ããã¯ã¹
ã¦ã£ã¸ã§ããã®é ç½®ã¯ããã£ã±ãã馴æã¿ã® ãããã³ã°ããã¯ã¹ã使ãã¾ãã
#!/usr/bin/env gst PackageLoader fileInPackage: 'GTK'. Object subclass: HelloWorld [ | box1 button1 button2 window | hello: aWidget string: aString [ ('Hello agein - ', aString, ' was pressed') printNl ] delete: aWiget event: aGdkEvent [ GTK.Gtk mainQuit. ^false ] show [ window := GTK.GtkWindow new: GTK.Gtk gtkWindowToplevel. window setTitle: 'Hello Buttons!'. window connectSignal: 'delete_event' to: self selector: #delete:event: userData: nil. window setBorderWidth: 10. box1 := GTK.GtkHBox new: false spacing: 0. window add: box1. button1 := GTK.GtkButton newWithLabel: 'Hello World'. button1 connectSignal: 'clicked' to: self selector: #hello:string: userData: 'button 1'. box1 packStart: button1 expand: true fill: true padding: 0. button1 show. button2 := GTK.GtkButton newWithLabel: 'Button 2'. button2 connectSignal: 'clicked' to: self selector: #hello:string: userData: 'button 2'. box1 packStart: button2 expand: true fill: true padding: 0. button2 show. box1 show. window show. ] ]. Eval [ hello := HelloWorld new. hello show. GTK.Gtk main ]
ãããã³ã°ããã¯ã¹ã«ã¯ GTK.GtkHBox 㨠GTK.GtkVBox ããã£ã¦ããããã水平詰ãã¨åç´è©°ãã«ç¨ãã¾ãã#packStart:expand:fill:padding: ã¡ãã»ã¼ã¸ã¨ã#packEnd:expand:fill:padding: ã¡ãã»ã¼ã¸ã§ã¦ã£ã¸ã§ãããç©ãã¦ããã¾ãï¼Start 㨠End ã®éãã¯ç®±ã®é ããè©°ããããå°»ããè©°ãããã§ãï¼ã
expand 㯠ããã¯ã¹å ã®ã¹ãã¼ã¹ãä½ãæãã¹ãã¼ã¹ãæ®ããªãããã«ã¦ã£ã¸ã§ããã®é åãåºãããå¦ããæå®ãã¾ããfill ã¯ãã®æã«ã¦ã£ã¸ã§ããèªä½ã§ãã®é åãåããããã«è¨ãã¾ãããã¦ã£ã¸ã§ããã®ã¾ããã«ããã£ã³ã°ãããã®æå®ã§ãã
GtkTextView / GtkTextBuffer
å ªãæ§ã®ãªããããã¯ãããã¹ããç·¨éããã¦ã£ã¸ã§ããã«ç®ç§»ããã¦ãã¾ã£ã¦ããããªããã¥ã¼ããªã¢ã«ãè±ç·ãã¦ãã¾ã...ã
#!/usr/bin/env gst PackageLoader fileInPackage: 'GTK'. Object subclass: PettitWorkspace [ | box1 sw textview textbuf doitBtn window | doit [ ^Behavior evalString: textbuf text to: self. ] delete: aWiget event: aGdkEvent [ GTK.Gtk mainQuit. ^false ] show [ window := GTK.GtkWindow new: GTK.Gtk gtkWindowToplevel. window setTitle: 'Pettit Workspace'. window connectSignal: 'delete_event' to: self selector: #delete:event: userData: nil. window setBorderWidth: 10. box1 := GTK.GtkVBox new: false spacing: 0. window add: box1. textview := GTK.GtkTextView new. textbuf := textview getBuffer. sw := GTK.GtkScrolledWindow withChild: textview. sw setPolicy: GTK.Gtk gtkPolicyAutomatic vscrollbarPolicy: GTK.Gtk gtkPolicyAutomatic. box1 packStart: sw expand: true fill: true padding: 0. sw show. textview show. doitBtn := GTK.GtkButton newWithLabel: 'Doit'. doitBtn connectSignal: 'clicked' to: self selector: #doit userData: nil. box1 packStart: doitBtn expand: true fill: true padding: 0. doitBtn show. box1 show. window show. ] ] Eval [ hello := HelloWorld new. hello show. GTK.Gtk main ]
ãã£ãããªã®ã§ Smalltalk ã® Workspace 風ã«ãã¦ã¿ã¾ããã
GtkTextView 㯠ãã®ã¢ãã« GtkTextBuffer ã¨ã»ããã§æ±ãããã«ã§ãã¦ãã¾ãã ããã¹ãã¸ã®æä½ï¼é¸æããã¦ããæååã®åå¾ããã¿ã°ä»ããªã©ï¼ã¯ Buffer ã«å¯¾ãã¦è¡ãã¾ãã
ä¸å¿ Workspace ã®ç«¯ãããªã®ã§ãSmalltalk ã³ã¼ããå®è¡ã§ãã¾ãã
Behavior >> #evalString:to: ã§ãself (PettitWorkspaceãªãã¸ã§ã¯ã) ã渡ãã¦ããã®ã§ãå®è¡ããã¾ã¾ GUI ãã³ãã³ãã§ãã¾ããããããã£å¤æ´ã ããããªãã£ã¦ã¦ã£ã¸ã§ãããå¢ããããã¨ããã
ãããã¦ããã°ãã¯ã©ã¹ãã©ã¦ã¶ããªãã¡ã¬ã³ã¹ãçºããªããé©å½ããªãã 使ãæ¹ã模索ã§ããã®ã§ããæãã
ãããããã¨ï¼åçããã°ã©ã ããããï¼ãããããã¨æã£ã¦ãã¾ãã®ã¯ãããæ®éã®è¦æ±ã®ãªã®ããããããSmalltalk ã«é¦´ãã¦ãã¾ã£ãå¤æ
ããã ãããã¯è§£ããªãã®ã§ãããGUI ãã¬ã¼ã ã¯ã¼ã¯ã®åå¼·ã®è¯ãæ¹æ³ã ã¨ãããã¯æãã¾ãã
ææ³
- Blox (TK ãã¤ã³ãã£ã³ã°)ã«ããã¹ã¦ãSmalltalkã£ã½ãã¢ã¬ã³ã¸ããã¦ãªã
- ã¨ããã PyGTK ãã®ã¾ãã¾ã£ã½ãï¼ä¸è¨ãã¥ã¼ããªã¢ã«ã éä¸ãã Smalltalkã©ã¤ãºãéã«åããã« Python ã³ã¼ãã«ãªã£ã¡ãããï¼
- èç®ã©ããã¼ãªã®ã¨ãä¸èº«ã c-call ã°ã£ãããªã®ã§ãã¯ã©ã¹ãã©ã¦ã¶ã§ãèªããããã«ã³ã¼ããã§ãã¦ããªãã®ã¯ Smalltalk ã¨ãã¦é常ã«éåæãï¼åçã³ã¼ããã³ã¡ã³ãããªãï¼
- åå空éãããã®ã«ãã¯ã©ã¹åããã¡ãã¡ GtkHogeHogeããªã®ã¯ã©ããªãã§ãããã
GNU Smalltalk 3.0 ç³»ã¯ãGNU ã¨ããOSã®ä¸ã®ã¹ã¯ãªããã£ã³ã°è¨èª ã¨ããå²ãåããåãã£ã¦ãææ³é¢ããããããæåãå²å¦é¢ã®æ¹ãå¼·ã Smalltalk ããããªãã¨æãããããã¾ãã
ã§ããããããå¦çç³»ããã£ã¦ããããããã¨ãããããããã¯ããã¯ããã§å¥½ãã ã£ãããã¾ãã