Computer Science Canada

GUI program

Author:  Punde [ Sun Jun 01, 2003 2:02 pm ]
Post subject:  GUI program

I posted a while ago but nobody helped, maybe it was the way it was posted I dunno.

I am using a GUI for a database, basically I need help calling the procedures to the main program i.e when menu is selected it will perform whatever procedure is called.

Here is my module:
code:

type MOV :
    record
        name : string
        studio : string
        leng : string
        dat : string
        actor : string
        genre : string
        rating : string
    end record

var filename : string
function countrec : int
    var num := 0
    var stream : int
    var movies : MOV
    put "Please enter the name of the file you want to open"
    get filename
    open : stream, filename, get
    loop
        get : stream, skip
        exit when eof (stream)
        get : stream, movies.name : *
        get : stream, movies.studio : *
        get : stream, movies.leng : *
        get : stream, movies.dat : *
        get : stream, movies.actor : *
        get : stream, movies.genre : *
        get : stream, movies.rating : *
        num += 1
    end loop
    close : stream
    result num
end countrec

proc readrecords (var movies : array 1 .. * of MOV, num : int)
    var stream : int
    open : stream, filename, get
    for i : 1 .. num
        get : stream, movies (i).name : *
        get : stream, movies (i).studio : *
        get : stream, movies (i).leng : *
        get : stream, movies (i).dat : *
        get : stream, movies (i).actor : *
        get : stream, movies (i).genre : *
        get : stream, movies (i).rating : *
    end for
    close : stream
end readrecords
var numrecords := countrec

proc view_records (movies : array 1 .. * of MOV, num : int)
    put "Hollywod Movie Database"
    put " "
    put "Name" : 15, "Studio" : 25, "Length" : 10, "Date" : 7, "Actor" : 15, "Genre" : 15, "Rating"
    for i : 1 .. num

        put movies (i).name : 15, movies (i).studio : 25, movies (i).leng : 10, movies (i).dat : 7, movies (i).actor : 15, movies (i).genre : 15, movies (i).rating
        delay (800)
    end for
    delay (1050)
end view_records

proc sortrecords (t : string, var movies : array 1 .. * of MOV, num : int)
    for i : 1 .. num - 1
        for j : 1 .. num - 1
            if t = "1" then
                if movies (j).name > movies (j + 1).name then
                    var temp := movies (j)
                    movies (j) := movies (j + 1)
                    movies (j + 1) := temp
                end if
            elsif t = "2" then
                if movies (j).studio > movies (j + 1).studio then
                    var temp := movies (j)
                    movies (j) := movies (j + 1)
                    movies (j + 1) := temp
                end if
            elsif t = "3" then
                if movies (j).leng > movies (j + 1).leng then
                    var temp := movies (j)
                    movies (j) := movies (j + 1)
                    movies (j + 1) := temp
                end if
            elsif t = "4" then
                if movies (j).dat > movies (j + 1).dat then
                    var temp := movies (j)
                    movies (j) := movies (j + 1)
                    movies (j + 1) := temp
                end if
            elsif t = "5" then
                if movies (j).actor > movies (j + 1).actor then
                    var temp := movies (j)
                    movies (j) := movies (j + 1)
                    movies (j + 1) := temp
                end if
            elsif t = "6" then
                if movies (j).genre > movies (j + 1).genre then
                    var temp := movies (j)
                    movies (j) := movies (j + 1)
                    movies (j + 1) := temp
                end if
            elsif t = "7" then
                if movies (j).rating > movies (j + 1).rating then
                    var temp := movies (j)
                    movies (j) := movies (j + 1)
                    movies (j + 1) := temp
                end if
            end if


        end for
    end for
end sortrecords

