Example #1
0
    def __init__(self, **kwargs):
        # Extract file from arguments
        file_name = kwargs.pop("file_name", None)
        super(CodeTab, self).__init__(**kwargs)

        # Initialize code input area
        self.code_input = CodeInput()
        # Assign file to hold the contents when saving or loading
        self.full_path = file_name
        if file_name is not None:
            # Parse file argument
            file_name = file_name.split(os.sep)[-1]
            # Populate CodeInput contents with file
            with open(file_name, 'r') as f:
                self.code_input.text = f.read()
            # Set tab name
            self.set_tab_name(file_name)
            # Mark as already saved
            self.is_edited = False
            # FIXME tab is marked as edited after loading
        else:
            # Assign temporal name
            self.set_tab_name("*new_file")
            # Mark as unsaved
            self.is_edited = True
        # Bind to text changed event
        self.code_input.bind(text=self._text_changed)
        # Assign code input to content for display
        self.content = self.code_input
Example #2
0
    def build(self):
        self.theme_cls.theme_style = "Dark"

        boxlayout = BoxLayout()
        code = ''
        with open(self.path_to_kv_file, "r") as kv_file:
            code = kv_file.read()
        codeinput = CodeInput(
            text=code,
            lexer=KivyLexer(),
            style_name="native",
            size_hint_x=.6,
        )
        codeinput.bind(text=self.update_kv_file)
        hot_reload_viewer = HotReloadViewer(
            size_hint_x=.4,
            path=self.path_to_kv_file,
            errors=True,
            errors_text_color=(1, 1, 0, 1),
            errors_background_color=self.theme_cls.bg_dark,
        )
        boxlayout.add_widget(codeinput)
        boxlayout.add_widget(hot_reload_viewer)

        return boxlayout
Example #3
0
    def maineditor(self, *args):
        layout = BoxLayout()
        if self.width < self.height:
            layout.orientation = 'vertical'
        else:
            layout.orientation = 'horizontal'
        #self.bind(self.current_ex=self.update_currentFile)
        man = self.element.manual(self.current_ex)
        codeFile = self.element.readFile(self.current_ex, self.current_file)
        code = CodeInput(text=codeFile)
        code.bind(focus=self.schedule_reload)
        splitter = Splitter()
        if layout.orientation == 'vertical':
            splitter.sizable_from = 'bottom'
        else:
            splitter.sizable_from = 'right'
        splitter.add_widget(code)
        layout.add_widget(splitter)

        if args[0] == 'e':
            layout.add_widget(RstDocument(text=man))
        else:

            layout.add_widget(terminal)
        return layout
    def maineditor(self,*args):
        layout=BoxLayout()
        if self.width < self.height:
            layout.orientation='vertical'
        else:
            layout.orientation='horizontal'
        #self.bind(self.current_ex=self.update_currentFile)
        man = self.element.manual(self.current_ex)
        codeFile = self.element.readFile(self.current_ex,self.current_file)
        code = CodeInput(text=codeFile)
        code.bind(focus =self.schedule_reload)
        splitter = Splitter()
        if layout.orientation == 'vertical':
            splitter.sizable_from='bottom'
        else:
            splitter.sizable_from='right'
        splitter.add_widget(code)
        layout.add_widget(splitter)

        if args[0]=='e':
            layout.add_widget(RstDocument(text=man))
        else:

            layout.add_widget(terminal)
        return layout
Example #5
0
    def build(self):
        codeinput = CodeInput(lexer=CythonLexer())
        boxwhole = BoxLayout()
        label = Label()
        codeinput.bind(text=label.setter("text"))
        boxwhole.add_widget(label)
        boxwhole.add_widget(codeinput)

        return boxwhole
    def build(self):
        b = BoxLayout(orientation='vertical')
        languages = Spinner(text='language',
                            values=sorted([
                                'KvLexer',
                            ] + lexers.LEXERS.keys()))

        languages.bind(text=self.change_lang)

        menu = BoxLayout(size_hint_y=None, height='30pt')
        fnt_size = Spinner(text='12', values=map(str, range(5, 40)))
        fnt_size.bind(text=self._update_size)
        fnt_name = Spinner(text='DroidSansMono',
                           option_cls=Fnt_SpinnerOption,
                           values=sorted(map(str, fonts.get_fonts())))
        fnt_name.bind(text=self._update_font)
        mnu_file = Spinner(text='File',
                           values=('Open', 'SaveAs', 'Save', 'Close'))
        mnu_file.bind(text=self._file_menu_selected)

        menu.add_widget(mnu_file)
        menu.add_widget(fnt_size)
        menu.add_widget(fnt_name)
        menu.add_widget(languages)
        b.add_widget(menu)

        self.codeinput = CodeInput(lexer=KivyLexer(),
                                   font_name='data/fonts/DroidSansMono.ttf',
                                   font_size=12,
                                   text=example_text)

        b.add_widget(self.codeinput)

        return b
Example #7
0
    def build(self):
        root = BoxLayout(orientation="vertical", padding=5)

        butn = GridLayout(cols=3, size_hint=[1, .07])

        self.nameF = TextInput(text="main.c",
                               size_hint=[1, .1],
                               background_color=[1, 1, 1, .5])
        root.add_widget(self.nameF)

        buttonA = Button(text='Add File', on_press=self.add)
        butn.add_widget(buttonA)

        buttonC = Button(text='Compile File', on_press=self.compile)
        butn.add_widget(buttonC)

        buttonS = Button(text='Save File', on_press=self.save)
        butn.add_widget(buttonS)

        root.add_widget(butn)

        self.code = CodeInput(text="", lexer=CLexer())
        root.add_widget(self.code)

        self.check = TextInput(text="",
                               size_hint=[1, .3],
                               background_color=[1, 1, 1, .5])
        root.add_widget(self.check)

        return root
