From: daz Date: 2003-12-09T22:42:03+09:00 Subject: Re: Idea: Linux PIM in Ruby Hal Fulton wrote: > Curt Hibbs wrote: >> Emmanuel Touzery wrote: >> >>> Hal Fulton wrote: >>> >>>> Then for example it would easy(-ier) to switch later from Fox >>>> to GTK or wxWin or whatever, or even make alternatives. >>> >>> wouldn't it be smarter to have a core which knows nothing about GUI and >>> then several GUI layers ontop of it? >>> you think application directing GUI. how about GUI directing >>> application? seems cleaner to me, but then again.. >> >> I think that is pretty much what Hal is saying. > > Yes, that is what I meant. > >> I would also like to reinforce this theme: A core "engine" with no gui. The >> gui can then be developed independently or, if you wish, separate (but >> similar) gui applications can be written that all use this same core engine. > > In practice, I find this difficult. > > To get back to basics: I think the GUI serves as an I/O mechanism. > > Sometimes the engine drives (calls) the GUI, to fill a window with data > or throw up a window or whatever. > > Sometime the GUI drives the engine: The user pushes a button, and an > engine method gets called. > > Hmm, can we separate these logically? Make two modules or classes, > perhaps? > I shall regret posting the moment I thump 'send' :-) Any repliers, please DELETE the whole script first ... once is enough. This paltry effort has, I hope, full separation of concerns. The PIM is a server to whatever the TUI/GUI client. As a non-programmer (SysProg), the challenging part of OOP is leaving the 'real world' and getting right inside the object rather than opening a class and force-feeding it with data through accessors from an external 'main' method as most of us start doing. #--------------------------------------------------------------- # 'ui_text' class UI Version = 'Text 0.0.1 (boxy)' #Text-only version (FX | VR | TK | WX etc. coming soon... :) def initialize(pim) @pim = pim @setup = false @cmd = 'setup' end def msgloop loop do @args = @cmd.split(/\s+/) @cmd = @args.shift # Sophisticated command parser ... cuh! case @cmd when /setup/ unless @setup @setup = true puts 'Initialising layout manager :-))' help() end when /nt/ draw_box_each() when /q(uit)?/, /exit/ return @cmd when /h(elp)?/ help() when /^\n/ else puts "I'm afraid I can't do ... #{@cmd} #{@args}" end print "\nReady > " @cmd = gets puts end end def help puts '', 'Minimally useful commands available:' puts ' h(elp) - ... this' puts ' q(uit) - Exit' puts ' nt - list of Name & Tel' end # Cruft alert - plz ignore this meth. def draw_box_each # calls each_'cmd' (e.g. each_nt) in PIM for content bar ='' @pim.method("each_#{@cmd}".intern).call do |row, nt, det| if row == 0 # Title line_width = 0 det.each {|n| line_width += (n+2)-1} bar = ' |---| ' << '-' * line_width << '|' puts bar print ' | n ' nt.each_with_index do |nm, eix| printf("| %-*s", det[eix], nm) # heading end puts '|', bar else printf(" |%2d ", row) nt.each_with_index do |ent, col| printf("| %-*s", det[col], ent) # entries end puts '|' end end puts bar end end #--------------------------------------------------------------- class PIM Version = '0.0.1 (alpha)' private_class_method :new def initialize @nt_struct = Struct.new(:name, :tel) @nt_detail = [30, 15] # field widths @nta = nil end def PIM.run UI.new(new).msgloop # Pass PIM object to whatever UI puts "\nThank you for using PIM #{Version} with #{UI::Version}\n\n" sleep 2 end ####### private ####### def each_nt @nta || load_nt # Column titles first (index = 0) yield 0, @nt_struct.members.map {|e| e.capitalize}, @nt_detail @nta.each_with_index do |nt, ix| yield ix+1, nt, @nt_detail end end def load_nt @nta = [] while nt = DATA.gets nt = nt.chomp.split(/,\s*/) @nta << @nt_struct.new(*nt) end end end #require 'ui_text' PIM.run # Return when UI receives quit # Test data follows __END__ # NOT suitable for this kind of app!! __END__ Yukihiro Matsumoto, 11-111-1111 bbb b bbbbbb, 22-222-2222 ccccccc ccccc, 33-333-3333 #---------- This isn't a bid to join (or be banned from) a team. If anything develops, it may be converted from a Linux PIM (what's that ?) to a splendid vruby/swin PIM (?) targeted at we occupants of the sinking ship Hal (apparently) can't wait to abandon :-) 'Scuse the cheek. Maximum respect to all open-sourcerers. daz