You are on page 1of 10

Ring Documentation, Release 1.5.

4.4 Calculator Application

The Calculator application is added to the Applications folder.


Screen Shot:

4.5 Better Ring Notepad

1. Ring Notepad is updated to include some new styles and the Main File ToolBar
The idea of the Main File ToolBar is to determine the main file in the project When the project contains many source
code files
This way you can run the project ( Main File ) at any time while opening other files in the project without the need to
switch to the Main File to run the project.
To quickly use this feature
(Open the project main file)
Press Ctrl+Shift+M to set the current source code file as the main file
Open and modify other source code files in the project
To run the project (Main File) at any time press Ctrl+Shift+F5 (GUI) or Ctrl+Shift+D (Console)
Screen Shots:

4.4. Calculator Application 35


Ring Documentation, Release 1.5.2

4.5. Better Ring Notepad 36


Ring Documentation, Release 1.5.2

2. The output window is updated to display the new lines correctly and contains the “Clear” button.
Screen Shot:

(3) The Ring Notepad is updated to quickly open and switch between large files while preparing the functions/classes
lists in the background.
Screen Shot:

4.5. Better Ring Notepad 37


Ring Documentation, Release 1.5.2

4.6 Better StdLib

New Functions
• Print2Str()
• ListAllFiles()
• SystemCmd()
1. The Print2Str() is a new function added to the StdLib
Example:
load "stdlib.ring"

world = "World!"
mystring = print2str("Hello, #{world} \nIn Year \n#{2000+17} \n")

see mystring + nl

Output:
Hello, World!
In Year
2017

2. The ListAllFiles() is a new function added to the StdLib


Using this function we can quickly do a process on a group of files in a folder and it’s sub folders.
Example:
load "stdlib.ring"
aList = ListAllFiles("c:/ring/ringlibs","ring") # *.ring only

4.6. Better StdLib 38


Ring Documentation, Release 1.5.2

aList = sort(aList)
see aList

Example:
load "stdlib.ring"
see listallfiles("b:/ring/ringlibs/weblib","") # All Files

3. The SystemCmd() is a new function added to the StdLib


The function will execute a system command like the System() function but will return the output in a string.
Example:
cYou = SystemCmd("whoami")
See "SystemCmd: whoami ====="+ nl + cYou +nl

Output:
SystemCmd: whoami =====
desktop-umberto\umberto

4.7 Better WebLib

The WebLib is updated to include the HTMLPage class


Using this class we can create HTML documents without printing the output to the standard output
So instead of using the WebLib in Web Applications only
We can use it in Console/GUI/Mobile Applications too
Example:
load "stdlib.ring"
load "weblib.ring"

import System.Web

func main