Example #8
0
    def build(self):
        root = BoxLayout(orientation="horizontal", padding=3)

        left = ScrollView(size_hint=[.4, 1])
        right = BoxLayout(orientation="vertical")

        leftGrid = GridLayout(cols=1, size_hint_y=None)
        leftGrid.bind(minimum_height=leftGrid.setter('height'))

        self.toggle = [0 for _ in range(35)]

        for index in range(len(ciphers)):

            self.toggle[index] = ToggleButton(id=str(index),
                                              text=ciphers[index],
                                              group='cipher',
                                              height=30,
                                              state="normal",
                                              size_hint_y=None)
            leftGrid.add_widget(self.toggle[index])

        left.add_widget(leftGrid)

        topBox = BoxLayout(orientation="horizontal", size_hint=[1, .33])

        self.key = TextInput(hint_text="Key", multiline=False, font_size=16)
        topBox.add_widget(self.key)

        rightTopBox = BoxLayout(orientation="vertical", size_hint=[.5, 1])
        rightTopBox.add_widget(
            Button(id='E', text="Encrypt", on_press=self.getCipher))
        rightTopBox.add_widget(
            Button(id='D', text="Decrypt", on_press=self.getCipher))

        topBox.add_widget(rightTopBox)
        right.add_widget(topBox)

        self.message = TextInput(hint_text="Message", font_size=16)
        right.add_widget(self.message)

        self.result = CodeInput(readonly=True,
                                hint_text="Result",
                                font_size=14,
                                background_color=[1, 1, 1, .8])
        right.add_widget(self.result)

        downBox = BoxLayout(orientation="horizontal", size_hint=[1, .15])

        downBox.add_widget(Button(id='C', text="Code",
                                  on_press=self.getCipher))
        downBox.add_widget(Button(text="Clear", on_press=self.clear))

        right.add_widget(downBox)

        root.add_widget(left)
        root.add_widget(right)

        return root
Example #9
0
  def build(self):

    return CodeInput(lexer = HtmlLexer())

    return Button(text = "Knopka!",
      font_size = 30,
      on_press = self.btn_press,
      background_color = [1.48, .79, .4, 1],
      background_normal = '' )
Example #10
0
    def setup(self):
        width = 500
        height = 500
        Window.size = (width, height)
        Window.bind(on_resize=self.on_window_resize)
        Config.set('graphics', 'resizable', '0')

        Window.bind(on_keyboard=self.on_keyboard)

        navBar = NavBarController()
        navBarBtnsContainer = navBar.setup(self.nav_container)

        codeinput = CodeInput(lexer=PythonLexer())
        self.choose_lexer()
        codeinput.lexer = TextEditor.lex
        codeinput.bind(text=TextEditor.on_text)

        self.text_container.add_widget(codeinput)
Example #11
0
    def build(self):
        self.label = Label()
        self.anchor_layout = AnchorLayout()
        self.box_layout = BoxLayout(orientation='vertical',
                                    padding=[10, 10, 10, 10],
                                    spacing=10)
        self.code_input = CodeInput(lexer=PythonLexer())
        self.widget_to_bl()

        self.anchor_layout.add_widget(self.box_layout)
        return self.anchor_layout
Example #12
0
    def build_code(self, path):
        filename = path.split('/')[-1]
        monokai = [.152, .156, .133, 1]  # monokai background color

        if filename.split('.')[-1] == 'kv':
            l = KivyLexer()
        else:
            l = get_lexer_for_filename(filename)

        code = open(path, 'r').read()

        return CodeInput(lexer=l,
                         text=code,
                         style_name='monokai',
                         background_color=monokai,
                         disabled=False)
Example #13
0
    def build(self):
        root = BoxLayout(orientation="vertical", padding=5)
        self.nameFile = TextInput(text="%s/main.py" % getcwd(),
                                  size_hint=[1, .1],
                                  background_color=[77, 77, 77, 1],
                                  multiline=False)
        root.add_widget(self.nameFile)

        button = GridLayout(cols=4, size_hint=[1, .07])
        ## The drop menu starts here

        dropmenu = DropDown()
        buttonForFile = Button(text="Save",
                               size_hint_y=None,
                               height=40,
                               on_press=self.saveFile)
        dropmenu.add_widget(buttonForFile)
        buttonForFile = Button(text="Open",
                               size_hint_y=None,
                               height=40,
                               on_press=self.openFile)
        dropmenu.add_widget(buttonForFile)

        mainbutton = Button(text="File", size_hint=(1, .07))
        mainbutton.bind(on_release=dropmenu.open)
        button.add_widget(mainbutton)

        ## The drop menu ends here
        button.add_widget(Button(text="Compile", on_press=self.compile))
        button.add_widget(Button(text="clean", on_press=self.clean))
        root.add_widget(button)
        self.code = CodeInput(
            text="",
            lexer=CythonLexer(),
        )
        button.add_widget(Button(text="about me", on_press=self.aboutme))

        root.add_widget(self.code)

        self.check = TextInput(text="",
                               size_hint=[1, .3],
                               background_color=[77, 77, 77, 1])
        root.add_widget(self.check)
        return root
Example #14
0
    def setup(self):
        width = 500
        height = 500
        Window.size = (width, height)
        Window.bind(on_resize=self.on_window_resize)
        Config.set('graphics', 'resizable', '0')
        Config.set('input', 'mouse', 'mouse,multitouch_on_demand')

        Window.bind(on_keyboard=self.on_keyboard)

        navBar = NavBarController()
        navBarBtnsContainer = navBar.setup(self.nav_container)

        TextEditor.codeinput = CodeInput()
        #TextEditor.choose_lexer()
        #TextEditor.codeinput.lexer = TextEditor.lex
        TextEditor.codeinput.bind(text=TextEditor.on_text)

        self.text_container.add_widget(TextEditor.codeinput)
