def __init__(self, config): self.config = config self.config.connect("on-change", self._on_config_change) self.gh = GithubConnect(self.config.github_auth_token, self.config.prspy_debug == "True") self.model = MainViewModel(self.gh, self.config) self.view = MainView() # register for exit self.view.window.connect("destroy", self._on_close) # Register for changed events from the model so # that the view can be told to update. self.model.connect("changed", self._on_model_change) self._first_show = True # Configure view's toolbar button events. self.view.quit_button.connect("clicked", self._on_quit_clicked) self.view.refresh_button.connect("clicked", self._on_refresh_clicked) self.view.preferences_button.connect("clicked", self._show_options_dialog) # When the selection changes in the view, update # the view's detail pain with the correct model data. self.view.event_tree_view.get_selection().connect("changed", self._on_selection_change) # When a row is double clicked, open the pull request in the # default browser. self.view.event_tree_view.connect("row-activated", self._on_pull_request_row_double_click) # When a comment row is doubleclicked, open it in the browser. self.view.comments_tab_list_view.connect("row-activated", self._on_comment_row_double_click)
class MainViewController(object): def __init__(self, config): self.config = config self.config.connect("on-change", self._on_config_change) self.gh = GithubConnect(self.config.github_auth_token, self.config.prspy_debug == "True") self.model = MainViewModel(self.gh, self.config) self.view = MainView() # register for exit self.view.window.connect("destroy", self._on_close) # Register for changed events from the model so # that the view can be told to update. self.model.connect("changed", self._on_model_change) self._first_show = True # Configure view's toolbar button events. self.view.quit_button.connect("clicked", self._on_quit_clicked) self.view.refresh_button.connect("clicked", self._on_refresh_clicked) self.view.preferences_button.connect("clicked", self._show_options_dialog) # When the selection changes in the view, update # the view's detail pain with the correct model data. self.view.event_tree_view.get_selection().connect("changed", self._on_selection_change) # When a row is double clicked, open the pull request in the # default browser. self.view.event_tree_view.connect("row-activated", self._on_pull_request_row_double_click) # When a comment row is doubleclicked, open it in the browser. self.view.comments_tab_list_view.connect("row-activated", self._on_comment_row_double_click) def show_main_view(self): # If it is the first time that the main view # was shown, load the data. self.view.show() self.view.on_config_update(self.config) if self.config.github_auth_token and self._first_show: self.refresh_model() if self._first_show: self._first_show = False def refresh_model(self): self.model.refresh() def _on_config_change(self, config): #update our github connection as the token may have changed # from the options dialog. self.gh.reconfigure(self.config.github_auth_token) self.view.on_config_update(self.config) def _on_model_change(self, model, cause): self.view.update(model.pull_requests.values()) def _on_selection_change(self, tree_selection): self.view.comments_tab_label.set_text("Comments") model, tree_iter = tree_selection.get_selected() if not tree_iter: self.view.update_details(None) return selection = model.get(tree_iter, 0) pull_request_num = int(selection[0]) pull = None if pull_request_num >= 0: pull = self.model.pull_requests[pull_request_num] self.view.selected_pull = pull self.view.update_details(pull) def _on_pull_request_row_double_click(self, treeview, path, column): tree_iter = treeview.get_model().get_iter(path) selection = treeview.get_model().get(tree_iter, 0) pull_request_num = int(selection[0]) self._open_pull_request_in_browser(pull_request_num) def _on_comment_row_double_click(self, treeview, path, column): tree_iter = treeview.get_model().get_iter(path) selection = treeview.get_model().get(tree_iter, 3) url = selection[0] self._open_comment_in_browser(url) def _open_pull_request_in_browser(self, pull_request_num): if not pull_request_num in self.model.pull_requests: return pull_request = self.model.pull_requests[pull_request_num] webbrowser.open(pull_request.html_url, 0, True) def _open_comment_in_browser(self, url): if not url: return webbrowser.open(url, 0, True) def _on_quit_clicked(self, button): self.quit() def _on_close(self, window): self.quit() def quit(self): gtk.main_quit() def _on_refresh_clicked(self, button): self.refresh_model() def _show_options_dialog(self, button): options_controller = OptionsDialogController(self.gh, self.config, self.view) options_controller.show_view()