mypage = new HtmlPage {


h1 { text("Customers Report") }
Table
{
style = stylewidth("100%") + stylegradient(4)
TR
{
TD { WIDTH="10%" text("Customers Count : " ) }
TD { text (100) }
}
}

Table
{
style = stylewidth("100%") + stylegradient(26)
TR
{
style = stylewidth("100%") + stylegradient(24)

4.7. Better WebLib 39


Ring Documentation, Release 1.5.2

TD { text("Name " ) }
TD { text("Age" ) }
TD { text("Country" ) }
TD { text("Job" ) }
TD { text("Company" ) }
}
for x = 1 to 100
TR
{
TD { text("Test" ) }
TD { text("30" ) }
TD { text("Egypt" ) }
TD { text("Sales" ) }
TD { text("Future" ) }
}
next
}

write("report.html",mypage.output())

Using this feature we can create reports quickly using WebLib & GUILib together
Example:
load "stdlib.ring"
load "weblib.ring"
load "guilib.ring"

import System.Web
import System.GUI

new qApp {
open_window(:CustomersReportController)
exec()
}

class CustomersReportController

oView = new CustomersReportView

func Start
CreateReport()

func CreateReport
mypage = new HtmlPage {
h1 { text("Customers Report") }
Table
{
style = stylewidth("100%") + stylegradient(4)
TR
{
TD { WIDTH="10%"
text("Customers Count : " ) }
TD { text (100) }
}
}
Table

4.7. Better WebLib 40


Ring Documentation, Release 1.5.2

{
style = stylewidth("100%") + stylegradient(26)
TR
{
style = stylewidth("100%") +
stylegradient(24)
TD { text("Name " ) }
TD { text("Age" ) }
TD { text("Country" ) }
TD { text("Job" ) }
TD { text("Company" ) }
}
for x = 1 to 100
TR
{
TD { text("Test" ) }
TD { text("30" ) }
TD { text("Egypt" ) }
TD { text("Sales" ) }
TD { text("Future" ) }
}
next
}
}
write("report.html",mypage.output())

func PrintEvent
printer1 = new qPrinter(0) {
setoutputformat(1)
setoutputfilename("report.pdf")
}
oView {
web.print(printer1)
web.show()
}
system ("report.pdf")

class CustomersReportView

win = new window() {


setwindowtitle("Report Window")
setgeometry(100,100,500,500)
web = new webview(win) {
setgeometry(100,100,1000,500)
loadpage(new qurl("file:///"+
currentdir()+"/report.html"))
}
new pushbutton(win) {
setGeometry(100,20,100,30)
settext("Print")
setclickevent(Method(:PrintEvent))
}
showMaximized()
}

Screen Shot:

4.7. Better WebLib 41


Ring Documentation, Release 1.5.2

4.8 Better RingQt

New classes added to RingQt :


• QStringRef
• QMutex
• QMutexLocker
• QBuffer
• QBluetoothAddress
• QBluetoothDeviceDiscoveryAgent
• QBluetoothDeviceInfo
• QBluetoothHostInfo
• QBluetoothLocalDevice
• QBluetoothServer
• QBluetoothServiceDiscoveryAgent
• QBluetoothServiceInfo
• QBluetoothSocket
• QBluetoothTransferManager
• QBluetoothTransferReply
• QBluetoothTransferRequest
• QBluetoothUuid

4.8. Better RingQt 42


Ring Documentation, Release 1.5.2

Example:
### Submits your car VIN - Vehicle Id Number - to the Web Site - vpic.nhtsa.dot.gov -
### Parses XML data returned
### Prints out the car info result

load "libcurl.ring"
load "guilib.ring"
load "stdlib.ring"

curl = curl_easy_init()

# request = "3G1JC5248YS251015?format=xml" ### VIN - Chevrolet


request = "3GYFK62847G247323?format=xml" ### VIN - Cadillac

call_type = "decodevinvalues/"
url = "https://vpic.nhtsa.dot.gov/api/vehicles/"
url_request = url + call_type + request

See "URL Request: "+ url_request +nl

curl_easy_setopt(curl, curlopt_url, url_request)


response = curl_easy_perform_silent(curl);

See nl +"Response Raw: "+ response +nl +nl

curl_easy_cleanup(curl)

xml = new qxmlstreamreader()


xml.adddata_2(response)

x = new qstringref()
while not xml.atend()
if xml.error()
see xml.errorstring() see nl
exit loop
ok

x = xml.text()
if not x.length() = 0
see "Length: " see x.length() +" --- "
see "Value: " see x.tostring() see nl
ok

xml.readnext()
end

get x

###------------------------------------------
### Results
#
# ==>Value: 115
# ==>Value: Results returned successfully
# ==>Value: VIN(s): 3G1JC5248YS251015
# ==>Value: 3G1JC5248YS251015
# ==>Value: Sedan/Saloon
# ==>Value: 4
# ==>Value: 2200.0

4.8. Better RingQt 43


Ring Documentation, Release 1.5.2

# ==>Value: 134.25223700841
# ==>Value: 2.2
# ==>Value: 4
# ==>Value: LN2
# ==>Value: CHEVROLET
# ==>Value: GENERAL MOTORS LLC
# ==>Value: Cavalier
# ==>Value: 2000
# ==>Value: Ramos Arzipe
# ==>Value: PASSENGER CAR
# ==>Value: 4
# ==>Value: In-Line
# ==>Value: 1st Row (Driver & Passenger)
# ==>Value: Sequential Fuel Injection (SFI)
# ==>Value: Mexico
# ==>Value: NA
# ==>Value: Manual
# ==>Value: Body Type: Sedan, 4-6 Window, Notchback (GM codes: 19, 69)
# ==>Value: Name Plate: Chevrolet, Pontiac
# ==>Value: 0 - VIN decoded clean. Check Digit (9th position) is correct
# ==>Value: LAN
# ==>Value: 984
#
###-----------------------------------------

4.9 Better Objects Library

The function Open_WindowInPackages() is added to the Objects library.


The Open_WindowInPackages() function is the same as Open_Window() but takes an extra list that determine the
packages to import before opening the window.
Syntax:
Open_WindowInPackages(cClassName,aPackagesList)

Example:
The next example from the Form Designer source code, Open the Window Flags window using the
open_windowInPackages() function.
We determine the class name “WindowFlagsController” and the packages name.
The Window Flags window uses the FormDesigner and System.GUI packages.
open_windowInPackages(:WindowFlagsController,[
"formdesigner",
"System.GUI"
])

4.10 RingFreeGLUT Extension

Ring 1.5 comes with RingFreeGLUT extension to support the FreeGLUT library
Example:

4.9. Better Objects Library 44

You might also like