<commit_before># -*- coding: utf-8 -*-


# This file is part of the OpenSYMORO project. Please see
# https://github.com/symoro/symoro/blob/master/LICENCE for the licence.


"""
This module creates the main window user interface and draws the
interface on the screen for the SYMORO package.
"""


import os
from collections import OrderedDict

import wx

from pysymoro.robot import Robot
from pysymoro import geometry
from pysymoro import kinematics
from pysymoro import dynamics
from pysymoro import invgeom
from pysymoro import pieper
from symoroutils import configfile
from symoroutils import filemgr
from symoroutils import parfile
from symoroutils import samplerobots
from symoroutils import tools
from symoroui import definition as ui_definition
from symoroui import geometry as ui_geometry
from symoroui import kinematics as ui_kinematics
from symoroui import labels as ui_labels
from symoroviz import graphics


class MainFrame(wx.Frame):
    """This Frame contains the main window for SYMORO"""
    def __init__(self, *args, **kwargs):
        """Constructor : creates the UI and draws it on the screen."""
        wx.Frame.__init__(self, *args, **kwargs)
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        # create status bar
        self.statusbar = self.CreateStatusBar()
        # create menu bar
        self.create_menu()
        # object to store different ui elements and their keys
        self.widgets = {}
        self.widget_keys = {}
        # object to store parameter values got from dialog box input
        self.par_dict = {}
        # setup panel and sizer for content
        self.panel = wx.Panel(self)
        self.szr_topmost = wx.BoxSizer(wx.VERTICAL)
        self.create_ui()
        self.panel.SetSizerAndFit(self.szr_topmost)
        self.Fit()
        # load robot
        self.robo = samplerobots.rx90()
        # update fields with data
        self.feed_data()
        # configure status bar
        self.statusbar.SetFieldsCount(number=2)
        self.statusbar.SetStatusWidths(widths=[-1, -1])
        self.statusbar.SetStatusText(text="Ready", number=0)
        self.statusbar.SetStatusText(
            text="Location of robot files is %s"
            % filemgr.get_base_path(), number = 1
        )

    def params_in_grid(self, szr_grd, elements, rows, cols, width=70):
        """Method to display a set of fields in a grid."""
        for idx, key in enumerate(elements):
            label = elements[key].label
            name = elements[key].name
            control = elements[key].control
            place = elements[key].place
            handler = getattr(self, elements[key].handler)
            field_id = int(elements[key].id)
            if control is 'cmb':
                ctrl = wx.ComboBox(
                    parent=self.panel, style=wx.CB_READONLY,
                    size=(width, -1), name=name
                )
                ctrl.Bind(wx.EVT_COMBOBOX, handler)
            elif control is 'lbl':<commit_msg>Modify to load the last used robot at program start<commit_after># -*- coding: utf-8 -*-


# This file is part of the OpenSYMORO project. Please see
# https://github.com/symoro/symoro/blob/master/LICENCE for the licence.


"""
This module creates the main window user interface and draws the
interface on the screen for the SYMORO package.
"""


import os
from collections import OrderedDict

import wx

from pysymoro.robot import Robot
from pysymoro import geometry
from pysymoro import kinematics
from pysymoro import dynamics
from pysymoro import invgeom
from pysymoro import pieper
from symoroutils import configfile
from symoroutils import filemgr
from symoroutils import parfile
from symoroutils import samplerobots
from symoroutils import tools
from symoroui import definition as ui_definition
from symoroui import geometry as ui_geometry
from symoroui import kinematics as ui_kinematics
from symoroui import labels as ui_labels
from symoroviz import graphics


class MainFrame(wx.Frame):
    """This Frame contains the main window for SYMORO"""
    def __init__(self, *args, **kwargs):
        """Constructor : creates the UI and draws it on the screen."""
        wx.Frame.__init__(self, *args, **kwargs)
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        # create status bar
        self.statusbar = self.CreateStatusBar()
        # create menu bar
        self.create_menu()
        # object to store different ui elements and their keys
        self.widgets = {}
        self.widget_keys = {}
        # object to store parameter values got from dialog box input
        self.par_dict = {}
        # setup panel and sizer for content
        self.panel = wx.Panel(self)
        self.szr_topmost = wx.BoxSizer(wx.VERTICAL)
        self.create_ui()
        self.panel.SetSizerAndFit(self.szr_topmost)
        self.Fit()
        # load robot
        self.robo = self.load_robot()
        # update fields with data
        self.feed_data()
        # configure status bar
        self.statusbar.SetFieldsCount(number=2)
        self.statusbar.SetStatusWidths(widths=[-1, -1])
        self.statusbar.SetStatusText(text="Ready", number=0)
        self.statusbar.SetStatusText(
            text="Location of robot files is {0}".format(
                filemgr.get_base_path()
            ), number = 1
        )

    def load_robot(self):
        """
        Load either the default robot or the last used robot at the
        start of the program.

        Returns:
            An instance of `Robot` class.
        """
        par_file_path = configfile.get_last_robot()
        if par_file_path is None:
            # when last used robot was not saved
            return samplerobots.rx90()
        elif not os.path.exists(par_file_path):
            # when the PAR file does not exist
            self.message_error("The PAR file does not exist.")
            return samplerobots.rx90()
        else:
            robo_name = os.path.split(par_file_path)[1][:-4]
            robo, flag = parfile.readpar(robo_name, par_file_path)
            if robo is None:
                robo = samplerobots.rx90()
                self.message_error("File could not be read!")
            elif flag == tools.FAIL:
                robo = samplerobots.rx90()
                self.message_warning(
                    "While reading file an error occured."
                )
            return robo

    def params_in_grid(self, szr_grd, elements, rows, cols, width=70):
        """Method to display a set of fields in a grid."""
        for idx, key in enumerate(elements):
            label = elements[key].label
            name = elements[key].name
            control = elements[key].control
            place = elements[key].place
            handler = getattr(self, elements[key].handler)
            field_id = int(elements[key].id)
            if control is 'cmb':
                ctrl = wx.ComboBox(
                    parent=self.panel, style=wx.CB_READONLY,
                    size=(width, -1), name=name
                )
                ctrl.Bind(wx.EVT_COMBOBOX, handler)
            elif control is 'lbl':
{'fraction_non_alphanumeric': 0.08143138912369681, 'fraction_numerical': 0.004367427444350521, 'mean_word_length': 2.3203928905519176, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7514144', 'n_tokens_mistral': 2046, 'n_tokens_neox': 1985, 'n_words': 633}