Παρασκευή 20 Νοεμβρίου 2015

Πρόγραμμα με παράθυρο στη Μ2000 (Εντολές στα Αγγλικά)

Προχωρημένο Θέμα!
Το πρόγραμμα παρακάτω θέλει να μας δείξει πέντε μεθόδους εισαγωγής την στιγμή που τρέχουν άλλες διεργασίες (νήμα/Thread) . Μια από αυτές χειρίζεται στους στόχους (Targets) και έτσι μπορούμε να κάνουμε ελαχιστοποίηση ή μετακίνηση του παραθύρου, την ώρα που ένα άλλο νήμα περιμένει εισαγωγή.
Δείτε επίσης πως εκκινούμε ένα νήμα για να μετακινούμε το παράθυρο, και το σταματάμε - σε αναμονή.
Όταν το περάσουμε στο διορθωτή της Μ2000 θα μας το χρωματίσει αυτόματα.


Thread.plan sequential
Dim label$(6)
label$(1)="Basic style Input for Input a number", "Field Input - Work the INS key","One line transparent textbox, cut, copy, paste, drag/drop, no menu","Multi line textbox with menu","Multi line for documents with transparent background"
Example= random(1, 5)
Global messrow
Escape Off
Global STATE=0
module global mayexit {
      Threads Erase
      Wait 10
      Targets New
      Input End
      Cursor 0,messrow+1 : Print Over : Print Part "End.."
      Cls #72ff77, messrow+4 \\ split screen from 7 (8th line)
}
Hide  \\ prepare window
Window 10,0 \\ center full size 10pt letters
Window random(9,14) , scale.x*.7, scale.y*.7;  \\ centered - random font size
Form width
Linespace 60
Form
Normal
Cls 15,0 \\ white bacground - no split screen
Gradient 0,15 \\ two colors gradient
Move 0,0
Fill scale.x,scale.y/height-25,1,6,0 \\ Gradient fill to window caption
Pen #FF7766
\\ Targets are from earlier versions - but works fine
\\ This is the windows caption. We change only a variable.
\\ Targets works with globals.
Target A,"STATE++",width-2,1,,,5,"M2000 THREAD-Input-HANDLE WINDOW"
Print @(width-2,0);
Pen 0
Let IamOut=False
\\ This is a second target, the X in the right corner
\\ when we click on it system call mayexit global module
Target b, {Title "M2000 Example",0} ,1,1,6,,5,"_"
Print @(width-1,0);
Target C, "mayexit" ,1,1,6,,5,"X"
Pen 15
Print @(0,1);  \\ like Cursor
Report "      Press some numbers keys and Then the return key. By clicking the X in the right up corner, you exit the module and enter to maunal mode.  You can move the window. There is another exit the Ctrl+C - or Break. Ctrl+C in some examples used for copy"
aa$=Field$("",10) \\ for second example - change gosub
let messrow=row+1 \\ we can use Let instead of messrow<=row+1
Pen 0
Refresh 40
Threads Erase
Thread { scan 0.01 : thread this Interval 10
    Cursor 0,messrow : Print Over : Print Part ~(0),"waiting..." , kk
} As LL : Thread LL Interval 10
Scroll split 1
Thread { \\ this thread used for moving the window
Cursor 0,messrow+1 : Print Over "MOVING"
Motion.W Motion.XW-MX+Mouse.X,Motion.YW-MY+Mouse.Y
If Mouse=0 Then {
            STATE<=0: Thread this Hold : Cursor 0,messrow+1 : Print Over "Hold": REFRESH
            }
} As Moveme
Thread moveme Hold \\ not started yet
Thread moveme Interval 100 \\ we set an Interval
Let kk=0, MayStart=True
main.task 10 {
      kk++
        If MayStart Then {
            A$=Inkey$
            If A$<>"" Then {
                  Cursor 0,messrow+1 : Print Over $(9), Label$(Example)
                  MayStart~: Keyboard A$
                  Select Case Example
                  Case 1
                        Gosub OpenField()
                  Case 2
                        Gosub OpenField1()
                  Case 3
                        Gosub OpenField2()
                  Case 4
                        Gosub OpenField3()
                  Else
                        Gosub OpenField4()
                  End Select
               
            }
      }
      If iamout Then iamout~: Cursor 0,messrow+1 : Print Over : Print Part "You press escape..."  
      If STATE=1 Then {
            Cursor 0,messrow+1 : Print Over : Print "start move"
            MX=Mouse.X:MY=Mouse.Y \\ setup now position
            Thread moveme restart \\ here we restart thread
            STATE++ \\ and we closed this if
      }
}
Cls, messrow+4
Cursor 0, messrow+3
Pen 15 { Report 2, "Just press enter or F1 to see the code" }
Fkey 1, "Edit a"
Keyboard "A"
Sub OpenField()
After 10 { \\ this is an automatic thread, for one time, After 10 miliseconds
      again:
      Cursor 10,10
      for i=1 to 4 : Print Over : Pen 15 { Print under } : next i
      Cursor 10,10
      A=0
      try ok { Input "Number:", A } \\ we can use Input in a thread.
      If ok Then { Cursor 0,messrow+2 : Print Over "Field:";A } Else goto again
      MayStart=True
     }
