Exemple #1
0
    def __init__(self, openPath):
        super(IDEWindow, self).__init__()

        ## Win General

        self.set_title('IDE')
        self.set_position(Gtk.WindowPosition.CENTER)
        self.set_default_size(1000, 500)
        # i = Gtk.Image.new_from_icon_name('document-edit-symbolic', Gtk.IconSize.MENU)
        self.set_default_icon_name('document-edit-symbolic')
        #self.set_border_width(10)
        self.connect('delete-event', self._quit)

        ### Win Accels

        accel = Gtk.AccelGroup()
        accel.connect(Gdk.keyval_from_name('s'), Gdk.ModifierType.CONTROL_MASK, 0, self.saveFile)
        accel.connect(Gdk.keyval_from_name('b'), Gdk.ModifierType.CONTROL_MASK, 0, self.compile)
        accel.connect(Gdk.keyval_from_name('f'), Gdk.ModifierType.CONTROL_MASK, 0, self.toggleSearch)
        # accel.connect(16777215, Gdk.ModifierType.SHIFT_MASK, 0, self.bracketComplete)
        #accel.connect(Gdk.keyval_from_name('p'), Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.SHIFT_MASK, 0, self.command) #future Ctrl + Shift + P command popup
        self.add_accel_group(accel)

        ## Editor General

        self.projectPath = None
        self.projectName = None
        self.curFileName = None
        self.curFileIndex = None
        self.curLanguage = None
        self.curSettings = None
        self.files = []
        self.tempFilesText = []
        self.langs = []
        self.compilerOptions = []
        self.running = False
        self.runningProccess = None

        self.filesObject = []
        self.comp = None

        self.waitingForBracketCompletion = False
        self.autoToggling = False
        ## Header Bar

        self.hb = Gtk.HeaderBar()

        # system-run = engine icon, media-playback-start = red play icon, gtk-media-play = white play
        self.compileBtn = Gtk.Button.new_from_icon_name('media-playback-start-symbolic', Gtk.IconSize.MENU)
        self.compileBtn.set_tooltip_text('Compile + Run')
        self.compileBtn.connect('clicked', self.compile)
        # self.compileBtn.set_sensitive(False)

        self.terminalBtn = Gtk.Button.new_from_icon_name('utilities-terminal-symbolic', Gtk.IconSize.MENU)
        self.terminalBtn.set_tooltip_text('Toggle terminal')
        self.terminalBtn.connect('clicked', self.toggleTerminal)

        ### Creating popup menu

        self.settingsBtn = Gtk.Button.new_from_icon_name('view-more-symbolic', Gtk.IconSize.MENU)
        self.settingsBtn.connect('clicked', self.onSettingsBtnClick)

        self.settingsPopover = Gtk.Popover()

        self.settingsList = Gtk.ListBox()

        r = Gtk.ListBoxRow()
        a = Gtk.CheckButton()
        a.set_label('Toggle Dark Mode')
        self.toggleDarkCheck = a
        self.toggleDarkCheck.connect('toggled', self.onToggleDark)
        r.add(a)
        r.set_margin_left(5)
        r.set_margin_right(5)
        r.set_margin_top(5)
        self.settingsList.insert(r, -1)

        r = Gtk.ListBoxRow()
        a = Gtk.CheckButton()
        a.set_label('Highlight Matching Brackets')
        self.toggleHighlightCheck = a
        self.toggleHighlightCheck.connect('toggled', self.onToggleHighlight)
        r.add(a)
        r.set_margin_left(5)
        r.set_margin_right(5)
        self.settingsList.insert(r, -1)

        r = Gtk.ListBoxRow()
        a = Gtk.CheckButton()
        a.set_label('Show Line Numbers')
        self.toggleLineCheck = a
        self.toggleLineCheck.connect('toggled', self.onToggleLine)
        r.add(a)
        r.set_margin_left(5)
        r.set_margin_right(5)
        self.settingsList.insert(r, -1)

        r = Gtk.ListBoxRow()
        a = Gtk.CheckButton()
        a.set_label('Word Wrap')
        self.toggleWordWrap = a
        self.toggleWordWrap.connect('toggled', self.onToggleWrap)
        r.add(a)
        r.set_margin_left(5)
        r.set_margin_right(5)
        self.settingsList.insert(r, -1)
        
        r = Gtk.ListBoxRow()
        _hb = Gtk.HBox()
        _hb.get_style_context().add_class('linked')
        self.styleChooserButton = GtkSource.StyleSchemeChooserButton()
        self.applyStyleButton = Gtk.Button.new_from_icon_name('emblem-ok-symbolic', Gtk.IconSize.MENU)
        self.applyStyleButton.connect('clicked', self.applyStyle)
        _hb.pack_start(self.styleChooserButton, True, True, 0)
        _hb.pack_start(self.applyStyleButton, True, True, 0)
        r.add(_hb)
        r.set_margin_left(5)
        r.set_margin_right(5)
        r.set_margin_bottom(5)
        self.settingsList.insert(r, -1)
        

        r = Gtk.ListBoxRow()
        _hb = Gtk.HBox()
        btn = Gtk.Button.new_from_icon_name('system-run-symbolic', Gtk.IconSize.MENU)
        btn.set_tooltip_text('Build Project')
        _hb.pack_start(btn, True, True, 0)
        btn = Gtk.Button.new_from_icon_name('media-playback-start-symbolic', Gtk.IconSize.MENU)
        btn.set_tooltip_text('Run Project')
        _hb.pack_start(btn, True, True, 0)
        btn = Gtk.Button.new_from_icon_name('document-edit-symbolic', Gtk.IconSize.MENU)
        btn.set_tooltip_text('Edit Project')
        _hb.pack_start(btn, True, True, 0)

        _hb.get_style_context().add_class('linked')
        r.add(_hb)
        r.set_margin_left(5)
        r.set_margin_right(5)
        r.set_margin_bottom(5)
        self.settingsList.insert(r, -1)

        # bx = Gtk.VBox()
        # bx.pack_start(self.settingsList, False, False, 0)
        # bx.set_border_width(10)

        self.settingsList.set_selection_mode(Gtk.SelectionMode.NONE)

        self.settingsPopover.add(self.settingsList)
        self.settingsPopover.set_relative_to(self.settingsBtn)

        self.hb.pack_end(self.settingsBtn)

        #self.folderBtn = Gtk.Button.new_from_icon_name('folder-new', Gtk.IconSize.MENU)
        #self.folderBtn.set_tooltip_text('Open Project Folder')
        #self.folderBtn.connect('clicked', self.openProject)
        #self.hb.pack_start(self.folderBtn)

        ########################################
        bx = Gtk.HBox()
        bx.get_style_context().add_class('linked')
        bx.pack_start(self.compileBtn, False, False, 0)
        self.stateEntry = Gtk.Entry()
        self.stateEntry.set_sensitive(False)
        self.stateEntry.set_text('Loaded')
        bx.pack_start(self.stateEntry, False, False, 0)
        self.hb.pack_start(bx)
        #self.hb.pack_start(self.terminalBtn)
        ########################################

        self.hb.set_title('Py IDE')
        self.hb.set_show_close_button(True)

        #self.hb.pack_end(self.searchEntry)

        ## Views And Buffers

        self.sview = GtkSource.View()
        self.stable = Gtk.TextTagTable()
        self.sbuff = GtkSource.Buffer.new(self.stable)
        self.found_tag = self.sbuff.create_tag('found-tag', background='rgba(200,200,200,.8)')
        self.error_tag = self.sbuff.create_tag('error-tag', underline=Pango.Underline.ERROR)
        self.lmngr = GtkSource.LanguageManager()
        self.sviewScroll = Gtk.ScrolledWindow()
        self.sviewBox = Gtk.HBox()
        self.smap = GtkSource.Map()

        self.smap.set_view(self.sview)

        self.sview.set_auto_indent(True)
        self.sview.set_buffer(self.sbuff)
        self.sview.set_indent_on_tab(True)
        self.sview.set_insert_spaces_instead_of_tabs(False)
        self.sview.set_left_margin(10)
        self.sview.set_property('smart-home-end', GtkSource.SmartHomeEndType.ALWAYS)
        self.sview.set_smart_backspace(True)
        font = Pango.FontDescription('Monospace 10')
        self.sview.modify_font(font)
        # self.sview.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        self.sview.set_tab_width(8)
        # self.sview.set_hscroll_policy(Gtk.ScrollablePolicy.MINIMAL)
        # self.sview.set_draw_spaces(GtkSource.DrawSpacesFlags.TAB)
        self.sbuff.connect('insert-text', self.onTextInsert)
        self.sbuff.connect('changed', self.onTextChanged)
        # self.sbuff.set_style_scheme(GtkSource.StyleScheme.get_style('tango'))
        #self.sview.set_pixels_above_lines(5)

        ### Testing completion

        self.sview_completion = self.sview.get_completion()
        self.sview_completion.set_property('remember-info-visibility', True)
        self.sview_completion.set_property('auto-complete-delay', 0)
        self.sview_provider = GtkSource.CompletionWords.new('PyIDE Completion 2', self.getPix('folder'))
        self.sview_provider.register(self.sbuff)
        self.sview_completion.add_provider(self.sview_provider)
        # provider = GtkSource.CompletionWords.new('PyIDE Completion 2')
        # context = GtkSource.CompletionContext()
        # context.add_proposals(provider, [GtkSource.CompletionItem(label='class', text='class', icon=self.getPix('insert-object-symbolic'), info='Define a class')], True)
        # self.sview_completion.add_provider(provider)

        ## TreeView

        self.treeView = None # Turn this into a Gtk.TreeView(self.fileStore) when fileStore has something
        self.fileList = []
        self.fileStore = None # Turn this into a Gtk.ListStore (lists that TreeView can display)

        ## Lines

        self.lines = Gtk.Button('0 Lines')

        self.linesPopover = Gtk.Popover()
        self.linesPopover.set_relative_to(self.lines)

        vb = Gtk.VBox()
        a = Gtk.Label('Lines: ')
        self.linesLbl = a
        vb.pack_start(a, True, True, 0)
        a = Gtk.Label('Chars: ')
        self.charsLbl = a
        vb.pack_start(a, True, True, 0)
        a = Gtk.Label('Language: ')
        self.languageLbl = a
        vb.pack_start(a, True, True, 0)
        vb.set_border_width(10)

        self.linesPopover.add(vb)

        self.lines.connect('clicked', self.onLinesCliked)

        ##

        hb = Gtk.HBox()
        hb.get_style_context().add_class('linked')
        self.sideNewFileBtn = Gtk.Button.new_from_icon_name('document-new-symbolic', Gtk.IconSize.MENU)
        self.sideNewFileBtn.connect('clicked', self.createNewFile)
        self.sideNewFolderBtn = Gtk.Button.new_from_icon_name('folder-new-symbolic', Gtk.IconSize.MENU)
        self.sideNewFolderBtn.connect('clicked', self.createNewFolder)
        hb.pack_start(self.sideNewFileBtn, False, False, 0)
        hb.pack_start(self.sideNewFolderBtn, False, False, 0)

        hb.pack_end(self.terminalBtn, False, False, 0)
        hb.pack_start(self.lines, True, True, 0)

        self.pane = Gtk.Paned.new(Gtk.Orientation.HORIZONTAL)
        self.pane.set_wide_handle(False)
        self.terminalPane = Gtk.Paned.new(Gtk.Orientation.VERTICAL)
        #self.terminalPane.set_wide_handle(True)

        self.terminal = Vte.Terminal()

        self.sideVBox = Gtk.VBox()
        self.sideVBox.pack_end(hb, False, False, 0)

        self.sideView = Gtk.ListBox()
        self.sideView.set_selection_mode(Gtk.SelectionMode.SINGLE)
        self.sideView.set_activate_on_single_click(True)
        self.sideView.connect('row-selected', self.handleSideClick)
        self.sideScroller = Gtk.ScrolledWindow()
        #self.sideScroller.add(self.sideView)
        # self.sideScroller.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)

        self.sideVBox.pack_start(self.sideScroller, True, True, 0)

        # MD Preview

        self.mdPreviewer = WebKit.WebView()
        self.mdPreviewer.load_uri('file://' + os.path.dirname(os.path.abspath(__file__)) + '/browser/index.html')

        #####################################

        self.searchToolbar = Gtk.Revealer()
        self.searchToolbar.set_transition_type(Gtk.RevealerTransitionType.SLIDE_DOWN)
        self.searchToolbar.set_transition_duration(300)

        self.searchEntry = Gtk.Entry()
        self.searchEntry.set_icon_from_icon_name(Gtk.EntryIconPosition.PRIMARY, 'preferences-system-search-symbolic')
        self.searchEntry.connect('changed', self.find)
        self.searchEntry.set_width_chars(50)

        self.searchFindButton = Gtk.Button('Find')
        self.searchFindButton.connect('clicked', self.find)

        self.searchCloseButton = Gtk.Button.new_from_icon_name('window-close-symbolic', Gtk.IconSize.MENU)
        self.searchCloseButton.connect('clicked', self.toggleSearch)

        self.searchVBox = Gtk.HBox()

        bx = Gtk.HBox()
        bx.pack_start(self.searchEntry, False, False, 0)
        bx.pack_start(self.searchFindButton, False, False, 0)
        bx.set_halign(Gtk.Align.CENTER)
        

        self.searchVBox.add(bx)
        self.searchVBox.pack_end(self.searchCloseButton, False, False, 0)

        self.searchToolbar.add(self.searchVBox)
        self.searchToolbar.set_reveal_child(False)

        #####################################

        # SVIEWSCROLL EVENTS

        #self.sviewScroll.connect('event-after', self.sviewScrollEvents)

        #self.sviewScroll.connect('scroll-child', self.updateMinimap)
        self.sviewScroll.add(self.sview)
        self.sviewBox.pack_start(self.sviewScroll, True, True, 0)

        self.sviewBox.pack_start(self.smap, False, False, 0)

        ##########################################

        self.searchPane = Gtk.VBox()

        self.sviewPaned = Gtk.Paned()
        self.sviewPaned.pack1(self.sviewBox, False, False)
        self.sviewPaned.pack2(self.mdPreviewer)

        self.pane.pack1(self.sideVBox, False, False)

        self.terminalPane.pack1(self.sviewPaned, True, True) ##################
        self.terminalPane.add2(self.terminal)

        self.searchPane.pack_start(self.searchToolbar, False, False, 0)
        self.searchPane.pack_start(self.terminalPane, True, True, 0)

        self.pane.add2(self.searchPane)

        self.add(self.pane)
        self.set_titlebar(self.hb)

        self.loadSettings()

        self.show_all()

        self.openProject(openPath)
        self.sviewPaned.get_child2().hide()

        ## Appending modules

        self.modules = []

        self.autoBracket = AutoBracket(self)
        self.modules.append(self.autoBracket)
        self.autoComplete = GediPlugin(self)
        self.modules.append(self.autoComplete)
        self.linter = Linter(self)
        self.modules.append(self.linter)

        for module in self.modules:
            module.do_activate()

        Gtk.main()