Example #15
0
 def build(self):
   al = AnchorLayout(anchor_x = "center", anchor_y = "center", size_hint = (1,.2))
   bl = BoxLayout(orientation = 'vertical')
   bl2 = BoxLayout(orientation = 'vertical')
   bl1 = BoxLayout(orientation = 'horizontal')
   bl3 = BoxLayout(orientation = 'horizontal', size_hint = (1,.2))
   self.lbl1 = Label(valign="top",text_size = (400,700*.8))
   
   self.lbl = Label(valign="top",text_size = (400,700*.8))
   self.ci = CodeInput(lexer = DelphiLexer())
   bl1.add_widget(self.ci)
   bl1.add_widget(self.lbl)
   bl1.add_widget(self.lbl1)
   bl.add_widget(bl1)
   bl3.add_widget(Button(text = "Трансформировать", on_press = self.print_text))
   bl3.add_widget(Button(text = "Далее", on_press = self.print_tables))
   bl.add_widget(bl3)
   
   return  bl
Example #16
0
    def build(self):
        b = BoxLayout(orientation='vertical')
        languages = Spinner(text='language',
                            values=sorted([
                                'KvLexer',
                            ] + list(lexers.LEXERS.keys())))

        languages.bind(text=self.change_lang)

        menu = BoxLayout(size_hint_y=None, height='30pt')
        fnt_size = Spinner(text='12',
                           values=list(map(str, list(range(5, 40)))))
        fnt_size.bind(text=self._update_size)

        fonts = [
            file for file in LabelBase._font_dirs_files
            if file.endswith('.ttf')
        ]

        fnt_name = Spinner(text='RobotoMono',
                           option_cls=Fnt_SpinnerOption,
                           values=fonts)
        fnt_name.bind(text=self._update_font)
        mnu_file = Spinner(text='File',
                           values=('Open', 'SaveAs', 'Save', 'Close'))
        mnu_file.bind(text=self._file_menu_selected)

        menu.add_widget(mnu_file)
        menu.add_widget(fnt_size)
        menu.add_widget(fnt_name)
        menu.add_widget(languages)
        b.add_widget(menu)

        self.codeinput = CodeInput(lexer=KivyLexer(),
                                   font_size=12,
                                   text=example_text)

        b.add_widget(self.codeinput)

        return b
Example #17
0
    def add(self):

        if self.layouts == []:
            self.ids.widget_list.clear_widgets()

        if len(self.ids.widget_list.children) < 4:
            layout = FloatLayout(pos_hint=self.fPos[self.count],
                                 size_hint=self.fS[self.count])
            widget = CodeInput(lexer=CythonLexer(),
                               pos_hint=self.codeBlocks[self.count],
                               size_hint=(.70, 1))
            widget2 = CheckBox(pos_hint=self.checkBox1[self.count],
                               size_hint=(.15, 1))
            widget3 = CheckBox(pos_hint=self.checkBox2[self.count],
                               size_hint=(.85, 1))
            self.count += 1
            layout.add_widget(widget2)
            layout.add_widget(widget)
            layout.add_widget(widget3)
            self.ids.widget_list.add_widget(layout)
            self.layouts.append(layout)
            self.update_hints()
Example #18
0
    def sourceView(self):
        """
        lemme show your the source!
        """
        def subFunction_Divisor(object):
            lambda xy: xy**xy // 3  # get the Power and return Divided in Floor Division

        self.main = ModalView(size_hint=(None, None), size=(420, 750))

        self.modalMain = FloatLayout()
        self.saveButton = Button(text="Save",
                                 size_hint=(None, None),
                                 size=(100, 40),
                                 pos=(320, 30))
        self.cancelButton = Button(text="Cancel",
                                   size_hint=(None, None),
                                   size=(100, 40),
                                   pos=(60, 30))
        self.head = Label(text="CoreTEX Source",
                          size_hint=(None, None),
                          pos=(60, 700))
        self.box = CodeInput(size_hint=(None, None),
                             size=(390, 650),
                             pos=(45, 77),
                             use_bubble=True)  #editor in modal view#
        self.box.text = str(self.ids.core.text)

        def cancelAll(instance):
            """
            self.main close trigger
            """
            self.main.dismiss()

        def saveAll(instance):
            """
            Load Cache.rst (Cache File from the coreEngine)
            everything will be saved as Cache... (Editable on Options)
            """
            cur = self.ids.core.source
            if "index.rst" in str(cur):
                self.main.dismiss(
                )  #dont ever let the editor edit this file :P
                return False

            if "new" in self.current:
                self.getLatestSaved()  # Run to get Eval code
                # load file
                _file = open(self.coreTexMimes["saved"], "rw+")
                _read = _file.read()
                # load file
                curCache = int(self.saved)
                cache_value = lambda ctex: ctex + 1
                cache_final = cache_value(curCache)
                return False

            box_strings = str(self.box.text)
            current = self.current  # add this on the Current working file
            cache_file_open = open("coreEngine/Rst/cache.rst", "w")
            cache_file_writeNow = cache_file_open.write(box_strings)
            cache_file_open.close()

            if cache_file_open.closed:
                pass  # Do everything here

            else:
                cancelAll()

        # lambda gbox:
        self.saveButton.bind(on_press=saveAll)
        self.cancelButton.bind(on_press=cancelAll)
        self.modalMain.add_widget(self.box)
        self.modalMain.add_widget(self.head)
        self.modalMain.add_widget(self.cancelButton)
        self.modalMain.add_widget(self.saveButton)
        self.main.add_widget(self.modalMain)
        #main.add_widget(cancelButton)
        self.main.open()
