def change_project_status(self, prj, new_status, queue_date=None): self._file_toady.move_project_folder(prj.summary, prj.status, new_status) prj_ = prj note = ProjectNote(prj=prj_) note.change_prj_status(new_status) if new_status == "queued": prj.queue_date = queue_date prj.status = new_status self.save_data()
def new_prj_notes_w_clicked_cb(self, widget, data=None): # FIXME: shit, what happens when a user changes the name of the project # after creating their notes? I should probably write a "rename prj" # method somewhere... if not self._note: self._note = ProjectNote(prj=self._prj) self._note.show()
def open_new_prj_dialog(self, prj, status, aofs, prj_notes=None, on_exit=None): """Open a new Project dialog. Args: prj: the new Project instance you want to build up status: project status - must be one of: "active"... (bleh) ..... finishing this later. on_exit: a dict to hold various options when we close the dialog """ self._prj = prj self._prj.status = status self.on_exit_hooks = on_exit #FIXME: this is incongruent with how I start up the NA dialog self._init_ui(prj.summary, aofs) self._do_magic(prj.summary) self._dialog.show() if prj_notes: self._note = ProjectNote(prj=self._prj, notes_for_new_prj=prj_notes) self._note.show()
def delete_prj(self, prj): utils.log_line("Deleting project: " + str(prj), datetime.datetime.now()) # trash the folders first self._file_toady.trash_project_folder(prj.summary, prj.status) # then ditch the project notes prj_ = prj ProjectNote(prj=prj_).delete() #this is /almost certainly/ The Hard Way... for a in self.aofs.keys(): matches = [] # Welcome to my entry in the "Obfuscated Python" contest! for p in xrange(len(self.aofs[a]['projects'])): if self.aofs[a]['projects'][p] == prj.key_name: matches.append({'aof': a, 'p_index': p}) for i in matches: del (self.aofs[i['aof']]['projects'][i['p_index']]) del (self.prjs[prj.key_name]) self.save_data()
class NewProjectDialog(GeeTeeDeeDialog): GTK_BUILDER_FILENAME = 'new_prj_dialog.ui' def __init__(self, caller, datamgr): super(NewProjectDialog, self).__init__(caller, datamgr) self._note = None def add_files_to_files_list(self, file_path=None): if file_path is None: chooser = gtk.FileChooserDialog( action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_ADD, gtk.RESPONSE_OK)) chooser.set_property("select-multiple", True) response = chooser.run() if response == gtk.RESPONSE_OK: for f in chooser.get_filenames(): row = ui.ProjectSupportFileRow(f) self._files_list_w.append(row) chooser.destroy() chooser = None else: row = ui.ProjectSupportFileRow(file_path) self._files_list_w.append(row) self._files_list_w.sort_by_attribute("isdir", order=gtk.SORT_ASCENDING) self._files_list_w.sort_by_attribute("name_lowercase", order=gtk.SORT_ASCENDING) def fill_na_list_w(self, fuck_you): self._new_prj_na_list_w.clear() for n in self._prj.next_actions: self._new_prj_na_list_w.append(n) last_item = len(self._new_prj_na_list_w) - 1 self._new_prj_na_list_w.select_paths([last_item]) def open_new_prj_dialog(self, prj, status, aofs, prj_notes=None, on_exit=None): """Open a new Project dialog. Args: prj: the new Project instance you want to build up status: project status - must be one of: "active"... (bleh) ..... finishing this later. on_exit: a dict to hold various options when we close the dialog """ self._prj = prj self._prj.status = status self.on_exit_hooks = on_exit #FIXME: this is incongruent with how I start up the NA dialog self._init_ui(prj.summary, aofs) self._do_magic(prj.summary) self._dialog.show() if prj_notes: self._note = ProjectNote(prj=self._prj, notes_for_new_prj=prj_notes) self._note.show() def _build_aof_list(self): if self._aof_w.get_selected() == defs.NO_AOF_ASSIGNED: return [] else: return [utils.format_for_dict_key(self._aof_w.get_selected())] def _build_due_date(self): return self._magical.get_magic_date(self._due_date_w.get_text()) def _build_file_list(self): file_list = [] # ZOMG I am so in love with Kiwi right now for f in self._files_list_w: file_list.append(f.full_path) return file_list def _build_prj(self, prj): for a in self._build_aof_list(): # set aofs prj.aofs.append(a) prj.summary = self._name_w.get_text() due = self._build_due_date() # set due date if due: prj.due_date = due if len(self._prj.next_actions) == 0: # set next_actions self._set_na_list() prj.priority = self._get_priority() # set priority qd = self._build_queue_date() # set queue_date if qd: prj.queue_date = qd if prj.queue_date: # set status - **must be set prj.status = "queued" # *after* queue_date, or this return prj # could be inaccurate! def _build_queue_date(self): #FIXME: gotta make this actually do something, too... #self._queue_date_w.get_text() return None def _cancel_prj(self): self._dialog.hide() if self._note: self._note.delete() def _create_prj(self, prj): if self._validate_me_please_i_needs_it(): prj = self._build_prj(prj) prj.file_list = self._build_file_list() self._dialog.hide() #FIXME: gawd, this is awful. must fiiiix. self._data_lumbergh.prjs[prj.key_name] = prj for a in prj.aofs: if a != "": #FIXME: surely this can't be what I intended with DataManager ;P self._data_lumbergh.aofs[a]['projects'].append(prj.key_name) for f in prj.file_list: self._data_lumbergh.copy_to_project_folder(f, prj) # if f.full_path.startswith(defs.INBOX_FOLDER): # gio.File(f).trash() # handle on_exit hooks if self.on_exit_hooks: if 'queued' in self.on_exit_hooks: self._caller.queue_project(prj) elif 'waiting_for' in self.on_exit_hooks: self._caller.mark_project_as_waiting_for(prj) # prj.file_list is intended to be "disposable", soooo... del(prj.file_list) self._data_lumbergh.save_data() self._caller.fill_prj_list_w() # FIXME: re-enable this at some point... *sigh* # selected = self._caller.prj_list_w.index(prj) # self._caller.prj_list_w.select_paths([selected]) # i.e.: are we on the Review tab? if self._caller.workflow_nb.get_current_page() == "1": gobject.idle_add(self._caller.prj_list_w.grab_focus) def _do_magic(self, prj_name): #get magic task (i.e.: 'mt') mt = self._magical.get_magic_task(prj_name) self._name_w.set_text(mt['summary']) #FIXME: this is hackish, might break eventually if I don't clean it up if 'priority' in mt: plabel = ui.PRIORITY_VALUES_TO_LABELS[mt['priority']] self._priority_w.select_item_by_label(plabel) if 'due_date' in mt: dtext = mt['due_date'].strftime(defs.GTK_DATE_TEXT_TEMPLATE) self._due_date_w.set_text(dtext) def _init_files_list_w(self, obj_list): #I have no idea why 23 worked best. obj_list.set_columns( [Column('icon', width=23, data_type=gtk.gdk.Pixbuf), Column('file_name', data_type=str, searchable=True, expand=True), Column('full_path', data_type=str, visible=False), Column('name_lowercase', data_type=str, visible=False), Column('isdir', data_type=bool, visible=False)]) obj_list.set_headers_visible(False) def _init_ui(self, prj_name, aof): #set the prj name and the areas of focus self._name_w.set_text(prj_name) #HACK: oh god... so, so sad. One day I'll learn proper OO design. *sigh* self._caller.fill_aofs_w(self._aof_w, self._data_lumbergh.aof_names, False) if aof != "": self._aof_w.select_item_by_label(aof) self._init_files_list_w(self._files_list_w) self._init_new_prj_na_list_w(self._new_prj_na_list_w) self._new_prj_na_summary_w.grab_focus() self._priority_w.select_item_by_label("Normal") def _init_new_prj_na_list_w(self, obj_list): obj_list.set_columns([Column('uuid', data_type=str, visible=False), Column('context', data_type=str), Column('formatted_summary', data_type=str, use_markup=True, searchable=True), Column('due_date', data_type=str)]) obj_list.set_headers_visible(False) def _map_fields_to_instance_names(self): self._dialog = self._builder.get_object("new_prj_dialog") self._name_w = self._builder.get_object("new_prj_name_w") self._new_prj_na_summary_w = self._builder.get_object("new_prj_na_summary_w") self._priority_w = self._builder.get_object("new_prj_priority_w") self._due_date_w = self._builder.get_object("new_prj_due_date_w") self._files_list_w = self._builder.get_object("files_list_w") self._aof_w = self._builder.get_object("new_prj_aof_w") self._new_prj_na_list_w = self._builder.get_object("new_prj_na_list_w") def _set_na_list(self): if self._new_prj_na_summary_w.props.text: # i.e.: we haven't appended our NA yet n = gee_tee_dee.NextAction(self._new_prj_na_summary_w.props.text) mt = self._magical.get_magic_task(n.summary) for name in mt.keys(): try: n.__setattr__(name, mt[name]) except: pass # and finally... self._prj.next_actions.append(n) def _type_ahead_combo(self, combo, gdk_keyval): ui.type_ahead_combo(combo, gdk_keyval) def _validate_me_please_i_needs_it(self): # check that name line isn't blank if self._name_w.get_text() == "": return False # then verify that the due date isn't f****d if self._due_date_w.get_text() == defs.UNRECOGNIZED_DATE_TEXT: self._due_date_w.grab_focus() return False #FIXME: add immediate prj queueing here # if self._queue_to_w.get_text() == defs.UNRECOGNIZED_DATE_TEXT: # self._queue_to_w.grab_focus() # return False return True #CALLBACKS def files_list_w_key_press_event_cb(self, widget, data=None): if gtk.gdk.keyval_name(data.keyval) == "Delete": self._files_list_w.remove(self._files_list_w.get_selected()) def files_list_w_row_activated_cb(self, widget, data=None): uri_header = "file://" selected = widget.get_selected_rows() # don't do anything if multiple files are selected if len(selected) == 1: path = selected[0].full_path gtk.show_uri(gtk.gdk.Screen(), uri_header + path, int(time.time())) def new_prj_add_w_clicked_cb(self, widget, data=None): widget.grab_focus() self._create_prj(self._prj) def new_prj_aof_w_content_changed_cb(self, widget, data=None): pass def new_prj_aof_w_key_press_event_cb(self, widget, data=None): self._type_ahead_combo(widget, data) def new_prj_cancel_w_clicked_cb(self, widget, data=None): self._cancel_prj() def new_prj_due_date_w_focus_out_event_cb(self, widget, data=None): self._set_valid_date_w(widget) def new_prj_files_add_w_clicked_cb(self, widget, data=None): self.add_files_to_files_list() def new_prj_files_remove_w_clicked_cb(self, widget, data=None): for f in self._files_list_w.get_selected_rows(): self._files_list_w.remove(f) def new_prj_na_edit_w_clicked_cb(self, widget, data=None): na = self._new_prj_na_list_w.get_selected() if na: nad = NewNextActionDialog(self, self._data_lumbergh) nad.edit_extant_na(na) def new_prj_na_remove_w_clicked_cb(self, widget, data=None): self._new_prj_na_list_w.remove(self._new_prj_na_list_w.get_selected()) def new_prj_na_summary_w_activate_cb(self, widget, data=None): if self._new_prj_na_summary_w.get_text() != "": nad = NewNextActionDialog(self, self._data_lumbergh) nad.start_new_na(self._new_prj_na_summary_w.get_text(), self._prj) self._new_prj_na_summary_w.set_text("") def new_prj_notes_w_clicked_cb(self, widget, data=None): # FIXME: shit, what happens when a user changes the name of the project # after creating their notes? I should probably write a "rename prj" # method somewhere... if not self._note: self._note = ProjectNote(prj=self._prj) self._note.show() def new_prj_priority_w_key_press_event_cb(self, widget, data=None): self._type_ahead_combo(widget, data)