def __init__(self, parent, title="pyHarvest Tracker"): self.validProjects = {} wx.Frame.__init__(self, parent, title=title) self.initMenus() self.initListeners() self.Show(True) self.conf = HarvestConfig() self.applicationUrl = self.conf.get("appUrl") if not self.applicationUrl: self.showAppUrlDialog() self.showAuthWindow() self.SetInitialSize()
class HarvestFrame(wx.Frame): def __init__(self, parent, title="pyHarvest Tracker"): self.validProjects = {} wx.Frame.__init__(self, parent, title=title) self.initMenus() self.initListeners() self.Show(True) self.conf = HarvestConfig() self.applicationUrl = self.conf.get("appUrl") if not self.applicationUrl: self.showAppUrlDialog() self.showAuthWindow() self.SetInitialSize() def initListeners(self): Publisher().subscribe(self.authEntered, ("auth.information_entered")) Publisher().subscribe(self.timerToggled, ("task.timer_toggle")) Publisher().subscribe(self.sendNewTask, ("task.new_task")) def initMenus(self): menuBar = wx.MenuBar() fileMenu = wx.Menu() newButton = fileMenu.Append(wx.NewId(), "&New Task") exitButton = fileMenu.Append(wx.ID_EXIT, "E&xit", "Exit.") self.Bind(wx.EVT_MENU, self.newTask, newButton) editMenu = wx.Menu() preferencesButton = editMenu.Append(wx.NewId(), "Preferences") menuBar.Append(fileMenu, "&File") menuBar.Append(editMenu, "Edit") self.SetMenuBar(menuBar) def showAppUrlDialog(self): dlg = wx.TextEntryDialog( self, "Please enter the URL of your harvest app. It will be https://{companyname}.harvestapp.com", "Please enter url", "", wx.OK | wx.TE_LEFT, ) if dlg.ShowModal(): self.applicationUrl = dlg.GetValue() self.conf.set("appUrl", self.applicationUrl) def showAuthWindow(self): self.username = self.conf.get("username") self.authWin = Auth.AuthPanel(self, self.username) self.authWin.Show() def showProjectError(self): dlg = wx.MessageDialog( self, "Sorry, either you have entered your credentials incorrectly, or you have no projects." + " If you feel you entered the data correctly, please contact your Harvest administrator.", "There was a problem.", ) dlg.ShowModal() dlg.Destroy() self.showAuthWindow() def showInterface(self): self.taskView = Tks.TaskView(self, self.dayData["entries"]) self.taskView.Show() self.SetInitialSize() def timerToggled(self, e): """ Called when the user clicks on a timer to be toggled. @param event e @return mixed """ id = e.data["id"] if not id: return return self.api.toggleTimer(id) def newTask(self, e): self.taskDialog = Tks.NewTaskDialog(self, self.validProjects, -1, "New Task") self.taskDialog.Show() def loadInitialData(self): self.api = Time.TimeApi(self.applicationUrl, self.username, self.password) self.dayData = self.api.getDaily() if not self.dayData or not self.dayData["projects"]: self.showProjectError() return self.breakdownProjects() self.showInterface() def authEntered(self, e): self.username = e.data["username"] self.conf.set("username", self.username) self.password = e.data["password"] self.authWin.Hide() self.authWin.Destroy() self.loadInitialData() def breakdownProjects(self): for project in self.dayData["projects"]: if not project.client: continue if not project.client in self.validProjects: self.validProjects[project.client] = {} if not project.name in self.validProjects[project.client]: self.validProjects[project.client][project.name] = None self.validProjects[project.client][project.name] = project def sendNewTask(self, e): res = self.api.createTask(e.data["notes"], e.data["project_id"], e.data["task_id"], e.data["hours"]) self.taskDialog.Hide() self.taskDialog.Destroy()