Example #19
0
content.add_widget(
    CodeInput(lexer=KivyLexer(),
              text="""# kivy 1.10.1
# Using kv language, it's easy to read what's going on
# in the code. The layout is clear and legible.
# The behavior (root.command()) associated with
# actions calls on functions in the Python code.

# Full arrangement
<Layout>
	orientation: 'horizontal' # is horizontally stacked
	padding: 20 # padded 20% per widget for aesthetic reasons

	# the "Hello World" button and its properties and behavior
	Button:
		id: hw
		text: 'Hello World! (click me!)'
		font_size: 25
		on_release: root.popup() #opens popup on release

	# the slider and its properties and behavior
	Slider:
		id: bgcolor
		orientation: 'vertical'
		min: 0
		max: 100
		value: 0
		on_value: root.recolor(bgcolor.value) # when value changes, background is 
		# recolored""",
              size_hint=(1, 0.8))
)  # size_hint dictates the fraction of the screen across (1) and from top to bottom (0.8) the code should occupy
Example #20
0
class NaoRecorderApp(App):

    files = ListProperty([None, ])

    def build(self):
        self.robot = Robot(status_display=self, code_display=self,
                           on_disconnect=self._on_disconnect,
                           on_stiffness=self._on_chain_stiffness_from_robot)

        # building Kivy Interface
        b = BoxLayout(orientation='vertical')

        menu = BoxLayout(
            size_hint_y=None,
            height='30pt')
        fnt_name = Spinner(
            text='DroidSansMono',
            option_cls=Fnt_SpinnerOption,
            values=sorted(map(str, fonts.get_fonts())))
        fnt_name.bind(text=self._update_font)

        # file menu
        mnu_file = Spinner(
            text=localized_text('file_menu_title'),
            values=(localized_text('file_connect'),
                    localized_text('file_open'),
                    localized_text('file_save_as'),
                    localized_text('file_save'),
                    localized_text('file_close')))
        mnu_file.bind(text=self._file_menu_selected)

        # motors on/off
        btn_motors = ToggleButton(text=localized_text('motors_on'),
                                  state='normal',
                                  background_down='stiff.png',
                                  background_normal='relaxed.png')
        btn_motors.bind(on_press=self._on_motors)
        self._motor_toggle_button = btn_motors

        btn_speech = ToggleButton(text=localized_text('speech_recognition'),
                                         state='down' if self.robot.is_speech_recognition_enabled else 'normal')
        btn_speech.bind(on_press=self._on_toggle_speech_recognition)

        btn_touch_sensors = ToggleButton(text=localized_text('touch_sensors'),
                                         state='down' if self.robot.is_touch_sensors_enabled else 'normal')
        btn_touch_sensors.bind(on_press=self._on_toggle_touch_sensors)

        # run script
        btn_run_script = Button(text=localized_text('run_script'))
        btn_run_script.bind(on_press=self._on_run_script)
        self.btn_run_script = btn_run_script

        # root actions menu
        robot_actions = Spinner(
            text=localized_text('action_menu_title'),
            values=sorted(self.robot.postures()))
        robot_actions.bind(text=self.on_action)

        # add to menu
        menu.add_widget(mnu_file)
        menu.add_widget(btn_speech)
        menu.add_widget(btn_touch_sensors)
        menu.add_widget(btn_motors)
        menu.add_widget(btn_run_script)
        menu.add_widget(robot_actions)
        b.add_widget(menu)

        controls = BoxLayout(
            size_hint_y=None,
            height='30pt')

        # add keyframe
        btn_add_keyframe = Button(text=localized_text('add_keyframe'))
        btn_add_keyframe.bind(on_press=self._on_add_keyframe)
        controls.add_widget(btn_add_keyframe)

        # set read joint angles to enable animation to start from known position
        btn_update_joints = Button(text=localized_text('read_joints'))
        btn_update_joints.bind(on_press=self._on_read_joints)
        controls.add_widget(btn_update_joints)

        kf_duration_label = Label(text=localized_text('keyframe_duration_colon'))
        controls.add_widget(kf_duration_label)

        kf_duration_input = TextInput(text=str(self.robot.keyframe_duration), multiline=False)
        kf_duration_input.bind(text=self._on_keyframe_duration)
        controls.add_widget(kf_duration_input)

        # allow user to select which translator to use
        active_translator = Spinner(
            text=self.robot.get_translator_name(),
            values=get_translator_names())
        active_translator.bind(text=self._on_translator_changed)
        controls.add_widget(active_translator)
        self.active_translator = active_translator
        self.is_translator_cancel = False

        b.add_widget(controls)

        m = BoxLayout()
        code_status = BoxLayout(orientation='vertical', size_hint=(0.6, 1))

        # code input
        self.codeinput = CodeInput(
            lexer=lexers.PythonLexer(),
            font_name='data/fonts/DroidSansMono.ttf', font_size=12,
            text="nao.say('hi')")
        code_status.add_widget(self.codeinput)

        # status window
        self.status = TextInput(text="", readonly=True, multiline=True, size_hint=(1.0, 0.25))
        code_status.add_widget(self.status)


        m.add_widget(code_status)
        self.joints_ui = NaoJoints(size_hint=(0.4, 1),
                                   on_joint_selection=self._on_joint_selection,
                                   on_chain_stiffness=self._on_chain_stiffness,
                                   on_hand_open_close=self._on_hand_open_close)
        m.add_widget(self.joints_ui)

        b.add_widget(m)
        return b

    def on_start(self):
        self.show_connection_dialog(None)

    def on_stop(self):
        self.robot.disconnect()

    def get_code(self):
        return self.codeinput.text

    def get_selected_code(self):
        return self.codeinput.selection_text

    def set_code(self, code):
        self.codeinput.text = code

    def set_lexer(self, new_lexer):
        # code = self.get_code()
        # self.codeinput = CodeInput(
        #    lexer=new_lexer,
        #    font_name='data/fonts/DroidSansMono.ttf', font_size=12,
        #    text=code)
        # self.codeinput.lexer = lexer
        pass

    def append_code(self, code):
        self.set_code(self.robot.append_command(self.get_code(), code))

    def add_status(self, text):
        self.status.text = self.status.text + "\n" + text

    def show_connection_dialog(self, b):
        p = ConnectionDialog()
        p.bind(on_dismiss=self.do_connect)
        p.open()

    def do_connect(self, popup):
        hostname = popup.f_hostname.text
        portnumber = int(popup.f_port.text)
        print "connect to = {}:{}".format(hostname, portnumber)

        main_logger.info("Connecting to robot at {host}:{port}".format(host=hostname, port=portnumber))
        if self.robot.connect(hostname, portnumber):
            self.add_status("Connected to robot at {host}:{port}".format(host=hostname, port=portnumber))
        else:
            self.add_status("Error connecting to robot at {host}:{port}".format(host=hostname, port=portnumber))
            self.show_connection_dialog(None)

    def _update_size(self, instance, size):
        self.codeinput.font_size = float(size)

    def _update_font(self, instance, fnt_name):
        instance.font_name = self.codeinput.font_name = \
            fonts.match_font(fnt_name)

    def _file_menu_selected(self, instance, value):
        if value == 'File':
            return
        instance.text = 'File'
        if value == localized_text('file_connect'):
            self.show_connection_dialog(None)

        elif value == localized_text('file_open'):
            if not hasattr(self, 'load_dialog'):
                self.load_dialog = LoadDialog()
            self.load_dialog.open()
            self.load_dialog.bind(chosen_file=self.setter('files'))
        elif value == localized_text('file_save_as'):
            if not hasattr(self, 'saveas_dialog'):
                self.saveas_dialog = SaveDialog()
            self.saveas_dialog.text = self.codeinput.text
            self.saveas_dialog.open()
        elif value == localized_text('file_save'):
            if self.files[0]:
                _file = codecs.open(self.files[0], 'w', encoding='utf8')
                _file.write(self.codeinput.text)
                _file.close()
        elif value == localized_text('file_close'):
            if self.files[0]:
                self.codeinput.text = ''
                Window.title = 'untitled'

    def on_files(self, instance, values):
        if not values[0]:
            return
        _file = codecs.open(values[0], 'r', encoding='utf8')
        self.codeinput.text = _file.read()
        _file.close()

    def _on_disconnect(self):
        self.show_connection_dialog(None)

    def on_action(self, instance, l):
        title = localized_text('action_menu_title')
        if self.robot.is_connected() and l != title:
            self.robot.go_to_posture(l)
            instance.text = localized_text('action_menu_title')

    def _on_translator_changed(self, instance, translator_name):
        if self.is_translator_cancel:
            self.is_translator_cancel = False
        else:
            if self.get_code().strip():
                if self.robot.can_convert_code():
                    msg = localized_text('translator_change_warning').format(src=self.robot.get_translator_name(), dest=translator_name)
                else:
                    msg = localized_text('translator_change_no_convert').format(src=self.robot.get_translator_name(), dest=translator_name)
                p = ConfirmationDialog()
                p.f_content.text = msg
                p.translator_name = translator_name
                p.bind(on_dismiss=self._on_translator_confirm_dismissed)
                p.open()
            else:
                # if code window is empty, no reason to warn
                self.robot.change_translator(translator_name, '')
                self._update_run_button()
                self.set_lexer(self.robot.translator.lexer)


    def _on_translator_confirm_dismissed(self, popup):
        if popup.is_ok:
            self.is_translator_cancel = False
            self.set_code(self.robot.change_translator(popup.translator_name, self.get_code()))
            self._update_run_button()
            self.set_lexer(self.robot.translator.lexer)
        else:
            # we need this as our callback will get called when we revert the value
            self.is_translator_cancel = True
            self.active_translator.text = self.robot.get_translator_name()

    def _update_run_button(self):
        # this won't have any effect on versions of kivy before 1.8.0
        self.btn_run_script.disabled = not self.robot.is_code_runnable()

    def _on_motors(self, motor_button):
        if motor_button.state == 'down':
            motor_button.text = localized_text('motors_off')
            self.robot.motors_on()
        else:
            motor_button.text = localized_text('motors_on')
            self.robot.motors_off()

    def _on_run_script(self, instance):
        if self.robot.is_connected() and self.robot.is_code_runnable():
            code = self.get_selected_code() if self.get_selected_code() else self.get_code()
            print "executing\n'{}'".format(code)
            self.robot.run_script(code)
            # Selected text is hidden when focus lost so remove selection to prevent confusion
            # when people click "run script" and only a portion of the code is run
            if self.get_selected_code():
                self.codeinput.select_text(0, 0)

    def _on_add_keyframe(self, dummy1=None, dummy2=None, dummy=None):
        code = self.robot.keyframe()
        if code:
            self.append_code(code)

    def _on_read_joints(self, instance):
        self.robot.update_joints()

    def _on_keyframe_duration(self, instance, value):
        try:
            kf_duration = float(instance.text)
            self.robot.keyframe_duration = kf_duration
            print "Keyframe duration set to {}".format(kf_duration)
        except ValueError:
            self.robot.keyframe_duration = 1.0

    def _on_toggle_speech_recognition(self, instance):
        self.robot.enable_speech_recognition(instance.state == 'down')
        print "Speech recognition enabled = {}".format(self.robot.is_speech_recognition_enabled)

    def _on_toggle_touch_sensors(self, instance):
        self.robot.enable_touch_sensors(instance.state == 'down')
        print "Touch sensors enabled = {}".format(self.robot.is_touch_sensors_enabled)

    def _on_joint_selection(self, enabled_joints):
        self.robot.set_enabled_joints(enabled_joints)

    # callback from NAO joints when button changes
    def _on_chain_stiffness(self, chain_names):
        self._motor_toggle_button.state = 'down' if chain_names else 'normal'
        self.robot.set_chains_with_motors_on(chain_names)

    # callback from Robot when stiffness changes
    def _on_chain_stiffness_from_robot(self, stiff_chains):
        self.joints_ui.set_chain_stiffness(stiff_chains)

    def _on_hand_open_close(self, hand_name, is_open):
        '''
        Callback from NAO joints when hand buttons change state
        '''
        self.robot.hand_open(hand_name, is_open)
