Exemple #1
0
class Interface(object):
    def __init__( self ):
        self.mainWindow = StandardWindow("epad", "Untitled - ePad", size=(600, 400))
        self.mainWindow.callback_delete_request_add(self.closeChecks)
        self.mainWindow.elm_event_callback_add(self.eventsCb)

        icon = Icon(self.mainWindow)
        icon.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND)
        icon.size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL)
        icon.standard_set('accessories-text-editor') # assumes image icon is in local dir, may need to change later
        icon.show()
        self.mainWindow.icon_object_set(icon.object_get())

        self.mainBox = Box(self.mainWindow, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        self.mainBox.show()

        self.mainTb = Toolbar(self.mainWindow, homogeneous=False, size_hint_weight=(0.0, 0.0), size_hint_align=(EVAS_HINT_FILL, 0.0))
        self.mainTb.menu_parent =  self.mainWindow

        self.mainTb.item_append("document-new", "New", self.newPress)
        self.mainTb.item_append("document-open", "Open", self.openPress)
        self.mainTb.item_append("document-save", "Save", self.savePress)
        self.mainTb.item_append("document-save-as", "Save As", self.saveAsPress)
        # -- Edit Dropdown Menu --
        tb_it = self.mainTb.item_append("edit", "Edit")
        tb_it.menu = True
        menu = tb_it.menu
        menu.item_add(None, "Copy", "edit-copy", self.copyPress)
        menu.item_add(None, "Paste", "edit-paste", self.pastePress)
        menu.item_add(None, "Cut", "edit-cut", self.cutPress)
        menu.item_separator_add()
        menu.item_add(None, "Select All", "edit-select-all", self.selectAllPress)
        # -----------------------
        # self.mainTb.item_append("settings", "Options", self.optionsPress)
        self.mainTb.item_append("dialog-information", "About", self.aboutPress)
        
        self.mainEn = Entry(self.mainWindow, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        self.mainEn.callback_changed_user_add(self.textEdited)
        self.mainEn.scrollable_set(True) # creates scrollbars rather than enlarge window
        self.mainEn.line_wrap_set(False) # does not allow line wrap (can be changed by user)
        self.mainEn.autosave_set(False) # set to false to reduce disk I/O
        self.mainEn.elm_event_callback_add(self.eventsCb)
        self.mainEn.markup_filter_append(self.textFilter)
        self.mainEn.show()
        
        self.mainTb.show()

        self.mainBox.pack_end(self.mainTb)
        self.mainBox.pack_end(self.mainEn)

        #Build our file selector for saving/loading files
        self.fileBox = Box(self.mainWindow, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        self.fileBox.show()

        self.fileLabel = Label(self.mainWindow, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH)
        self.fileLabel.text = ""
        self.fileLabel.show()

        self.fileSelector = Fileselector(self.mainWindow, is_save=False, expandable=False, folder_only=False,
                      path=os.getenv("HOME"), size_hint_weight=EXPAND_BOTH,
                      size_hint_align=FILL_BOTH)
        self.fileSelector.callback_done_add(self.fileSelected)
        #self.fileSelector.callback_selected_add(fs_cb_selected, win)
        #self.fileSelector.callback_directory_open_add(fs_cb_directory_open, win)
        self.fileSelector.show()

        self.fileBox.pack_end(self.fileLabel)
        self.fileBox.pack_end(self.fileSelector)

        # the flip object has the file selector on one side and the GUI on the other
        self.flip = Flip(self.mainWindow, size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)
        self.flip.part_content_set("front", self.mainBox)
        self.flip.part_content_set("back", self.fileBox)
        self.mainWindow.resize_object_add(self.flip)
        self.flip.show()

        self.isSaved = True
        self.isNewFile = False
        self.confirmPopup = None

    def newPress( self, obj, it ):
        self.newFile()
        it.selected_set(False)

    def openPress( self, obj, it ):
        self.openFile()
        it.selected_set(False)

    def savePress( self, obj, it ):
        self.saveFile()
        it.selected_set(False)

    def saveAsPress( self, obj, it ):
        self.saveAs()
        it.selected_set(False)

    def optionsPress( self, obj, it ):
        it.selected_set(False)

    def copyPress( self, obj, it ):
        self.mainEn.selection_copy()
        it.selected_set(False)

    def pastePress( self, obj, it ):
        self.mainEn.selection_paste()
        it.selected_set(False)

    def cutPress( self, obj, it ):
        self.mainEn.selection_cut()
        it.selected_set(False)

    def selectAllPress( self, obj, it ):
        self.mainEn.select_all()
        it.selected_set(False)

    def textEdited( self, obj ):
        ourFile = self.mainEn.file_get()[0]
        if ourFile and not self.isNewFile:
            self.mainWindow.title_set("*%s - ePad"%self.mainEn.file_get()[0].split("/")[len(self.mainEn.file_get()[0].split("/"))-1])
        else:
            self.mainWindow.title_set("*Untitlted - ePad")
        self.isSaved = False

    def fileSelected( self, fs, file_selected, onStartup=False ):
        if not onStartup:
            self.flip.go(ELM_FLIP_INTERACTION_ROTATE)
        print(file_selected)
        IsSave = fs.is_save_get()
        if file_selected:
            if IsSave:
                newfile = open(file_selected,'w') # creates new file
                tmp_text = self.mainEn.entry_get()
                newfile.write(tmp_text)
                newfile.close()
                self.mainEn.file_set(file_selected, ELM_TEXT_FORMAT_PLAIN_UTF8)
                self.mainEn.entry_set(tmp_text)
                self.mainEn.file_save()
                self.mainWindow.title_set("%s - ePad" % file_selected.split("/")[len(file_selected.split("/"))-1])
                self.isSaved = True
                self.isNewFile = False
            else:
                try:
                    self.mainEn.file_set(file_selected, ELM_TEXT_FORMAT_PLAIN_UTF8)
                except RuntimeError:
                    print("Empty file: {0}".format(file_selected))
                self.mainWindow.title_set("%s - ePad" % file_selected.split("/")[len(file_selected.split("/"))-1])

    def aboutPress( self, obj, it ):
        #About popup
        self.popupAbout = Popup(self.mainWindow, size_hint_weight=EXPAND_BOTH)
        self.popupAbout.text = "ePad - A simple text editor written in python and elementary<br><br> " \
                     "By: Jeff Hoogland"
        bt = Button(self.mainWindow, text="Done")
        bt.callback_clicked_add(self.aboutClose)
        self.popupAbout.part_content_set("button1", bt)
        self.popupAbout.show()
        it.selected_set(False)

    def aboutClose( self, bt ):
        self.popupAbout.delete()

    def newFile( self , obj=None, ignoreSave=False ):
        if self.isSaved == True or ignoreSave == True:
            trans = Transit()
            trans.object_add(self.mainEn)
            trans.auto_reverse = True

            trans.effect_wipe_add(
                ELM_TRANSIT_EFFECT_WIPE_TYPE_HIDE,
                ELM_TRANSIT_EFFECT_WIPE_DIR_RIGHT)

            trans.duration = 0.5
            trans.go()
            
            time.sleep(0.5)

            self.mainWindow.title_set("Untitlted - ePad")
            self.mainEn.delete()
            self.mainEn = Entry(self.mainWindow, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
            self.mainEn.callback_changed_user_add(self.textEdited)
            self.mainEn.scrollable_set(True) # creates scrollbars rather than enlarge window
            self.mainEn.line_wrap_set(False) # does not allow line wrap (can be changed by user)
            self.mainEn.autosave_set(False) # set to false to reduce disk I/O
            self.mainEn.elm_event_callback_add(self.eventsCb)
            self.mainEn.markup_filter_append(self.textFilter)
            self.mainEn.show()
            
            self.mainBox.pack_end(self.mainEn)

            self.isNewFile = True
        elif self.confirmPopup == None:
            self.confirmSave(self.newFile)

    def openFile( self, obj=None, ignoreSave=False ):
        if self.isSaved == True or ignoreSave == True:
            self.fileSelector.is_save_set(False)
            self.fileLabel.text = "<b>Select a text file to open:</b>"
            self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)
        elif self.confirmPopup == None:
            self.confirmSave(self.openFile)

    def confirmSave( self, ourCallback=None ):
        self.confirmPopup = Popup(self.mainWindow, size_hint_weight=EXPAND_BOTH)
        self.confirmPopup.part_text_set("title,text","File Unsaved")
        if self.mainEn.file_get()[0]:
            self.confirmPopup.text = "Save changes to '%s'?" % self.mainEn.file_get()[0].split("/")[len(self.mainEn.file_get()[0].split("/"))-1]
        else:
            self.confirmPopup.text = "Save changes to 'Untitlted'?"
        # Close without saving button
        no_btt = Button(self.mainWindow)
        no_btt.text = "No"
        no_btt.callback_clicked_add(self.closePopup, self.confirmPopup)
        if ourCallback is not None:
            no_btt.callback_clicked_add(ourCallback, True)
        no_btt.show()
        # cancel close request
        cancel_btt = Button(self.mainWindow)
        cancel_btt.text = "Cancel"
        cancel_btt.callback_clicked_add(self.closePopup, self.confirmPopup)
        cancel_btt.show()
        # Save the file and then close button
        sav_btt = Button(self.mainWindow)
        sav_btt.text = "Yes"
        sav_btt.callback_clicked_add(self.saveFile)
        sav_btt.callback_clicked_add(self.closePopup, self.confirmPopup)
        sav_btt.show()
        
        # add buttons to popup
        self.confirmPopup.part_content_set("button1", no_btt)
        self.confirmPopup.part_content_set("button2", cancel_btt)
        self.confirmPopup.part_content_set("button3", sav_btt)
        self.confirmPopup.show()

    def saveAs( self ):
        self.fileSelector.is_save_set(True)
        self.fileLabel.text = "<b>Save new file to where:</b>"
        self.flip.go(ELM_FLIP_ROTATE_XZ_CENTER_AXIS)

    def saveFile( self, obj=False ):
        if self.mainEn.file_get()[0] == None or self.isNewFile:
            self.saveAs()
        else:
            self.mainEn.file_save()
            self.mainWindow.title_set("%s - ePad"%self.mainEn.file_get()[0].split("/")[len(self.mainEn.file_get()[0].split("/"))-1])
            self.isSaved = True

    def closeChecks( self, obj ):
        print(self.isSaved)
        if self.isSaved == False and self.confirmPopup == None:
            self.confirmSave(self.closeApp)
        else:
            self.closeApp()

    def closePopup( self, bt, confirmPopup ):
        self.confirmPopup.delete()
        self.confirmPopup = None

    def closeApp( self, obj=False, trash=False ):
        elementary.exit()

    def eventsCb( self, obj, src, event_type, event ):
        #print event_type
        #print event.key
        #print "Control Key Status: %s" %event.modifier_is_set("Control")
        #print "Shift Key Status: %s" %event.modifier_is_set("Shift")
        #print event.modifier_is_set("Alt")
        if event.modifier_is_set("Control"):
            if event.key.lower() == "n":
                self.newFile()
            elif event.key.lower() == "s" and event.modifier_is_set("Shift"):
                self.saveAs()
            elif event.key.lower() == "s":
                self.saveFile()
            elif event.key.lower() == "o":
                self.openFile()

    def textFilter( self, obj, theText, data ):
        #print theText

        #Block ctrl+hot keys
        if theText == "" or theText == "" or theText == "":
            return None
        else:
            return theText

    def launch( self, startingFile=False ):
        if startingFile:
            self.fileSelected(self.fileSelector, startingFile, True)
        self.mainWindow.show()
Exemple #2
0
class SwamiModule(Box):
    def __init__(self, rent):
        Box.__init__(self, rent)
        self.parent = rent

        #This appears on the button in the main swmai window
        self.name = "Startup Applications"
        #The section in the main window the button is added to
        self.section = "Applications"
        #Search terms that this module should appear for
        self.searchData = ["startup", "command", "applications", "apps"]
        #Command line argument to open this module directly
        self.launchArg = "--startupapps"
        #Should be none by default. This value is used internally by swami
        self.button = None

        self.icon = Icon(self,
                         size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)
        #Use FDO icons -> http://standards.freedesktop.org/icon-naming-spec/latest/ar01s04.html
        self.icon.standard_set('system-run')
        self.icon.show()

        self.mainBox = Box(self,
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)
        self.mainBox.show()

        buttonBox = Box(self,
                        size_hint_weight=EXPAND_HORIZ,
                        size_hint_align=FILL_BOTH)
        buttonBox.horizontal = True

        buttonApply = StandardButton(self, "Apply", "ok", self.applyPressed)
        buttonApply.show()

        buttonFlip = StandardButton(self, "Startup Commands",
                                    "preferences-system", self.flipPressed)
        buttonFlip.show()

        buttonReturn = StandardButton(self, "Back", "go-previous",
                                      self.returnPressed)
        buttonReturn.show()

        buttonBox.pack_end(buttonApply)
        buttonBox.pack_end(buttonFlip)
        buttonBox.pack_end(buttonReturn)
        buttonBox.show()

        startupApplications = []

        with open(StartupApplicationsFile, "a+") as startupFile:
            for line in startupFile:
                startupApplications.append(line.rstrip())

        desktopFiles = []

        for ourPath in ApplicationPaths:
            desktopFiles += [
                os.path.join(dp, f) for dp, dn, filenames in os.walk(ourPath)
                for f in filenames if os.path.splitext(f)[1] == '.desktop'
            ]

        self.startupList = startupList = List(self,
                                              size_hint_weight=EXPAND_BOTH,
                                              size_hint_align=FILL_BOTH)

        self.applicationsList = applicationsList = SearchableList(
            self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)

        startupToAdd = []
        applicationsToAdd = []

        for d in desktopFiles:
            if os.access(d, os.R_OK):
                with open(d) as desktopFile:
                    fileName = d.split("/")[-1]
                    icon = None
                    for line in desktopFile:
                        if line[:5] == "Name=":
                            name = line[5:][:-1]

                        if line[:5] == "Icon=":
                            icon = line[5:].strip()

                    try:
                        iconObj = Icon(self,
                                       standard=icon,
                                       size_hint_weight=EXPAND_BOTH,
                                       size_hint_align=FILL_BOTH)
                    except:
                        iconObj = Icon(self,
                                       standard="preferences-system",
                                       size_hint_weight=EXPAND_BOTH,
                                       size_hint_align=FILL_BOTH)
                        icon = None

                    if fileName in startupApplications:
                        startupToAdd.append([name, iconObj, fileName, icon])
                    else:
                        applicationsToAdd.append(
                            [name, iconObj, fileName, icon])
            else:
                # Broken link or file problem, inform user
                print "Swami IOError: [Errno 2] No such file or directory: {0}".format(
                    d)

        startupToAdd.sort()
        applicationsToAdd.sort()

        for s in startupToAdd:
            ourItem = startupList.item_append(s[0], s[1])
            ourItem.data["file"] = s[2]
            ourItem.data["icon"] = s[3]
            #ourItem.append_to(startupList)
            #startupList.item_append(ourItem)

        for a in applicationsToAdd:
            ourItem = applicationsList.item_append(a[0], a[1])
            ourItem.data["file"] = a[2]
            ourItem.data["icon"] = a[3]
            #ourItem.append_to(applicationsList.ourList)
            #applicationsList.item_append(a[0], a[1])

        startupList.callback_clicked_double_add(self.startupAppRemove)
        applicationsList.callback_clicked_double_add(self.startupAppAdd)

        startupList.go()
        startupList.show()
        applicationsList.show()

        startupFrame = Frame(self,
                             size_hint_weight=EXPAND_BOTH,
                             size_hint_align=FILL_BOTH)
        startupFrame.text = "Startup Applications"
        startupFrame.content_set(startupList)
        startupFrame.show()

        otherFrame = Frame(self,
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)
        otherFrame.text = "Other Applications"
        otherFrame.content_set(applicationsList)
        otherFrame.show()

        self.mainBox.pack_end(startupFrame)
        self.mainBox.pack_end(otherFrame)

        self.backBox = Box(self,
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)
        self.backBox.show()

        self.commandsList = commandsList = List(self,
                                                size_hint_weight=EXPAND_BOTH,
                                                size_hint_align=FILL_BOTH)

        with open(StartupCommandsFile, "a+") as scf:
            for line in scf:
                if line.rstrip()[-3:] == "| \\":
                    commandsList.item_append(line.rstrip()[:-3])
                else:
                    commandsList.item_append(line.rstrip())

        commandsList.callback_clicked_right_add(self.commandRightClicked)

        commandsList.go()
        commandsList.show()

        commandBox = Box(self,
                         size_hint_weight=EXPAND_HORIZ,
                         size_hint_align=(1, 0.5))
        commandBox.horizontal = True
        commandBox.show()

        self.newCommandEntry = newCommandEntry = Entry(
            self, size_hint_weight=EXPAND_HORIZ, size_hint_align=FILL_BOTH)
        newCommandEntry.single_line = True
        newCommandEntry.text = "<i>Type command here</i>"
        newCommandEntry.data["default text"] = True
        newCommandEntry.callback_clicked_add(self.entryClicked)
        newCommandEntry.show()

        newCommandButton = StandardButton(self, "Add Command", "add",
                                          self.newCmdPressed)
        newCommandButton.show()

        delCommandButton = StandardButton(self, "Delete Command", "exit",
                                          self.delCmdPressed)
        delCommandButton.show()

        commandBox.pack_end(newCommandButton)
        commandBox.pack_end(delCommandButton)

        newCommandFrame = Frame(self,
                                size_hint_weight=EXPAND_HORIZ,
                                size_hint_align=FILL_BOTH)
        newCommandFrame.text = "Add Startup Command:"
        newCommandFrame.content_set(newCommandEntry)
        newCommandFrame.show()

        self.backBox.pack_end(commandsList)
        self.backBox.pack_end(newCommandFrame)
        self.backBox.pack_end(commandBox)

        self.flip = Flip(self,
                         size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)
        self.flip.part_content_set("front", self.mainBox)
        self.flip.part_content_set("back", self.backBox)
        self.flip.show()

        self.pack_end(self.flip)
        self.pack_end(buttonBox)

    def startupAppRemove(self, lst, itm):
        text = itm.text
        dataFile = itm.data["file"]
        dataIcon = itm.data["icon"]
        itm.delete()

        if dataIcon:
            iconObj = Icon(self,
                           standard=dataIcon,
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)
        else:
            iconObj = Icon(self,
                           standard="preferences-system",
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)

        ourItem = self.applicationsList.item_append(text, iconObj)
        ourItem.data["file"] = dataFile
        ourItem.data["icon"] = dataIcon
        self.applicationsList.ourList.go()

    def startupAppAdd(self, lst, itm):
        text = itm.text
        dataFile = itm.data["file"]
        dataIcon = itm.data["icon"]
        itm.delete()

        if dataIcon:
            iconObj = Icon(self,
                           standard=dataIcon,
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)
        else:
            iconObj = Icon(self,
                           standard="preferences-system",
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)

        ourItem = self.startupList.item_append(text, iconObj)
        ourItem.data["file"] = dataFile
        ourItem.data["icon"] = dataIcon
        self.startupList.go()

    def flipPressed(self, btn):
        if btn.text == "Startup Commands":
            btn.text = "Startup Applications"
        else:
            btn.text = "Startup Commands"

        self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)

    def commandRightClicked(self, lst, itm):
        self.delCmdMenu.move(1, 1)
        self.delCmdMenu.show()

    def entryClicked(self, entry):
        if entry.data["default text"]:
            entry.data["default text"] = False
            entry.text = ""

    def newCmdPressed(self, btn):
        self.commandsList.item_append(self.newCommandEntry.text)
        self.newCommandEntry.text = ""
        self.commandsList.go()

    def delCmdPressed(self, btn):
        selectedCommand = self.commandsList.selected_item_get()
        selectedCommand.delete()

    def applyPressed(self, btn):
        with open(StartupApplicationsFile, 'w') as saf:
            for i in self.startupList.items_get():
                saf.write(i.data["file"])
                saf.write("\n")

        with open(StartupCommandsFile, 'w') as scf:
            lastI = self.commandsList.last_item_get()
            for i in self.commandsList.items_get():
                if i != lastI:
                    scf.write(i.text + " | \\ \n")
                else:
                    scf.write(i.text)

        p = Popup(self, size_hint_weight=EXPAND_BOTH, timeout=3.0)
        p.text = "Changes Successfully Applied"
        p.show()

    def returnPressed(self, btn):
        self.parent.returnMain()
class SwamiModule(Box):
    def __init__(self, rent):
        Box.__init__(self, rent)
        self.parent = rent
        
        #This appears on the button in the main swmai window
        self.name = "Startup Applications"
        #The section in the main window the button is added to
        self.section = "Applications"
        #Search terms that this module should appear for
        self.searchData = ["startup", "command", "applications", "apps"]
        #Command line argument to open this module directly
        self.launchArg = "--startupapps"
        #Should be none by default. This value is used internally by swami
        self.button = None
        
        self.icon = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        #Use FDO icons -> http://standards.freedesktop.org/icon-naming-spec/latest/ar01s04.html
        self.icon.standard_set('system-run')
        self.icon.show()
        
        self.mainBox = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        self.mainBox.show()
        
        buttonBox = Box(self, size_hint_weight = EXPAND_HORIZ, size_hint_align = FILL_BOTH)
        buttonBox.horizontal = True
        
        buttonApply = StandardButton(self, "Apply", "ok", self.applyPressed)
        buttonApply.show()
        
        buttonFlip = StandardButton(self, "Startup Commands", "preferences-system", self.flipPressed)
        buttonFlip.show()
        
        buttonReturn = StandardButton(self, "Back", "go-previous", self.returnPressed)
        buttonReturn.show()
        
        buttonBox.pack_end(buttonApply)
        buttonBox.pack_end(buttonFlip)
        buttonBox.pack_end(buttonReturn)
        buttonBox.show()
        
        startupApplications = []
        
        with open(StartupApplicationsFile) as startupFile:
            for line in startupFile:
                startupApplications.append(line.rstrip())
        
        desktopFiles = []
        
        for ourPath in ApplicationPaths:
            desktopFiles += [os.path.join(dp, f) for dp, dn, filenames in os.walk(ourPath) for f in filenames if os.path.splitext(f)[1] == '.desktop']
        
        self.startupList = startupList = List(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        
        self.applicationsList = applicationsList = SearchableList(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)

        startupToAdd = []
        applicationsToAdd = []

        for d in desktopFiles:
            with open(d) as desktopFile:
                fileName = d.split("/")[-1]
                icon = None
                for line in desktopFile:
                    if line[:5] == "Name=":
                        name = line[5:][:-1]
                    
                    if line[:5] == "Icon=":
                        icon = line[5:].strip()
                
                try:
                    iconObj = Icon(self, standard=icon, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
                except:
                    iconObj = Icon(self, standard="preferences-system", size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
                    icon = None
                
                if fileName in startupApplications:
                    startupToAdd.append([name, iconObj, fileName, icon])
                else:
                    applicationsToAdd.append([name, iconObj, fileName, icon])
        
        startupToAdd.sort()
        applicationsToAdd.sort()
        
        for s in startupToAdd:
            ourItem = startupList.item_append(s[0], s[1])
            ourItem.data["file"] = s[2]
            ourItem.data["icon"] = s[3]
            #ourItem.append_to(startupList)
            #startupList.item_append(ourItem)
        
        for a in applicationsToAdd:
            ourItem = applicationsList.item_append(a[0], a[1])
            ourItem.data["file"] = a[2]
            ourItem.data["icon"] = a[3]
            #ourItem.append_to(applicationsList.ourList)
            #applicationsList.item_append(a[0], a[1])
        
        startupList.callback_clicked_double_add(self.startupAppRemove)
        applicationsList.callback_clicked_double_add(self.startupAppAdd)
        
        startupList.go()
        startupList.show()
        applicationsList.show()
        
        startupFrame = Frame(self, size_hint_weight = EXPAND_BOTH, size_hint_align=FILL_BOTH)
        startupFrame.text = "Startup Applications"
        startupFrame.content_set(startupList)
        startupFrame.show()
        
        otherFrame = Frame(self, size_hint_weight = EXPAND_BOTH, size_hint_align=FILL_BOTH)
        otherFrame.text = "Other Applications"
        otherFrame.content_set(applicationsList)
        otherFrame.show()
        
        self.mainBox.pack_end(startupFrame)
        self.mainBox.pack_end(otherFrame)
        
        self.backBox = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        self.backBox.show()
        
        self.commandsList = commandsList = List(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        
        with open(StartupCommandsFile) as scf:
            for line in scf:
                if line.rstrip()[-3:] == "| \\":
                    commandsList.item_append(line.rstrip()[:-3])
                else:
                    commandsList.item_append(line.rstrip())
                
        commandsList.callback_clicked_right_add(self.commandRightClicked)
        
        commandsList.go()
        commandsList.show()
        
        commandBox = Box(self, size_hint_weight=EXPAND_HORIZ, size_hint_align=(1, 0.5))
        commandBox.horizontal = True
        commandBox.show()
        
        self.newCommandEntry = newCommandEntry = Entry(self, size_hint_weight = EXPAND_HORIZ, size_hint_align = FILL_BOTH)
        newCommandEntry.single_line = True
        newCommandEntry.text = "<i>Type command here</i>"
        newCommandEntry.data["default text"] = True
        newCommandEntry.callback_clicked_add(self.entryClicked)
        newCommandEntry.show()
        
        newCommandButton = StandardButton(self, "Add Command", "add", self.newCmdPressed)
        newCommandButton.show()
        
        delCommandButton = StandardButton(self, "Delete Command", "exit", self.delCmdPressed)
        delCommandButton.show()
        
        commandBox.pack_end(newCommandButton)
        commandBox.pack_end(delCommandButton)
        
        newCommandFrame = Frame(self, size_hint_weight = EXPAND_HORIZ, size_hint_align = FILL_BOTH)
        newCommandFrame.text = "Add Startup Command:"
        newCommandFrame.content_set(newCommandEntry)
        newCommandFrame.show()
        
        self.backBox.pack_end(commandsList)
        self.backBox.pack_end(newCommandFrame)
        self.backBox.pack_end(commandBox)
        
        self.flip = Flip(self, size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)
        self.flip.part_content_set("front", self.mainBox)
        self.flip.part_content_set("back", self.backBox)
        self.flip.show()
        
        self.pack_end(self.flip)
        self.pack_end(buttonBox)
    
    def startupAppRemove(self, lst, itm):
        text = itm.text
        dataFile = itm.data["file"]
        dataIcon = itm.data["icon"]
        itm.delete()
        
        if dataIcon:
            iconObj = Icon(self, standard=dataIcon, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        else:
            iconObj = Icon(self, standard="preferences-system", size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        
        ourItem = self.applicationsList.item_append(text, iconObj)
        ourItem.data["file"] = dataFile
        ourItem.data["icon"] = dataIcon
        self.applicationsList.ourList.go()
    
    def startupAppAdd(self, lst, itm):
        text = itm.text
        dataFile = itm.data["file"]
        dataIcon = itm.data["icon"]
        itm.delete()
        
        if dataIcon:
            iconObj = Icon(self, standard=dataIcon, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        else:
            iconObj = Icon(self, standard="preferences-system", size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        
        ourItem = self.startupList.item_append(text, iconObj)
        ourItem.data["file"] = dataFile
        ourItem.data["icon"] = dataIcon
        self.startupList.go()
    
    def flipPressed(self, btn):
        if btn.text == "Startup Commands":
            btn.text = "Startup Applications"
        else:
            btn.text = "Startup Commands"
        
        self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)
    
    def commandRightClicked(self, lst, itm):
        self.delCmdMenu.move(1, 1)
        self.delCmdMenu.show()
    
    def entryClicked(self, entry):
        if entry.data["default text"]:
            entry.data["default text"] = False
            entry.text = ""
    
    def newCmdPressed(self, btn):
        self.commandsList.item_append(self.newCommandEntry.text)
        self.newCommandEntry.text = ""
        self.commandsList.go()
    
    def delCmdPressed(self, btn):
        selectedCommand = self.commandsList.selected_item_get()
        selectedCommand.delete()
    
    def applyPressed(self, btn):
        with open(StartupApplicationsFile, 'w') as saf:
            for i in self.startupList.items_get():
                saf.write(i.data["file"])
                saf.write("\n")
        
        with open(StartupCommandsFile, 'w') as scf:
            lastI = self.commandsList.last_item_get()
            for i in self.commandsList.items_get():
                if i != lastI:
                    scf.write(i.text + " | \\ \n")
                else:
                    scf.write(i.text)
        
        p = Popup(self, size_hint_weight=EXPAND_BOTH, timeout=3.0)
        p.text = "Changes Successfully Applied"
        p.show()
    
    def returnPressed(self, btn):
        self.parent.returnMain()
Exemple #4
0
class Interface(object):
    def __init__(self):
        self.mainWindow = StandardWindow("epad",
                                         "Untitled - ePad",
                                         size=(600, 400))
        self.mainWindow.callback_delete_request_add(self.closeChecks)
        self.mainWindow.elm_event_callback_add(self.eventsCb)

        icon = Icon(self.mainWindow,
                    size_hint_weight=EXPAND_BOTH,
                    size_hint_align=FILL_BOTH)
        icon.standard_set('accessories-text-editor')
        icon.show()
        self.mainWindow.icon_object_set(icon.object_get())

        self.mainBox = Box(self.mainWindow,
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)
        self.mainBox.show()

        self.mainTb = ePadToolbar(self, self.mainWindow)
        self.mainTb.show()
        self.mainBox.pack_end(self.mainTb)

        # Initialize Text entry box
        print("Word wrap Initialized: {0}".format(self.wordwrap))
        self.entryInit()

        # Add label to show current cursor position
        if SHOW_POS:
            self.line_label = Label(self.mainWindow,
                                    size_hint_weight=EXPAND_HORIZ,
                                    size_hint_align=ALIGN_RIGHT)
            self.curChanged(self.mainEn, self.line_label)
            self.line_label.show()
            self.mainBox.pack_end(self.line_label)
            self.mainEn.callback_cursor_changed_add(self.curChanged,
                                                    self.line_label)

        # Build our file selector for saving/loading files
        self.fileBox = Box(self.mainWindow,
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)
        self.fileBox.show()

        self.fileLabel = Label(self.mainWindow,
                               size_hint_weight=EXPAND_HORIZ,
                               size_hint_align=FILL_BOTH,
                               text="")
        self.fileLabel.show()

        self.fileSelector = Fileselector(self.mainWindow,
                                         is_save=False,
                                         expandable=False,
                                         folder_only=False,
                                         path=os.getenv("HOME"),
                                         size_hint_weight=EXPAND_BOTH,
                                         size_hint_align=FILL_BOTH)
        self.fileSelector.callback_done_add(self.fileSelected)
        self.fileSelector.show()

        self.fileBox.pack_end(self.fileLabel)
        self.fileBox.pack_end(self.fileSelector)

        # Flip object has the file selector on one side
        #   and the GUI on the other
        self.flip = Flip(self.mainWindow,
                         size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)
        self.flip.part_content_set("front", self.mainBox)
        self.flip.part_content_set("back", self.fileBox)
        self.mainWindow.resize_object_add(self.flip)
        self.flip.show()

        self.isSaved = True
        self.isNewFile = False
        self.confirmPopup = None

    def entryInit(self):
        self.mainEn = Entry(self.mainWindow,
                            scrollable=True,
                            line_wrap=self.wordwrap,
                            autosave=False,
                            size_hint_weight=EXPAND_BOTH,
                            size_hint_align=FILL_BOTH)
        self.mainEn.callback_changed_user_add(self.textEdited)
        self.mainEn.elm_event_callback_add(self.eventsCb)
        # self.mainEn.markup_filter_append(self.textFilter)
        self.mainEn.show()
        self.mainBox.pack_end(self.mainEn)

    def curChanged(self, entry, label):
        # get linear index into current text
        index = entry.cursor_pos_get()
        # Replace <br /> tag with single char
        #   to simplify (line, col) calculation
        tmp_text = entry.entry_get().replace("<br/>", "\n")
        line = tmp_text[:index].count("\n") + 1
        col = len(tmp_text[:index].split("\n")[-1]) + 1
        # Update label text with line, col
        label.text = "Ln {0} Col {1} ".format(line, col)

    def textEdited(self, obj):
        current_file = self.mainEn.file[0]
        current_file = \
            os.path.basename(current_file) if \
            current_file and not self.isNewFile else \
            "Untitled"
        self.mainWindow.title = "*%s - ePad" % (current_file)
        self.isSaved = False

    def fileSelected(self, fs, file_selected, onStartup=False):
        if not onStartup:
            self.flip.go(ELM_FLIP_INTERACTION_ROTATE)
        print(file_selected)
        IsSave = fs.is_save_get()
        if file_selected:
            if IsSave:
                newfile = open(file_selected, 'w')
                tmp_text = self.mainEn.entry_get()
                newfile.write(tmp_text)
                newfile.close()
                self.mainEn.file_set(file_selected, ELM_TEXT_FORMAT_PLAIN_UTF8)
                self.mainEn.entry_set(tmp_text)
                self.mainEn.file_save()
                self.mainWindow.title_set("%s - ePad" %
                                          os.path.basename(file_selected))
                self.isSaved = True
                self.isNewFile = False
            else:
                try:
                    self.mainEn.file_set(file_selected,
                                         ELM_TEXT_FORMAT_PLAIN_UTF8)
                except RuntimeError:
                    print("Empty file: {0}".format(file_selected))
                self.mainWindow.title_set("%s - ePad" %
                                          os.path.basename(file_selected))

    def newFile(self, obj=None, ignoreSave=False):
        if self.isSaved is True or ignoreSave is True:
            trans = Transit()
            trans.object_add(self.mainEn)
            trans.auto_reverse = True

            trans.effect_wipe_add(ELM_TRANSIT_EFFECT_WIPE_TYPE_HIDE,
                                  ELM_TRANSIT_EFFECT_WIPE_DIR_RIGHT)

            trans.duration = 0.5
            trans.go()

            time.sleep(0.5)

            self.mainWindow.title_set("Untitled - ePad")
            self.mainEn.delete()
            self.entryInit()
            self.isNewFile = True
        elif self.confirmPopup is None:
            self.confirmSave(self.newFile)

    def openFile(self, obj=None, ignoreSave=False):
        if self.isSaved is True or ignoreSave is True:
            self.fileSelector.is_save_set(False)
            self.fileLabel.text = "<b>Select a text file to open:</b>"
            self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)
        elif self.confirmPopup is None:
            self.confirmSave(self.openFile)

    def confirmSave(self, ourCallback=None):
        self.confirmPopup = Popup(self.mainWindow,
                                  size_hint_weight=EXPAND_BOTH)
        self.confirmPopup.part_text_set("title,text", "File Unsaved")
        current_file = self.mainEn.file[0]
        current_file = \
            os.path.basename(current_file) if current_file else "Untitled"
        self.confirmPopup.text = "Save changes to '%s'?" % (current_file)
        # Close without saving button
        no_btt = Button(self.mainWindow)
        no_btt.text = "No"
        no_btt.callback_clicked_add(self.closePopup, self.confirmPopup)
        if ourCallback is not None:
            no_btt.callback_clicked_add(ourCallback, True)
        no_btt.show()
        # cancel close request
        cancel_btt = Button(self.mainWindow)
        cancel_btt.text = "Cancel"
        cancel_btt.callback_clicked_add(self.closePopup, self.confirmPopup)
        cancel_btt.show()
        # Save the file and then close button
        sav_btt = Button(self.mainWindow)
        sav_btt.text = "Yes"
        sav_btt.callback_clicked_add(self.saveFile)
        sav_btt.callback_clicked_add(self.closePopup, self.confirmPopup)
        sav_btt.show()

        # add buttons to popup
        self.confirmPopup.part_content_set("button1", no_btt)
        self.confirmPopup.part_content_set("button2", cancel_btt)
        self.confirmPopup.part_content_set("button3", sav_btt)
        self.confirmPopup.show()

    def saveAs(self):
        self.fileSelector.is_save_set(True)
        self.fileLabel.text = "<b>Save new file to where:</b>"
        self.flip.go(ELM_FLIP_ROTATE_XZ_CENTER_AXIS)

    def saveFile(self, obj=False):
        if self.mainEn.file_get()[0] is None or self.isNewFile:
            self.saveAs()
        else:
            self.mainEn.file_save()
            self.mainWindow.title_set("%s - ePad" %
                                      os.path.basename(self.mainEn.file[0]))
            self.isSaved = True

    def closeChecks(self, obj):
        print(self.isSaved)
        if self.isSaved is False and self.confirmPopup is None:
            self.confirmSave(self.closeApp)
        else:
            self.closeApp()

    def closePopup(self, bt, confirmPopup):
        self.confirmPopup.delete()
        self.confirmPopup = None

    def closeApp(self, obj=False, trash=False):
        elementary.exit()

    def eventsCb(self, obj, src, event_type, event):
        if event.modifier_is_set("Control"):
            if event.key.lower() == "n":
                self.newFile()
            elif event.key.lower() == "s" and event.modifier_is_set("Shift"):
                self.saveAs()
            elif event.key.lower() == "s":
                self.saveFile()
            elif event.key.lower() == "o":
                self.openFile()

    # Legacy hack no longer needed
    #  there was an issue in elementary entry where it would
    #  accept those character controls

    # def textFilter( self, obj, theText, data ):
    #    # Block ctrl+hot keys used in eventsCb
    #    #
    #    #             Ctrl O   Ctrl N   Ctrl S
    #    ctrl_block = [chr(14), chr(15), chr(19)]
    #    if theText in ctrl_block:
    #        return None
    #    else:
    #        return theText

    def launch(self, startingFile=False):
        if startingFile:
            self.fileSelected(self.fileSelector, startingFile, True)
        self.mainWindow.show()
Exemple #5
0
class SwamiModule(Box):
    def __init__(self, rent):
        Box.__init__(self, rent)
        self.parent = rent

        self.name = "Theme Selector"
        self.section = "Appearance"
        self.searchData = [
            "theme", "gtk", "elementary", "elm", "gnome", "appearance", "look"
        ]
        self.launchArg = "--theme"
        self.button = None

        self.icon = Icon(self,
                         size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)
        self.icon.standard_set('preferences-desktop-theme')
        self.icon.show()

        self.foundThemes = []

        self.currentPreview = None
        self.selectedTheme = None

        self.previewBox = previewBox = Scroller(self,
                                                size_hint_weight=EXPAND_BOTH,
                                                size_hint_align=FILL_BOTH)
        previewBox.show()

        self.themeList = List(self,
                              size_hint_weight=(0.35, 1.0),
                              size_hint_align=FILL_BOTH,
                              mode=ELM_LIST_COMPRESS)
        #Adds themes in the ThemePaths to the list for selection
        self.populateThemes()
        self.themeList.go()
        self.themeList.show()

        themeBox = Box(self,
                       size_hint_weight=EXPAND_BOTH,
                       size_hint_align=FILL_BOTH)
        themeBox.horizontal_set(True)
        themeBox.pack_end(self.themeList)
        themeBox.pack_end(self.previewBox)
        themeBox.show()

        self.fs = fs = FileSelector(self,
                                    size_hint_weight=EXPAND_BOTH,
                                    size_hint_align=FILL_BOTH)
        fs.setMode("Open")
        fs.show()

        #need to do this to shutdown threading for the file selector
        self.parent.callback_delete_request_add(self.shutDownFS)

        fs.callback_activated_add(self.fileSelected)

        # Flip object has the file selector on one side
        #   and the GUI on the other
        self.flip = Flip(self,
                         size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)
        self.flip.part_content_set("front", themeBox)
        self.flip.part_content_set("back", self.fs)
        self.flip.show()

        fs.callback_cancel_add(
            lambda o: self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS))

        #self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)

        self.mainBox = Box(self,
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)
        self.mainBox.pack_end(self.flip)
        self.mainBox.show()

        buttonBox = Box(self,
                        size_hint_weight=EXPAND_HORIZ,
                        size_hint_align=FILL_BOTH)
        buttonBox.horizontal = True

        buttonApply = StandardButton(self, "Apply Selected", "ok",
                                     self.applyPressed)
        buttonApply.show()

        buttonWeb = StandardButton(self, "Get Themes", "applications-internet",
                                   self.webPressed)
        buttonWeb.show()

        #buttonGTK = StandardButton(self, "GTK Theme", "preferences-desktop-gnome", self.gtkPressed)
        #buttonGTK.show()

        #buttonElm = StandardButton(self, "Elementary Theme", "", self.elmPressed)
        #buttonElm.show()

        buttonImport = StandardButton(self, "Import Theme",
                                      "preferences-desktop-theme",
                                      self.importPressed)
        buttonImport.show()

        buttonReturn = StandardButton(self, "Back", "go-previous",
                                      self.returnPressed)
        buttonReturn.show()

        buttonBox.pack_end(buttonApply)
        buttonBox.pack_end(buttonWeb)
        #buttonBox.pack_end(buttonGTK)
        #buttonBox.pack_end(buttonElm)
        buttonBox.pack_end(buttonImport)
        buttonBox.pack_end(buttonReturn)
        buttonBox.show()

        self.pack_end(self.mainBox)
        self.pack_end(buttonBox)

    def populateThemes(self):
        for ourPath in ThemePaths:
            for k in os.walk(ourPath):
                for themeFile in k[2]:
                    self.addTheme(themeFile, ourPath)

    def addTheme(self, themeFile, ourPath):
        edjeObj = Edje(self.evas,
                       size_hint_weight=EXPAND_BOTH,
                       size_hint_align=FILL_BOTH)

        try:
            edjeObj.file_set("%s/%s" % (ourPath, themeFile), "moksha/preview")
        except:
            edjeObj.file_set("%s/%s" % (ourPath, themeFile),
                             "e/desktop/background")

        edjeObj.show()

        listItem = self.themeList.item_append("%s" % themeFile,
                                              edjeObj,
                                              callback=self.themeSelected)
        listItem.data["filePath"] = "%s%s" % (ourPath, themeFile)
        listItem.selected_set(True)

        self.foundThemes.append("%s%s" % (ourPath, themeFile))

        self.themeSelected(None, listItem)

    def themeSelected(self, obj, item):
        #self.previewBox.clear()

        edjeObj = Edje(self.evas,
                       size_hint_weight=EXPAND_BOTH,
                       size_hint_align=FILL_BOTH)
        filePath = item.data["filePath"]

        try:
            edjeObj.file_set(filePath, "moksha/preview")
        except:
            edjeObj.file_set(filePath, "e/desktop/background")

        edjeObj.show()

        self.previewBox.content_set(edjeObj)
        self.currentPreview = edjeObj
        self.selectedTheme = filePath

    def fileSelected(self, fs, ourFile):
        self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)
        ourPath, themeFile = os.path.split(ourFile)
        if ourFile[-4:] == ".edj":
            shutil.copy2(ourFile, "%s/.e/e/themes" % UserHome)
            self.addTheme(themeFile, "%s/.e/e/themes/" % UserHome)
        else:
            errorPop = StandardPopup(
                self,
                "%s does not appear to be a valid theme file." % themeFile,
                'dialog-warning',
                size_hint_weight=EXPAND_BOTH)
            errorPop.show()

    def returnPressed(self, btn):
        self.parent.returnMain()

    def webPressed(self, btn):
        webbrowser.open(ThemeURL)
        try:
            os.wait()
        except:
            pass

    def gtkPressed(self, btn):
        pass

    def elmPressed(self, btn):
        pass

    def importPressed(self, btn):
        self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)

    def applyPressed(self, btn):
        #Accessing global data
        #print edje.file_data_get(themeFile, "gtk-theme")
        #The current selected theme path - self.selectedTheme

        #Dbus call to stop Moksha from fighting with our changes
        bus = dbus.SessionBus()
        obj = bus.get_object('org.enlightenment.wm.service',
                             '/org/enlightenment/wm/RemoteObject')
        iface = dbus.Interface(obj,
                               dbus_interface='org.enlightenment.wm.Config')
        iface.SaveBlock()

        #Update Moksha Theme
        #Get existing profile
        eProfileFile = neet.EETFile()
        eProfileFile.importFile("%s/.e/e/config/profile.cfg" % UserHome, "-x")
        eProfile = eProfileFile.readValue()

        #change to a tmp profile so we aren't writing to the one in memory
        #ecore.Exe("cp -a %s/.e/e/config/%s %s/.e/e/config/__tmpprofile"%(UserHome, eProfile, UserHome))
        #time.sleep(1)
        #ecore.Exe("enlightenment_remote -default-profile-set __tmpprofile")

        eCFG = neet.EETFile()
        eCFG.importFile("%s/.e/e/config/%s/e.cfg" % (UserHome, eProfile))
        ethemeData = eCFG.readValue(
            (("list", "themes"), ("item", "E_Config_Theme", "category",
                                  "theme"), ("value", "file")))

        ethemeData.data = self.selectedTheme
        #print ethemeData.data
        eCFG.saveData()

        #Update elm theme order
        #elmProfile = "standard" #same as eProfile - shouldn't just assume
        elmProfileFile = neet.EETFile()
        elmProfileFile.importFile(
            "%s/.elementary/config/profile.cfg" % UserHome, "-x")
        elmProfile = elmProfileFile.readValue()

        elmCFG = neet.EETFile()
        elmCFG.importFile("%s/.elementary/config/%s/base.cfg" %
                          (UserHome, elmProfile))

        themeData = elmCFG.readValue((("value", "theme"), ))

        themeName = edje.file_data_get(self.selectedTheme, "elm-theme")

        themeData.data = "%s:MokshaRadiance:default" % themeName

        elmCFG.saveData()

        #Swap back to our updated profile
        #ecore.Exe("enlightenment_remote -default-profile-set %s"%eProfile)

        #Remove the __tmpprofile
        #shutil.rmtree("%s/.e/e/config/__tmpprofile"%(UserHome))

        #Give Moksha control of the config data again
        iface.Load()
        iface.SaveRelease()

        #Restart to apply the new theme
        ecore.Exe("enlightenment_remote -restart")

        #Flush Elm settings
        elementary.Configuration.all_flush

    def shutDownFS(self, arg):
        self.fs.shutdown()
Exemple #6
0
class SwamiModule(Box):
    def __init__(self, rent):
        Box.__init__(self, rent)
        self.parent = rent

        self.name = "Wallpaper"
        self.section = "Appearance"
        self.searchData = ["wallpaper", "appearance", "look"]
        self.launchArg = "--wallpaper"
        self.button = None

        self.icon = Icon(self,
                         size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)
        #Use FDO icons -> http://standards.freedesktop.org/icon-naming-spec/latest/ar01s04.html
        self.icon.standard_set('wallpaper')
        self.icon.show()

        self.foundWalls = []

        self.currentPreview = None
        self.selectedWall = None

        self.flip = Flip(self,
                         size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)

        wallBox = Box(self.flip,
                      size_hint_weight=EXPAND_BOTH,
                      size_hint_align=FILL_BOTH)
        wallBox.horizontal_set(True)

        self.previewBox = previewBox = Scroller(wallBox,
                                                size_hint_weight=EXPAND_BOTH,
                                                size_hint_align=FILL_BOTH)
        previewBox.show()

        self.wallList = List(self,
                             size_hint_weight=(0.35, 1.0),
                             size_hint_align=FILL_BOTH,
                             mode=ELM_LIST_COMPRESS)
        #Adds walls in the WallPaths to the list for selection
        self.populateWalls()
        self.wallList.go()
        self.wallList.show()

        wallBox.pack_end(self.wallList)
        wallBox.pack_end(self.previewBox)
        wallBox.show()

        self.fs = fs = FileSelector(self,
                                    size_hint_weight=EXPAND_BOTH,
                                    size_hint_align=FILL_BOTH)
        fs.setMode("Open")
        fs.show()

        #need to do this to shutdown threading for the file selector
        self.parent.callback_delete_request_add(self.shutDownFS)

        fs.callback_activated_add(self.fileSelected)

        # Flip object has the file selector on one side
        #   and the GUI on the other
        self.flip.part_content_set("front", wallBox)
        self.flip.part_content_set("back", self.fs)
        self.flip.show()

        fs.callback_cancel_add(
            lambda o: self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS))

        #self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)

        self.mainBox = Box(self,
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)
        self.mainBox.pack_end(self.flip)
        self.mainBox.show()

        buttonBox = Box(self,
                        size_hint_weight=EXPAND_HORIZ,
                        size_hint_align=FILL_BOTH)
        buttonBox.horizontal = True

        buttonApply = StandardButton(self, "Apply Selected", "ok",
                                     self.applyPressed)
        buttonApply.show()

        buttonImport = StandardButton(self, "Import Wallpaper", "wallpaper",
                                      self.importPressed)
        buttonImport.show()

        buttonReturn = StandardButton(self, "Back", "go-previous",
                                      self.returnPressed)
        buttonReturn.show()

        buttonBox.pack_end(buttonApply)
        #buttonBox.pack_end(buttonWeb)
        buttonBox.pack_end(buttonImport)
        buttonBox.pack_end(buttonReturn)
        buttonBox.show()

        self.pack_end(self.mainBox)
        self.pack_end(buttonBox)

    def populateWalls(self):
        for ourPath in WallPaths:
            for k in os.walk(ourPath):
                for wallFile in k[2]:
                    self.addWall(wallFile, ourPath)

    def addWall(self, wallFile, ourPath):
        '''edjeObj = Edje(self.evas, size_hint_weight=EXPAND_BOTH, 
                        size_hint_align=FILL_BOTH)
        edjeObj.file_set("%s/%s"%(ourPath, wallFile), "e/desktop/background")
        edjeObj.show()'''

        listItem = self.wallList.item_append("%s" % wallFile,
                                             callback=self.wallSelected)
        listItem.data["filePath"] = "%s%s" % (ourPath, wallFile)
        listItem.selected_set(True)

        self.foundWalls.append("%s%s" % (ourPath, wallFile))

        self.wallSelected(None, listItem)

    def wallSelected(self, obj, item):
        #self.previewBox.clear()

        #edjeObj = Layout(self.previewBox, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)

        edjeObj = Edje(self.previewBox.evas,
                       size_hint_weight=EXPAND_BOTH,
                       size_hint_align=FILL_BOTH)

        filePath = item.data["filePath"]
        edjeObj.file_set(filePath, "e/desktop/background")
        edjeObj.show()

        self.previewBox.content_set(edjeObj)
        self.currentPreview = edjeObj
        self.selectedWall = filePath

    def fileSelected(self, fs, ourPath):
        self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)

        #move the file to temp dir / rename it so we can work around a issue with spaces in file names
        tmpCount = 1
        while os.path.isfile("/tmp/swamiwall_%s" % tmpCount):
            tmpCount += 1

        shutil.copy2(ourPath, '/tmp/swamiwall_%s' % tmpCount)

        time.sleep(1)

        ourFile = os.path.splitext(os.path.basename(ourPath))[0].replace(
            " ", "")

        ecore.Exe('convertimage.sh %s %s' %
                  ('/tmp/swamiwall_%s' % tmpCount, ourFile))

        time.sleep(1)
        self.addWall("%s.edj" % ourFile, "%s/.e/e/backgrounds/" % UserHome)

    def returnPressed(self, btn):
        self.parent.returnMain()

    def importPressed(self, btn):
        self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)

    def applyPressed(self, btn):
        #Dbus call to stop Moksha from fighting with our changes
        bus = dbus.SessionBus()
        obj = bus.get_object('org.enlightenment.wm.service',
                             '/org/enlightenment/wm/RemoteObject')
        iface = dbus.Interface(obj,
                               dbus_interface='org.enlightenment.wm.Config')
        iface.SaveBlock()

        #Update Moksha Theme
        #Get existing profile
        eProfileFile = neet.EETFile()
        eProfileFile.importFile("%s/.e/e/config/profile.cfg" % UserHome, "-x")
        eProfile = eProfileFile.readValue()

        eCFG = neet.EETFile()
        eCFG.importFile("%s/.e/e/config/%s/e.cfg" % (UserHome, eProfile))
        ewallData = eCFG.readValue((("value", "desktop_default_background"), ))

        ewallData.data = self.selectedWall
        #print ewallData
        eCFG.saveData()

        #Give Moksha control of the config data again
        iface.Load()
        iface.SaveRelease()

    def shutDownFS(self, arg):
        self.fs.shutdown()
Exemple #7
0
class Interface(object):
    def __init__(self):
        self.mainWindow = StandardWindow("epad", "Untitled - ePad",
                                         size=(600, 400))
        self.mainWindow.callback_delete_request_add(self.closeChecks)
        self.mainWindow.elm_event_callback_add(self.eventsCb)

        icon = Icon(self.mainWindow,
                    size_hint_weight=EXPAND_BOTH,
                    size_hint_align=FILL_BOTH)
        icon.standard_set('accessories-text-editor')
        icon.show()
        self.mainWindow.icon_object_set(icon.object_get())

        self.mainBox = Box(self.mainWindow,
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)
        self.mainBox.show()

        self.mainTb = ePadToolbar(self, self.mainWindow)
        self.mainTb.show()
        self.mainBox.pack_end(self.mainTb)

        # Initialize Text entry box
        print("Word wrap Initialized: {0}".format(self.wordwrap))
        self.entryInit()

        # Add label to show current cursor position
        if SHOW_POS:
            self.line_label = Label(self.mainWindow,
                                    size_hint_weight=EXPAND_HORIZ,
                                    size_hint_align=ALIGN_RIGHT)
            self.curChanged(self.mainEn, self.line_label)
            self.line_label.show()
            self.mainBox.pack_end(self.line_label)
            self.mainEn.callback_cursor_changed_add(self.curChanged,
                                                    self.line_label)

        # Build our file selector for saving/loading files
        self.fileBox = Box(self.mainWindow,
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)
        self.fileBox.show()

        self.fileLabel = Label(self.mainWindow,
                               size_hint_weight=EXPAND_HORIZ,
                               size_hint_align=FILL_BOTH, text="")
        self.fileLabel.show()

        self.fileSelector = Fileselector(self.mainWindow, is_save=False,
                                         expandable=False, folder_only=False,
                                         path=os.getenv("HOME"),
                                         size_hint_weight=EXPAND_BOTH,
                                         size_hint_align=FILL_BOTH)
        self.fileSelector.callback_done_add(self.fileSelected)
        self.fileSelector.show()

        self.fileBox.pack_end(self.fileLabel)
        self.fileBox.pack_end(self.fileSelector)

        # Flip object has the file selector on one side
        #   and the GUI on the other
        self.flip = Flip(self.mainWindow, size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)
        self.flip.part_content_set("front", self.mainBox)
        self.flip.part_content_set("back", self.fileBox)
        self.mainWindow.resize_object_add(self.flip)
        self.flip.show()

        self.isSaved = True
        self.isNewFile = False
        self.confirmPopup = None

    def entryInit(self):
        self.mainEn = Entry(self.mainWindow, scrollable=True,
                            line_wrap=self.wordwrap, autosave=False,
                            size_hint_weight=EXPAND_BOTH,
                            size_hint_align=FILL_BOTH)
        self.mainEn.callback_changed_user_add(self.textEdited)
        self.mainEn.elm_event_callback_add(self.eventsCb)
        # self.mainEn.markup_filter_append(self.textFilter)
        self.mainEn.show()
        self.mainBox.pack_end(self.mainEn)

    def curChanged(self, entry, label):
        # get linear index into current text
        index = entry.cursor_pos_get()
        # Replace <br /> tag with single char
        #   to simplify (line, col) calculation
        tmp_text = entry.entry_get().replace("<br/>", "\n")
        line = tmp_text[:index].count("\n") + 1
        col = len(tmp_text[:index].split("\n")[-1]) + 1
        # Update label text with line, col
        label.text = "Ln {0} Col {1} ".format(line, col)

    def textEdited(self, obj):
        current_file = self.mainEn.file[0]
        current_file = \
            os.path.basename(current_file) if \
            current_file and not self.isNewFile else \
            "Untitled"
        self.mainWindow.title = "*%s - ePad" % (current_file)
        self.isSaved = False

    def fileSelected(self, fs, file_selected, onStartup=False):
        if not onStartup:
            self.flip.go(ELM_FLIP_INTERACTION_ROTATE)
        print(file_selected)
        IsSave = fs.is_save_get()
        if file_selected:
            if IsSave:
                newfile = open(file_selected, 'w')
                tmp_text = self.mainEn.entry_get()
                newfile.write(tmp_text)
                newfile.close()
                self.mainEn.file_set(file_selected, ELM_TEXT_FORMAT_PLAIN_UTF8)
                self.mainEn.entry_set(tmp_text)
                self.mainEn.file_save()
                self.mainWindow.title_set("%s - ePad"
                                          % os.path.basename(file_selected))
                self.isSaved = True
                self.isNewFile = False
            else:
                try:
                    self.mainEn.file_set(file_selected,
                                         ELM_TEXT_FORMAT_PLAIN_UTF8)
                except RuntimeError:
                    print("Empty file: {0}".format(file_selected))
                self.mainWindow.title_set("%s - ePad"
                                          % os.path.basename(file_selected))

    def newFile(self, obj=None, ignoreSave=False):
        if self.isSaved is True or ignoreSave is True:
            trans = Transit()
            trans.object_add(self.mainEn)
            trans.auto_reverse = True

            trans.effect_wipe_add(
                ELM_TRANSIT_EFFECT_WIPE_TYPE_HIDE,
                ELM_TRANSIT_EFFECT_WIPE_DIR_RIGHT)

            trans.duration = 0.5
            trans.go()

            time.sleep(0.5)

            self.mainWindow.title_set("Untitled - ePad")
            self.mainEn.delete()
            self.entryInit()
            self.isNewFile = True
        elif self.confirmPopup is None:
            self.confirmSave(self.newFile)

    def openFile(self, obj=None, ignoreSave=False):
        if self.isSaved is True or ignoreSave is True:
            self.fileSelector.is_save_set(False)
            self.fileLabel.text = "<b>Select a text file to open:</b>"
            self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)
        elif self.confirmPopup is None:
            self.confirmSave(self.openFile)

    def confirmSave(self, ourCallback=None):
        self.confirmPopup = Popup(self.mainWindow,
                                  size_hint_weight=EXPAND_BOTH)
        self.confirmPopup.part_text_set("title,text", "File Unsaved")
        current_file = self.mainEn.file[0]
        current_file = \
            os.path.basename(current_file) if current_file else "Untitled"
        self.confirmPopup.text = "Save changes to '%s'?" % (current_file)
        # Close without saving button
        no_btt = Button(self.mainWindow)
        no_btt.text = "No"
        no_btt.callback_clicked_add(self.closePopup, self.confirmPopup)
        if ourCallback is not None:
            no_btt.callback_clicked_add(ourCallback, True)
        no_btt.show()
        # cancel close request
        cancel_btt = Button(self.mainWindow)
        cancel_btt.text = "Cancel"
        cancel_btt.callback_clicked_add(self.closePopup, self.confirmPopup)
        cancel_btt.show()
        # Save the file and then close button
        sav_btt = Button(self.mainWindow)
        sav_btt.text = "Yes"
        sav_btt.callback_clicked_add(self.saveFile)
        sav_btt.callback_clicked_add(self.closePopup, self.confirmPopup)
        sav_btt.show()

        # add buttons to popup
        self.confirmPopup.part_content_set("button1", no_btt)
        self.confirmPopup.part_content_set("button2", cancel_btt)
        self.confirmPopup.part_content_set("button3", sav_btt)
        self.confirmPopup.show()

    def saveAs(self):
        self.fileSelector.is_save_set(True)
        self.fileLabel.text = "<b>Save new file to where:</b>"
        self.flip.go(ELM_FLIP_ROTATE_XZ_CENTER_AXIS)

    def saveFile(self, obj=False):
        if self.mainEn.file_get()[0] is None or self.isNewFile:
            self.saveAs()
        else:
            self.mainEn.file_save()
            self.mainWindow.title_set("%s - ePad"
                                      % os.path.basename(self.mainEn.file[0]))
            self.isSaved = True

    def closeChecks(self, obj):
        print(self.isSaved)
        if self.isSaved is False and self.confirmPopup is None:
            self.confirmSave(self.closeApp)
        else:
            self.closeApp()

    def closePopup(self, bt, confirmPopup):
        self.confirmPopup.delete()
        self.confirmPopup = None

    def closeApp(self, obj=False, trash=False):
        elementary.exit()

    def eventsCb(self, obj, src, event_type, event):
        if event.modifier_is_set("Control"):
            if event.key.lower() == "n":
                self.newFile()
            elif event.key.lower() == "s" and event.modifier_is_set("Shift"):
                self.saveAs()
            elif event.key.lower() == "s":
                self.saveFile()
            elif event.key.lower() == "o":
                self.openFile()

    # Legacy hack no longer needed
    #  there was an issue in elementary entry where it would
    #  accept those character controls

    # def textFilter( self, obj, theText, data ):
    #    # Block ctrl+hot keys used in eventsCb
    #    #
    #    #             Ctrl O   Ctrl N   Ctrl S
    #    ctrl_block = [chr(14), chr(15), chr(19)]
    #    if theText in ctrl_block:
    #        return None
    #    else:
    #        return theText

    def launch(self, startingFile=False):
        if startingFile:
            self.fileSelected(self.fileSelector, startingFile, True)
        self.mainWindow.show()
Exemple #8
0
class MainWin(StandardWindow):
    def __init__(self, app):
        # create the main window
        StandardWindow.__init__(self,
                                "eepdater",
                                "eepDater - System Updater",
                                autodel=True,
                                size=(320, 320))
        self.callback_delete_request_add(lambda o: elementary.exit())
        self.app = app

        icon = Icon(self)
        icon.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND)
        icon.size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL)
        icon.standard_set('software-center')
        icon.show()
        self.icon_object_set(icon.object_get())

        # build the two main boxes
        self.mainBox = self.buildMainBox()
        self.loadBox = self.buildLoadBox()

        # build the information details inwin object
        self.buildDetailsWin()

        # the flip object has the load screen on one side and the GUI on the other
        self.flip = Flip(self,
                         size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)
        self.flip.part_content_set("front", self.mainBox)
        self.flip.part_content_set("back", self.loadBox)
        self.resize_object_add(self.flip)
        self.flip.show()

        # show the window
        self.show()

    def buildDetailsWin(self):
        self.updateText = Entry(self,
                                size_hint_weight=EXPAND_BOTH,
                                size_hint_align=FILL_BOTH)
        self.updateText.editable_set(False)
        self.updateText.scrollable_set(True)
        self.updateText.show()

        closebtn = Button(self)
        closebtn.text_set("Done")
        closebtn.callback_pressed_add(self.innerWinHide)
        closebtn.show()

        box = Box(self,
                  size_hint_weight=EXPAND_BOTH,
                  size_hint_align=FILL_BOTH)
        box.pack_end(self.updateText)
        box.pack_end(closebtn)
        box.show()

        self.innerWin = InnerWindow(self,
                                    size_hint_weight=EXPAND_BOTH,
                                    size_hint_align=FILL_HORIZ)
        self.innerWin.content_set(box)

    def innerWinShow(self, obj=False):
        self.innerWin.show()
        self.innerWin.activate()

    def innerWinHide(self, obj=False):
        self.innerWin.hide()

    def buildLoadBox(self):
        # build the load label
        loadLable = Label(self,
                          size_hint_weight=EXPAND_BOTH,
                          size_hint_align=FILL_HORIZ)
        loadLable.text = "<b>Processing</b>"
        loadLable.show()

        # build the spinning wheel
        wheel = Progressbar(self,
                            pulse_mode=True,
                            size_hint_weight=EXPAND_BOTH,
                            size_hint_align=FILL_HORIZ)
        wheel.pulse(True)
        wheel.show()

        detailsbtn = Button(self, style="anchor")
        detailsbtn.text_set("Details")
        detailsbtn.callback_pressed_add(self.innerWinShow)
        detailsbtn.show()

        # build the status label
        self.statusLabel = Label(self,
                                 size_hint_weight=EXPAND_BOTH,
                                 size_hint_align=FILL_HORIZ)
        self.statusLabel.show()

        # put all the built objects in a vertical box
        box = Box(self,
                  size_hint_weight=EXPAND_BOTH,
                  size_hint_align=FILL_BOTH)
        box.pack_end(loadLable)
        box.pack_end(wheel)
        box.pack_end(self.statusLabel)
        box.pack_end(detailsbtn)
        box.show()

        return box

    def buildMainBox(self):
        # build our toolbar
        self.mainTb = Toolbar(self,
                              homogeneous=False,
                              size_hint_weight=(0.0, 0.0),
                              size_hint_align=(EVAS_HINT_FILL, 0.0))
        self.mainTb.item_append("remove", "Clear", self.clearPressed)
        self.mainTb.item_append("system-run", "Select All",
                                self.selectAllPressed)
        self.mainTb.item_append("view-refresh", "Refresh", self.refreshPressed)
        self.mainTb.item_append("info", "Log", self.detailsPressed)
        self.mainTb.item_append("ok", "Apply", self.installUpdatesPressed)
        self.mainTb.show()

        # build our sortable list that displays packages that need updates
        titles = [("Upgrade", True), ("Package", True), ("Installed", True),
                  ("Available", True)]
        scr = Scroller(self,
                       size_hint_weight=EXPAND_BOTH,
                       size_hint_align=FILL_BOTH)
        self.packageList = sl.SortedList(scr,
                                         titles=titles,
                                         homogeneous=False,
                                         size_hint_weight=EXPAND_HORIZ)
        scr.content = self.packageList
        scr.show()

        # build the label that shows the package's description
        self.currentDescription = Label(self, size_hint_weight=FILL_BOTH)
        self.currentDescription.text = "Select a package for information"
        self.currentDescription.line_wrap_set(True)
        self.currentDescription.show()

        self.desFrame = Frame(self,
                              size_hint_weight=EXPAND_HORIZ,
                              size_hint_align=FILL_HORIZ)
        self.desFrame.text = "Description"
        self.desFrame.content = self.currentDescription
        self.desFrame.show()

        # add all of our objects to the box
        box = Box(self,
                  size_hint_weight=EXPAND_BOTH,
                  size_hint_align=FILL_BOTH)
        box.pack_end(self.mainTb)
        box.pack_end(scr)
        box.pack_end(self.desFrame)
        box.show()

        return box

    def detailsPressed(self, obj, it):
        it.selected = False
        self.innerWinShow()

    def clearPressed(self, obj, it):
        it.selected = False
        for rw in self.packageList.rows:
            rw[0].state = False
            self.app.checkChange(rw[0])

    def selectAllPressed(self, obj, it):
        it.selected = False
        for rw in self.packageList.rows:
            rw[0].state = True
            self.app.checkChange(rw[0])

    def refreshPressed(self, obj, it):
        it.selected = False
        self.app.refreshPackages()

    def installUpdatesPressed(self, obj, it):
        it.selected = False
        self.app.installUpdates()

    def packagePressed(self, obj):
        self.desFrame.text = "Description - %s" % obj.text
        self.currentDescription.text = obj.data["packageDes"]

    def addPackage(self, pak):
        row = []

        ourCheck = Check(self)
        ourCheck.data['packageName'] = pak.name
        ourCheck.callback_changed_add(self.app.checkChange)
        ourCheck.show()
        row.append(ourCheck)

        ourName = Button(self,
                         style="anchor",
                         size_hint_weight=EXPAND_HORIZ,
                         size_hint_align=FILL_HORIZ)
        ourName.text = pak.name
        ourName.data["packageDes"] = pak.candidate.description
        ourName.callback_pressed_add(self.packagePressed)
        ourName.show()
        row.append(ourName)

        ourVersion = Label(self,
                           size_hint_weight=EXPAND_HORIZ,
                           size_hint_align=(0.1, 0.5))
        ourVersion.text = pak.installed.version
        ourVersion.show()
        row.append(ourVersion)

        newVersion = Label(self,
                           size_hint_weight=EXPAND_HORIZ,
                           size_hint_align=(0.1, 0.5))
        newVersion.text = pak.candidate.version
        newVersion.show()
        row.append(newVersion)

        self.app.packagesToUpdate[pak.name] = {
            'check': ourCheck,
            'selected': False
        }
        self.packageList.row_pack(row, sort=False)

    def showDialog(self, title, msg):
        dia = Popup(self)
        dia.part_text_set("title,text", title)
        dia.part_text_set("default", msg)

        bt = Button(dia, text="Ok")
        bt.callback_clicked_add(lambda b: dia.delete())
        dia.part_content_set("button1", bt)

        dia.show()