proc search (var movies : array 1 .. * of MOV, num : int)
    var choice : string
    put ""
    put "Input the name you want to find: " ..
    get choice : *
    put "Name" : 15, "Studio" : 25, "Length" : 10, "Date" : 7, "Actor" : 15, "Genre" : 15, "Rating"
    for i : 1 .. num
        if choice = movies (i).name then
            put ">", movies (i).name : 15, movies (i).studio : 25, movies (i).leng : 10, movies (i).dat : 15, movies (i).actor : 7, movies (i).genre : 15, movies (i).rating
        elsif choice = movies (i).studio then
            put movies (i).name : 15, ">", movies (i).studio : 23, movies (i).leng : 10, movies (i).dat : 15, movies (i).actor : 7, movies (i).genre : 15, movies (i).rating
        elsif choice = movies (i).leng then
            put movies (i).name : 15, movies (i).studio : 25, ">", movies (i).leng : 8, movies (i).dat : 15, movies (i).actor : 7, movies (i).genre : 15, movies (i).rating
        elsif choice = movies (i).dat then
            put movies (i).name : 15, movies (i).studio : 25, movies (i).leng : 10, ">", movies (i).dat : 13, movies (i).actor : 7, movies (i).genre : 15, movies (i).rating
        elsif choice = movies (i).actor then
            put movies (i).name : 15, movies (i).studio : 25, movies (i).leng : 10, movies (i).dat : 15, ">", movies (i).actor : 5, movies (i).genre : 15, movies (i).rating
        elsif choice = movies (i).genre then
            put movies (i).name : 15, movies (i).studio : 25, movies (i).leng : 10, movies (i).dat : 15, movies (i).actor : 7, ">", movies (i).genre : 15, movies (i).rating
        elsif choice = movies (i).rating then
            put movies (i).name : 15, movies (i).studio : 25, movies (i).leng : 10, movies (i).dat : 15, movies (i).actor : 7, ">", movies (i).genre : 15, movies (i).rating
        end if
    end for
end search

%proc insert (name1, studio1, actor1, genre1, rating1, dat1 : string, num : int, leng1 : real)

%   pre size < maxsize
%  post size <= maxsize and movies (size).name = name1 and movies (size).studio = studio1 and
%     movies (size).actor = actor1 and movies (size).genre = genre1 and movies (size).rating = rating1 and movies (size).dat = dat1 and movies (size).leng = leng1
%size += 1
%movies (size).name := name1
%movies (size).studio := studio1
%movies (size).actor := actor1
%movies (size).genre := genre1
%movies (size).rating := rating1
%movies (size).dat := dat1
%movies (size).leng := leng1
%end insert


And here is my main Program (the one that has the actual GUI)
code:

% Main Program
import GUI in "%oot/lib/GUI"
include "main.tu"
View.Set ("graphics:800;600")
var first, second, third, fourth, fifth : int  % The menus.
var item : array 1 .. 24 of int % The menu items.
var name2 : array 1 .. 13 of string (25) :=
    init ("Open", "View", "---", "Quit", "Add movie", "Delete movie", "By name...", "By studio...", "By length...", "By rating...", "Find...",
    "About Simon", "About Salman")

%=============================================================================
procedure MenuSelected
    if item (1) = GUI.GetEventWidgetID then %Open
        delay (4000)
        cls
    end if
    if item (2) = GUI.GetEventWidgetID then     %View Files
        delay (1050)
        cls
    end if
    if item (4) = GUI.GetEventWidgetID then %Quit
        GUI.Quit
        put " "
        put " "
        put "Thank you for using our program."
    end if
    if item (5) = GUI.GetEventWidgetID then % Add movie
        put "hahah"
        delay (4000)
        cls
    end if
    if item (6) = GUI.GetEventWidgetID then % Delete Movie
        put "hahah"
        delay (4000)
        cls
    end if
    if item (7) = GUI.GetEventWidgetID then %By name...
        put "hahah"
        delay (4000)
        cls
    end if
    if item (8) = GUI.GetEventWidgetID then    %By studio...
        put "hahah"
        delay (4000)
        cls
    end if
    if item (9) = GUI.GetEventWidgetID then    %By length...
        put "hahah"
        delay (4000)
        cls
    end if
    if item (10) = GUI.GetEventWidgetID then    %By rating....
        put "hahah"
        delay (4000)
        cls
    end if
    if item (11) = GUI.GetEventWidgetID then        %Find...
        put "hahah"
        delay (4000)
        cls
    end if
    if item (12) = GUI.GetEventWidgetID then        %About Simon
        put "hahah"
        delay (4000)
        cls
    end if
    if item (13) = GUI.GetEventWidgetID then            %About Salman
        put "hahah"
        delay (4000)
        cls
    end if
    GUI.ShowMenuBar
