python - Get full file path from GtkTreeView -
so, found tutorial on creating file browser using gtk.treeview i'm facing problem, when select file inside folder cant file's full path. can model path don't know it.
this project tree:
. ├── browser │ ├── index.html │ └── markdown.min.js ├── compiler.py ├── ide-preview.png ├── __init__.py ├── main.py ├── __pycache__ │ ├── compiler.cpython-35.pyc │ └── welcomewindow.cpython-35.pyc ├── pyide-settings.json ├── readme.md ├── resources │ └── icons │ ├── git-branch.svg │ ├── git-branch-uptodate.svg │ └── git-branch-waitforcommit.svg ├── test.py ├── welcomewindow.glade └── welcomewindow.py
when click on main.py
path 4
, if click on browser/markdown.min.js
0:1
.
in code check if path's length (i split path ':') bigger 1, if not open file normally, if is... i'm stuck. can help?
here treeselection on changed function:
def onrowactivated(self, selection): # print(path.to_string()) # might job... model, row = selection.get_selected() if row not none: # print(model[row][0]) path = model.get_path(row).to_string() patharr = path.split(':') filefullpath = '' if not os.path.isdir(os.path.realpath(model[row][0])): # self.openfile(os.path.realpath(model[row][0])) if len(patharr) <= 1: self.openfile(os.path.realpath(model[row][0])) else: # don't know do! self.languagelbl.set_text('language: {}'.format(self.sbuff.get_language().get_name())) else: print('none')
full code available @ https://github.com/raggesilver/pyide/blob/master/main.py
edit 1: more specific, problem when name of file treeview, can't path before it, index.html
instead of browser/index.html
.
i found solution problem, logic iterate through path (e.g.: 4:3:5:0) backwards , last parent's name , prepend path variable. have:
def onrowactivated(self, selection): # print(path.to_string()) # might job... model, row = selection.get_selected() if row not none: # print(model[row][0]) path = model.get_path(row).to_string() patharr = path.split(':') filefullpath = '' if len(patharr) <= 1: if not os.path.isdir(os.path.realpath(os.path.join(self.projectpath, model[row][0]))): self.openfile(os.path.realpath(os.path.join(self.projectpath, model[row][0]))) self.autocomplete.on_document_load() else: exp = self.sidescroller.get_child().row_expanded(model.get_path(row)) if not exp: self.sidescroller.get_child().expand_row(model.get_path(row), false) else: self.sidescroller.get_child().collapse_row(model.get_path(row)) else: ## here solution p = model[row][0] # last item in path = model.iter_depth(row) j = cur = none while j > 0: # each parent add last p cur = model.iter_parent(cur) if not cur none else model.iter_parent(row) p = model[cur][0] + '/' + p # p = last parent + '/' + p j -= 1 if not os.path.isdir(os.path.realpath(os.path.join(self.projectpath, p))): self.openfile(os.path.realpath(os.path.join(self.projectpath, p))) self.autocomplete.on_document_load() else: exp = self.sidescroller.get_child().row_expanded(model.get_path(row)) if not exp: self.sidescroller.get_child().expand_row(model.get_path(row), false) else: self.sidescroller.get_child().collapse_row(model.get_path(row)) self.languagelbl.set_text('language: {}'.format(self.sbuff.get_language().get_name() if not self.sbuff.get_language() none else "plain")) else: print('none')
Comments
Post a Comment