Example #21
0
    def build(self):
        #main widget
        self.wm = ScreenManager()
        logsc = Screen()
        logstate = BoxLayout(orientation=VERTICAL)
        lab = Label(text="Welcome to PyIDEkv" ,color="blue")
        but = Button(text = "Start" ,on_press=lambda x:self.change("main"))
        but.size_hint=1,1
        logstate.add_widget(lab)
        logstate.add_widget(but)
        logsc.add_widget(logstate)

        logsc.name = "login"
        testscreen = Screen()
        testscreen.name = "main"
        box = BoxLayout()
        box.orientation = VERTICAL
        global p,l, codeout
        p = Popup()
        p.title = "Choose your file!"
        self.x = FileChooserIconView()
        anlay = BoxLayout()
        anlay.add_widget(self.x)
        anolay = BoxLayout()
        anolay.size_hint=0.5,0.5
        anlay.orientation= VERTICAL
        anolay.add_widget(Button(text="Open", on_press=self.op))
        anolay.add_widget(Button(text="Cancel", on_press=lambda instance:p.dismiss()))
        anlay.add_widget(anolay)
        
        p.add_widget(anlay)
        toolwid = BoxLayout()
        toolwid.size_hint = 1, 0.3
        btn = Button(text="Open", on_press=lambda instance:p.open())
        btn.size_hint = 0.25, 1
        toolwid.add_widget(btn)
        btn2 = Button(text="Save", on_press=self.save)
        btn2.size_hint = 0.25,1
        toolwid.add_widget(btn2)
        btn3 = Button(text="Run", on_press=lambda ins:self.executor())
        btn3.size_hint = 0.25,1
        toolwid.add_widget(btn3)
        box.add_widget(toolwid)
        #code widget
        s = Splitter()
        s.max_size = 100000
        s.min_size = 0
        s.sizable_from = "bottom"
        l = CodeInput()
        s.add_widget(l)
        box.add_widget(s)
        codeout = CodeInput()
        codeout.readonly = True
        codeout.multiline = True
        box.add_widget(codeout)
        testscreen.add_widget(box)
        self.wm.add_widget(logsc)
        self.wm.add_widget(testscreen)
        
        #return style
        
        return self.wm
