def __init__(self, model, dag, parent=None, settings=None): MainWindow.__init__(self, parent) self.setAttribute(Qt.WA_MacMetalStyle) self.setMinimumSize(420, 420) # change when widgets are added/removed self.widget_version = 2 self.model = model self.dag = dag self.settings = settings self.commits = {} self.commit_list = [] self.thread = ReaderThread(dag, self) self.revtext = completion.GitLogLineEdit() self.maxresults = standard.SpinBox() self.zoom_out = qtutils.create_action_button( tooltip=N_('Zoom Out'), icon=qtutils.theme_icon('zoom-out.png')) self.zoom_in = qtutils.create_action_button( tooltip=N_('Zoom In'), icon=qtutils.theme_icon('zoom-in.png')) self.zoom_to_fit = qtutils.create_action_button( tooltip=N_('Zoom to Fit'), icon=qtutils.theme_icon('zoom-fit-best.png')) self.notifier = notifier = observable.Observable() self.notifier.refs_updated = refs_updated = 'refs_updated' self.notifier.add_observer(refs_updated, self.display) self.treewidget = CommitTreeWidget(notifier, self) self.diffwidget = DiffWidget(notifier, self) self.filewidget = FileWidget(notifier, self) self.graphview = GraphView(notifier, self) self.controls_layout = qtutils.hbox(defs.no_margin, defs.spacing, self.revtext, self.maxresults) self.controls_widget = QtGui.QWidget() self.controls_widget.setLayout(self.controls_layout) self.log_dock = qtutils.create_dock(N_('Log'), self, stretch=False) self.log_dock.setWidget(self.treewidget) log_dock_titlebar = self.log_dock.titleBarWidget() log_dock_titlebar.add_corner_widget(self.controls_widget) self.file_dock = qtutils.create_dock(N_('Files'), self) self.file_dock.setWidget(self.filewidget) self.diff_dock = qtutils.create_dock(N_('Diff'), self) self.diff_dock.setWidget(self.diffwidget) self.graph_controls_layout = qtutils.hbox(defs.no_margin, defs.button_spacing, self.zoom_out, self.zoom_in, self.zoom_to_fit) self.graph_controls_widget = QtGui.QWidget() self.graph_controls_widget.setLayout(self.graph_controls_layout) self.graphview_dock = qtutils.create_dock(N_('Graph'), self) self.graphview_dock.setWidget(self.graphview) graph_titlebar = self.graphview_dock.titleBarWidget() graph_titlebar.add_corner_widget(self.graph_controls_widget) self.lock_layout_action = qtutils.add_action_bool( self, N_('Lock Layout'), self.set_lock_layout, False) self.refresh_action = qtutils.add_action(self, N_('Refresh'), self.refresh, 'Ctrl+R') # Create the application menu self.menubar = QtGui.QMenuBar(self) # View Menu self.view_menu = qtutils.create_menu(N_('View'), self.menubar) self.view_menu.addAction(self.refresh_action) self.view_menu.addAction(self.log_dock.toggleViewAction()) self.view_menu.addAction(self.graphview_dock.toggleViewAction()) self.view_menu.addAction(self.diff_dock.toggleViewAction()) self.view_menu.addAction(self.file_dock.toggleViewAction()) self.view_menu.addSeparator() self.view_menu.addAction(self.lock_layout_action) self.menubar.addAction(self.view_menu.menuAction()) self.setMenuBar(self.menubar) left = Qt.LeftDockWidgetArea right = Qt.RightDockWidgetArea self.addDockWidget(left, self.log_dock) self.addDockWidget(left, self.diff_dock) self.addDockWidget(right, self.graphview_dock) self.addDockWidget(right, self.file_dock) # Update fields affected by model self.revtext.setText(dag.ref) self.maxresults.setValue(dag.count) self.update_window_title() # Also re-loads dag.* from the saved state if not self.restore_state(settings=settings): self.resize_to_desktop() qtutils.connect_button(self.zoom_out, self.graphview.zoom_out) qtutils.connect_button(self.zoom_in, self.graphview.zoom_in) qtutils.connect_button(self.zoom_to_fit, self.graphview.zoom_to_fit) self.thread.connect(self.thread, self.thread.commits_ready, self.add_commits) self.thread.connect(self.thread, self.thread.done, self.thread_done) self.connect(self.treewidget, SIGNAL('diff_commits'), self.diff_commits) self.connect(self.graphview, SIGNAL('diff_commits'), self.diff_commits) self.connect(self.maxresults, SIGNAL('editingFinished()'), self.display) self.connect(self.revtext, SIGNAL('changed()'), self.display) self.connect(self.revtext, SIGNAL('textChanged(QString)'), self.text_changed) self.connect(self.revtext, SIGNAL('returnPressed()'), self.display) # The model is updated in another thread so use # signals/slots to bring control back to the main GUI thread self.model.add_observer(self.model.message_updated, self.emit_model_updated) self.connect(self, SIGNAL('model_updated'), self.model_updated) qtutils.add_action(self, 'Focus search field', lambda: self.revtext.setFocus(), 'Ctrl+L') qtutils.add_close_action(self)
def __init__(self, model, ctx, parent=None, settings=None): standard.MainWindow.__init__(self, parent) self.setAttribute(Qt.WA_MacMetalStyle) self.setMinimumSize(420, 420) # change when widgets are added/removed self.widget_version = 2 self.model = model self.ctx = ctx self.settings = settings self.commits = {} self.commit_list = [] self.selection = [] self.thread = ReaderThread(ctx, self) self.revtext = completion.GitLogLineEdit() self.maxresults = standard.SpinBox() self.zoom_out = qtutils.create_action_button(tooltip=N_('Zoom Out'), icon=icons.zoom_out()) self.zoom_in = qtutils.create_action_button(tooltip=N_('Zoom In'), icon=icons.zoom_in()) self.zoom_to_fit = qtutils.create_action_button( tooltip=N_('Zoom to Fit'), icon=icons.zoom_fit_best()) self.notifier = notifier = observable.Observable() self.notifier.refs_updated = refs_updated = 'refs_updated' self.notifier.add_observer(refs_updated, self.display) self.notifier.add_observer(filelist.HISTORIES_SELECTED, self.histories_selected) self.notifier.add_observer(filelist.DIFFTOOL_SELECTED, self.difftool_selected) self.notifier.add_observer(diff.COMMITS_SELECTED, self.commits_selected) self.treewidget = CommitTreeWidget(notifier, self) self.diffwidget = diff.DiffWidget(notifier, self) self.filewidget = filelist.FileWidget(notifier, self) self.graphview = GraphView(notifier, self) self.controls_layout = qtutils.hbox(defs.no_margin, defs.spacing, self.revtext, self.maxresults) self.controls_widget = QtGui.QWidget() self.controls_widget.setLayout(self.controls_layout) self.log_dock = qtutils.create_dock(N_('Log'), self, stretch=False) self.log_dock.setWidget(self.treewidget) log_dock_titlebar = self.log_dock.titleBarWidget() log_dock_titlebar.add_corner_widget(self.controls_widget) self.file_dock = qtutils.create_dock(N_('Files'), self) self.file_dock.setWidget(self.filewidget) self.diff_dock = qtutils.create_dock(N_('Diff'), self) self.diff_dock.setWidget(self.diffwidget) self.graph_controls_layout = qtutils.hbox(defs.no_margin, defs.button_spacing, self.zoom_out, self.zoom_in, self.zoom_to_fit, defs.spacing) self.graph_controls_widget = QtGui.QWidget() self.graph_controls_widget.setLayout(self.graph_controls_layout) self.graphview_dock = qtutils.create_dock(N_('Graph'), self) self.graphview_dock.setWidget(self.graphview) graph_titlebar = self.graphview_dock.titleBarWidget() graph_titlebar.add_corner_widget(self.graph_controls_widget) self.lock_layout_action = qtutils.add_action_bool( self, N_('Lock Layout'), self.set_lock_layout, False) self.refresh_action = qtutils.add_action(self, N_('Refresh'), self.refresh, hotkeys.REFRESH) # Create the application menu self.menubar = QtGui.QMenuBar(self) # View Menu self.view_menu = qtutils.create_menu(N_('View'), self.menubar) self.view_menu.addAction(self.refresh_action) self.view_menu.addAction(self.log_dock.toggleViewAction()) self.view_menu.addAction(self.graphview_dock.toggleViewAction()) self.view_menu.addAction(self.diff_dock.toggleViewAction()) self.view_menu.addAction(self.file_dock.toggleViewAction()) self.view_menu.addSeparator() self.view_menu.addAction(self.lock_layout_action) self.menubar.addAction(self.view_menu.menuAction()) self.setMenuBar(self.menubar) left = Qt.LeftDockWidgetArea right = Qt.RightDockWidgetArea self.addDockWidget(left, self.log_dock) self.addDockWidget(left, self.diff_dock) self.addDockWidget(right, self.graphview_dock) self.addDockWidget(right, self.file_dock) # Update fields affected by model self.revtext.setText(ctx.ref) self.maxresults.setValue(ctx.count) self.update_window_title() # Also re-loads dag.* from the saved state if not self.restore_state(settings=settings): self.resize_to_desktop() qtutils.connect_button(self.zoom_out, self.graphview.zoom_out) qtutils.connect_button(self.zoom_in, self.graphview.zoom_in) qtutils.connect_button(self.zoom_to_fit, self.graphview.zoom_to_fit) self.thread.connect(self.thread, self.thread.begin, self.thread_begin, Qt.QueuedConnection) self.thread.connect(self.thread, self.thread.status, self.thread_status, Qt.QueuedConnection) self.thread.connect(self.thread, self.thread.add, self.add_commits, Qt.QueuedConnection) self.thread.connect(self.thread, self.thread.end, self.thread_end, Qt.QueuedConnection) self.connect(self.treewidget, SIGNAL('diff_commits(PyQt_PyObject,PyQt_PyObject)'), self.diff_commits) self.connect(self.graphview, SIGNAL('diff_commits(PyQt_PyObject,PyQt_PyObject)'), self.diff_commits) self.connect(self.maxresults, SIGNAL('editingFinished()'), self.display) self.connect(self.revtext, SIGNAL('textChanged(QString)'), self.text_changed) self.connect(self.revtext, SIGNAL('activated()'), self.display) self.connect(self.revtext, SIGNAL('return()'), self.display) self.connect(self.revtext, SIGNAL('down()'), self.focus_tree) # The model is updated in another thread so use # signals/slots to bring control back to the main GUI thread self.model.add_observer(self.model.message_updated, self.emit_model_updated) self.connect(self, SIGNAL('model_updated()'), self.model_updated, Qt.QueuedConnection) qtutils.add_action(self, 'Focus Input', self.focus_input, hotkeys.FOCUS) qtutils.add_close_action(self)