The cerebro.core module provides access to the application data and to the control functions.
cerebro.core.activities()
Returns: | activity types. |
Return type: | cerebro.aclasses.Activities |
cerebro.core.application_dir()
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/”
cerebro.core.current_attachment()
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 not file_name or file_name == '': # if the file is absent, attempting to download it
cerebro.cargador.download_file(attach.file_hash())
See also
cerebro.core.current_message()
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()
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
cerebro.core.has_flag(flags, flag)
Parameters: | |
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)
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 |
cerebro.core.has_perm_message(message_id, perm_type)
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)
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()
Returns: | True, if Cerebro is online. |
cerebro.core.message(message_id)
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)
Parameters: | |
cerebro.core.notify_user('This task is starting in 5 minutes', task.id())
cerebro.core.print_debug(level, text)
Parameters: | level (int) – debugging info level. |
The debugging info is not displayed in the Cerebro console, if the level exceeds the one set in Cerebro (Main menu/Cerebro/Preferences/Debug).
See also
cerebro.core.print_error(text)
Outputs an error into the Cerebro console.
See also
cerebro.core.print_info(text)
Outputs data into the Cerebro console.
See also
cerebro.core.print_warning(text)
Outputs a warning into the Cerebro console.
See also
cerebro.core.refresh_all()
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
cerebro.core.refresh_tasks()
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
cerebro.core.root_tasks()
Returns: | root tasks list. |
Return type: | list(cerebro.aclasses.Task) |
See also
cerebro.core.selected_attachments()
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) |
See also
cerebro.core.selected_messages()
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()
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
cerebro.core.set_current_task(task_id)
Parameters: | task_id (int) – task ID. |
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
cerebro.core.start_timer(function, interval)
Starts the timer which calls the ‘function’ function once in the interval.
Parameters: | |
'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
cerebro.core.statuses()
Returns: | statuses. |
Return type: | cerebro.aclasses.Statuses |
cerebro.core.stop_timer(function)
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
cerebro.core.task(task_id)
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)
Parameters: | |
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
cerebro.core.to_do_task_list(user_id, with_done_task)
Parameters: | |
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()
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()
Returns: | users. |
Return type: | cerebro.aclasses.Users |
cerebro.core.version_app()
Returns: | build version. |
Return type: | string |
cerebro.core.version_python_api()
Returns: | API version. |
Return type: | string |