Example #22
0
    def build(self):
        self.robot = Robot(status_display=self, code_display=self,
                           on_disconnect=self._on_disconnect,
                           on_stiffness=self._on_chain_stiffness_from_robot)

        # building Kivy Interface
        b = BoxLayout(orientation='vertical')

        menu = BoxLayout(
            size_hint_y=None,
            height='30pt')
        fnt_name = Spinner(
            text='DroidSansMono',
            option_cls=Fnt_SpinnerOption,
            values=sorted(map(str, fonts.get_fonts())))
        fnt_name.bind(text=self._update_font)

        # file menu
        mnu_file = Spinner(
            text=localized_text('file_menu_title'),
            values=(localized_text('file_connect'),
                    localized_text('file_open'),
                    localized_text('file_save_as'),
                    localized_text('file_save'),
                    localized_text('file_close')))
        mnu_file.bind(text=self._file_menu_selected)

        # motors on/off
        btn_motors = ToggleButton(text=localized_text('motors_on'),
                                  state='normal',
                                  background_down='stiff.png',
                                  background_normal='relaxed.png')
        btn_motors.bind(on_press=self._on_motors)
        self._motor_toggle_button = btn_motors

        btn_speech = ToggleButton(text=localized_text('speech_recognition'),
                                         state='down' if self.robot.is_speech_recognition_enabled else 'normal')
        btn_speech.bind(on_press=self._on_toggle_speech_recognition)

        btn_touch_sensors = ToggleButton(text=localized_text('touch_sensors'),
                                         state='down' if self.robot.is_touch_sensors_enabled else 'normal')
        btn_touch_sensors.bind(on_press=self._on_toggle_touch_sensors)

        # run script
        btn_run_script = Button(text=localized_text('run_script'))
        btn_run_script.bind(on_press=self._on_run_script)
        self.btn_run_script = btn_run_script

        # root actions menu
        robot_actions = Spinner(
            text=localized_text('action_menu_title'),
            values=sorted(self.robot.postures()))
        robot_actions.bind(text=self.on_action)

        # add to menu
        menu.add_widget(mnu_file)
        menu.add_widget(btn_speech)
        menu.add_widget(btn_touch_sensors)
        menu.add_widget(btn_motors)
        menu.add_widget(btn_run_script)
        menu.add_widget(robot_actions)
        b.add_widget(menu)

        controls = BoxLayout(
            size_hint_y=None,
            height='30pt')

        # add keyframe
        btn_add_keyframe = Button(text=localized_text('add_keyframe'))
        btn_add_keyframe.bind(on_press=self._on_add_keyframe)
        controls.add_widget(btn_add_keyframe)

        # set read joint angles to enable animation to start from known position
        btn_update_joints = Button(text=localized_text('read_joints'))
        btn_update_joints.bind(on_press=self._on_read_joints)
        controls.add_widget(btn_update_joints)

        kf_duration_label = Label(text=localized_text('keyframe_duration_colon'))
        controls.add_widget(kf_duration_label)

        kf_duration_input = TextInput(text=str(self.robot.keyframe_duration), multiline=False)
        kf_duration_input.bind(text=self._on_keyframe_duration)
        controls.add_widget(kf_duration_input)

        # allow user to select which translator to use
        active_translator = Spinner(
            text=self.robot.get_translator_name(),
            values=get_translator_names())
        active_translator.bind(text=self._on_translator_changed)
        controls.add_widget(active_translator)
        self.active_translator = active_translator
        self.is_translator_cancel = False

        b.add_widget(controls)

        m = BoxLayout()
        code_status = BoxLayout(orientation='vertical', size_hint=(0.6, 1))

        # code input
        self.codeinput = CodeInput(
            lexer=lexers.PythonLexer(),
            font_name='data/fonts/DroidSansMono.ttf', font_size=12,
            text="nao.say('hi')")
        code_status.add_widget(self.codeinput)

        # status window
        self.status = TextInput(text="", readonly=True, multiline=True, size_hint=(1.0, 0.25))
        code_status.add_widget(self.status)


        m.add_widget(code_status)
        self.joints_ui = NaoJoints(size_hint=(0.4, 1),
                                   on_joint_selection=self._on_joint_selection,
                                   on_chain_stiffness=self._on_chain_stiffness,
                                   on_hand_open_close=self._on_hand_open_close)
        m.add_widget(self.joints_ui)

        b.add_widget(m)
        return b
