Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
СПО - задание по лабам.doc
Скачиваний:
4
Добавлен:
17.11.2019
Размер:
113.15 Кб
Скачать

Пример программы на fxruby

require 'fox16'

include Fox

class TableWindow < FXMainWindow

def initialize(app)

super(app, "Редактор матрицы")

menubar = FXMenuBar.new(self)

FXHorizontalSeparator.new(self)

frame = FXVerticalFrame.new(self, LAYOUT_FILL_X|LAYOUT_FILL_Y )

@frame1 = FXHorizontalFrame.new(frame, LAYOUT_FILL_X|LAYOUT_FILL_Y)

FXLabel.new(@frame1, "Кол-во строк:")

@rows = FXLabel.new(@frame1, "" )

FXLabel.new(@frame1, "колонок:")

@cols = FXLabel.new(@frame1, "")

#';';;';'

@table = FXTable.new(frame,

:opts => TABLE_COL_SIZABLE|TABLE_ROW_SIZABLE|LAYOUT_FILL_X|LAYOUT_FILL_Y )

@table.visibleRows = 20

@table.visibleColumns = 8

@table.setTableSize(50, 14)

set_contens

filemenu = FXMenuPane.new(self)

FXMenuCommand.new(filemenu, "&Выход\tCtl-Q", nil, getApp(), FXApp::ID_QUIT)

FXMenuTitle.new(menubar, "&Файл", nil, filemenu)

manipmenu = FXMenuPane.new(self)

FXMenuCommand.new(manipmenu, "Изменить размеры").connect(SEL_COMMAND, method(:onCmdResizeTable))

FXMenuTitle.new(menubar, "&Манипуляции", nil, manipmenu)

end

def onCmdResizeTable(sender, sel, ptr)

dlg = FXDialogBox.new(self, "Изменить размеры")

frame = FXVerticalFrame.new(dlg, LAYOUT_FILL_X|LAYOUT_FILL_Y)

frame1 = FXHorizontalFrame.new(frame, LAYOUT_FILL_X|LAYOUT_FILL_Y)

frame2 = FXHorizontalFrame.new(frame, LAYOUT_FILL_X|LAYOUT_FILL_Y)

FXLabel.new(frame1, "Rows:")

rows = FXTextField.new(frame1, 50 )

FXLabel.new(frame1, "Columns:")

cols = FXTextField.new(frame1, 5)

FXButton.new(frame2, "Cancel", nil, dlg, FXDialogBox::ID_CANCEL )

FXButton.new(frame2, " OK ", nil, dlg, FXDialogBox::ID_ACCEPT )

oldnr, oldnc = @table.numRows, @table.numColumns

rows.text = oldnr.to_s

cols.text = oldnc.to_s

if dlg.execute != 0

nr, nc = rows.text.to_i, cols.text.to_i

nr = 0 if nr < 0

nc = 0 if nc < 0

@table.setTableSize(nr, nc)

set_contens

end

return 1

end

def set_contens

(0...@table.numColumns).each { |c| @table.setColumnText(c, "Col#{c}" ) }

(0...@table.numRows).each { |r| @table.setRowText(r, "Row#{r}") }

(0...@table.numRows).each do |r|

(0...@table.numColumns).each do |c|

@table.setItemText(r, c, "r:#{r} c:#{c}")

end

end

@rows.text = @table.numRows.to_s

@cols.text = @table.numColumns.to_s

end

def create

super

show(PLACEMENT_SCREEN)

end

end

if __FILE__ == $0

application = FXApp.new()

TableWindow.new(application)

application.create

application.run

end

Литература

  1. Фултон Х. Программирование на языке Ruby. – М.: ДМК. 2007.

  2. Дейтел Х. Операционные системы. – М.: Бином. 2006.