|
From: <fu...@us...> - 2003-12-14 08:40:39
|
Update of /cvsroot/neelix/neelix/view
In directory sc8-pr-cvs1:/tmp/cvs-serv22349/view
Modified Files:
fox.rb
Log Message:
In the middle of major refactoring for the GUI. The GUI as a result is less
functional than before, but much cleaner.
Index: fox.rb
===================================================================
RCS file: /cvsroot/neelix/neelix/view/fox.rb,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** fox.rb 12 Dec 2003 22:50:47 -0000 1.1
--- fox.rb 13 Dec 2003 17:56:48 -0000 1.2
***************
*** 1,263 ****
include Fox
- require 'model/model.rb'
-
- class CookbookForm < FXPacker
- def initialize(parent, cookbook)
- super(parent)
-
- FXLabel.new(self,"Name ")
-
- dt = cookbook.targets['name']
- name = FXTextField.new(self, 80, dt, FXDataTarget::ID_VALUE)
-
- FXButton.new(self,"Accept").connect(SEL_COMMAND) do
- cookbook.commit
- end
- end
- end
-
- class CategoryForm < FXPacker
- def initialize(parent, category)
- super(parent)
-
- FXLabel.new(self,"Name ")
- dt = category.targets['name']
- name = FXTextField.new(self, 80,dt,DT::ID_VALUE)
-
- FXButton.new(self,"Accept").connect(SEL_COMMAND) do
- category.commit
- end
- end
- end
-
- class RecipeForm < FXPacker
- def initialize(parent, recipe)
- super(parent)
-
- FXLabel.new(self,"Name")
- dt = recipe.targets['name']
- name = FXTextField.new(self, 80,dt,DT::ID_VALUE)
-
- FXLabel.new(self,"by")
- dt = recipe.targets['author']
- author = FXTextField.new(self, 80,dt,DT::ID_VALUE)
-
- FXLabel.new(self,"Prep and Cook Time")
- dt = recipe.targets['tottime']
- tottime = FXTextField.new(self, 80,dt,DT::ID_VALUE)
-
- FXLabel.new(self,"Makes")
- dt = recipe.targets['yields']
- yields = FXTextField.new(self, 80,dt,DT::ID_VALUE)
-
- FXLabel.new(self,"Oven Temp")
- dt = recipe.targets['temp']
- temp = FXTextField.new(self, 80,dt,DT::ID_VALUE)
-
- # The ingredients table shall always have an empty row, ie it grows as
- # the user enters ingredients. It may have more than one empty row, but
- # of course the database only updated by non-empty rows.
- FXLabel.new(self,"Ingredients")
- ingred_table = FXTable.new(self,6,4,nil,0)
- ingred_table.setTableSize(recipe.ingredients.size+2,4)
- ingred_table.leadingRows = 1
- cols = ["Quantity","Measure","Ingredient","Modifier"]
- (0..3).each { |c|
- ingred_table.setItemText(0,c,cols[c])
- }
- (0..recipe.ingredients.size).each { |r|
- next if r >= recipe.ingredients.size
- ingredient = recipe.ingredients[r]
- ingred_table.setItemText(r+1,0,ingredient.quantity.to_s)
- ingred_table.setItemText(r+1,1,ingredient.measure.to_s)
- ingred_table.setItemText(r+1,2,ingredient.food.to_s)
- ingred_table.setItemText(r+1,3,ingredient.modifier.to_s)
- }
-
- FXLabel.new(self,"Directions")
- directions = FXText.new(self)
- directions.text = recipe.directions
-
- FXLabel.new(self,"Note")
- note = FXText.new(self)
- note.text = recipe.note
-
- FXButton.new(self,"Accept").connect(SEL_COMMAND) do
- # these text fields aren't connected to DataTargets
- recipe.directions = directions.text
- recipe.note = note.text
- recipe.commit
- end
- end
- end
-
- class BlankForm < FXLabel
- def initialize(parent, assocObj)
- super(parent, '')
- end
- end
-
class NeelixMainWindow < FXMainWindow
def initialize(app)
! # initialize base class
! super(app, "Neelix", nil, nil, DECOR_ALL, 0, 0, 800, 600)
!
! # set up main window contents, etc.
! contents = FXHorizontalFrame.new(self, LAYOUT_FILL_X| LAYOUT_FILL_Y)
! splitter = FXSplitter.new(contents,
! LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y|
! SPLITTER_HORIZONTAL)
! # create the shelf (nav tree)
! @shelf = Shelf.new(splitter)
$replicator.shelf.each do |cookbook|
! cookbook_item = @shelf.addItem(nil, cookbook.name,
! proc { |item|
! @counter.current.tab.target = cookbook.targets['name']
! @counter.current.tab.selector = DT::ID_VALUE
! @counter.current.tab.text = cookbook.name
! @counter.current.item = item
! children = @counter.current.page.children
! children.each { |child|
! @counter.current.page.removeChild(child)
! }
! CookbookForm.new(@counter.current.page, cookbook).create
! })
cookbook.categories.each do |category|
! category_item = @shelf.addItem(cookbook_item, category.name,
! proc { |item|
! @counter.current.tab.target = category.targets['name']
! @counter.current.tab.selector = DT::ID_VALUE
! @counter.current.tab.text = category.name
! @counter.current.item = item
! children = @counter.current.page.children
! children.each { |child|
! @counter.current.page.removeChild(child)
! }
! CategoryForm.new(@counter.current.page, category).create
! })
category.recipes.each do |recipe|
! @shelf.addItem(category_item, recipe.name,
! proc { |item|
! @counter.current.tab.target = recipe.targets['name']
! @counter.current.tab.selector = DT::ID_VALUE
! @counter.current.tab.text = recipe.name
! @counter.current.item = item
! children = @counter.current.page.children
! children.each { |child|
! @counter.current.page.removeChild(child)
! }
! RecipeForm.new(@counter.current.page, recipe).create
! })
! end
! end
! end
!
! # create the counter (tabs)
! @counter = Counter.new(splitter)
!
! myProc = proc do |item|
! @shelf.tree.selectItem(item) unless item.nil?
! end
!
! tab = @counter.addTab('Shelf', nil, myProc)
! BlankForm.new(tab.page, nil)
! end
! end
!
! class Shelf < FXGroupBox
! attr_reader :tree
! def initialize(parent)
! super(parent, "Cookbook Shelf", LAYOUT_FILL_X| LAYOUT_FILL_Y| FRAME_GROOVE)
! frame = FXVerticalFrame.new(self, LAYOUT_FILL_X| LAYOUT_FILL_Y)
!
! @procs = Hash.new
! @tree = FXTreeList.new(frame, 0, nil, 0,
! TREELIST_SINGLESELECT| TREELIST_SHOWS_LINES|
! TREELIST_SHOWS_BOXES| TREELIST_ROOT_BOXES| LAYOUT_FILL_Y|
! LAYOUT_FILL_X)
!
! @tree.connect(SEL_COMMAND) do |sender, sel, item|
! getApp().beginWaitCursor do
! if not item.equal?(@current) then
! @current = item
! @procs[item].call(item)
! end
! end
! end
!
! @current = nil
! end
! def create
! super
! setWidth(@tree.font.getTextWidth('MMMMMMMMMMMMMMMM'))
! end
! def addItem(parentItem, text, assocProc = proc { })
! item = FXTreeItem.new(text)
! @tree.addItemLast(parentItem, item)
! @procs[item] = assocProc
! return item
! end
! end
!
! class Counter < FXTabBook
! attr_reader :current
! def initialize(parent)
! super(parent, nil, 0, LAYOUT_FILL_X| LAYOUT_FILL_Y| LAYOUT_RIGHT)
!
! self.connect(SEL_COMMAND) do |sender, sel, index|
! getApp().beginWaitCursor do
! if not @current.equal?(@tabs[index])
! @current = @tabs[index]
! @current.activate
end
end
end
-
- @tabs = Array.new
- @current = nil
- end
- def addTab(title, assocItem = nil, assocProc = proc { })
- tab = CounterTab.new(self, title, assocItem, assocProc)
- @tabs << tab
- @current = tab if @current.nil?
- return tab
end
end
! class CounterTab
! attr_reader :tab, :page, :item
! def initialize(parent, title, assocItem, assocProc)
! @tab = FXTabItem.new(parent, title)
! @page = FXHorizontalFrame.new(parent, FRAME_RAISED)
! @item = assocItem
! @proc = assocProc
! @content = nil
! end
! def activate
! @proc.call(@item)
! end
! def setContent(contentClass, contentArg)
! if not @content.nil? then
! # do something to get rid of existing content
! end
! #@content = contentClass.new(self, contentArg)
! end
! def item=(item)
! @item = item
! end
!
! end
!
! # main()
! dbh = DBI.connect("dbi:sqlite:#{ARGV[0]}")
! $replicator.attach(dbh)
! application = FXApp.new('Neelix', 'Fugal')
! application.init(ARGV)
! neelix = NeelixMainWindow.new(application)
! application.create
neelix.show
! application.run
--- 1,34 ----
+ require 'fox'
include Fox
class NeelixMainWindow < FXMainWindow
def initialize(app)
! super(app, 'Neelix',nil,nil,DECOR_ALL,0,0,800,600)
! frame = FXHorizontalFrame.new(self, LAYOUT_FILL_X|LAYOUT_FILL_Y)
! splitter = FXSplitter.new(frame,SPLITTER_HORIZONTAL|LAYOUT_FILL_X|LAYOUT_FILL_Y)
! groupbox = FXGroupBox.new(splitter,"Shelf",FRAME_GROOVE)
! counter = FXGroupBox.new(splitter,"Counter",FRAME_GROOVE)
+ frame = FXVerticalFrame.new(groupbox,LAYOUT_FILL_X|LAYOUT_FILL_Y)
+ shelf = FXTreeList.new(frame,0,nil,0,TREELIST_SINGLESELECT|TREELIST_SHOWS_LINES|TREELIST_SHOWS_BOXES|TREELIST_ROOT_BOXES|LAYOUT_FILL_X|LAYOUT_FILL_Y)
$replicator.shelf.each do |cookbook|
! cookbook_item = shelf.addItemLast(nil, FXTreeItem.new(cookbook.name))
! cookbook_item.expanded = true
cookbook.categories.each do |category|
! category_item = shelf.addItemLast(cookbook_item, FXTreeItem.new(category.name))
category.recipes.each do |recipe|
! shelf.addItemLast(category_item, FXTreeItem.new(recipe.name))
end
end
end
end
end
! app = FXApp.new('Neelix', 'fugalh')
! app.init(ARGV)
! neelix = NeelixMainWindow.new(app)
! app.create
neelix.show
! app.run
|