Vous êtes sur la page 1sur 10

Ring Documentation, Release 1.5.

58.1 The Designer Windows

• Toolbox : To select controls to be added to the window.


• Properties : To set the properties of the active window or controls.
• Design Region : To select, move and resize the window and the controls.

58.2 The Toolbox

We have many buttons.


• Lock : We can use it to draw many controls of the same type quickly.
• Select : We can use it to select a control in the Design Region
• Controls Buttons : Select a control to be added to the window.

58.3 The Properties

• When we select the window or one control, We will have the selected object properties.
• Also In the properties window we have a combobox to select the active control.
• Some properties provide a button next to the property value. We can click on the button to get more options.
• When we select more than one control, We will have options for multi-selection

58.1. The Designer Windows 655


Ring Documentation, Release 1.5.2

58.4 Running Forms

When we save the form file (*.rform), The Form Designer will create two Ring files
• The Controller Class
• The View Class
For example, if the form file is helloworld.rform
The form designer will generate two files
• helloworldcontroller.ring
• helloworldview.ring
To run the program, Open the controller class file then click the Run button (CTRL+F5)

Tip: When you open a form using Ring Notepad, the controller class will be opened automatically, So we can press
(CTRL+F5) or click on the Run button while the form designer window is active.

58.5 Events Code

1. Just type the method name in the event property.

58.4. Running Forms 656


Ring Documentation, Release 1.5.2

(2) Then write the method code in the controller class.

58.5. Events Code 657


Ring Documentation, Release 1.5.2

In this example we write


func CloseWindow
oView.win.close()

Where inside the controller class, We uses the oView object to access the form.
Another Example :

58.5. Events Code 658


Ring Documentation, Release 1.5.2

The Event Code


func SayHello
oView {
LineEdit2.setText("Hello "+ LineEdit1.text() )
}

58.6 Keyboard Shortcuts

After selecting one or group of controls


• Use the Arrows (Up, Down, Left and Right) to move them around.
• Shift + the Arrows (Up, Down, Left and Right) to Resize the controls.
• Del button to delete the controls.
• CTRL+SHIFT+V to Duplicate the controls.

58.7 Menubar Designer

From the Window properties we can open the Menubar Designer

58.6. Keyboard Shortcuts 659


Ring Documentation, Release 1.5.2

58.8 Window Flags

From the Window properties we can open the Window Flags window.

58.8. Window Flags 660


Ring Documentation, Release 1.5.2

58.9 Entering Items

For some controls like the List Widget we can enter items separated by comma ‘,’

58.10 Using Layouts

1. To use layouts, At first add the layout control to the window.


2. Use the window “Set Layout” property to determine the main layout.
3. From the layout properties determine the controls and the layout type.

58.11 More Samples and Tests

Check the folder : ring/applications/formdesigner/tests


Online : https://github.com/ring-lang/ring/tree/master/applications/formdesigner/tests

58.9. Entering Items 661


CHAPTER

FIFTYNINE

SCOPE RULES FOR VARIABLES AND ATTRIBUTES

In this chapter we will learn about scope rules and how Ring find variables.
Also we will learn about conflicts and how to solve/avoid them.
The next information are important once you start developing large applications using Ring
These application may uses
• Global variables (Try to avoid them)
• Classes (Object-Oriented)
• braces { } to access objects
• Declarative Programming
• Natural Programming

59.1 Three Scopes

In Ring we have three scopes :-


1. Public/Global Scope - Each variable you define in the statements part (before functions and classes)
2. Object Scope - When you are inside an object (Inside class method or using { } to access the object )
3. Local Scope - Related to functions and methods

59.2 Defining Variables and Variables Access

1. Ring uses lexical scoping, i.e. the scope of the variable is based on where we defined the variable.
2. Inside braces { } when you access an object, You will change the current active object scope to this object scope
but you still can access the global scope and the local scope.
3. After the ‘Class’ keyword and the class name, when you write variable names to be defined as attributes, You
still can access the global scope.
In this region (class region - after the class name and before methods) we have
• Global Scope —-> The Global Scope
• Object Scope —-> The Object Scope
• Local Scope —-> The Object Scope

662
Ring Documentation, Release 1.5.2

Note: Since the local scope in the class region point also to the object scope in this region, we can use nested braces
and still have access to the object scope of the class through the local scope.

Tip: You can create windows and controls as attibutes by defining them in this region.

Tip: In the class region if you created objects and used braces {} to access them then using self.attribute inside braces
will use the class (not the object that you access) because you have access to the class through the local scope.

4. Function Parameters are automatically defined in the local scope.

59.3 How Ring find the variable?

1 - Search First in the Local Scope


if not found !
2 - Search in the Object Scope
if not found !
3 - Search in the public scope
if not found —-> Runtime Error
if found —-> Check if we can do optimization to avoid searching next time (Cache / Pointers for performance).

59.4 Using Object.Attribute

When we use object.attribute the search will be in the object attributes only.
I.e. no search will be done in the local scope or in the global scope for the object attribute.

Note: Using self.attribute will search for the first self before searching for attributes.

59.5 The Self Object

The self object is a reference to the current object that we can use from the class methods.
When we are inside class method and use Self we mean the object that will be created from this class.
Inside the class methods if we used Braces { } this will change the current object scope and self will be changed also
inside braces to reference the object that we access using Braces.
Inside the Class Region (after the class name and before any method) we have access to the object through the object
scope and the local scope also. In this region using Self will always be a reference to the class object. if we used
Braces to change the object scope then used Self inside Braces, Also self will be a reference to the class object (not
the object that we already access using braces) because in the class region we have :-
• Global Scope —> Global Scope
• Object Scope —> Object Scope

59.3. How Ring find the variable? 663


Ring Documentation, Release 1.5.2

• Local Scope —> Object Scope


And using Braces changes the object scope only (not the local scope) and when Ring search for variables it will search
in the Local Scope first so it will find self in the class that we are inside.

59.6 How Ring Define Variables and Attributes

Ring will use the variable name in the Assignment operation


1 - Search using the variable name
2 - If not found —> Avoid the runtime error and define the variable in the current scope
3 - If found —> Use the variable and don’t define anything in the current scope
• In the global region (before any function or class) the current scope is the global scope.
• In the class region (after the class name and before any method) the current scope is the object attributes.
• In Functions and methods the current scope is the local scope.

59.7 Conflict between Global Variables and Class Attributes

Look at this example:


name = "test"
o1 = new person
see o1

class person
name
address
phone

In the previous example we have a global variable called ‘name’ inside the class person.
when we use the variable ‘name’, Ring will start the search operation and will try to find it.
if found —> Use it
if not found —> Define new attribute
But the variable name is a global variable, so it will be found and used!
We will not have the attribute name! added to the object.
Solution (1) - Use the Main Function
func main
name = "test"
o1 = new person
see o1

class person
name
address
phone

Solution (2) - Use special mark for global variable names like $

59.6. How Ring Define Variables and Attributes 664

Vous aimerez peut-être aussi