Simple image viewer

You can post your code snippets here for others to use and learn from
Post Reply
User avatar
Redlion
Posts: 73
Joined: Sun Jul 10, 2011 5:05 am
Location: Perth, Western Australia

Simple image viewer

Post by Redlion » Wed Apr 15, 2015 2:39 pm

Hi again,

I needed to find some images for a program I am writing to log all the books that I have read, so I came up with this.

Just love MUIRoyale and Hollywood 6, so quick to put something together.

Code: Select all

@VERSION 6,0
@REQUIRE "MUIRoyale"
@APPTITLE "QLook"
@APPVERSION "$VER: 1.0 (14.03.15)"
@APPCOPYRIGHT "©2015, George Leo den Hollander"
@APPAUTHOR "Leo den Hollander"
@APPDESCRIPTION "Image Viewer Program"

@DISPLAY {Hidden = True}
Dim Location[10000]

MUI.CreateGui([[
<?xml version="1.0" encoding="iso-8859-1"?>
<application base="DidL">
<window title="Q-Look - Image Viewer Program" id="window" width="1280" notify="closerequest" >
    <hgroup background="pre_ShadowFill">
        <hgroup>
            <vgroup>
                <button id="SearchOK" maxwidth="200" notify="pressed">SEARCH</button>
                <hgroup>
                    <Label>No. Found :</Label>
                    <string id="Searching" contents=""/>
                </hgroup>
                <listview Id="Vols" maxheight="150" >
                    <column/>
                </listview>
                <listview Id="Found" notify="active">
                    <column/>
                </listview>
                <string id="Size" contents=""/>
            </vgroup>
            <vgroup>
            <hollywood display="1" minwidth="1024" minheight="768"/>
            <hgroup>
                <Label>Searching :</Label>
                <string id="Directories" contents=""/>
            </hgroup>
            </vgroup>
       </hgroup>
    </hgroup>
</window>
</application>
]])

backcolor = GetPen(0, True)
frontcolor = #BLACK

CreateBGPic(1, 800, 600, backcolor)
DisplayBGPic(1)

devices = {}
harddisks = {}
optical = {}
usb = {}
Devs = {}

CreateBrush(2,800,600,RGB(0,0,0))

Function p_ListDrives() ; List drives ***********************************************************************
    Execute("info devices sort volume >TEXTCLIP:")
    type, data = GetClipboard()
    h = 0
    o = 0
    u = 0
    devices, NoofDevices = SplitStr(data,"\n")
    For Local x = 1 to NoofDevices-1
        line = devices[x-1]
        If FindStr(line,"DH",False) = 0
            harddisks[h] = MidStr(line,0, FindStr(line,":"))
            h = h +1
        ElseIf FindStr(line,"CD",False) = 0
            optical[o] = MidStr(line,0, FindStr(line,":"))
            o = o +1
        ElseIf FindStr(line,"USB",False) = 0
            usb[u] = MidStr(line,0, FindStr(line,":"))
            u = u +1
        EndIf
    Next
    L=0
    For Local d = 0 to h-1
        MUI.DoMethod("Vols","Insert","Bottom",Harddisks[d]..":")
    Next
    For Local d = 0 to o-1
        MUI.DoMethod("Vols","Insert","Bottom",optical[d]..":")
    Next
    For Local d = 0 to u-1
        MUI.DoMethod("Vols","Insert","Bottom",USB[d]..":")
    Next
EndFunction

Function p_Search(SearchDir$) ; * Search Drive *************************************************************
    Local dirno
    Local Lookdir$
    LookDir$ =  SearchDir$
    Dirno = OpenDirectory(NIL, LookDir$)
    MUI.set("Directories","Contents",LookDir$)
    Local Entry
    Entry = NextDirectoryEntry(Dirno)
    While Entry <> Nil
        If Entry.type = #DOSTYPE_FILE
            if MatchPattern(Entry.name,"*.JPG") or MatchPattern(Entry.name,"*.jpg") or
                MatchPattern(Entry.name,"*.IFF") or MatchPattern(Entry.name,"*.iff")
                MUI.DoMethod("Found", "Insert", "Bottom",Entry.name)
                Location[SN] = LookDir$..Entry.name
                SN = SN + 1
                MUI.Set("Searching", "Contents"," ".. SN.." files ...")
            EndIf
        EndIf
        If Entry.type = #DOSTYPE_DIRECTORY
            LookDir$ = LookDir$..Entry.name.."/"
            p_search(Lookdir$)
            LookDir$ = SearchDir$
        EndIf
        Entry = NextDirectoryEntry(dirno)
    Wend
    CloseDirectory(Dirno)
Endfunction

Function p_MUIEvent(id) ; * Joint event handler for MUI buttons and menus ***********************************
    Switch id
        Case "SearchOK"
            SN = 0
            MUI.DoMethod("Found","Clear")
            MUI.Set("Searching", "Contents","") 
            Pos = MUI.get("Vols","Active")
            SearchFrom$ = MUI.DoMethod("Vols","GetEntry",Pos)
            p_Search(SearchFrom$)
            MUI.Set("Searching","Contents"," "..SN.." files.")
        
        Case "quit":
            End
    EndSwitch
EndFunction

Function p_EventFunc(msg) ; ===================================================================================
    Switch msg.action
        Case "MUIRoyale":
            Switch msg.attribute
                Case "CloseRequest":
                     End
        
                Case "Pressed":
                    p_MUIEvent(msg.id)

                
                Case "Active":
                    Pos = mui.get("Found","Active")
                    ;FP$ = mui.DoMethod("Found","GetEntry",Pos)
                    MUI.Set("Directories", "Contents",Location[Pos])
                    LoadBrush(1,Location[Pos])
                    Bwidth = GetAttribute(#BRUSH,1,#ATTRWIDTH)
                    Bheight = GetAttribute(#BRUSH,1,#ATTRHEIGHT)

                    BW = Bwidth/800
                    BH = Bheight/600
                    if Bwidth < 801 and Bheight < 601
                        NBW = bwidth
                        NBH = bheight
                    elseif BW > BH
                        NBW = Bwidth/BW
                        NBH = Bheight/BW
                    elseif BH > BW
                        NBW = Bwidth/BH
                        NBH = Bheight/BH
                    else
                        NBW = bwidth/BW
                        NBH = bheight/BW
                    endif
                    MUI.Set("Size", "Contents"," Size : "..bwidth.."W  x "..bheight.."H")
                    DisplayBrush(2,0,0,{width=800,600})
                    DisplayBrush(1,0,0,{width=NBW,height=NBH})

            Endswitch

        Case "HideWindow":
            MUI.Set("app", "iconified", True)

        Case "ShowWindow":
            MUI.Set("app", "iconified", False)

    EndSwitch
EndFunction

; listen to these events!
InstallEventHandler({MUIRoyale = p_EventFunc, HideWindow = p_EventFunc, ShowWindow = p_EventFunc})

p_ListDrives()

MUI.set("Vols","Active",0)
SearchFrom$ = MUI.DoMethod("Vols","GetEntry",0)
;

; main loop!
Repeat
    WaitEvent
Forever
This is pretty simple.

Enjoy, Leo
----------------------------------------------------------------------------------------
Redlion
Sam460 Lite
A4000 A3000 A2000 A1200 A1000 A600 A500 CD32

Post Reply