Example #23
0
 def build(self):
     codeinput = CodeInput(lexer=HtmlLexer())
     return codeinput
Example #24
0
    def build(self):
        self.ScreenManager = ScreenManager()
        self.sc1 = Screen(name='firstscreen')
        self.sc2 = Screen(name='secscreen')

        self.file_dir = ''
        self.file_name = ''

        self.compile = Button(text='Скомпилировать', on_press=self.CompileCPP)
        self.run = Button(text='Запустить', on_press=self.StartEXE)

        self.dropdown = DropDown()
        self.btn1 = Button(text='Сохранить как',
                           size_hint_y=None,
                           height=30,
                           on_press=self.SaveAsFile)
        self.btn2 = Button(text='Сохранить',
                           size_hint_y=None,
                           height=30,
                           on_press=self.SaveAs)
        self.btn3 = Button(text='Открыть файл',
                           size_hint_y=None,
                           height=30,
                           on_press=self.ReadFromFile)
        self.btn4 = Button(text='Подсказки',
                           size_hint_y=None,
                           height=30,
                           on_press=self.secrets)

        self.btn1.bind()

        self.secscrbutt1 = Button(text='Назад',
                                  size_hint_y=None,
                                  pos_hint={'top': 1},
                                  height=30,
                                  on_press=self.MainWindow)

        self.secscrBox = BoxLayout()
        self.secscrBox.add_widget(self.secscrbutt1)
        self.secscrAnch = AnchorLayout(anchor_y='top')
        self.secscrAnch.add_widget(self.secscrBox)

        self.secscrtext = CodeInput(text="", lexer=CLexer())
        self.secscrBox2 = BoxLayout(size_hint=[.8, .953])
        self.secscrBox2.add_widget(self.secscrtext)
        self.secscrAnch2 = AnchorLayout(anchor_y='bottom', anchor_x='right')
        self.secscrAnch2.add_widget(self.secscrBox2)

        self.pod1 = Button(text='Hello World!', on_press=self.Tips)
        self.pod2 = Button(text='Типы данных', on_press=self.Tips)
        self.pod3 = Button(text='Циклы', on_press=self.Tips)
        self.pod4 = Button(text='Массивы', on_press=self.Tips)
        self.pod5 = Button(text='Функции', on_press=self.Tips)
        self.pod6 = Button(text='Указатели', on_press=self.Tips)
        self.pod7 = Button(text='Классы', on_press=self.Tips)

        self.secscrBox3 = BoxLayout(orientation='vertical',
                                    size_hint=[.2, .953],
                                    spacing=1)
        self.secscrAnch3 = AnchorLayout(anchor_y='bottom', anchor_x='left')
        self.secscrBox3.add_widget(self.pod1)
        self.secscrBox3.add_widget(self.pod2)
        self.secscrBox3.add_widget(self.pod3)
        self.secscrBox3.add_widget(self.pod4)
        self.secscrBox3.add_widget(self.pod5)
        self.secscrBox3.add_widget(self.pod6)
        self.secscrBox3.add_widget(self.pod7)

        self.secscrAnch3.add_widget(self.secscrBox3)

        self.dropdown.add_widget(self.btn1)
        self.dropdown.add_widget(self.btn2)
        self.dropdown.add_widget(self.btn3)
        self.dropdown.add_widget(self.btn4)

        self.fileButton = Button(text='Меню')

        self.fileButton.bind(on_release=self.dropdown.open)
        self.dropdown.bind(
            on_select=lambda instance, x: setattr(self.fileButton, 'text', x))

        self.MyText = CodeInput(text="", lexer=CLexer())
        self.MyBox = BoxLayout(orientation='horizontal', size_hint=[1, .07])
        self.MyBox.add_widget(self.fileButton)
        self.MyBox.add_widget(self.compile)
        self.MyBox.add_widget(self.run)

        self.MyBox2 = BoxLayout(size_hint=[1, .93])
        self.MyBox2.add_widget(self.MyText)

        self.MyAnchor = AnchorLayout(anchor_y='top', anchor_x='left')
        self.MyAnchor2 = AnchorLayout(anchor_y='bottom')
        self.MyAnchor.add_widget(self.MyBox)
        self.MyAnchor2.add_widget(self.MyBox2)

        self.OAnchor = AnchorLayout()
        self.OAnchor.add_widget(self.MyAnchor)
        self.OAnchor.add_widget(self.MyAnchor2)

        self.sc1.add_widget(self.OAnchor)

        self.sc2.add_widget(self.secscrAnch)
        self.sc2.add_widget(self.secscrAnch2)
        self.sc2.add_widget(self.secscrAnch3)

        self.ScreenManager.add_widget(self.sc1)
        self.ScreenManager.add_widget(self.sc2)

        return self.ScreenManager
