ウィンドウの表示
Posted feedbacks - Nested
Flatten HiddenSqueak システムは GUI も自前なので、ホスト OS 向けにウインドウが開くわけではありませんが…(^_^;)。参考まで。
1 2 3 4 | | window |
window := SystemWindow labelled: 'こんにちは、GUI!'.
window width: 100; height: 75; center: Display center.
window openAsIs
|
後々のためにも問題をチュートリアル編とアルゴリズム編に分けたほうがよいと思われますが、隊長、どうでしょう。
お題にもタグをつけられるようにすればいいのかも?
XAMLでGUI!
1 2 3 4 5 6 7 8 | <Window x:Class="Window.Konnichiwa"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Doukaku" Width="100" Height="75" WindowStartupLocation="CenterScreen" WindowStyle="ToolWindow">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock FontSize="8">こんにちは、GUI!</TextBlock>
</StackPanel>
</Window>
|
おわ!
お題を読み違えてた...。
すんません、書き直します。
VisualuRuby(仮称)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | require 'vr/vrcontrol'
w, h = 100, 75
x = (VRLocalScreen.width - w) / 2
y = (VRLocalScreen.height - h) / 2
x = x < 0 ? 0 : x
y = y < 0 ? 0 : y
frm = VRLocalScreen.newform
frm.move(x, y, w, h)
frm.caption = "こんにちは、GUI!"
frm.create.show
VRLocalScreen.messageloop
|
100x75だと「こんにち...」になっちゃうけど許して(笑)。
1 2 3 4 5 | <Window x:Class="Window.Konnichiwa"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="こんにちは、GUI!" Width="100" Height="75" WindowStartupLocation="CenterScreen" WindowStyle="ToolWindow">
</Window>
|
IronPythonで参戦。100x75だと幅を指定しても100より大きくなってしまう(^^;) 回避方法あるのだろうか。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # -*- coding: utf-8 -*-
import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Windows.Forms import Form, FormStartPosition, Application
from System.Drawing import Size
class HelloForm(Form):
def __init__(self):
self.Text = u'こんにちは、GUI'
self.StartPosition = FormStartPosition.CenterScreen
self.Size = Size(100, 75)
if __name__ == '__main__':
Application.Run(HelloForm())
|
data スキームを使っているので、 IE では動きません。
1 | open('data:text/plain;charset=utf8,\u3053\u3093\u306B\u3061\u306F\u3001GUI', '_blank','height=100,width=75');
|
data スキームを使わないバージョン
1 2 3 | var d = open('about:blank', '_blank', 'height=100,width=75').document;
d.write('\u3053\u3093\u306B\u3061\u306F\u3001GUI');
d.close();
|
C# WindowsForms版
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | using System;
using System.Windows.Forms;
namespace Doukaku
{
static class Konnichiwa
{
[STAThread]
static void Main()
{
Form window = new Form();
window.StartPosition = FormStartPosition.CenterScreen;
window.FormBorderStyle = FormBorderStyle.FixedToolWindow;
window.Width = 100;
window.Height = 75;
window.Text = "こんにちは、GUI!";
window.ShowDialog();
}
}
}
|
なるほど。FormBorderStyleを指定すれば幅を100にできるのですね…。
1 2 3 4 5 6 7 8 9 | import Graphics.UI.Gtk
main = do initGUI
window <- windowNew
windowSetTitle window "こんにちは、GUI!"
windowSetDefaultSize window 100 75
windowSetPosition window WinPosCenter
widgetShowAll window
mainGUI
|
erl -noshell -s hellogui hello のように実行します. Erlangの標準GUIツールのgsは日本語未対応のようです. 文字化けするので,タイトルは英語版で…
1 2 3 4 5 6 7 8 9 10 11 12 13 | -module(hellogui).
-export([hello/0]).
hello() ->
GS = gs:start(),
Win = gs:create(window, GS, [{width, 200}, {height, 75}, {title, "Hello, GUI!"}]),
gs:config(Win, {map, true}),
event_loop(Win).
event_loop(Win) ->
receive
_Any -> event_loop(Win)
end.
|
100x75は無理っぽいので400x300にて
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import javax.swing.JFrame;
import java.awt.Toolkit;
import java.awt.Dimension;
public class Window {
public static void main(String args[]) {
int width = 400;
int height = 300;
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(width, height);
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension d = toolkit.getScreenSize();
frame.setLocation(((int)d.getWidth() - width) / 2, ((int)d.getHeight() - height) / 2);
frame.setVisible(true);
}
}
|
Scalaで。日本語アレなんでタイトルは英語です。
1 2 3 4 5 6 | import javax.swing._
val f = new JFrame("Hello GUI!")
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
f.setSize(400, 300)
f.setLocationRelativeTo(null)
f.setVisible(true)
|
C++,FLTK
1 2 3 4 5 6 7 8 9 10 11 | #include <FL/Fl.H>
#include <FL/Fl_Window.H>
int main(int argc, char ** argv) {
const int w = 400, h = 300;
Fl_Window *window = new Fl_Window(w, h, "こんにちは、GUI!");
window->end();
window->resize((Fl::w() - w) / 2, (Fl::h() - h) / 2, w, h);
window->show(argc, argv);
return Fl::run();
}
|
pygtkはGUI楽でいいですよね。
1 2 3 4 5 6 7 8 9 10 | # -*- coding: utf-8 -*-
import gtk
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
win.connect("delete-event", gtk.main_quit)
win.set_title("こんにちわ GUI")
win.set_size_request(100, 75)
win.set_position(gtk.WIN_POS_CENTER)
win.show()
gtk.main()
|
awtでやっつけ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class WindowOpener {
public static void main(String args[]) {
int width = 400;
int height = 300;
final Frame frame = new Frame("こんにちは、GUI!");
frame.setSize(width, height);
frame.setLocation(0, 0);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
frame.dispose();
}
}
);
frame.setVisible(true);
}
}
|
参考:
http://www.strangelights.com/fsharp/wiki/default.aspx/FSharpWiki/InteractiveWindows.html
1 2 3 4 5 6 7 8 9 10 11 12 13 | open System.Drawing;;
open System.Windows.Forms;;
let form = new Form();;
form.Visible <- true;;
form.Size <- new Size(100,75);;
let rTextBox = new RichTextBox();;
form.Controls.Add( rTextBox );;
rTextBox.Dock <- DockStyle.Fill;;
rTextBox.Text <- "こんにちは、GUI!";;
do Application.Run(form);;
|
JRubyで。
日本語だせなかった...
1 2 3 4 5 6 | require 'java'
f = javax.swing.JFrame.new('Hello,GUI!')
f.set_size(400,300)
d = java.awt.Toolkit.get_default_toolkit.get_screen_size
f.set_location(d.width / 2, d.height / 2)
f.show
|
Python/Tkinterで。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # coding: shift_jis
import Tkinter as Tk
root = Tk.Tk()
root.title(u"こんにちは、GUI!")
w = 400
h = 300
root.geometry("%dx%d+%d+%d" % (w, h,
(root.winfo_screenwidth() - w) / 2,
(root.winfo_screenheight() - h) / 2))
root.mainloop()
|
VC++&MFCで。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <afxwin.h>
class CMainWindow : public CFrameWnd
{
public:
CMainWindow()
{
CRect rect(0, 0, 400, 300);
Create(NULL, _T("こんにちは、GUI!"), WS_OVERLAPPEDWINDOW, rect);
CenterWindow();
};
};
class CHelloGUIApp : public CWinApp
{
public:
virtual BOOL InitInstance()
{
m_pMainWnd = new CMainWindow();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
};
CHelloGUIApp helloGUIApp;
|
WindowsプログラムでPeekMessage()でループは厳禁です.これだとCPUリソースを食いつぶします.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | case WM_CLOSE:
- g_nExit = 1;
+ PostQuitMessage(0);
- while(g_nExit==0){
- if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ){
- TranslateMessage( &msg );
- DispatchMessage( &msg);
- }
- }
+ while (GetMessage(&msg, NULL, 0, 0) > 0) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
|
既にあるけど
1 2 3 4 5 6 7 8 9 10 11 | class Program
{
static void Main()
{
Form dlg = new Form();
dlg.Text = "こんにちは、GUI!";
dlg.Size = new Size(400, 300);
dlg.StartPosition = FormStartPosition.CenterScreen;
dlg.ShowDialog();
}
}
|
Perl/Tkで。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | use encoding 'cp932'; # windows
use Tk;
use constant {
MW_WIDTH => 400,
MW_HEIGHT => 300
};
my $mw = new Tk::MainWindow(
-title => 'こんにちは、GUI!',
-width => MW_WIDTH,
-height => MW_HEIGHT);
my $x = int(($mw->screenwidth - MW_WIDTH) / 2);
my $y = int(($mw->screenheight - MW_HEIGHT) / 2);
$mw->geometry("+$x+$y");
Tk::MainLoop();
|
つまらない例ですがGtk+のC++バインドで。
1 2 3 4 5 6 7 8 9 10 11 12 | #include <gtkmm.h>
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Gtk::Window window;
window.set_title("こんにちは、GUI!");
window.set_default_size(100, 175);
Gtk::Main::run(window);
return 0;
}
|
Simpleに。
1 2 3 4 5 6 7 8 9 10 11 12 13 | import javax.swing.JFrame;
class HelloGUI extends JFrame {
public HelloGUI() {
super("こんにちは、GUI!");
this.setSize(400, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new HelloGUI().setVisible(true);
}
}
|
単純なフレームだとサイズの指定ができないようです. 中身にダミーのオブジェクトを入れて大きくしています. 「こんにちは、GUI!」と表示させたかったのですが,Mathematicaのフロントエンドで 「、」を入れると自動的に「,」に変換されてしまうので,少し違う文字列になっています.
1 2 3 4 5 6 7 8 | Needs["GUIKit`"];
GUIRunModal[
Widget["Frame", {"title" -> "こんにちは, GUI!",
Widget["TextPanel", {
"preferredSize" -> Widget["Dimension", {"width" -> 200,
"height" -> 100}],
"text" -> ""}]
}]];
|
ウィンドウの表示だけだったら0行で書けるんですけどね。
ゲーム用のスクリプト言語はこのあたりが便利だ。
1 2 | screen 0, 400, 300
mes "こんにちは、GUI!"
|
LTK (Tcl/Tk) ベースの GUI です。
1 2 3 4 5 | (use-package :ltk)
(defun hello-1 ()
(with-ltk ()
(wm-title *tk* "こんにちは、GUI!")
(set-geometry-wh *tk* 400 300)))
|
LispWorks の GUI ライブラリ CAPI です。
1 2 3 4 5 6 7 | (capi:define-interface hello-2 ()
()
(:default-initargs
:width 400
:height 300
:title "こんにちは、GUI!"))
(capi:display (make-instance 'hello-2))
|
AllegroCL の GUI ライブラリ Common Graphics です。
1 2 3 | (require :cg)
(cg:initialize-cg)
(cg:make-window :hello-3 :class 'cg:dialog :width 400 :height 300 :title "こんにちは、GUI!")
|
日本語が化ける問題点がありますが、Xlibを利用したウィンドウの表示です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include <stdio.h>
#include <X11/Xlib.h>
int main(int argc, char *argv[])
{
Display *display;
Window window;
char *title = "こんにちは、GUI!";
int x_size = 400;
int y_size = 300;
display = XOpenDisplay(NULL);
window = XCreateSimpleWindow(display, DefaultRootWindow(display),
DisplayWidth(display, 0)/2,
DisplayHeight(display, 0)/2,
x_size, y_size, 50,
BlackPixel(display, 0),
WhitePixel(display, 0));
XSetStandardProperties(display, window, title, NULL,
None, argv, argc, NULL);
XMapWindow(display, window);
XFlush(display);
getchar();
XCloseDisplay(display);
return 0;
}
|
Gauche+Gauche-glでやってみました。
でもタイトルはutf-8で渡しても化けるなあ…
1 2 3 4 5 6 7 8 9 10 11 12 13 | ;; -*- coding: utf-8 -*-
(use gl)
(use gl.glut)
(define (main args)
(glut-init args)
(glut-init-display-mode GLUT_SINGLE)
(glut-init-window-size 100 75)
(glut-create-window "こんにちは、GUI!")
(gl-clear-color 0 0 0 0)
(glut-display-func (lambda () (gl-clear GL_COLOR_BUFFER_BIT) (gl-flush)))
(glut-main-loop)
0)
|
R TclTkを使いました。
1 2 3 4 | require(tcltk)
tt <- tktoplevel()
tkwm.geometry(tt, "100x75")
tkwm.title(tt, "こんにちは、GUI!")
|
いまさらですが、お題の「画面中央に」を満たしていなかったので直しました。
1 2 3 4 5 6 7 8 9 | library(tcltk)
w <- 100
h <- 75
tt <- tktoplevel(width=w, height=h)
g <- paste("+", c(round((as.integer(tkwinfo("screenwidth", tt)) - w)/2),
round((as.integer(tkwinfo("screenheight", tt)) - h)/2)),
sep="", collapse="")
tkwm.geometry(tt, g)
tkwm.title(tt, "こんにちは、GUI!")
|
wxPython始めました。
1 2 3 4 5 6 7 8 9 10 11 12 | # -*- coding: utf-8 -*-
import wx
class App(wx.App):
def OnInit(self):
frame = wx.Frame(parent=None, title=u'こんにちは、GUI!', |





にしお
#3363()
Rating0/0=0.00
タイトルには「こんにちは、GUI!」と表示してください。
使用するGUIライブラリに名前が付いているならば、それをタグでつけてください。(例えば「Swing」など。)
追記:100x75はあまりに小さすぎるようなので、小さすぎるせいでうまく行かない場合は400x300でもいいということにします。 このお題の意図は「小さいウィンドウを出せ」というわけではないので。
[ reply ]