def sortCatFunction(self, e): #Change between what is already set if self.ASC_DESC == "ASC": self.ASC_DESC = "DESC" else: self.ASC_DESC = "ASC" #get selected catOne = self.SortCatOne.GetValue() catTwo = self.SortCatTwo.GetValue() #get info if catOne != "[Item 1]" and catTwo != "[Item 2]": allData = ToDoListDatabase.sortListBy_Two(self.CurrentTable, catOne, catTwo, self.ASC_DESC) elif catOne != "[Item 1]" and catTwo == "[Item 2]": allData = ToDoListDatabase.sortListBy_One(self.CurrentTable, catOne, self.ASC_DESC) elif catOne == "[Item 1]" and catTwo != "[Item 2]": allData = ToDoListDatabase.sortListBy_One(self.CurrentTable, catTwo, self.ASC_DESC) elif catOne == "[Item 1]" and catTwo == "[Item 2]": return #delete everything in listCtrl self.listCtrl.DeleteAllItems() #loop through and append data for row in allData: self.listCtrl.Append(row)
def saveFunction(self, e): category = self.CategoryTF.GetValue() item = self.toDoTF.GetValue() current = self.CurrentDateTF.GetValue() due = self.DueDateTF.GetValue() itemList = [category, item, current, due, self.Task] ToDoListDatabase.updateItem(self.CurrentTable,self.ID, itemList) self.Destroy()
def changeDatabaseFunction (self, e): wildcard = "Python source (*.db)|*.db|" \ "All files (*.*)|*.*" currentDir = os.getcwd() dlg = wx.FileDialog( self, message="Choose a file", defaultDir=currentDir, defaultFile="", wildcard=wildcard, style=wx.OPEN | wx.CHANGE_DIR) if dlg.ShowModal() == wx.ID_OK: databaseName = dlg.GetFilename() ToDoListDatabase.chooseDatabase(databaseName) self.addToListBox()
def addTaskFunction (self, e): itemList = self.getTaskInfoFunction() if itemList[0] != "[Category]": #add to database ToDoListDatabase.addNewItem(self.CurrentTable,itemList) #add to listBox self.addToListBox() #make sure radio button is correct if self.CurrentTable == self.MainTable: self.MainRB.SetValue(True) else: self.DailyRB.SetValue(True)
def deleteFunction (self, e): #get data from the row to be deleted row = [] rowNum = self.listCtrl.GetFocusedItem() for colNum in range (0,6): print self.listCtrl.GetItemText(rowNum,colNum) print "\n" #remove from database row_count = self.listCtrl.SelectedItemCount if row_count == 1: ToDoListDatabase.deleteItem(self.CurrentTable, self.item_ID) self.addToListBox()
def updateCategoryList (self): self.category_list = ToDoListDatabase.getDistinctCategories() self.CategoryTF.Clear() for item in self.category_list: self.CategoryTF.Append(item) if not self.category_list: self.category_list = ["[Category]","Other"] self.CategoryTF.SetValue(self.category_list[0])
def __init__(self, ID, CurrentTable): #600 = width, 700 = height wx.Frame.__init__(self, None, size = (270, 425)) #align to the center of the screen self.Center() #add container that groups things such as buttons and text panel = wx.Panel(self) #set id self.ID = ID self.CurrentTable = CurrentTable #set title self.SetTitle("Edit ID #{}...".format(self.ID)) # self.category_list = ["[Category]","Other"] self.CategoryTF = None self.toDoTF = None self.CurrentDateTF = None self.DueDateTF = None #CREATE PANELS #category wx.StaticText(panel, label="Category:",pos=(10,10)) #self.CategoryTF = wx.TextCtrl(panel, pos=(10,35), size=(150,-1)) self.CategoryTF = wx.ComboBox (panel, pos=(10,35), size=(230,-1), \ choices=self.category_list, value =self.category_list[0]) self.updateCategoryList() #to do list description wx.StaticText(panel, label="To Do Item:",pos=(10,70)) self.toDoTF = wx.TextCtrl (panel, style=wx.TE_MULTILINE, pos=(10,95), size=(230,50) ) #dates #current date wx.StaticText(panel, label="Current Date:",pos=(10,150)) self.CurrentDateTF = wx.TextCtrl(panel, pos=(10,175), size=(150,-1)) #due date wx.StaticText(panel, label="Due Date:",pos=(10,210)) self.DueDateTF = wx.TextCtrl(panel, pos=(10,235), size=(150,-1)) #daily task #cannot change if daily task #create save button saveBTN = wx.Button (panel, label = "Save", pos=(10,340), size=(100,30)) saveBTN.Bind(wx.EVT_BUTTON, self.saveFunction) #create cancel button cancelBTN = wx.Button (panel, label = "Cancel", pos=(125,340), size=(100,30)) cancelBTN.Bind(wx.EVT_BUTTON, self.cancelFunction) #populate cells itemList = ToDoListDatabase.getItem(self.CurrentTable,self.ID) self.CategoryTF.SetValue(str(itemList[1])) self.toDoTF.SetValue(str(itemList[2])) self.CurrentDateTF.SetValue(str(itemList[3])) self.DueDateTF.SetValue(str(itemList[4])) self.Task = str(itemList[5])
def addToListBox (self): self.listCtrl.DeleteAllItems() allData = ToDoListDatabase.displayAll(self.CurrentTable) #loop through and append data if allData: for row in allData: #print row self.listCtrl.Append(row) self.updateCategoryList() self.getItemCountFunction()
def __init__ (self, *args, **kwargs): super(windowClass, self).__init__(*args, **kwargs) #Creat Window basics self.SetTitle("To Do List Express") self.CreateStatusBar() self.SetStatusText('Ready') self.SetSize((770,710)) self.width = self.GetSize()[0] self.height = self.GetSize()[1] self.Centre() #panel = wx.Panel(self) #panel.SetSize((self.width,self.height)) #size=DefaultSize panel = wx.PyScrolledWindow( self, -1) panel.SetScrollbars(10, 10, (self.width/10)-3.5, (self.height/10)-8.5) #print panel.GetSize() #SET variables self.MainTable = "ToDoListTable" self.DailyTable = "DailyTasksTable" self.category_list = None self.toDoTF = None self.CurrentDateTF = None self.DueDateTF = None # self.NoRB = None self.YesRB = None self.DailyTask = "False" # self.MainRB = None self.DailyRB = None self.CurrentTable = self.MainTable self.tableLabel = None # self.listCtrl = None self.itemCountLabel = None self.itemCount = 0 self.item_ID = 1 self.ASC_DESC = "ASC" colmn_list=["[Item 1]","ID", "Category", "Item", "Current_date", "Due_date", "Daily_task"] self.SortCatOne = None self.SortCatTwo = None #dates self.now = str(datetime.datetime.now()) self.now = self.now[:10] # #self.deletedItems = [] #buttons '''addBTN #sortCatBTN #editBTN #refreshBTN #deleteBTN''' #functions '''setTableFunction getDailyTask getTaskInfoFunction''' #CREATE MENU BAR menuBar = wx.MenuBar() fileButton = wx.Menu() helpButton = wx.Menu() newItem = fileButton.Append(wx.ID_ANY, "&New\tCtrl+N", "Clears information in Task Box") saveItem = fileButton.Append(wx.ID_ANY, "&Save\tCtrl+S", "Adds the task item from Task Box to list") editItem = fileButton.Append(wx.ID_ANY, "&Edit\tCtrl+E", "Edits the selected item") deleteItem = fileButton.Append(wx.ID_ANY, "&Delete\tCtrl+D", "Deletes the selected item") changeDatabase = fileButton.Append(wx.ID_ANY, "Change Database", "Lets you work from a different database") addDailyItem = fileButton.Append(wx.ID_ANY, "&Add Daily", "Adds the tasks that you do daily to the list") exitItem = fileButton.Append(wx.ID_ANY, "&Quit\tCtrl+Q", "Quit the program") helpLabel = "About {}".format(self.GetTitle()) helpItem = helpButton.Append(wx.ID_ANY, helpLabel, "About the program") menuBar.Append(fileButton, "&File") menuBar.Append(helpButton, "&Help") self.SetMenuBar(menuBar) self.Bind (wx.EVT_MENU, self.newFunction, newItem) self.Bind (wx.EVT_MENU, self.addTaskFunction, saveItem) self.Bind (wx.EVT_MENU, self.editFunction, editItem) self.Bind (wx.EVT_MENU , self.deleteFunction, deleteItem) self.Bind (wx.EVT_MENU, self.changeDatabaseFunction, changeDatabase) self.Bind (wx.EVT_MENU, self.addDailyFunction, addDailyItem) self.Bind (wx.EVT_MENU, self.Quit, exitItem) self.Bind (wx.EVT_MENU, self.helpFunction, helpItem) #CREATE PANELS #panel wx.StaticBox(panel, label="Task Box: ", pos=(10,10),size=(715,165)) #category wx.StaticText(panel, label="Category:",pos=(20,30)) self.category_list = ToDoListDatabase.getDistinctCategories() if not self.category_list: self.category_list = ["[Category]","Other"] self.CategoryTF = wx.ComboBox (panel, pos=(20,55), size=(230,-1), \ choices=self.category_list, value =self.category_list[0]) #to do list description wx.StaticText(panel, label="To Do Item:",pos=(20,90)) self.toDoTF = wx.TextCtrl (panel, style=wx.TE_MULTILINE, pos=(20,110), size=(230,50) ) #current date wx.StaticText(panel, label="Current Date:",pos=(370,30)) self.CurrentDateTF = wx.TextCtrl(panel, pos=(370,50), size=(150,-1)) self.CurrentDateTF.SetValue(str(self.now)) #due date wx.StaticText(panel, label="Due Date:",pos=(370,80)) self.DueDateTF = wx.TextCtrl(panel, pos=(370,100), size=(150,-1)) self.DueDateTF.SetValue(str(self.now)) #Daily task wx.StaticText(panel, label="Daily Task?",pos=(570,30)) self.NoRB = wx.RadioButton(panel, label='No', pos=(570, 55), style=wx.RB_GROUP) self.YesRB = wx.RadioButton(panel, label='Yes', pos=(570, 75)) #create add button addBTN = wx.Button (panel, label = "Add", pos=(570,130), size=(100,30)) addBTN.Bind(wx.EVT_BUTTON, self.addTaskFunction) #--------------------------------------------------------------------- #Daily task wx.StaticText(panel, label="Choose List:",pos=(20,190)) self.MainRB = wx.RadioButton(panel, label='To Do List', pos=(100, 190), style=wx.RB_GROUP) self.DailyRB = wx.RadioButton(panel, label='Daily Tasks', pos=(180, 190)) self.MainRB.Bind(wx.EVT_RADIOBUTTON, self.setTableFunction) self.DailyRB.Bind(wx.EVT_RADIOBUTTON, self.setTableFunction) self.tableLabel = wx.StaticText(panel, label="You are currently working on: To Do List",pos=(450,190)) #add list self.listCtrl = wx.ListCtrl (panel, pos=(20,215), size=(700,340), \ style=wx.LC_REPORT | wx.BORDER_SUNKEN) #set columns self.listCtrl.InsertColumn(0, "ID") self.listCtrl.InsertColumn(1, "Category") self.listCtrl.InsertColumn(2, "To Do List Item ", width=-1) self.listCtrl.InsertColumn(3, "Creation Date") self.listCtrl.InsertColumn(4, "Due Date") self.listCtrl.InsertColumn (5, "Daily Task") self.listCtrl.SetColumnWidth(0, -1) self.listCtrl.SetColumnWidth(2, -2) self.listCtrl.Bind(wx.EVT_LIST_ITEM_SELECTED, self.getRow) #display item Count self.itemCountLabel = wx.StaticText(panel, label="Item count:",pos=(625,560)) #add sort by self.SortCatOne = wx.ComboBox (panel, pos=(20,580), \ choices=colmn_list, style=wx.CB_READONLY, value =colmn_list[0]) colmn_list[0] = "[Item 2]" self.SortCatTwo = wx.ComboBox (panel, pos=(130,580), \ choices=colmn_list, style=wx.CB_READONLY, value =colmn_list[0]) sortCatBTN = wx.Button (panel, label = "Sort By Cat", pos=(240,580), size=(100,30)) sortCatBTN.Bind(wx.EVT_BUTTON, self.sortCatFunction) #add edit editBTN = wx.Button (panel, label = "Edit Item", pos=(410,580), size=(100,30)) editBTN.Bind(wx.EVT_BUTTON, self.editFunction) #add update list refreshBTN = wx.Button (panel, label = "Refresh List", pos=(520,580), size=(100,30)) refreshBTN.Bind(wx.EVT_BUTTON, self.refreshFunction) #add delete deleteBTN = wx.Button (panel, label = "Delete Item", pos=(630,580), size=(100,30)) deleteBTN.Bind(wx.EVT_BUTTON, self.deleteFunction) #populate listbox self.addToListBox()
def addDailyFunction(self, e): ToDoListDatabase.getDailyTasks() self.addToListBox()
def getItemCountFunction(self): selectedCount = self.listCtrl.GetSelectedItemCount() self.itemCount = ToDoListDatabase.getItemCount(self.CurrentTable) self.itemCountLabel.SetLabel("Item count: {}/{}".format(selectedCount,self.itemCount))