GUI model example#

This example presents Python code that demonstrates the specification of a model consisting of a Structural model and a GUI model. By exploring this code, you will gain a clear understanding of how to effectively model a mobile app GUI. The code showcases the creation of a screen that represents a key component of the GUI, allowing users to interact with the mobile app. Additionally, the model includes various elements such as lists, buttons, and view components, which contribute to the overall functionality and visual representation of the GUI.

 1
 2from besser.BUML.metamodel.gui import *
 3from besser.BUML.metamodel.structural import *
 4from besser.generators.python_classes import PythonGenerator
 5from besser.generators.django import DjangoGenerator
 6from besser.generators.sql_alchemy import SQLAlchemyGenerator
 7from besser.generators.sql import SQLGenerator
 8
 9
10###################################################
11#   Library class - structural model definition   #
12###################################################
13
14# Primitive DataTypes
15t_str: PrimitiveDataType = PrimitiveDataType("str")
16
17# Library definition
18library_name: Property = Property(name="name", type=t_str)
19address: Property = Property(name="address", type=t_str)
20library: Class = Class (name="Library", attributes={library_name, address})
21
22##################################
23#      GUI model definition      #
24##################################
25
26#DataSource definition
27datasource_library: ModelElement = ModelElement(name="AwesomeLibrary", dataSourceClass=library, fields={library_name, address})
28
29# List definition
30MyList: List=List(name="LibraryList", description="A comprehensive collection of libraries", list_sources={datasource_library})
31
32#Buttons definition:
33#Button1:
34Button1: Button=Button(name="viewListButton", description= "Explore the Complete List", Label="View List")
35
36#Button2:
37Button2: Button=Button(name="cancelButton", description="Abort the Current Operation" , Label="Cancel")
38
39#ViewComponent definition
40ViewComponent1: ViewComponent=ViewComponent(name="my_component", description= "Detailed Information at a Glance")
41
42#Screen definition
43MyScreen: Screen=Screen(name="Library List Page", description="Discover nearby libraries with names and addresses", x_dpi="x_dpi", y_dpi= "y_dpi", size="SmallScreen", components={MyList,Button1,Button2})
44
45#Module definition:
46MyModule: Module=Module(name="module_name", screens={MyScreen})
47
48#Application definition:
49MyApp: Application=Application(name="Library List App", package="com.example.librarylistapp",versionCode="1",versionName="1.0",description="This is a simple Android app",screenCompatibility=False,modules={MyModule})
50
51
52print("This App has" + " "+ str(len(MyScreen.components)) +" components")
53
54for source in MyList.list_sources:
55    
56    print("The concept of " + source.name + " is characterized by two key features, as outlined below:")
57    for field in source.fields:
58      print(field.name)
59    print("   ")