def init_results_widget(self): results_widget = QTabWidget(self) results_widget.setTabsClosable(False) table_view = QTableView(self) table_view.setModel(self.model) table_view.sizePolicy().setVerticalPolicy( QSizePolicy.MinimumExpanding) results_widget.addTab(table_view, 'Data') log = QTextEdit(self) log.setReadOnly(True) self.model.executed.connect(log.append) results_widget.addTab(log, 'Events') return results_widget
class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setMinimumWidth(640) self.setMinimumHeight(480) # Set up QTabWidget as a central widget self.tab_widget = QTabWidget(self) self.tab_widget.setTabsClosable(True) self.tab_widget.tabCloseRequested.connect(self.on_tab_close_clicked) self.setCentralWidget(self.tab_widget) # Create "Connection" menu menu_bar = self.menuBar() connection_menu = menu_bar.addMenu('Connection') # Add "Create" connection button create_connection_action = QAction('Create', self) create_connection_action.triggered.connect(self.add_new_tab) connection_menu.addAction(create_connection_action) # Add "Close" connection button close_connection_action = QAction('Close', self) close_connection_action.triggered.connect(self.close_current_tab) connection_menu.addAction(close_connection_action) # self.tool_bar = self.addToolBar('test bar') # self.connect_action = self.tool_bar.addAction('connect') self.add_new_tab() def add_new_tab(self): connection_widget = ConnectionWidget(self.tab_widget) connection_widget.title_changed.connect(self.on_tab_name_changed) self.tab_widget.addTab(connection_widget, 'Untitled') def close_current_tab(self): idx = self.tab_widget.currentIndex() self.tab_widget.removeTab(idx) def on_tab_close_clicked(self, idx): self.tab_widget.removeTab(idx) def on_tab_name_changed(self, widget, name): idx = self.tab_widget.indexOf(widget) if idx != -1: self.tab_widget.setTabText(idx, name)
def build_results_widget(self): # Initialize QTabWidget to display table view and log # in differnt unclosable tabs results_widget = QTabWidget(self) results_widget.setTabsClosable(False) # Add table view table_view = QTableView(self) table_view.setModel(self.model) table_view.sizePolicy().setVerticalPolicy(QSizePolicy.MinimumExpanding) results_widget.addTab(table_view, UI.QUERY_RESULTS_DATA_TAB_TEXT) # Att log view log = QTextEdit(self) log.setReadOnly(True) self.model.executed.connect(log.append) results_widget.addTab(log, UI.QUERY_RESULTS_EVENTS_TAB_TEXT) return results_widget
def init_results_widget(self): # Initialize QTabWidget to display table view and log # in differnt unclosable tabs results_widget = QTabWidget(self) results_widget.setTabsClosable(False) # Add table view table_view = QTableView(self) table_view.setModel(self.model) table_view.sizePolicy().setVerticalPolicy( QSizePolicy.MinimumExpanding) results_widget.addTab(table_view, 'Data') # Att log view log = QTextEdit(self) log.setReadOnly(True) self.model.executed.connect(log.append) results_widget.addTab(log, 'Events') return results_widget
class MainWin(QMainWindow): """ It's a window, stores a TabWidget """ def __init__(self, parent=None): super(MainWin, self).__init__(parent) self.setWindowTitle("Eilat Browser") # gc.set_debug(gc.DEBUG_LEAK) self.last_closed = None self.tab_widget = QTabWidget(self) self.tab_widget.setTabBar(MidClickTabBar(self)) self.tab_widget.tabBar().setMovable(True) self.tab_widget.setTabsClosable(True) # the right side of the tab already has the space for # a non-shown close button self.tab_widget.setStyleSheet( 'QTabBar::tab {padding-top: 0px; padding-bottom: 0px; ' 'padding-left: 0.3em;} ' 'QTabBar::tab:selected {color: #00f;}') # tabCloseRequested carries int (index of a tab) self.tab_widget.tabCloseRequested.connect(self.del_tab) self.setCentralWidget(self.tab_widget) self.tooltip = NotifyLabel(parent=self) def restore_last_closed(): """ One-use callback for QShortcut. Opens a fresh new tab with the url address of the last tab closed """ if self.last_closed is not None: url = self.last_closed self.add_tab(url) self.last_closed = None def dump_gc(): """ prints sizes for large memory collectable objects """ objs = gc.get_objects() pairs = [(str(k)[:80], type(k).__name__, sys.getsizeof(k)) for k in objs if sys.getsizeof(k) > 1024*4*5] for pair in pairs: print(pair) def reload_disk_init(): """ transfer options.yaml and the css directory to global maps """ load_options() load_css() notify("reloaded disk config") set_shortcuts([ ("F9", self, dump_gc), # reload configuration ("Ctrl+Shift+R", self, reload_disk_init), # new tabs ("Ctrl+T", self, self.add_tab), ("Ctrl+Shift+T", self, partial(self.add_tab, scripting=True)), ("Y", self, self.new_tab_from_clipboard), # movement ("M", self, self.inc_tab), ("N", self, partial(self.inc_tab, -1)), ("Ctrl+PgUp", self, partial(self.inc_tab, -1)), ("Ctrl+PgDown", self, self.inc_tab), # destroy/undestroy ("U", self, restore_last_closed), ("Ctrl+W", self, self.del_tab), ("Ctrl+Q", self, self.finalize) ]) def new_tab_from_clipboard(self): """ One-use callback for QShortcut. Reads the content of the PRIMARY clipboard and navigates to it on a new tab. """ url = clipboard() if url is not None: self.add_tab(url) # aux. action (en register_actions) def inc_tab(self, incby=1): """ Takes the current tab index, modifies wrapping around, and sets as current. Afterwards the active tab has focus on its webkit area. """ if self.tab_widget.count() < 2: return idx = self.tab_widget.currentIndex() idx += incby if idx < 0: idx = self.tab_widget.count()-1 elif idx >= self.tab_widget.count(): idx = 0 self.tab_widget.setCurrentIndex(idx) self.tab_widget.currentWidget().webkit.setFocus() def finalize(self): """ Just doing self.close() doesn't clean up; for example, closing when the address bar popup is visible doesn't close the popup, and leaves the window hidden and unclosable (except e.g. for KILL 15) Makes a hard app close through os._exit to prevent garbage collection; cleanup has typically done more harm than good. Any state that we may want to preserve we should do ourselves (e.g. cookies through the NAMs) """ idx = self.tab_widget.currentIndex() self.tab_widget.widget(idx).deleteLater() self.tab_widget.removeTab(idx) close_managers() # also does an os._exit # action y connect en llamada en constructor def del_tab(self, idx=None): """ Closes a tab. If 'idx' is set, it was called by a tabCloseRequested signal (maybe mid click). If not, it was called by a keyboard action and closes the currently active tab. Afterwards the active tab has focus on its webkit area. It closes the window when deleting the last active tab. """ if idx is None: idx = self.tab_widget.currentIndex() self.tab_widget.widget(idx).webkit.stop() self.last_closed = self.tab_widget.widget(idx).webkit.url() self.tab_widget.widget(idx).deleteLater() self.tab_widget.removeTab(idx) if len(self.tab_widget) == 0: close_managers() # also does an os.__exit else: self.tab_widget.currentWidget().webkit.setFocus() # action (en register_actions) # only way to create a new tab # called externally in eilat.py to create the first tab def add_tab(self, url=None, scripting=False): """ Creates a new tab, either empty or navegating to the url. Sets itself as the active tab. If navegating to an url it gives focus to the webkit area. Otherwise, the address bar is focused. """ tab = WebTab(parent=self.tab_widget) self.tab_widget.addTab(tab, tab.current['title']) self.tab_widget.setCurrentWidget(tab) tab_idx = self.tab_widget.indexOf(tab) self.tab_widget.tabBar().tabButton(tab_idx, 1).hide() # 1: right align if scripting: tab.toggle_script() if url is not None: qurl = fix_url(url) tab.webkit.navigate(qurl) else: tab.address_bar.setFocus()
class MainWin(QMainWindow): """ It's a window, stores a TabWidget """ def __init__(self, parent=None): super(MainWin, self).__init__(parent) self.setWindowTitle("Eilat Browser") # gc.set_debug(gc.DEBUG_LEAK) self.last_closed = None self.tab_widget = QTabWidget(self) self.tab_widget.setTabBar(MidClickTabBar(self)) self.tab_widget.tabBar().setMovable(True) self.tab_widget.setTabsClosable(True) # the right side of the tab already has the space for # a non-shown close button self.tab_widget.setStyleSheet( 'QTabBar::tab {padding-top: 0px; padding-bottom: 0px; ' 'padding-left: 0.3em;} ' 'QTabBar::tab:selected {color: #00f;}') # tabCloseRequested carries int (index of a tab) self.tab_widget.tabCloseRequested.connect(self.del_tab) self.setCentralWidget(self.tab_widget) self.tooltip = NotifyLabel(parent=self) def restore_last_closed(): """ One-use callback for QShortcut. Opens a fresh new tab with the url address of the last tab closed """ if self.last_closed is not None: url = self.last_closed self.add_tab(url) self.last_closed = None def dump_gc(): """ prints sizes for large memory collectable objects """ objs = gc.get_objects() pairs = [(str(k)[:80], type(k).__name__, sys.getsizeof(k)) for k in objs if sys.getsizeof(k) > 1024 * 4 * 5] for pair in pairs: print(pair) def reload_disk_init(): """ transfer options.yaml and the css directory to global maps """ load_options() load_css() notify("reloaded disk config") set_shortcuts([ ("F9", self, dump_gc), # reload configuration ("Ctrl+Shift+R", self, reload_disk_init), # new tabs ("Ctrl+T", self, self.add_tab), ("Ctrl+Shift+T", self, partial(self.add_tab, scripting=True)), ("Y", self, self.new_tab_from_clipboard), # movement ("M", self, self.inc_tab), ("N", self, partial(self.inc_tab, -1)), ("Ctrl+PgUp", self, partial(self.inc_tab, -1)), ("Ctrl+PgDown", self, self.inc_tab), # destroy/undestroy ("U", self, restore_last_closed), ("Ctrl+W", self, self.del_tab), ("Ctrl+Q", self, self.finalize) ]) def new_tab_from_clipboard(self): """ One-use callback for QShortcut. Reads the content of the PRIMARY clipboard and navigates to it on a new tab. """ url = clipboard() if url is not None: self.add_tab(url) # aux. action (en register_actions) def inc_tab(self, incby=1): """ Takes the current tab index, modifies wrapping around, and sets as current. Afterwards the active tab has focus on its webkit area. """ if self.tab_widget.count() < 2: return idx = self.tab_widget.currentIndex() idx += incby if idx < 0: idx = self.tab_widget.count() - 1 elif idx >= self.tab_widget.count(): idx = 0 self.tab_widget.setCurrentIndex(idx) self.tab_widget.currentWidget().webkit.setFocus() def finalize(self): """ Just doing self.close() doesn't clean up; for example, closing when the address bar popup is visible doesn't close the popup, and leaves the window hidden and unclosable (except e.g. for KILL 15) Makes a hard app close through os._exit to prevent garbage collection; cleanup has typically done more harm than good. Any state that we may want to preserve we should do ourselves (e.g. cookies through the NAMs) """ idx = self.tab_widget.currentIndex() self.tab_widget.widget(idx).deleteLater() self.tab_widget.removeTab(idx) close_managers() # also does an os._exit # action y connect en llamada en constructor def del_tab(self, idx=None): """ Closes a tab. If 'idx' is set, it was called by a tabCloseRequested signal (maybe mid click). If not, it was called by a keyboard action and closes the currently active tab. Afterwards the active tab has focus on its webkit area. It closes the window when deleting the last active tab. """ if idx is None: idx = self.tab_widget.currentIndex() self.tab_widget.widget(idx).webkit.stop() self.last_closed = self.tab_widget.widget(idx).webkit.url() self.tab_widget.widget(idx).deleteLater() self.tab_widget.removeTab(idx) if len(self.tab_widget) == 0: close_managers() # also does an os.__exit else: self.tab_widget.currentWidget().webkit.setFocus() # action (en register_actions) # only way to create a new tab # called externally in eilat.py to create the first tab def add_tab(self, url=None, scripting=False): """ Creates a new tab, either empty or navegating to the url. Sets itself as the active tab. If navegating to an url it gives focus to the webkit area. Otherwise, the address bar is focused. """ tab = WebTab(parent=self.tab_widget) self.tab_widget.addTab(tab, tab.current['title']) self.tab_widget.setCurrentWidget(tab) tab_idx = self.tab_widget.indexOf(tab) self.tab_widget.tabBar().tabButton(tab_idx, 1).hide() # 1: right align if scripting: tab.toggle_script() if url is not None: qurl = fix_url(url) tab.webkit.navigate(qurl) else: tab.address_bar.setFocus()