def __init__(self): """ Here we define the features for the window environment that manages the user settings. """ super().__init__( "../GUI/glade/settings.glade") # We create the basic features self.configPath = "../config/config.json" # Below we define which items we will use self.submit = self.builder.get_object("submitButton") self.cancel = self.builder.get_object("cancelButton") self.startOnSwitch = self.builder.get_object("starton-switch") self.csStudentSwitch = self.builder.get_object("CS-switch") self.nonCSStudentSwitch = self.builder.get_object("NonCS-switch") # Below we set the previous values. self.startOnSwitch.set_active( jsonHandler.readJson( self.configPath)['configInfo']['startONPowerButtonON']) self.csStudentSwitch.set_active( jsonHandler.readJson(self.configPath)['configInfo']['csButtonON']) self.nonCSStudentSwitch.set_active( jsonHandler.readJson( self.configPath)['configInfo']['nonCSButtonON']) # Below we define what will be the functions of each object in the window. self.window.connect("destroy", self.destroy) self.cancel.connect("clicked", self.destroy) self.csStudentSwitch.connect("button-press-event", self.sigleSwitchON) self.csStudentSwitch.connect("key-press-event", self.sigleSwitchON) self.nonCSStudentSwitch.connect("button-press-event", self.sigleSwitchON) self.nonCSStudentSwitch.connect("key-press-event", self.sigleSwitchON) self.submit.connect("clicked", self.onSubmit)
def onSubmit(self, widget): """ This method refers to the button that stores user information in the json file. """ configUpdate = jsonHandler.readJson(self.configPath) # We put the settings chosen by the user in the file. configUpdate['configInfo'][ 'startONPowerButtonON'] = self.startOnSwitch.get_active() configUpdate['configInfo'][ 'csButtonON'] = self.csStudentSwitch.get_active() configUpdate['configInfo'][ 'nonCSButtonON'] = self.nonCSStudentSwitch.get_active() # If the user wishes to activate or deactivate the program when # activating the computer then the following operation will be performed if self.startOnSwitch.get_active(): os.system("sh ../shellScripts/addStartUp.sh") else: os.system("sh ../shellScripts/removeStartUp.sh") # In this condition we define the appropriate settings so that the other # program understands what type of student we are referring to. if self.csStudentSwitch.get_active(): configUpdate['configInfo']['isCSStudent'] = True else: configUpdate['configInfo']['isCSStudent'] = False jsonHandler.writeJson(self.configPath, configUpdate)
def configureIcon(): """ In this function we inform the json file about the locations of icon. """ defaultPath=(os.popen("pwd").read()).replace("\n","") iconPath=defaultPath+"/icon/icon.png" # icon path updateConfig=jsonHandler.readJson("config/config.json") # read the json. updateConfig['configInfo']['paths']['notificationIcon']=iconPath jsonHandler.writeJson("config/config.json",updateConfig) # update json.
def showNotify(self, title): """ This method displays the new announcement """ Notify.init("University News") iconLocation = jsonHandler.readJson( self.configPath)['configInfo']['paths']['notificationIcon'] newNotification = Notify.Notification.new( "There is an announcement from the University of Piraeus.", title, iconLocation) newNotification.show()
def getMostRecent(self): """ This method checks if there is a new announcement, if it exists then updates the json file with the new announcement and displays a message saying there is a new announcement. """ isCSStudent = jsonHandler.readJson( self.configPath)['configInfo']['isCSStudent'] webSites = jsonHandler.readJson(self.jsonPath) # We read the necessary information to proceed with the process if isCSStudent: # If the unipi student is an IT student then check the cs.unipi page. page = "ITMainPage" mainPageUrl = webSites['websites']['ITMainPage']['url'] announcementLoc = webSites['websites']['ITMainPage'][ 'announcementLocation'] previousAnnouncement = webSites['websites']['ITMainPage'][ 'latestAnnouncement'] else: # If the unipi student is not an IT student then check the main page. page = "UNIPIMainPage" mainPageUrl = webSites['websites']['UNIPIMainPage']['url'] announcementLoc = webSites['websites']['UNIPIMainPage'][ 'announcementLocation'] previousAnnouncement = webSites['websites']['UNIPIMainPage'][ 'latestAnnouncement'] # get's the new a announcement newAnnouncement = self.getLatestAnnouncement(mainPageUrl, announcementLoc) if newAnnouncement != previousAnnouncement and newAnnouncement: # We check if there is an announcement and save it if exists. webSites['websites'][page]['latestAnnouncement'] = newAnnouncement jsonHandler.writeJson(self.jsonPath, webSites) self.showNotify(newAnnouncement) else: pass