End Sub
Sub OpenField1() \\ this is an alternative by using Field
      After 10 {
            Field 10,10,10 As aa$
            If Field=99 Then {
                  IamOut=True : aa$=""
                  Field New \\ Clear feedback from Field statement.
                  A$=Inkey$
            } Else Cursor 0,messrow+2 : Print Over "Field:";aa$ : aa$=""
            MayStart=True
     }
End Sub
Sub OpenField2()
      After 10 {
            Cursor 10,10
            aa$=inkey$
            IF aa$<" " Then aa$=""
            Input ! aa$, 10 len=30
            If Field=99 Then {
                  IamOut=True : aa$=""
                  Field New \\ Clear feedback from Field statement.
                  A$=Inkey$
            } Else Cursor 0,messrow+2 : Print Over "Field:";aa$ : aa$=""
            Field New
           MayStart=True
      }
End Sub
Sub OpenField3()
      After 10 {
            Cursor 10,10
            Clear aa$
            aa$=inkey$
            if asc(aa$)<32 Then aa$=""
            Input ! aa$, 20, 8
            document aa$ \\ upgrade to document
            Cursor 0,messrow+2 : Print Over "Field:";paragraph$(aa$,1) : aa$=""
           MayStart=True
      }
End Sub
Sub OpenField4()
      After 10 {
            Cursor 10,10
            Clear aa$
            Document bb$=""  \\ this is a New variable, but not for Sub, Sub ends before this thread run.
            bb$=inkey$
            if asc(bb$)<32 Then Clear bb$
            Scroll split 10
            Pen 1 {
            Edit.Doc bb$, 1,,Pen
            }
            Cursor 0,messrow+2 : Print Over "Field:";paragraph$(bb$,1)
            Clear bb$
           MayStart=True
      }
End
Sub
Επειδή οι ρουτίνες εδώ δεν έχουν τοπκέες μεταβλητές, ούτε σε παραμέτρους θα μπορούσαν να χρησιμοποιηθούν ετικέτες
        If MayStart Then {
            A$=Inkey$
            If A$<>"" Then {
                  Cursor 0,messrow+1 : Print Over $(9), Label$(Example)
                  MayStart~: Keyboard A$
                  ON Example GOSUB OpenField,OpenField1,OpenField2,OpenField3,OpenField4
            }
      }
................................
OpenField4:
      After 10 {
            Cursor 10,10
            Clear aa$
            Document bb$=""  \\ this is a New variable, but not for Sub, Sub ends before this thread run.
            bb$=inkey$
            if asc(bb$)<32 Then Clear bb$
            Scroll split 10
            Pen 1 {
            Edit.Doc bb$, 1,,Pen
            }
            Cursor 0,messrow+2 : Print Over "Field:";paragraph$(bb$,1)
            Clear bb$
           MayStart=True
      }
Return


Ουσιαστικά όταν η MayStart το επιτρέπει δημιουργούμε ένα νήμα με την AFTER (Μετά) για μια φορά, το οποίο θα τρέξει όταν πια θα έχουμε φύγει από την ρουτίνα. Σε αυτό η ροή θα σταματήσει στην εισαγωγή, αλλά τά άλλα νήματα θα συνεχίσουν να τρέχουν! Οι στόχοι ανιχνεύονται μόνο στην Scan (Σάρωσε). Όταν επιλέγουμε στόχο καλούμε στην ουσία τον εκτελεστή γραμμής εντολών..έτσι πρέπει το τμήμα που θέλουμε να είναι γενικό, ή αν αλλάξουμε τιμή σε μεταβλητή να είναι και αυτή γενική (και δεν έχει σημασία που φτιάχτηκε απλά εκείνη την ώρα να υπάρχει ως γενική δηλωμένη)! Στη Μ2000 αν ορίσουμε γενική την ώρα που υπάρχει γενική με το ίδιο όνομα, τότε σκιάζεται η προηγούμενη, και όταν το τμήμα που την έφτιαξε τερματίσει, επανέρχεται η προηγούμενη στο προσκήνιο.

Τρέχει το πρόγραμμα και με Thread.plan concurrent




 

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου

You can feel free to write any suggestion, or idea on the subject.