end MenuSelected


%Create the menus
first := GUI.CreateMenu ("File")
for cnt : 1 .. 4
    item (cnt) := GUI.CreateMenuItem (name2 (cnt),
        MenuSelected)
end for

second := GUI.CreateMenu ("Edit")
for cnt : 5 .. 6
    item (cnt) := GUI.CreateMenuItem (name2 (cnt),
        MenuSelected)
end for
third := GUI.CreateMenu ("Sort")
for cnt : 7 .. 10
    item (cnt) := GUI.CreateMenuItem (name2 (cnt),
        MenuSelected)
end for
fourth := GUI.CreateMenu ("Search")
for cnt : 11 .. 11
    item (cnt) := GUI.CreateMenuItem (name2 (cnt),
        MenuSelected)
end for
fifth := GUI.CreateMenu ("About")
for cnt : 12 .. 13
    item (cnt) := GUI.CreateMenuItem (name2 (cnt),
        MenuSelected)
end for
loop
    exit when GUI.ProcessEvent
end loop


Sorry for the long post, I think it might help better if you can see the whole code. PLease help me with this. Thanks in advance.

Author:  Punde [ Mon Jun 02, 2003 6:45 pm ]
Post subject: 

how can noone help with this?! please people!!

Author:  Tony [ Mon Jun 02, 2003 9:57 pm ]
Post subject: 

well maybe its because you just posted your whole code with saying "this dont work - fix it"

Seriosly though, if you want some feedback, you need to post a more specific problem. Line of code you have problem with, or what not...

GUI items perform procedure when activated.. its the part of their syntax, so I donno what you're having problems with there...

And dont really take this personally. Not many of us are coumfortable with GUI cuz we ether move on to a better language or just make our own since one in Turing sucks

Author:  Punde [ Tue Jun 03, 2003 5:11 pm ]
Post subject: 

I had a post before, same problems precise, and only the code that I needed help with, nobody replied, so I don't think that's it.

Author:  Homer_simpson [ Tue Jun 03, 2003 5:33 pm ]
Post subject: 

the only reason i didn't look at it was that it was soooo long and i dont like reading other people's codes to understand them... =/

Author:  ShadowStorm [ Tue Jun 03, 2003 6:39 pm ]
Post subject: 

yeah.. really man.. you're code is pretty long and i don't think anyone will sit down to read it all and then figure out your problem.. think about it.. would you sit down and read ALL that and figure out what\s the problem... Exactly... 8)

Author:  PaddyLong [ Tue Jun 03, 2003 7:08 pm ]
Post subject: 

I'm on the same agree with Homer ... hate reading other people's code to try to find out what their program is suppose to do

Author:  Punde [ Wed Jun 04, 2003 5:16 pm ]
Post subject: 

I agree so I redirect you to my old post:
http://www.compsci.ca/bbs/viewtopic.php?t=1115

Author:  Homer_simpson [ Wed Jun 04, 2003 8:16 pm ]
Post subject: 

come on ppl he might really need help... yo i'll read yer code as soon as i find the time...

Author:  Punde [ Thu Jun 05, 2003 7:29 pm ]
Post subject: 

Thank you very much Smile

Author:  Homer_simpson [ Thu Jun 05, 2003 9:20 pm ]
Post subject: 

yo i seem to b e needing some sorta file created by your program can u give me a sample file...?!

Author:  Homer_simpson [ Thu Jun 05, 2003 9:41 pm ]
Post subject: 

i went to your gui it's seems to be working fine for me... isn't this what it's supposed to look like?!