Exemple #9
0
class SwamiModule(Box):
    def __init__(self, rent):
        Box.__init__(self, rent)
        self.parent = rent
        
        self.name = "Date and Time"
        self.section = "System Settings"
        self.searchData = ["clock", "timezone", "date", "system"]
        self.launchArg = "--time"
        self.button = None
        
        self.timezones = getTimeZones()
        
        self.icon = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        #Use FDO icons -> http://standards.freedesktop.org/icon-naming-spec/latest/ar01s04.html
        self.icon.standard_set('clock')
        self.icon.show()
        
        cframe = Frame(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        cframe.text = "Current Time"
        cframe.show()

        self.clock = clock = Clock(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        clock.show_seconds_set(True)
        clock.show_am_pm_set(True)
        clock.show()
        
        cframe.content = clock
        
        dframe = Frame(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        dframe.text = "Current Day"
        dframe.show()

        self.cal = cal = Calendar(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        cal.select_mode = ELM_CALENDAR_SELECT_MODE_NONE
        cal.show()
        
        dframe.content = cal
        
        tzframe = Frame(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        tzframe.text = "Current Timezone"
        tzframe.show()

        self.tz = tz = Label(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        tz.text = "<b>%s</b>"%time.tzname[0]
        tz.show()
        
        tzframe.content = tz
        
        self.mainBox = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        self.mainBox.pack_end(cframe)
        self.mainBox.pack_end(dframe)
        self.mainBox.pack_end(tzframe)
        self.mainBox.show()
        
        self.zoneList = zoneList = SearchableList(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        zoneList.callback_item_focused_add(self.enableTZSelect)
        self.zones = []
        for tz in self.timezones:
            for each in self.timezones[tz]:
                if each not in self.zones:
                    self.zones.append(each)
        self.zones.sort(reverse=True)
        for zone in self.zones:
            zoneList.item_append(zone)
        zoneList.show()
        
        self.buttonTZSelect = buttonTZSelect = StandardButton(self, "Select", "ok", self.tzselectPressed)
        buttonTZSelect.disabled = True
        buttonTZSelect.show()
        
        buttonTZCancel = StandardButton(self, "Cancel", "close", self.tzcancelPressed)
        buttonTZCancel.show()
        
        tzBBox = Box(self, size_hint_weight = EXPAND_HORIZ, size_hint_align = FILL_BOTH)
        tzBBox.horizontal = True
        tzBBox.pack_end(buttonTZSelect)
        tzBBox.pack_end(buttonTZCancel)
        tzBBox.show()

        tzChangeBox = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        tzChangeBox.pack_end(zoneList)
        tzChangeBox.pack_end(tzBBox)
        tzChangeBox.show()
        
        self.flip = Flip(self, size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)
        self.flip.part_content_set("front", self.mainBox)
        self.flip.part_content_set("back", tzChangeBox)
        self.flip.show()
        
        buttonBox = Box(self, size_hint_weight = EXPAND_HORIZ, size_hint_align = FILL_BOTH)
        buttonBox.horizontal = True
        
        self.buttonApply = buttonApply = StandardButton(self, "Apply Changes", "ok", self.applyPressed)
        buttonApply.disabled = True
        buttonApply.show()
        
        self.buttonSync = buttonSync = StandardButton(self, "Sync from Internet", "refresh", self.syncPressed)
        buttonSync.show()
        
        self.buttonDT = buttonDT = StandardButton(self, "Edit Date and Time", "x-office-calendar", self.editDTPressed)
        buttonDT.show()
        
        self.buttonTZ = buttonTZ = StandardButton(self, "Change Timezone", "clock", self.editTZPressed)
        buttonTZ.show()
        
        buttonReturn = StandardButton(self, "Back", "go-previous", self.returnPressed)
        buttonReturn.show()
        
        buttonBox.pack_end(buttonApply)
        buttonBox.pack_end(buttonSync)
        buttonBox.pack_end(buttonDT)
        buttonBox.pack_end(buttonTZ)
        buttonBox.pack_end(buttonReturn)
        buttonBox.show()
        
        self.pack_end(self.flip)
        self.pack_end(buttonBox)
        
    def returnPressed(self, btn):
        self.parent.returnMain()
    
    def applyPressed(self, btn):
        self.changeTime()
        self.cal.select_mode = ELM_CALENDAR_SELECT_MODE_NONE
        
        self.clock.edit_set(False)
        self.buttonApply.disabled = True
    
    def syncPressed(self, btn):
        self.runCommand('ntpdate pool.ntp.org')
    
    def editTZPressed(self, btn):
        self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)
        self.buttonSync.disabled = True
        self.buttonDT.disabled = True
        self.buttonTZ.disabled = True
    
    def editDTPressed(self, btn):
        self.buttonApply.disabled = False
        self.cal.select_mode = ELM_CALENDAR_SELECT_MODE_ONDEMAND
        self.clock.edit_set(True)
    
    def tzselectPressed(self, btn):
        self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)
        self.buttonSync.disabled = False
        self.buttonDT.disabled = False
        self.buttonTZ.disabled = False
        
        selectedZone = self.zoneList.selected_item_get().text
        
        self.runCommand('changetz.sh %s'%selectedZone)
        self.tz.text = "<b>%s</b>"%selectedZone
    
    def tzcancelPressed(self, btn):
        self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)
        self.buttonSync.disabled = False
        self.buttonDT.disabled = False
        self.buttonTZ.disabled = False
    
    def enableTZSelect(self, lst, item):
        self.buttonTZSelect.disabled = False
    
    def changeTime(self):
        #print "In the change time function"
        times = list(self.clock.time_get())
        for x in times:
            if x < 10:
                times[times.index(x)] = "0%s"%x
        if not self.cal.selected_time:
            self.cal.selected_time = dt.date.today()
        self.runCommand('changetime.sh %s %s %s %s'%(self.cal.selected_time, times[0], times[1], times[2]))
    
    def runCommand(self, ourCommand):
        cmd = esudo.eSudo(ourCommand, self.parent)
Exemple #10
0
def flip_interactive_clicked(obj, item=None):
    win = StandardWindow("flip", "Flip", autodel=True, size=(320, 320))

    box = Box(win, size_hint_weight=EXPAND_BOTH)
    win.resize_object_add(box)
    box.show()

    # flip object
    fl = Flip(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH,
        interaction=ELM_FLIP_INTERACTION_NONE)
    fl.interaction_direction_enabled_set(ELM_FLIP_DIRECTION_UP, True)
    fl.interaction_direction_enabled_set(ELM_FLIP_DIRECTION_DOWN, True)
    fl.interaction_direction_enabled_set(ELM_FLIP_DIRECTION_LEFT, True)
    fl.interaction_direction_enabled_set(ELM_FLIP_DIRECTION_RIGHT, True)
    fl.interaction_direction_hitsize_set(ELM_FLIP_DIRECTION_UP, 0.25)
    fl.interaction_direction_hitsize_set(ELM_FLIP_DIRECTION_DOWN, 0.25)
    fl.interaction_direction_hitsize_set(ELM_FLIP_DIRECTION_LEFT, 0.25)
    fl.interaction_direction_hitsize_set(ELM_FLIP_DIRECTION_RIGHT, 0.25)
    fl.callback_animate_begin_add(my_flip_animate_begin)
    fl.callback_animate_done_add(my_flip_animate_done)
    box.pack_end(fl)
    fl.show()

    # front content (image)
    o = Background(win, size_hint_weight=EXPAND_BOTH,
        file=os.path.join(img_path, "sky_01.jpg"))
    fl.part_content_set("front", o)
    o.show()

    # back content (layout)
    ly = Layout(win, size_hint_weight=EXPAND_BOTH,
        file=(os.path.join(script_path, "test.edj"), "layout"))
    fl.part_content_set("back", ly)
    ly.show()

    bt = Button(win, text="Button 1")
    ly.part_content_set("element1", bt)
    bt.show()

    bt = Button(win, text="Button 2")
    ly.part_content_set("element2", bt)
    bt.show()

    bt = Button(win, text="Button 3")
    ly.part_content_set("element3", bt)
    bt.show()


    # radio buttons
    rd = Radio(win, state_value=ELM_FLIP_INTERACTION_NONE, text="None")
    rd.callback_changed_add(my_cb_radios, fl)
    box.pack_end(rd)
    rd.show()
    rdg = rd

    rd = Radio(win, state_value=ELM_FLIP_INTERACTION_ROTATE, text="Rotate")
    rd.callback_changed_add(my_cb_radios, fl)
    rd.group_add(rdg)
    box.pack_end(rd)
    rd.show()

    rd = Radio(win, state_value=ELM_FLIP_INTERACTION_CUBE, text="Cube")
    rd.callback_changed_add(my_cb_radios, fl)
    rd.group_add(rdg)
    box.pack_end(rd)
    rd.show()

    rd = Radio(win, state_value=ELM_FLIP_INTERACTION_PAGE, text="Page")
    rd.callback_changed_add(my_cb_radios, fl)
    rd.group_add(rdg)
    box.pack_end(rd)
    rd.show()

    # window show
    win.show()
Exemple #11
0
def flip_clicked(obj, item=None):
    win = StandardWindow("flip", "Flip", autodel=True, size=(320, 320))

    box = Box(win, size_hint_weight=EXPAND_BOTH)
    win.resize_object_add(box)
    box.show()

    fl = Flip(win, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
    fl.callback_animate_begin_add(my_flip_animate_begin)
    fl.callback_animate_done_add(my_flip_animate_done)
    box.pack_end(fl)
    fl.show()

    # flip front content
    o = Background(win, size_hint_weight=EXPAND_BOTH,
        file=os.path.join(img_path, "sky_01.jpg"))
    fl.part_content_set("front", o)
    o.show()

    # flip back content
    ly = Layout(win, file=(os.path.join(script_path, "test.edj"), "layout"),
        size_hint_weight=EXPAND_BOTH)
    fl.part_content_set("back", ly)
    ly.show()

    bt = Button(win, text="Button 1")
    ly.part_content_set("element1", bt)
    bt.show()

    bt = Button(win, text="Button 2")
    ly.part_content_set("element2", bt)
    bt.show()

    bt = Button(win, text="Button 3")
    ly.part_content_set("element3", bt)
    bt.show()

    # flip buttons (first row)
    hbox = Box(win, size_hint_weight=EXPAND_HORIZ,
        size_hint_align=(EVAS_HINT_FILL, 0.0), horizontal=True)
    hbox.show()
    box.pack_end(hbox)
    count = 1

    for mode in [ELM_FLIP_ROTATE_X_CENTER_AXIS,
                 ELM_FLIP_ROTATE_Y_CENTER_AXIS,
                 ELM_FLIP_ROTATE_XZ_CENTER_AXIS,
                 ELM_FLIP_ROTATE_YZ_CENTER_AXIS]:
        bt = Button(win, size_hint_weight=EXPAND_BOTH,
            size_hint_align=FILL_BOTH, text=str(count))
        bt.callback_clicked_add(my_flip_go, fl, mode)
        hbox.pack_end(bt)
        bt.show()
        count += 1

    # flip buttons (second row)
    hbox = Box(win, size_hint_weight=EXPAND_HORIZ,
        size_hint_align=(EVAS_HINT_FILL, 0.0), horizontal=True)
    hbox.show()
    box.pack_end(hbox)

    for mode in [ELM_FLIP_CUBE_LEFT,
                 ELM_FLIP_CUBE_RIGHT,
                 ELM_FLIP_CUBE_UP,
                 ELM_FLIP_CUBE_DOWN]:
        bt = Button(win, size_hint_weight=EXPAND_BOTH,
            size_hint_align=FILL_BOTH, text=str(count))
        bt.callback_clicked_add(my_flip_go, fl, mode)
        hbox.pack_end(bt)
        bt.show()
        count += 1

    # flip buttons (third row)
    hbox = Box(win, size_hint_weight=EXPAND_HORIZ,
        size_hint_align=(EVAS_HINT_FILL, 0.0), horizontal=True)
    hbox.show()
    box.pack_end(hbox)

    for mode in [ELM_FLIP_PAGE_LEFT,
                 ELM_FLIP_PAGE_RIGHT,
                 ELM_FLIP_PAGE_UP,
                 ELM_FLIP_PAGE_DOWN]:
        bt = Button(win, size_hint_weight=EXPAND_BOTH,
            size_hint_align=FILL_BOTH, text=str(count))
        bt.callback_clicked_add(my_flip_go, fl, mode)
        hbox.pack_end(bt)
        bt.show()
        count += 1

    win.show()
class SwamiModule(Box):
    def __init__(self, rent):
        Box.__init__(self, rent)
        self.parent = rent
        
        self.name = "Theme Selector"
        self.section = "Appearance"
        self.searchData = ["theme", "gtk", "elementary", "elm", "gnome",
                    "appearance", "look"]
        self.launchArg = "--theme"
        self.button = None
        
        self.icon = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        self.icon.standard_set('preferences-desktop-theme')
        self.icon.show()
        
        self.foundThemes = []
        
        self.currentPreview = None
        self.selectedTheme = None
        
        self.previewBox = previewBox = Scroller(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        previewBox.show()
        
        self.themeList = List(self, size_hint_weight=(0.35, 1.0), 
                    size_hint_align=FILL_BOTH, mode=ELM_LIST_COMPRESS)
        #Adds themes in the ThemePaths to the list for selection
        self.populateThemes()
        self.themeList.go()
        self.themeList.show()
        
        themeBox = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        themeBox.horizontal_set(True)
        themeBox.pack_end(self.themeList)
        themeBox.pack_end(self.previewBox)
        themeBox.show()
        
        self.fs = fs = FileSelector(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        fs.setMode("Open")
        fs.show()

        #need to do this to shutdown threading for the file selector
        self.parent.callback_delete_request_add(self.shutDownFS)
        
        fs.callback_activated_add(self.fileSelected)
        
        # Flip object has the file selector on one side
        #   and the GUI on the other
        self.flip = Flip(self, size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)
        self.flip.part_content_set("front", themeBox)
        self.flip.part_content_set("back", self.fs)
        self.flip.show()
        
        fs.callback_cancel_add(lambda o: self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS))
        
        #self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)
        
        self.mainBox = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        self.mainBox.pack_end(self.flip)
        self.mainBox.show()
        
        buttonBox = Box(self, size_hint_weight = EXPAND_HORIZ, size_hint_align = FILL_BOTH)
        buttonBox.horizontal = True
        
        buttonApply = StandardButton(self, "Apply Selected", "ok", self.applyPressed)
        buttonApply.show()
        
        buttonWeb = StandardButton(self, "Get Themes", "applications-internet", self.webPressed)
        buttonWeb.show()
        
        #buttonGTK = StandardButton(self, "GTK Theme", "preferences-desktop-gnome", self.gtkPressed)
        #buttonGTK.show()
        
        #buttonElm = StandardButton(self, "Elementary Theme", "", self.elmPressed)
        #buttonElm.show()
        
        buttonImport = StandardButton(self, "Import Theme", "preferences-desktop-theme", self.importPressed)
        buttonImport.show()
        
        buttonReturn = StandardButton(self, "Back", "go-previous", self.returnPressed)
        buttonReturn.show()
        
        buttonBox.pack_end(buttonApply)
        buttonBox.pack_end(buttonWeb)
        #buttonBox.pack_end(buttonGTK)
        #buttonBox.pack_end(buttonElm)
        buttonBox.pack_end(buttonImport)
        buttonBox.pack_end(buttonReturn)
        buttonBox.show()
        
        self.pack_end(self.mainBox)
        self.pack_end(buttonBox)
    
    def populateThemes(self):
        for ourPath in ThemePaths:
            for k in os.walk(ourPath):
                for themeFile in k[2]:
                    self.addTheme(themeFile, ourPath)
    
    def addTheme(self, themeFile, ourPath):
        edjeObj = Edje(self.evas, size_hint_weight=EXPAND_BOTH, 
                        size_hint_align=FILL_BOTH)
        
        try:
            edjeObj.file_set("%s/%s"%(ourPath, themeFile), "moksha/preview")
        except:
            edjeObj.file_set("%s/%s"%(ourPath, themeFile), "e/desktop/background")
        
        edjeObj.show()
        
        listItem = self.themeList.item_append("%s"%themeFile, edjeObj, callback=self.themeSelected)
        listItem.data["filePath"] = "%s%s"%(ourPath, themeFile)
        listItem.selected_set(True)
        
        self.foundThemes.append("%s%s"%(ourPath, themeFile))
        
        self.themeSelected(None, listItem)
    
    def themeSelected(self, obj, item):
        #self.previewBox.clear()
        
        edjeObj = Edje(self.evas, size_hint_weight=EXPAND_BOTH, 
                size_hint_align=FILL_BOTH)
        filePath = item.data["filePath"]
        
        try:
            edjeObj.file_set(filePath, "moksha/preview")
        except:
            edjeObj.file_set(filePath, "e/desktop/background")
        
        edjeObj.show()
        
        self.previewBox.content_set(edjeObj)
        self.currentPreview = edjeObj
        self.selectedTheme = filePath
    
    def fileSelected(self, fs, ourFile):
        self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)
        ourPath, themeFile = os.path.split(ourFile)
        if ourFile[-4:] == ".edj":
            shutil.copy2(ourFile, "%s/.e/e/themes"%UserHome)
            self.addTheme(themeFile, "%s/.e/e/themes/"%UserHome)
        else:
            errorPop = StandardPopup(self, "%s does not appear to be a valid theme file."%themeFile, 'dialog-warning', size_hint_weight=EXPAND_BOTH)
            errorPop.show()
    
    def returnPressed(self, btn):
        self.parent.returnMain()
    
    def webPressed(self, btn):
        webbrowser.open(ThemeURL)
        try:
            os.wait()
        except:
            pass
    
    def gtkPressed(self, btn):
        pass
    
    def elmPressed(self, btn):
        pass
    
    def importPressed(self, btn):
        self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)
    
    def applyPressed(self, btn):
        #Accessing global data
        #print edje.file_data_get(themeFile, "gtk-theme")
        #The current selected theme path - self.selectedTheme
        
        #Dbus call to stop Moksha from fighting with our changes
        bus = dbus.SessionBus()
        obj = bus.get_object('org.enlightenment.wm.service', '/org/enlightenment/wm/RemoteObject')
        iface = dbus.Interface(obj, dbus_interface='org.enlightenment.wm.Config')
        iface.SaveBlock()
        
        #Update Moksha Theme
        #Get existing profile
        eProfileFile = neet.EETFile()
        eProfileFile.importFile("%s/.e/e/config/profile.cfg"%UserHome, "-x")
        eProfile = eProfileFile.readValue()
        
        #change to a tmp profile so we aren't writing to the one in memory
        #ecore.Exe("cp -a %s/.e/e/config/%s %s/.e/e/config/__tmpprofile"%(UserHome, eProfile, UserHome))
        #time.sleep(1)
        #ecore.Exe("enlightenment_remote -default-profile-set __tmpprofile")
        
        eCFG = neet.EETFile()
        eCFG.importFile("%s/.e/e/config/%s/e.cfg"%(UserHome, eProfile))
        ethemeData = eCFG.readValue((("list", "themes"), ("item", "E_Config_Theme",  "category" , "theme"), ("value", "file")))
        
        ethemeData.data = self.selectedTheme
        #print ethemeData.data
        eCFG.saveData()
        
        #Update elm theme order
        #elmProfile = "standard" #same as eProfile - shouldn't just assume
        elmProfileFile = neet.EETFile()
        elmProfileFile.importFile("%s/.elementary/config/profile.cfg"%UserHome, "-x")
        elmProfile = elmProfileFile.readValue()
        
        elmCFG = neet.EETFile()
        elmCFG.importFile("%s/.elementary/config/%s/base.cfg"%(UserHome, elmProfile))
        
        themeData = elmCFG.readValue((("value", "theme"),))
        
        themeName = edje.file_data_get(self.selectedTheme, "elm-theme")
        
        themeData.data = "%s:MokshaRadiance:default"%themeName
        
        elmCFG.saveData()
        
        #Swap back to our updated profile
        #ecore.Exe("enlightenment_remote -default-profile-set %s"%eProfile)
        
        #Remove the __tmpprofile
        #shutil.rmtree("%s/.e/e/config/__tmpprofile"%(UserHome))
        
        #Give Moksha control of the config data again
        iface.Load()
        iface.SaveRelease()
        
        #Restart to apply the new theme
        ecore.Exe("enlightenment_remote -restart")
        
        #Flush Elm settings
        elementary.Configuration.all_flush
        
    def shutDownFS(self, arg):
        self.fs.shutdown()
Exemple #13
0
class Interface(object):
    def __init__(self):
        self.mainWindow = StandardWindow("epad",
                                         "Untitled - ePad",
                                         size=(600, 400))
        self.mainWindow.callback_delete_request_add(self.closeChecks)
        self.mainWindow.elm_event_callback_add(self.eventsCb)

        icon = Icon(self.mainWindow)
        icon.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND)
        icon.size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL)
        icon.standard_set(
            'accessories-text-editor'
        )  # assumes image icon is in local dir, may need to change later
        icon.show()
        self.mainWindow.icon_object_set(icon.object_get())

        self.mainBox = Box(self.mainWindow,
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)
        self.mainBox.show()

        self.mainTb = Toolbar(self.mainWindow,
                              homogeneous=False,
                              size_hint_weight=(0.0, 0.0),
                              size_hint_align=(EVAS_HINT_FILL, 0.0))
        self.mainTb.menu_parent = self.mainWindow

        self.mainTb.item_append("document-new", "New", self.newPress)
        self.mainTb.item_append("document-open", "Open", self.openPress)
        self.mainTb.item_append("document-save", "Save", self.savePress)
        self.mainTb.item_append("document-save-as", "Save As",
                                self.saveAsPress)
        # -- Edit Dropdown Menu --
        tb_it = self.mainTb.item_append("edit", "Edit")
        tb_it.menu = True
        menu = tb_it.menu
        menu.item_add(None, "Copy", "edit-copy", self.copyPress)
        menu.item_add(None, "Paste", "edit-paste", self.pastePress)
        menu.item_add(None, "Cut", "edit-cut", self.cutPress)
        menu.item_separator_add()
        menu.item_add(None, "Select All", "edit-select-all",
                      self.selectAllPress)
        # -----------------------
        # self.mainTb.item_append("settings", "Options", self.optionsPress)
        self.mainTb.item_append("dialog-information", "About", self.aboutPress)

        self.mainEn = Entry(self.mainWindow,
                            size_hint_weight=EXPAND_BOTH,
                            size_hint_align=FILL_BOTH)
        self.mainEn.callback_changed_user_add(self.textEdited)
        self.mainEn.scrollable_set(
            True)  # creates scrollbars rather than enlarge window
        self.mainEn.line_wrap_set(
            False)  # does not allow line wrap (can be changed by user)
        self.mainEn.autosave_set(False)  # set to false to reduce disk I/O
        self.mainEn.elm_event_callback_add(self.eventsCb)
        self.mainEn.markup_filter_append(self.textFilter)
        self.mainEn.show()

        self.mainTb.show()

        self.mainBox.pack_end(self.mainTb)
        self.mainBox.pack_end(self.mainEn)

        #Build our file selector for saving/loading files
        self.fileBox = Box(self.mainWindow,
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)
        self.fileBox.show()

        self.fileLabel = Label(self.mainWindow,
                               size_hint_weight=EXPAND_HORIZ,
                               size_hint_align=FILL_BOTH)
        self.fileLabel.text = ""
        self.fileLabel.show()

        self.fileSelector = Fileselector(self.mainWindow,
                                         is_save=False,
                                         expandable=False,
                                         folder_only=False,
                                         path=os.getenv("HOME"),
                                         size_hint_weight=EXPAND_BOTH,
                                         size_hint_align=FILL_BOTH)
        self.fileSelector.callback_done_add(self.fileSelected)
        #self.fileSelector.callback_selected_add(fs_cb_selected, win)
        #self.fileSelector.callback_directory_open_add(fs_cb_directory_open, win)
        self.fileSelector.show()

        self.fileBox.pack_end(self.fileLabel)
        self.fileBox.pack_end(self.fileSelector)

        # the flip object has the file selector on one side and the GUI on the other
        self.flip = Flip(self.mainWindow,
                         size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)
        self.flip.part_content_set("front", self.mainBox)
        self.flip.part_content_set("back", self.fileBox)
        self.mainWindow.resize_object_add(self.flip)
        self.flip.show()

        self.isSaved = True
        self.isNewFile = False
        self.confirmPopup = None

    def newPress(self, obj, it):
        self.newFile()
        it.selected_set(False)

    def openPress(self, obj, it):
        self.openFile()
        it.selected_set(False)

    def savePress(self, obj, it):
        self.saveFile()
        it.selected_set(False)

    def saveAsPress(self, obj, it):
        self.saveAs()
        it.selected_set(False)

    def optionsPress(self, obj, it):
        it.selected_set(False)

    def copyPress(self, obj, it):
        self.mainEn.selection_copy()
        it.selected_set(False)

    def pastePress(self, obj, it):
        self.mainEn.selection_paste()
        it.selected_set(False)

    def cutPress(self, obj, it):
        self.mainEn.selection_cut()
        it.selected_set(False)

    def selectAllPress(self, obj, it):
        self.mainEn.select_all()
        it.selected_set(False)

    def textEdited(self, obj):
        ourFile = self.mainEn.file_get()[0]
        if ourFile and not self.isNewFile:
            self.mainWindow.title_set(
                "*%s - ePad" % self.mainEn.file_get()[0].split("/")[
                    len(self.mainEn.file_get()[0].split("/")) - 1])
        else:
            self.mainWindow.title_set("*Untitlted - ePad")
        self.isSaved = False

    def fileSelected(self, fs, file_selected, onStartup=False):
        if not onStartup:
            self.flip.go(ELM_FLIP_INTERACTION_ROTATE)
        print(file_selected)
        IsSave = fs.is_save_get()
        if file_selected:
            if IsSave:
                newfile = open(file_selected, 'w')  # creates new file
                tmp_text = self.mainEn.entry_get()
                newfile.write(tmp_text)
                newfile.close()
                self.mainEn.file_set(file_selected, ELM_TEXT_FORMAT_PLAIN_UTF8)
                self.mainEn.entry_set(tmp_text)
                self.mainEn.file_save()
                self.mainWindow.title_set(
                    "%s - ePad" %
                    file_selected.split("/")[len(file_selected.split("/")) -
                                             1])
                self.isSaved = True
                self.isNewFile = False
            else:
                try:
                    self.mainEn.file_set(file_selected,
                                         ELM_TEXT_FORMAT_PLAIN_UTF8)
                except RuntimeError:
                    print("Empty file: {0}".format(file_selected))
                self.mainWindow.title_set(
                    "%s - ePad" %
                    file_selected.split("/")[len(file_selected.split("/")) -
                                             1])

    def aboutPress(self, obj, it):
        #About popup
        self.popupAbout = Popup(self.mainWindow, size_hint_weight=EXPAND_BOTH)
        self.popupAbout.text = "ePad - A simple text editor written in python and elementary<br><br> " \
                     "By: Jeff Hoogland"
        bt = Button(self.mainWindow, text="Done")
        bt.callback_clicked_add(self.aboutClose)
        self.popupAbout.part_content_set("button1", bt)
        self.popupAbout.show()
        it.selected_set(False)

    def aboutClose(self, bt):
        self.popupAbout.delete()

    def newFile(self, obj=None, ignoreSave=False):
        if self.isSaved == True or ignoreSave == True:
            trans = Transit()
            trans.object_add(self.mainEn)
            trans.auto_reverse = True

            trans.effect_wipe_add(ELM_TRANSIT_EFFECT_WIPE_TYPE_HIDE,
                                  ELM_TRANSIT_EFFECT_WIPE_DIR_RIGHT)

            trans.duration = 0.5
            trans.go()

            time.sleep(0.5)

            self.mainWindow.title_set("Untitlted - ePad")
            self.mainEn.delete()
            self.mainEn = Entry(self.mainWindow,
                                size_hint_weight=EXPAND_BOTH,
                                size_hint_align=FILL_BOTH)
            self.mainEn.callback_changed_user_add(self.textEdited)
            self.mainEn.scrollable_set(
                True)  # creates scrollbars rather than enlarge window
            self.mainEn.line_wrap_set(
                False)  # does not allow line wrap (can be changed by user)
            self.mainEn.autosave_set(False)  # set to false to reduce disk I/O
            self.mainEn.elm_event_callback_add(self.eventsCb)
            self.mainEn.markup_filter_append(self.textFilter)
            self.mainEn.show()

            self.mainBox.pack_end(self.mainEn)

            self.isNewFile = True
        elif self.confirmPopup == None:
            self.confirmSave(self.newFile)

    def openFile(self, obj=None, ignoreSave=False):
        if self.isSaved == True or ignoreSave == True:
            self.fileSelector.is_save_set(False)
            self.fileLabel.text = "<b>Select a text file to open:</b>"
            self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)
        elif self.confirmPopup == None:
            self.confirmSave(self.openFile)

    def confirmSave(self, ourCallback=None):
        self.confirmPopup = Popup(self.mainWindow,
                                  size_hint_weight=EXPAND_BOTH)
        self.confirmPopup.part_text_set("title,text", "File Unsaved")
        if self.mainEn.file_get()[0]:
            self.confirmPopup.text = "Save changes to '%s'?" % self.mainEn.file_get(
            )[0].split("/")[len(self.mainEn.file_get()[0].split("/")) - 1]
        else:
            self.confirmPopup.text = "Save changes to 'Untitlted'?"
        # Close without saving button
        no_btt = Button(self.mainWindow)
        no_btt.text = "No"
        no_btt.callback_clicked_add(self.closePopup, self.confirmPopup)
        if ourCallback is not None:
            no_btt.callback_clicked_add(ourCallback, True)
        no_btt.show()
        # cancel close request
        cancel_btt = Button(self.mainWindow)
        cancel_btt.text = "Cancel"
        cancel_btt.callback_clicked_add(self.closePopup, self.confirmPopup)
        cancel_btt.show()
        # Save the file and then close button
        sav_btt = Button(self.mainWindow)
        sav_btt.text = "Yes"
        sav_btt.callback_clicked_add(self.saveFile)
        sav_btt.callback_clicked_add(self.closePopup, self.confirmPopup)
        sav_btt.show()

        # add buttons to popup
        self.confirmPopup.part_content_set("button1", no_btt)
        self.confirmPopup.part_content_set("button2", cancel_btt)
        self.confirmPopup.part_content_set("button3", sav_btt)
        self.confirmPopup.show()

    def saveAs(self):
        self.fileSelector.is_save_set(True)
        self.fileLabel.text = "<b>Save new file to where:</b>"
        self.flip.go(ELM_FLIP_ROTATE_XZ_CENTER_AXIS)

    def saveFile(self, obj=False):
        if self.mainEn.file_get()[0] == None or self.isNewFile:
            self.saveAs()
        else:
            self.mainEn.file_save()
            self.mainWindow.title_set(
                "%s - ePad" % self.mainEn.file_get()[0].split("/")[
                    len(self.mainEn.file_get()[0].split("/")) - 1])
            self.isSaved = True

    def closeChecks(self, obj):
        print(self.isSaved)
        if self.isSaved == False and self.confirmPopup == None:
            self.confirmSave(self.closeApp)
        else:
            self.closeApp()

    def closePopup(self, bt, confirmPopup):
        self.confirmPopup.delete()
        self.confirmPopup = None

    def closeApp(self, obj=False, trash=False):
        elementary.exit()

    def eventsCb(self, obj, src, event_type, event):
        #print event_type
        #print event.key
        #print "Control Key Status: %s" %event.modifier_is_set("Control")
        #print "Shift Key Status: %s" %event.modifier_is_set("Shift")
        #print event.modifier_is_set("Alt")
        if event.modifier_is_set("Control"):
            if event.key.lower() == "n":
                self.newFile()
            elif event.key.lower() == "s" and event.modifier_is_set("Shift"):
                self.saveAs()
            elif event.key.lower() == "s":
                self.saveFile()
            elif event.key.lower() == "o":
                self.openFile()

    def textFilter(self, obj, theText, data):
        #print theText

        #Block ctrl+hot keys
        if theText == "" or theText == "" or theText == "":
            return None
        else:
            return theText

    def launch(self, startingFile=False):
        if startingFile:
            self.fileSelected(self.fileSelector, startingFile, True)
        self.mainWindow.show()
class SwamiModule(Box):
    def __init__(self, rent):
        Box.__init__(self, rent)
        self.parent = rent
        
        self.name = "Wallpaper"
        self.section = "Appearance"
        self.searchData = ["wallpaper", "appearance", "look"]
        self.launchArg = "--wallpaper"
        self.button = None
        
        self.icon = Icon(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        #Use FDO icons -> http://standards.freedesktop.org/icon-naming-spec/latest/ar01s04.html
        self.icon.standard_set('wallpaper')
        self.icon.show()
        
        self.foundWalls = []
        
        self.currentPreview = None
        self.selectedWall = None
        
        self.flip = Flip(self, size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)
        
        wallBox = Box(self.flip, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        wallBox.horizontal_set(True)
        
        self.previewBox = previewBox = Scroller(wallBox, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        previewBox.show()
        
        self.wallList = List(self, size_hint_weight=(0.35, 1.0), 
                    size_hint_align=FILL_BOTH, mode=ELM_LIST_COMPRESS)
        #Adds walls in the WallPaths to the list for selection
        self.populateWalls()
        self.wallList.go()
        self.wallList.show()
        
        wallBox.pack_end(self.wallList)
        wallBox.pack_end(self.previewBox)
        wallBox.show()
        
        self.fs = fs = FileSelector(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        fs.setMode("Open")
        fs.show()

        #need to do this to shutdown threading for the file selector
        self.parent.callback_delete_request_add(self.shutDownFS)
        
        fs.callback_activated_add(self.fileSelected)
        
        # Flip object has the file selector on one side
        #   and the GUI on the other
        self.flip.part_content_set("front", wallBox)
        self.flip.part_content_set("back", self.fs)
        self.flip.show()
        
        fs.callback_cancel_add(lambda o: self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS))
        
        #self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)
        
        self.mainBox = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        self.mainBox.pack_end(self.flip)
        self.mainBox.show()
        
        buttonBox = Box(self, size_hint_weight = EXPAND_HORIZ, size_hint_align = FILL_BOTH)
        buttonBox.horizontal = True
        
        buttonApply = StandardButton(self, "Apply Selected", "ok", self.applyPressed)
        buttonApply.show()
        
        buttonImport = StandardButton(self, "Import Wallpaper", "wallpaper", self.importPressed)
        buttonImport.show()
        
        buttonReturn = StandardButton(self, "Back", "go-previous", self.returnPressed)
        buttonReturn.show()
        
        buttonBox.pack_end(buttonApply)
        #buttonBox.pack_end(buttonWeb)
        buttonBox.pack_end(buttonImport)
        buttonBox.pack_end(buttonReturn)
        buttonBox.show()
        
        self.pack_end(self.mainBox)
        self.pack_end(buttonBox)
    
    def populateWalls(self):
        for ourPath in WallPaths:
            for k in os.walk(ourPath):
                for wallFile in k[2]:
                    self.addWall(wallFile, ourPath)
    
    def addWall(self, wallFile, ourPath):
        '''edjeObj = Edje(self.evas, size_hint_weight=EXPAND_BOTH, 
                        size_hint_align=FILL_BOTH)
        edjeObj.file_set("%s/%s"%(ourPath, wallFile), "e/desktop/background")
        edjeObj.show()'''
        
        listItem = self.wallList.item_append("%s"%wallFile, callback=self.wallSelected)
        listItem.data["filePath"] = "%s%s"%(ourPath, wallFile)
        listItem.selected_set(True)
        
        self.foundWalls.append("%s%s"%(ourPath, wallFile))
        
        self.wallSelected(None, listItem)
    
    def wallSelected(self, obj, item):
        #self.previewBox.clear()
        
        #edjeObj = Layout(self.previewBox, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        
        edjeObj = Edje(self.previewBox.evas, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        
        filePath = item.data["filePath"]
        edjeObj.file_set(filePath, "e/desktop/background")
        edjeObj.show()
        
        self.previewBox.content_set(edjeObj)
        self.currentPreview = edjeObj
        self.selectedWall = filePath
    
    def fileSelected(self, fs, ourPath):
        self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)
        
        #move the file to temp dir / rename it so we can work around a issue with spaces in file names
        tmpCount = 1
        while os.path.isfile("/tmp/swamiwall_%s"%tmpCount):
            tmpCount += 1
        
        shutil.copy2(ourPath, '/tmp/swamiwall_%s'%tmpCount)
        
        time.sleep(1)
        
        ourFile = os.path.splitext(os.path.basename(ourPath))[0].replace(" ", "")
        
        ecore.Exe('convertimage.sh %s %s'%('/tmp/swamiwall_%s'%tmpCount, ourFile))
        
        time.sleep(1)
        self.addWall("%s.edj"%ourFile, "%s/.e/e/backgrounds/"%UserHome)
    
    def returnPressed(self, btn):
        self.parent.returnMain()
        
    def importPressed(self, btn):
        self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)
    
    def applyPressed(self, btn):
        #Dbus call to stop Moksha from fighting with our changes
        bus = dbus.SessionBus()
        obj = bus.get_object('org.enlightenment.wm.service', '/org/enlightenment/wm/RemoteObject')
        iface = dbus.Interface(obj, dbus_interface='org.enlightenment.wm.Config')
        iface.SaveBlock()
        
        #Update Moksha Theme
        #Get existing profile
        eProfileFile = neet.EETFile()
        eProfileFile.importFile("%s/.e/e/config/profile.cfg"%UserHome, "-x")
        eProfile = eProfileFile.readValue()
        
        eCFG = neet.EETFile()
        eCFG.importFile("%s/.e/e/config/%s/e.cfg"%(UserHome, eProfile))
        ewallData = eCFG.readValue((("value", "desktop_default_background"),))
        
        ewallData.data = self.selectedWall
        #print ewallData
        eCFG.saveData()
        
        #Give Moksha control of the config data again
        iface.Load()
        iface.SaveRelease()
    
    def shutDownFS(self, arg):
        self.fs.shutdown()
Exemple #15
0
class MainWin(StandardWindow):
    def __init__(self, app):
        # create the main window
        StandardWindow.__init__(self, "eepdater", "eepDater - System Updater",
                                autodel=True, size=(320, 320))
        self.callback_delete_request_add(lambda o: elementary.exit())
        self.app = app

        icon = Icon(self)
        icon.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND)
        icon.size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL)
        icon.standard_set('software-center')
        icon.show()
        self.icon_object_set(icon.object_get())

        # build the two main boxes
        self.mainBox = self.buildMainBox()
        self.loadBox = self.buildLoadBox()
        
        # build the information details inwin object
        self.buildDetailsWin()

        # the flip object has the load screen on one side and the GUI on the other
        self.flip = Flip(self, size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)
        self.flip.part_content_set("front", self.mainBox)
        self.flip.part_content_set("back", self.loadBox)
        self.resize_object_add(self.flip)
        self.flip.show()

        # show the window
        self.show()

    def buildDetailsWin(self):
        self.updateText = Entry(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        self.updateText.editable_set(False)
        self.updateText.scrollable_set(True)
        self.updateText.show()

        closebtn = Button(self)
        closebtn.text_set("Done")
        closebtn.callback_pressed_add(self.innerWinHide)
        closebtn.show()

        box = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        box.pack_end(self.updateText)
        box.pack_end(closebtn)
        box.show()

        self.innerWin = InnerWindow(self, size_hint_weight=EXPAND_BOTH,
                          size_hint_align=FILL_HORIZ)
        self.innerWin.content_set(box)

    def innerWinShow(self, obj=False):
        self.innerWin.show()
        self.innerWin.activate()

    def innerWinHide(self, obj=False):
        self.innerWin.hide()

    def buildLoadBox(self):
        # build the load label
        loadLable = Label(self, size_hint_weight=EXPAND_BOTH,
                          size_hint_align=FILL_HORIZ)
        loadLable.text = "<b>Processing</b>"
        loadLable.show()
        
        # build the spinning wheel
        wheel = Progressbar(self, pulse_mode=True,
                            size_hint_weight=EXPAND_BOTH,
                            size_hint_align=FILL_HORIZ)
        wheel.pulse(True)
        wheel.show()

        detailsbtn = Button(self, style="anchor")
        detailsbtn.text_set("Details")
        detailsbtn.callback_pressed_add(self.innerWinShow)
        detailsbtn.show()

        # build the status label
        self.statusLabel = Label(self, size_hint_weight=EXPAND_BOTH,
                                 size_hint_align=FILL_HORIZ)
        self.statusLabel.show()

        # put all the built objects in a vertical box
        box = Box(self, size_hint_weight=EXPAND_BOTH, size_hint_align=FILL_BOTH)
        box.pack_end(loadLable)
        box.pack_end(wheel)
        box.pack_end(self.statusLabel)        
        box.pack_end(detailsbtn)
        box.show()

        return box

    def buildMainBox(self):
        # build our toolbar
        self.mainTb = Toolbar(self, homogeneous=False,
                              size_hint_weight=(0.0, 0.0),
                              size_hint_align=(EVAS_HINT_FILL, 0.0))
        self.mainTb.item_append("remove", "Clear", self.clearPressed)
        self.mainTb.item_append("system-run", "Select All", self.selectAllPressed)
        self.mainTb.item_append("view-refresh", "Refresh", self.refreshPressed)
        self.mainTb.item_append("info", "Log", self.detailsPressed)
        self.mainTb.item_append("ok", "Apply", self.installUpdatesPressed)
        self.mainTb.show()

        # build our sortable list that displays packages that need updates
        titles = [("Upgrade", True), ("Package", True),
                  ("Installed", True), ("Available", True)]
        scr = Scroller(self, size_hint_weight=EXPAND_BOTH,
                       size_hint_align=FILL_BOTH)
        self.packageList = sl.SortedList(scr, titles=titles, homogeneous=False,
                                         size_hint_weight=EXPAND_HORIZ)
        scr.content = self.packageList
        scr.show()

        # build the label that shows the package's description
        self.currentDescription = Label(self,
                                        size_hint_weight=FILL_BOTH)
        self.currentDescription.text = "Select a package for information"
        self.currentDescription.line_wrap_set(True)
        self.currentDescription.show()

        self.desFrame = Frame(self, size_hint_weight=EXPAND_HORIZ,
                              size_hint_align=FILL_HORIZ)
        self.desFrame.text = "Description"
        self.desFrame.content = self.currentDescription
        self.desFrame.show()

        # add all of our objects to the box
        box = Box(self, size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)
        box.pack_end(self.mainTb)
        box.pack_end(scr)
        box.pack_end(self.desFrame)
        box.show()

        return box

    def detailsPressed(self, obj, it):
        it.selected = False
        self.innerWinShow()

    def clearPressed(self, obj, it):
        it.selected = False
        for rw in self.packageList.rows:
            rw[0].state = False
            self.app.checkChange(rw[0])

    def selectAllPressed(self, obj, it):
        it.selected = False
        for rw in self.packageList.rows:
            rw[0].state = True
            self.app.checkChange(rw[0])

    def refreshPressed(self, obj, it):
        it.selected = False
        self.app.refreshPackages()

    def installUpdatesPressed(self, obj, it):
        it.selected = False
        self.app.installUpdates()

    def packagePressed(self, obj):
        self.desFrame.text = "Description - %s" % obj.text
        self.currentDescription.text = obj.data["packageDes"]

    def addPackage(self, pak):
        row = []

        ourCheck = Check(self)
        ourCheck.data['packageName'] = pak.name
        ourCheck.callback_changed_add(self.app.checkChange)
        ourCheck.show()
        row.append(ourCheck)

        ourName = Button(self, style="anchor", size_hint_weight=EXPAND_HORIZ,
                         size_hint_align=FILL_HORIZ)
        ourName.text = pak.name
        ourName.data["packageDes"] = pak.candidate.description
        ourName.callback_pressed_add(self.packagePressed)
        ourName.show()
        row.append(ourName)

        ourVersion = Label(self, size_hint_weight=EXPAND_HORIZ,
                           size_hint_align=(0.1, 0.5))
        ourVersion.text = pak.installed.version
        ourVersion.show()
        row.append(ourVersion)

        newVersion = Label(self, size_hint_weight=EXPAND_HORIZ,
                           size_hint_align=(0.1, 0.5))
        newVersion.text = pak.candidate.version
        newVersion.show()
        row.append(newVersion)

        self.app.packagesToUpdate[pak.name] = {'check':ourCheck, 'selected':False}
        self.packageList.row_pack(row, sort=False)

    def showDialog(self, title, msg):
        dia = Popup(self)
        dia.part_text_set("title,text", title)
        dia.part_text_set("default", msg)

        bt = Button(dia, text="Ok")
        bt.callback_clicked_add(lambda b: dia.delete())
        dia.part_content_set("button1", bt)

        dia.show()
Exemple #16
0
class Interface(object):
    def __init__(self):
        self.mainWindow = StandardWindow("epad", "Untitled - ePad",
                                         size=(600, 400))
        self.mainWindow.callback_delete_request_add(self.closeChecks)
        self.mainWindow.elm_event_callback_add(self.eventsCb)

        icon = Icon(self.mainWindow,
                    size_hint_weight=EXPAND_BOTH,
                    size_hint_align=FILL_BOTH)
        icon.standard_set('accessories-text-editor')
        icon.show()
        self.mainWindow.icon_object_set(icon.object_get())

        self.mainBox = Box(self.mainWindow,
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)
        self.mainBox.show()

        self.newInstance = NEW_INSTANCE
        self.mainTb = ePadToolbar(self, self.mainWindow)
        self.mainTb.focus_allow = False
        self.mainTb.show()
        self.mainBox.pack_end(self.mainTb)
        # Root User Notification
        if os.geteuid() == 0:
            printErr("Caution: Root User")
            if NOTIFY_ROOT:
                notifyBox = Box(self.mainWindow, horizontal=True)
                notifyBox.show()
                notify = Notify(self.mainWindow, size_hint_weight=EXPAND_BOTH,
                                align=(ELM_NOTIFY_ALIGN_FILL, 0.0),
                                content=notifyBox)
                notifyLabel = Label(self.mainWindow)
                notifyLabel.text = "<b><i>Root User</i></b>"
                notifyBox.pack_end(notifyLabel)
                notifyLabel.show()
                self.mainBox.pack_end(notifyBox)
        self.about = aboutWin(self, self.mainWindow)
        self.about.hide()
        # Initialize Text entry box and line label

        # FIXME: self.wordwrap initialized by ePadToolbar
        print("Word wrap Initialized: {0}".format(self.wordwrap))
        self.entryInit()

        # Build our file selector for saving/loading files
        self.fileBox = Box(self.mainWindow,
                           size_hint_weight=EXPAND_BOTH,
                           size_hint_align=FILL_BOTH)
        self.fileBox.show()

        self.fileLabel = Label(self.mainWindow,
                               size_hint_weight=EXPAND_HORIZ,
                               size_hint_align=FILL_BOTH, text="")
        self.fileLabel.show()
        self.lastDir = os.getenv("HOME")
        self.fileSelector = Fileselector(self.mainWindow, is_save=False,
                                         expandable=False, folder_only=False,
                                         hidden_visible=SHOW_HIDDEN,
                                         path=self.lastDir,
                                         size_hint_weight=EXPAND_BOTH,
                                         size_hint_align=FILL_BOTH)
        self.fileSelector.callback_done_add(self.fileSelected)
        self.fileSelector.callback_activated_add(self.fileSelected)
        self.fileSelector.callback_directory_open_add(self.updateLastDir)
        self.fileSelector.path_set(os.getcwd())
        self.fileSelector.show()

        self.fileBox.pack_end(self.fileLabel)
        self.fileBox.pack_end(self.fileSelector)

        # Flip object has the file selector on one side
        #   and the GUI on the other
        self.flip = Flip(self.mainWindow, size_hint_weight=EXPAND_BOTH,
                         size_hint_align=FILL_BOTH)
        self.flip.part_content_set("front", self.mainBox)
        self.flip.part_content_set("back", self.fileBox)
        self.mainWindow.resize_object_add(self.flip)
        self.flip.show()

        self.isSaved = True
        self.isNewFile = False
        self.confirmPopup = None
        self.fileExistsFlag = False

    def entryInit(self):
        self.mainEn = Entry(self.mainWindow, scrollable=True,
                            line_wrap=self.wordwrap, autosave=False,
                            size_hint_weight=EXPAND_BOTH,
                            size_hint_align=FILL_BOTH)
        self.mainEn.callback_changed_user_add(self.textEdited)
        self.mainEn.elm_event_callback_add(self.eventsCb)
        self.mainEn.callback_clicked_add(resetCloseMenuCount)
        # delete line lable if it exist so we can create and add new one
        #    Later need to rethink logic here
        try:
            self.line_label.delete()
        except AttributeError:
            pass
        # Add label to show current cursor position
        if SHOW_POS:
            self.line_label = Label(self.mainWindow,
                                    size_hint_weight=EXPAND_HORIZ,
                                    size_hint_align=ALIGN_RIGHT)

            self.mainEn.callback_cursor_changed_add(self.curChanged,
                                                    self.line_label)
            self.curChanged(self.mainEn, self.line_label)
            self.line_label.show()
            self.mainBox.pack_end(self.line_label)
        # self.mainEn.markup_filter_append(self.textFilter)

        self.mainEn.show()
        self.mainEn.focus_set(True)
        try:
            self.mainBox.pack_before(self.mainEn, self.line_label)
        except AttributeError:
            # line_label has not been initialized on first run
            #   Should have better logic on all this
            self.mainBox.pack_end(self.mainEn)

    def curChanged(self, entry, label):
        # get linear index into current text
        index = entry.cursor_pos_get()
        # Replace <br /> tag with single char
        #   to simplify (line, col) calculation
        tmp_text = markup_to_utf8(entry.entry_get())
        line = tmp_text[:index].count("\n") + 1
        col = len(tmp_text[:index].split("\n")[-1]) + 1
        # Update label text with line, col
        label.text = "Ln {0} Col {1} ".format(line, col)

    def textEdited(self, obj):
        current_file = self.mainEn.file[0]
        current_file = \
            os.path.basename(current_file) if \
            current_file and not self.isNewFile else \
            "Untitled"
        self.mainWindow.title = "*%s - ePad" % (current_file)
        self.isSaved = False

    def newFile(self, obj=None, ignoreSave=False):
        if self.newInstance:

            # sh does not properly handle space between -d and path
            command = "epad -d'{0}'".format(self.lastDir)
            print("Launching new instance: {0}".format(command))
            ecore.Exe(command, ecore.ECORE_EXE_PIPE_READ |
                      ecore.ECORE_EXE_PIPE_ERROR | ecore.ECORE_EXE_PIPE_WRITE)
            return
        if self.isSaved is True or ignoreSave is True:
            trans = Transit()
            trans.object_add(self.mainEn)
            trans.auto_reverse = True

            trans.effect_wipe_add(
                ELM_TRANSIT_EFFECT_WIPE_TYPE_HIDE,
                ELM_TRANSIT_EFFECT_WIPE_DIR_RIGHT)

            trans.duration = 0.5
            trans.go()

            time.sleep(0.5)

            self.mainWindow.title_set("Untitled - ePad")
            self.mainEn.delete()
            self.entryInit()
            self.isNewFile = True

        elif self.confirmPopup is None:
            self.confirmSave(self.newFile)
        self.mainEn.focus_set(True)

    def openFile(self, obj=None, ignoreSave=False):
        if self.isSaved is True or ignoreSave is True:
            self.fileSelector.is_save_set(False)
            self.fileLabel.text = "<b>Select a text file to open:</b>"
            self.flip.go(ELM_FLIP_ROTATE_YZ_CENTER_AXIS)
        elif self.confirmPopup is None:
            self.confirmSave(self.openFile)

    def confirmSave(self, ourCallback=None):
        self.confirmPopup = Popup(self.mainWindow,
                                  size_hint_weight=EXPAND_BOTH)
        self.confirmPopup.part_text_set("title,text", "File Unsaved")
        current_file = self.mainEn.file[0]
        current_file = \
            os.path.basename(current_file) if current_file else "Untitled"
        self.confirmPopup.text = "Save changes to '%s'?" % (current_file)
        # Close without saving button
        no_btt = Button(self.mainWindow)
        no_btt.text = "No"
        no_btt.callback_clicked_add(self.closePopup, self.confirmPopup)
        if ourCallback is not None:
            no_btt.callback_clicked_add(ourCallback, True)
        no_btt.show()
        # cancel close request
        cancel_btt = Button(self.mainWindow)
        cancel_btt.text = "Cancel"
        cancel_btt.callback_clicked_add(self.closePopup, self.confirmPopup)
        cancel_btt.show()
        # Save the file and then close button
        sav_btt = Button(self.mainWindow)
        sav_btt.text = "Yes"
        sav_btt.callback_clicked_add(self.saveFile)
        sav_btt.callback_clicked_add(self.closePopup, self.confirmPopup)
        sav_btt.show()

        # add buttons to popup
        self.confirmPopup.part_content_set("button1", no_btt)
        self.confirmPopup.part_content_set("button2", cancel_btt)
        self.confirmPopup.part_content_set("button3", sav_btt)
        self.confirmPopup.show()

    def saveAs(self):
        self.fileSelector.is_save_set(True)
        self.fileLabel.text = "<b>Save new file to where:</b>"
        self.flip.go(ELM_FLIP_ROTATE_XZ_CENTER_AXIS)

    def saveFile(self, obj=False):
        if self.mainEn.file_get()[0] is None or self.isNewFile:
            self.saveAs()
        else:
            file_selected = self.mainEn.file_get()[0]
            # Detect save errors as entry.file_save currently returns no errors
            #   even in the case where the file fails to save :(
            try:
                newfile = open(file_selected, 'w')
            except IOError as err:
                if err.errno == errno.EACCES:
                    errorMsg = ("Permision denied: <b>'%s'</b>."
                                "<br><br>Operation failed !!!"
                                % (file_selected))
                    errorPopup(self.mainWindow, errorMsg)
                else:
                    errorMsg = ("ERROR: %s: '%s'"
                                "<br><br>Operation failed !!!"
                                % (err.strerror, file_selected))
                    errorPopup(self.mainWindow, errorMsg)
                return
            newfile.close()
            # if entry is empty and the file does not exists then
            #   entry.file_save will destroy the file created about by the
            #   open statement above for some odd reason ...
            if not self.mainEn.is_empty:
                self.mainEn.file_save()
            self.mainWindow.title_set("%s - ePad"
                                      % os.path.basename(self.mainEn.file[0]))
            self.isSaved = True

    def doSelected(self, obj):

        # Something I should avoid but here I prefer a polymorphic function
        if isinstance(obj, Button):
            file_selected = self.fileSelector.selected_get()
        else:
            file_selected = obj

        IsSave = self.fileSelector.is_save_get()
        if file_selected:
            if IsSave:
                try:
                    newfile = open(file_selected, 'w')
                except IOError as err:
                    print("ERROR: {0}: '{1}'".format(err.strerror,
                                                     file_selected))
                    if err.errno == errno.EACCES:
                        errorMsg = ("Permision denied: <b>'%s'</b>."
                                    "<br><br>Operation failed !!!</br>"
                                    % (file_selected))
                        errorPopup(self.mainWindow, errorMsg)
                    else:
                        errorMsg = ("ERROR: %s: '%s'"
                                    "<br><br>Operation failed !!!</br>"
                                    % (err.strerror, file_selected))
                        errorPopup(self.mainWindow, errorMsg)
                    return
                tmp_text = self.mainEn.entry_get()
                # FIXME: Why save twice?
                newfile.write(tmp_text)
                newfile.close()
                # Suppress error message when empty file is saved
                try:
                    self.mainEn.file_set(file_selected,
                                         ELM_TEXT_FORMAT_PLAIN_UTF8)
                except RuntimeError:
                    print("Empty file saved:{0}".format(file_selected))
                self.mainEn.entry_set(tmp_text)
                # if empty file entry.file_save destroys file :(
                if len(tmp_text):
                    self.mainEn.file_save()
                self.mainWindow.title_set("%s - ePad"
                                          % os.path.basename(file_selected))
                self.isSaved = True
                self.isNewFile = False
            else:
                if os.path.isdir(file_selected):
                    print("ERROR: {0}: is a directory. "
                          "Could not set file.".format(file_selected))
                    current_file = os.path.basename(file_selected)
                    errorMsg = ("<b>'%s'</b> is a folder."
                                "<br><br>Operation failed !!!</br>"
                                % (current_file))
                    errorPopup(self.mainWindow, errorMsg)
                    return
                # Test to see if file can be opened to catch permission errors
                #   as entry.file_set function does not differentiate
                #   different possible errors.
                try:
                    with open(file_selected) as f:
                        tmp_text = f.readline()
                except IOError as err:

                    if err.errno == errno.ENOENT:
                        print("Creating New file '{0}'".format(file_selected))
                        # self.fileSelector.current_name_set(file_selected)
                        self.isSaved = False
                    elif err.errno == errno.EACCES:
                        print("ERROR: {0}: '{1}'".format(err.strerror,
                              file_selected))
                        errorMsg = ("Permision denied: <b>'%s'</b>."
                                    "<br><br>Operation failed !!!</br>"
                                    % (file_selected))
                        errorPopup(self.mainWindow, errorMsg)
                        return
                    else:
                        print("ERROR: {0}: '{1}'".format(err.strerror,
                              file_selected))
                        errorMsg = ("ERROR: %s: '%s'"
                                    "<br><br>Operation failed !!!</br>"
                                    % (err.strerror, file_selected))
                        errorPopup(self.mainWindow, errorMsg)
                        return
                try:
                    self.mainEn.file_set(file_selected,
                                         ELM_TEXT_FORMAT_PLAIN_UTF8)
                except RuntimeError as msg:
                    # Entry.file_set fails on empty files
                    print("Empty file: {0}".format(file_selected))
                self.mainWindow.title_set("%s - ePad"
                                          % os.path.basename(file_selected))

                self.mainEn.focus_set(True)

    def fileExists(self, filePath):

        self.confirmPopup = Popup(self.mainWindow,
                                  size_hint_weight=EXPAND_BOTH)

        # Add a table to hold dialog image and text to Popup
        tb = Table(self.confirmPopup, size_hint_weight=EXPAND_BOTH)
        self.confirmPopup.part_content_set("default", tb)
        tb.show()

        # Add dialog-error Image to table
        need_ethumb()
        icon = Icon(self.confirmPopup, thumb='True')
        icon.standard_set('dialog-question')
        # Using gksudo or sudo fails to load Image here
        #   unless options specify using preserving their existing environment.
        #   may also fail to load other icons but does not raise an exception
        #   in that situation.
        # Works fine using eSudo as a gksudo alternative,
        #   other alternatives not tested
        try:
            dialogImage = Image(self.confirmPopup,
                                size_hint_weight=EXPAND_HORIZ,
                                size_hint_align=FILL_BOTH,
                                file=icon.file_get())
            tb.pack(dialogImage, 0, 0, 1, 1)
            dialogImage.show()
        except RuntimeError:
            # An error message is displayed for this same error
            #   when aboutWin is initialized so no need to redisplay.
            pass
        # Add dialog text to table
        dialogLabel = Label(self.confirmPopup, line_wrap=ELM_WRAP_WORD,
                            size_hint_weight=EXPAND_HORIZ,
                            size_hint_align=FILL_BOTH)
        current_file = os.path.basename(filePath)
        dialogLabel.text = "'%s' already exists. Overwrite?<br><br>" \
                           % (current_file)
        tb.pack(dialogLabel, 1, 0, 1, 1)
        dialogLabel.show()

        # Close without saving button
        no_btt = Button(self.mainWindow)
        no_btt.text = "No"
        no_btt.callback_clicked_add(self.closePopup, self.confirmPopup)
        no_btt.show()
        # Save the file and then close button
        sav_btt = Button(self.mainWindow)
        sav_btt.text = "Yes"
        sav_btt.callback_clicked_add(self.doSelected)
        sav_btt.callback_clicked_add(self.closePopup, self.confirmPopup)
        sav_btt.show()

        # add buttons to popup
        self.confirmPopup.part_content_set("button1", no_btt)
        self.confirmPopup.part_content_set("button3", sav_btt)
        self.confirmPopup.show()

    def fileSelected(self, fs, file_selected, onStartup=False):
        if not onStartup:
            self.flip.go(ELM_FLIP_INTERACTION_ROTATE)
            # Markup can end up in file names because file_selector name_entry
            #   is an elementary entry. So lets sanitize file_selected.
            file_selected = markup_to_utf8(file_selected)
        if file_selected:
            print("File Selected: {0}".format(file_selected))
            self.lastDir = os.path.dirname(file_selected)
            fs.path_set(self.lastDir)
            # This fails if file_selected does not exist yet
            try:
                fs.selected = file_selected
            except RuntimeError:
                # FIXME: would be nice if I could set fileSelector name entry
                pass

        IsSave = fs.is_save_get()

        if file_selected:
            if IsSave:
                if os.path.isdir(file_selected):
                    current_file = os.path.basename(file_selected)
                    errorMsg = ("<b>'%s'</b> is a folder."
                                "<br><br>Operation failed !!!"
                                % (current_file))
                    errorPopup(self.mainWindow, errorMsg)
                    return
                elif os.path.exists(file_selected):
                    self.fileExistsFlag = True
                    self.fileExists(file_selected)
                    return
        self.doSelected(file_selected)

    def updateLastDir(self, fs, path):
        self.lastDir = path

    def closeChecks(self, obj):
        print("File is Saved: ", self.isSaved)
        if not self.flip.front_visible_get():
            self.flip.go(ELM_FLIP_ROTATE_XZ_CENTER_AXIS)
        elif self.isSaved is False and self.confirmPopup is None:
            self.confirmSave(self.closeApp)
        else:
            self.closeApp()

    def closePopup(self, bt, confirmPopup):
        self.confirmPopup.delete()
        self.confirmPopup = None

    def showAbout(self):
        self.about.launch()

    def closeApp(self, obj=False, trash=False):
        elementary.exit()

    def eventsCb(self, obj, src, event_type, event):
        if event.modifier_is_set("Control"):
            if event.key.lower() == "n":
                self.newFile()
            elif event.key.lower() == "s" and event.modifier_is_set("Shift"):
                self.saveAs()
            elif event.key.lower() == "s":
                self.saveFile()
            elif event.key.lower() == "o":
                self.openFile()
            elif event.key.lower() == "h":
                if not self.flip.front_visible_get():
                    toggleHidden(self.fileSelector)
            elif event.key.lower() == "q":
                closeCtrlChecks(self)

    # Legacy hack no longer needed
    #  there was an issue in elementary entry where it would
    #  accept those character controls

    # def textFilter( self, obj, theText, data ):
    #    # Block ctrl+hot keys used in eventsCb
    #    #
    #    #             Ctrl O   Ctrl N   Ctrl S
    #    ctrl_block = [chr(14), chr(15), chr(19)]
    #    if theText in ctrl_block:
    #        return None
    #    else:
    #        return theText

    def launch(self, start=[]):
        if start and start[0] and os.path.dirname(start[0]) == '':
                start[0] = os.getcwd() + '/' + start[0]
        if start and start[0]:
            if os.path.isdir(os.path.dirname(start[0])):
                self.fileSelected(self.fileSelector, start[0], True)
            else:
                print("Error: {0} is an Invalid Path".format(start))
                errorMsg = ("<b>'%s'</b> is an Invalid path."
                            "<br><br>Open failed !!!" % (start))
                errorPopup(self.mainWindow, errorMsg)
        if start and start[1]:
            if os.path.isdir(start[1]):
                print("Initializing file selection path: {0}".format(start[1]))
                self.fileSelector.path_set(start[1])
                self.lastDir = start[1]
            else:
                print("Error: {0} is an Invalid Path".format(start[1]))
        self.mainWindow.show()