Skip to content

Commit

Permalink
file and directory name editing added
Browse files Browse the repository at this point in the history
  • Loading branch information
bfaure committed Jan 10, 2017
1 parent bdeaa2f commit 2681926
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 2 deletions.
2 changes: 1 addition & 1 deletion data/prefs.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
home-->/Users/Faure/Desktop
home-->C:\Users\bfaure\Desktop
open_to_home_by_default-->YES
Binary file modified lib/image_editor_files/image_editor.pyc
Binary file not shown.
Binary file modified lib/text_editor_files/ext/__init__.pyc
Binary file not shown.
Binary file modified lib/text_editor_files/ext/datetime.pyc
Binary file not shown.
Binary file modified lib/text_editor_files/ext/find.pyc
Binary file not shown.
Binary file modified lib/text_editor_files/ext/table.pyc
Binary file not shown.
Binary file modified lib/text_editor_files/ext/wordcount.pyc
Binary file not shown.
Binary file modified lib/text_editor_files/text_editor.pyc
Binary file not shown.
70 changes: 69 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ def init_vars(self):
# list of tab_details structs, one for each tab that is open
self.tabs = []

self.user_changing_list_item = False

def init_ui(self):

# Layout items
Expand Down Expand Up @@ -380,7 +382,9 @@ def init_ui(self):
display = QListWidget()
display_layout.addWidget(display)
display.itemDoubleClicked.connect(self.item_chosen)

#display.currentTextChanged.connect(self.user_changed_list_item)
display.itemChanged.connect(self.user_changed_list_item)

# button to open new tab
self.tabButton = QToolButton(self)
self.tabButton.setText('+')
Expand Down Expand Up @@ -410,6 +414,66 @@ def init_ui(self):
QtCore.QObject.connect(self.prefs_window, QtCore.SIGNAL("return_prefs()"), self.end_pref_edit)
self.show()

# check if text follows rules for file or folder naming
def item_text_validator(self,text):
not_allowed = [",","/","\\"]
text = str(text)
for item in not_allowed:
if text.find(item)!=-1:
return False
return True

# slot activated whenever one of the list items is changed, we only
# respond if the self.user_changing_list_item flag is set to true.
def user_changed_list_item(self):

if hasattr(self,'user_changing_list_item')==False:
return
if self.user_changing_list_item==False:
return
if self.current_display_widget.currentRow()!=self.change_index:
return

item_changed = self.current_display_widget.currentItem()
new_text = item_changed.text()
old_text = self.list_item_text
#print "new_text = "+new_text+" old_text = "+old_text

if self.item_text_validator(new_text)==False:
item_changed.setText(old_text)
return

old_path = self.current_location+_delim+old_text
new_path = self.current_location+_delim+new_text

try:
os.rename(old_path,new_path)

except:
item_changed.setText(old_text)

# slot called when user clicks certain keys
def keyPressEvent(self,event):

# return if user is not interacting with display
if self.current_display_widget.hasFocus()==False:
return

allow_editing_on = [Qt.Key_Return,Qt.Key_Enter,16777224]
if event.key() in allow_editing_on:
print "change the name here"
item = self.current_display_widget.currentItem()
self.list_item_text = item.text()
item.setFlags(item.flags() | Qt.ItemIsEditable)
self.current_display_widget.editItem(item)
self.user_changing_list_item = True
self.change_index = self.current_display_widget.currentRow()

# On space we want to allow the user to open the information pane
elif event.key() == Qt.Key_I:
print "open the information pane here"


# slot called when tab is changed
def tab_changed(self):

Expand Down Expand Up @@ -472,6 +536,10 @@ def create_new_tab(self):
# initializing some layouts
display_layout = QVBoxLayout(new_tab_parent) # display square
display = QListWidget()
#display.currentTextChanged.connect(self.user_changed_list_item)
display.itemChanged.connect(self.user_changed_list_item)


display_layout.addWidget(display)
display.itemDoubleClicked.connect(self.item_chosen)

Expand Down
Binary file added resources/screenshots/windows1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/screenshots/windows2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2681926

Please sign in to comment.