Author:  Punde [ Sun Jun 08, 2003 5:27 pm ]
Post subject: 

Yeah, the gui is fine, except I don't know how to make it do a procedure or a function when it is selected. For example when the Open menu is selected it needs to do function countrec, and procedure readrecords.

Author:  Homer_simpson [ Sun Jun 08, 2003 5:54 pm ]
Post subject: 

here u go this should be what u want

Author:  Punde [ Tue Jun 10, 2003 5:45 pm ]
Post subject: 

Thx a lot, but would you mind telling me what exactly you did in order to be able to call the function and the procedure when the menu is selected?? I want to be able to do it for the other ones too, but I can't seem to figure out what you did. Thanks again!

Author:  Homer_simpson [ Tue Jun 10, 2003 6:11 pm ]
Post subject: 

i dont remember... Embarassed
lemme check the file again Laughing

Author:  Punde [ Tue Jun 10, 2003 7:16 pm ]
Post subject: 

haha no problem Smile

Author:  Punde [ Thu Jun 12, 2003 5:03 pm ]
Post subject: 

Have you figure it out yet?? I need this for next week. Sry if it looks like I am rushing you Sad

Author:  Punde [ Thu Jun 12, 2003 5:22 pm ]
Post subject: 

Anyone please!!! This is due tomorrow!!! I need to know how to do this!!! PLEASE HELP ME!!!!

Author:  Homer_simpson [ Thu Jun 12, 2003 5:31 pm ]
Post subject: 

see this part :
code:
    if item (1) = GUI.GetEventWidgetID then %Open
        delay (4000)
        cls
    end if
    if item (2) = GUI.GetEventWidgetID then     %View Files
        delay (1050)
        cls
    end if
    if item (4) = GUI.GetEventWidgetID then %Quit
        GUI.Quit
        put " "
        put " "
        put "Thank you for using our program."
    end if
    if item (5) = GUI.GetEventWidgetID then % Add movie
        put "hahah"
        delay (4000)
        cls
    end if
    if item (6) = GUI.GetEventWidgetID then % Delete Movie
        put "hahah"
        delay (4000)
        cls
    end if
    if item (7) = GUI.GetEventWidgetID then %By name...
        put "hahah"
        delay (4000)
        cls
    end if
    if item (8) = GUI.GetEventWidgetID then    %By studio...
        put "hahah"
        delay (4000)
        cls
    end if
    if item (9) = GUI.GetEventWidgetID then    %By length...
        put "hahah"
        delay (4000)
        cls
    end if
    if item (10) = GUI.GetEventWidgetID then    %By rating....
        put "hahah"
        delay (4000)
        cls
    end if
    if item (11) = GUI.GetEventWidgetID then        %Find...
        put "hahah"
        delay (4000)
        cls
    end if
    if item (12) = GUI.GetEventWidgetID then        %About Simon
        put "hahah"
        delay (4000)
        cls
    end if
    if item (13) = GUI.GetEventWidgetID then            %About Salman
        put "hahah"
        delay (4000)
        cls
    end if


just change the parts inside every if statement that's how it works...(haven't u wrote this script yourself?!)

Author:  Punde [ Thu Jun 12, 2003 5:40 pm ]
Post subject: 

What do you mean by change the parts inside?
I tried pasting the proc inside the if statement but it doesn't work. It says procedure can only be declared on monitor etc. level. I basically need to know how to call a procedure from a module inside that piece of code. What should I do? Please help me with this. Thx.

P.S If you can please come on MSN it will be much better : neoexitus@hotmail.com Thank you.

Author:  Homer_simpson [ Thu Jun 12, 2003 8:21 pm ]
Post subject: 

ok for example if u want to put something on the screen when open is selected you change
code:
    if item (1) = GUI.GetEventWidgetID then %Open
        delay (4000)
        cls
    end if

to
code:
    if item (1) = GUI.GetEventWidgetID then %Open
locate(10,10)
put"somethig"
delay(1000)
cls
    end if


: