10.4. Module core

The cerebro.core module provides access to the application data and to the control functions.

Functions

cerebro.core.activities()[source]
Returns:activity types.
Return type:cerebro.aclasses.Activities
cerebro.core.application_dir()[source]
Returns:path to the Cerebro application directory.
Return type:string

Warning

In Mac OS X the application directory is the directory located inside the application package - “Cerebro.app/Contents/MacOs/”

See also

python_api_dir().

cerebro.core.current_attachment()[source]
Returns:an attachment on which a user’s menu item is activated.
Return type:cerebro.aclasses.Attachment
def example_attachment_menu():
        # Downloading attachment
        attach = cerebro.core.current_attachment() # getting current attachment on which a user's menu was called
        file_name = cerebro.cargador.file_name_form_hash(attach.file_hash()) # resolving file name by its hash sum
        if file_name == '' or file_name == None: # if the file is not downloaded, attempting to download it
                cerebro.cargador.download_file(attach.file_hash())
cerebro.core.current_message()[source]
Returns:a message on which a user’s menu item is activated.
Return type:cerebro.aclasses.Message
def example_message_menu():
        print('Calling example_message_menu by click on "My Forum menu item"')  
        
        # Getting current message
        message = cerebro.core.current_message()
        if message:
                print('Текущее сообщение',  message.text_as_plain())
cerebro.core.current_task()[source]
Returns:current task in Cerebro GUI.
Return type:cerebro.aclasses.Task
def example_task_menu():
        print('Call example_task_menu on clicking "My menu item"')      
        
        # Getting current task
        task = cerebro.core.current_task()
        print('Current task:',  task.name())

See also

selected_tasks().

cerebro.core.has_flag(flags, flag)[source]
Parameters:
  • flags (int) – flag values.
  • flag (int) – flag.
Returns:

presence of ‘flag’ in the value of ‘flags’.

Return type:

bool

Checks if the ‘flag’ flag is set up in the ‘flags’ value being passed.

res = cerebro.core.has_flag(task.flags(),  task.FLAG_HAS_CHILD)
print('The 'task' task has subtasks:',  res)
cerebro.core.has_perm_global(perm_type)[source]
Parameters:perm_type (int) – the type of global operation, that requires permission.
Returns:True, if the current user is permitted to make the global operation.
Return type:bool

The function checks if the user is permitted to make certain global operations, e.g., create new user accounts.

cerebro.core.has_perm_message(message_id, perm_type)[source]
Parameters:
Returns:

True, if the current user is permitted to make the operation on the message.

Return type:

bool

The function checks if the user is permitted to make certain operations on the message, e.g., switch message visibility for clients.

cerebro.core.has_perm_task(task_id, perm_type)[source]
Parameters:
Returns:

True, if the current user is permitted to make the operation on the task.

Return type:

bool

The function checks if the user is permitted to make certain operations on the task, e.g., edit tags or derive subtasks from the task.

task = cerebro.core.current_task()
if cerebro.core.has_perm_task(task.id(), cerebro.aclasses.Perm.PERM_TASK_BUDGET):
        task.set_budget(100)
cerebro.core.is_logon()[source]
Returns:True, if Cerebro is online.
cerebro.core.message(message_id)[source]
Parameters:message_id (int) – message ID.
Returns:message by its ID.
Return type:cerebro.aclasses.Message
cerebro.core.notify_user(message, task_id=None, is_show_box=True)[source]
Parameters:
  • message (string) – notification message.
  • task_id (int) – task ID.
  • is_show_box (bool) – display message window.

Notifies a user. If is_show_box = True, activation of the notification by user calls a window with the notification message. If task ID is set, activation of the notification by user opens the task.

cerebro.core.notify_user('This task is starting in 5 minutes', task.id())
cerebro.core.print_debug(level, text)[source]
Parameters:level (int) – debugging info level.

Outputs debugging info into the Cerebro console.

The debugging info is not displayed in the Cerebro console, if the level exceeds the one set in Cerebro (Main menu/Cerebro Serpens/Settings).

cerebro.core.print_error(text)[source]

Outputs an error into the Cerebro console.

cerebro.core.print_info(text)[source]

Outputs data into the Cerebro console.

cerebro.core.print_warning(text)[source]

Outputs a warning into the Cerebro console.

cerebro.core.python_api_dir()[source]
Returns:path to the directory py-frontend, which contains the API modules.
Return type:string

See also

application_dir().

cerebro.core.refresh_all()[source]

Refreshes all data in Cerebro.

If you’re making considerable data changes, don’t forget to call this function to refresh all pre-cached data in the interface.

See also

refresh_tasks().

cerebro.core.refresh_tasks()[source]

Refreshes task tree in Cerebro.

Keep in mind to call this function to refresh the task tree in the interface if you are adding/changing tasks/messages or edidting their properties. The exceptions to this rule are event handling functions, which apply the changes and refresh automatically.

tasks = cerebro.core.selected_tasks()
for task in tasks:
        task.set_progress(100) 

cerebro.core.refresh_tasks()

See also

refresh_all().

cerebro.core.root_tasks()[source]
Returns:root tasks list.
Return type:list(cerebro.aclasses.Task,)

See also

task_children().

cerebro.core.selected_attachments()[source]
Returns:a list of attachments in the attachments windows (Search, Forum), which were highlighted (selected) and on which a user’s menu item was activated.
Return type:list(cerebro.aclasses.Attachment,)
cerebro.core.selected_messages()[source]
Returns:a messages on which a user’s menu item is activated.
Return type:list(cerebro.aclasses.Message,)
def example_message_menu():
        print('Calling example_message_menu by click on "My Forum menu item"')  
        
        # Getting selected messages
        messages = cerebro.core.selected_messages()
        if messages:
                for message in messages:
                        print('Current message:',  message.text_as_plain())     
cerebro.core.selected_tasks()[source]
Returns:a list of picked (selected) tasks in Cerebro GUI.
Return type:list(cerebro.aclasses.Task,)
def example_task_menu():
        print('Call example_task_menu on clicking "My menu item"')              
        
        # Getting selected tasks
        tasks = cerebro.core.selected_tasks()
        print('Selected tasks:',  len(tasks))   

See also

current_task().

cerebro.core.set_current_task(task_id)[source]
Parameters:task_id (int) – task ID.

Sets current task by its ID in Cerebro GUI.

current_task = cerebro.core.current_task()
tasks = cerebro.core.task_children(current_task.id())
if len(tasks) > 0:
        cerebro.core.set_current_task(tasks[0].id()) # the first subtask of the task becomes current

See also

current_task().

cerebro.core.start_timer(function, interval)[source]

Starts the timer which calls the ‘function’ function once in the interval.

Parameters:
  • function (string) – the function called by the timer.
  • interval (int) – time interval, milliseconds.

Format of the function argument:

'module_name.function_name'

If the module is included in a package, the format must be:

'package_name.module_name.function_name'

Warning

sys.path must contain the path to the module/package.

# logon.py file         
# logon module

import cerebro
import examples         
        
# The function handling Cerebro logon
def logon():                    
        examples.logon.logon()   # calling an example of logon handling 
# examples/logon.py file
# examples package
# logon module

import cerebro

def logon():    
        # Starting the timer to call 'example_timer' function
        cerebro.core.start_timer('examples.logon.example_timer', 1000) # restarting the timer each second

def example_timer():
        print('Calling example_timer by timer')         

Call cerebro.core.stop_timer() to stop the timer.

See also

stop_timer().

cerebro.core.statuses()[source]
Returns:statuses.
Return type:cerebro.aclasses.Statuses
cerebro.core.stop_timer(function)[source]

Stops the timer that calls ‘function’ function.

Parameters:function (string) – the function that was passed to the cerebro.core.start_timer() on timer start.
# logoff.py file                
# logoff module

import cerebro
import examples         
        
# The function handling Cerebro session logoff
def logoff():                   
        examples.logoff.logoff()         # calling an example of Cerebro session logoff handling
        return True
# examples/logoff.py file
# examples package
# logoff module

import cerebro

def logoff():   
        # Stopping the timer calling 'example_timer' function, started on login to Cerebro
        cerebro.core.stop_timer('examples.logon.example_timer') 
        print('Timer calling example_timer stopped')                            

See also

start_timer().

cerebro.core.task(task_id)[source]
Parameters:task_id (int) – task ID.
Returns:task by its ID.
Return type:cerebro.aclasses.Task
cerebro.core.task_children(task_id, with_references=False)[source]
Parameters:
  • task_id (int) – task ID.
  • with_done_task (bool) – return with task references included.
Returns:

a subtask list with task_id.

Return type:

list(cerebro.aclasses.Task,)

If with_references = True, the returning list includes task references, otherwise - omits them. If there are no subtasks in the task, None is returned.

if cerebro.core.has_flag(task.flags(), task.FLAG_HAS_CHILD): # checking for subtasks
        children = cerebro.core.task_children(task.id())        

See also

root_tasks().

cerebro.core.to_do_task_list(user_id, with_done_task)[source]
Parameters:
  • user_id (int) – user ID.
  • with_done_task (bool) – return with completed tasks included.
Returns:

a list of tasks the user is allocated to.

Return type:

list(cerebro.aclasses.Task,)

If with_done_task = True, the returning list includes completed (with progress = 100%)tasks, otherwise - omits them.

# Getting all incomplete tasks the current user is allocated to
current_user = cerebro.core.user_profile()
tasks = cerebro.core.to_do_task_list(current_user[cerebro.aclasses.Users.DATA_ID], False)
cerebro.core.user_profile()[source]
Returns:user profile.
Return type:tuple. Tuple data is described in the cerebro.aclasses.Users class.
profile = cerebro.core.user_profile()
print('user e-mail:', profile[cerebro.aclasses.Users.DATA_EMAIL])
cerebro.core.users()[source]
Returns:users.
Return type:cerebro.aclasses.Users
cerebro.core.version_app()[source]
Returns:build version.
Return type:string
cerebro.core.version_python_api()[source]
Returns:API version.
Return type:string