Example #25
0
    CodeInput(lexer=CythonLexer(),
              text="""# Button and Slider
# 
# This simple button and slider was built entirely in Python using no Kv. 
# It uses a box layout to arrange the two separate widgets and just two of Kivy's 
# many offered widgets. 
# Take a look at the code. Does it seem tedious or hard to follow?


# opens the core functionality of the Kivy framework
import kivy 
# set this to the version of Kivy you are running to ensure compatibility
kivy.require('1.10.1') 
# imports the ability to create "Apps" or groups of widgets to be executed
from kivy.app import App
# imports the abilities to create Buttons, Sliders, manipulate the window properties (color), and arrange widgets
from kivy.uix.button import Button
from kivy.uix.slider import Slider
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout

# executes this popup
# instance is input name (self.btn)
def popup(instance):
	print("Popup opened!") # check the console!
	code.open() # opens this popup

# recolors the background every time the slider is moved
# instance2 is the value of the slider
def recolor(instance,instance2):
	val = float(instance2)/100.0 # retrieves a fraction out of 1 (rgba values from 0-1)
	Window.clearcolor = (val,val,val,1) # sets window color

# the "App" or group of widgets that can all be run in one window
class MyFirstButton(App):
	# the widgets to build into the app
	def build(self):
		self.content=BoxLayout(orientation="horizontal") # sets the layout of the window -- in this case, box layout indicates that widgets are "stacked" based on the orientation
		self.slider = Slider(orientation='vertical', min=0, max=100, value = 0) # vertical slider from 0-100 with default 0
		self.slider.bind(value=recolor) # binds the "recolor" function to every time the value of the slider changes
		self.btn = Button(text='Hello World! (this is a button)', font_size = 25) # new button with text property "Hello World!" and font size 25
		self.btn.bind(on_press=popup) # sets button behavior (calls function "popup")
		self.content.add_widget(self.btn) # adds button to box layout (horizontal "stack")
		self.content.add_widget(self.slider) # adds slider to box layout
		return self.content # returns the arranged content of the app

# if still in original file
if __name__ == '__main__':
    MyFirstButton().run() # runs the "app" in a new window

# Open the hellowworld.py file in Sublime to learn more about how this Popup was 
# created!""",
              size_hint=(1, 0.8))
Example #26
0
class CodeTab(TabbedPanelHeader):
    @staticmethod
    def get_or_create(file_name):
        """
        Check whether an input file is already loaded as a code tab, or load it.

        :param file_name: The input file name to check or create.
        :return: The code tab corresponding to the input file.
        """
        code_tab = Cache.get("code_tabs", file_name)
        if code_tab is None:
            # Did not find tab, create it instead
            code_tab = CodeTab(file_name=file_name)
            Cache.append("code_tabs", key=file_name, obj=code_tab)
        return code_tab

    def __init__(self, **kwargs):
        # Extract file from arguments
        file_name = kwargs.pop("file_name", None)
        super(CodeTab, self).__init__(**kwargs)

        # Initialize code input area
        self.code_input = CodeInput()
        # Assign file to hold the contents when saving or loading
        self.full_path = file_name
        if file_name is not None:
            # Parse file argument
            file_name = file_name.split(os.sep)[-1]
            # Populate CodeInput contents with file
            with open(file_name, 'r') as f:
                self.code_input.text = f.read()
            # Set tab name
            self.set_tab_name(file_name)
            # Mark as already saved
            self.is_edited = False
            # FIXME tab is marked as edited after loading
        else:
            # Assign temporal name
            self.set_tab_name("*new_file")
            # Mark as unsaved
            self.is_edited = True
        # Bind to text changed event
        self.code_input.bind(text=self._text_changed)
        # Assign code input to content for display
        self.content = self.code_input

    def __del__(self):
        # TODO ask for confirmation if file is unsaved
        # Remove from cache
        Cache.remove("code_tab", self.full_path)

    def set_tab_name(self, name: str):
        """
        Update the display name of the tab.

        This method also updates the tab lexer based on the filename extension.

        :param name: The new name to display.
        """
        # Update tab text
        self.text = name
        # Find appropriate lexer
        self.code_input.lexer = lexer_utils.get_code_lexer_for_filename(name)

    def set_full_path(self, path: str):
        """
        Assign the code input contents to a file designed by a path.

        :param path: The path to the file to assign the contents to.
        """
        self.full_path = path
        self.save_contents()
        # Update tab name and lexer
        file_name = path.split(os.sep)[-1]
        self.set_tab_name(file_name)

    def save_contents(self):
        """
        Store the contents of the CodeInput into the assigned file.

        If there is no file assigned, a dialog is created to select the output
        file.
        """
        if self.full_path is None:
            dialog = FileChooserDialog(size_hint=(0.75, 0.75))
            dialog.set_callback(self.set_full_path)
            dialog.open()
        else:
            # Store contents to file
            with open(self.full_path, 'w') as f:
                f.write(self.content.text)
            # Contents changed
            if self.is_edited:
                # Remove flag
                self.is_edited = False
                # Remove indicator from tab name
                self.text = self.text.lstrip("*")

    def _text_changed(self, instance, value):
        if not self.is_edited:
            self.is_edited = True
            self.text = f"*{self.text}"