def _afterAppInit(self): """ Fired after WinterApp initialisation """ url = 'http://store.steampowered.com/search/tab?tab=Discounts&count=99' css = 'http://cdn.store.steampowered.com/public/css/styles_storev5.css' css = 'http://cdn.store.steampowered.com/public/css/styles_storev5.css' # g = Grab() # g.go(url) # persents=g.search_rex(re.compile('-\d+%')) # print persents.group(0) wi = EtherIntegration(self, UI=False) widget = wi.getWebView(toolbar=False) widget.view.js( 'var fileref=document.createElement("link");fileref.setAttribute("rel", "stylesheet");fileref.setAttribute("type", "text/css");fileref.setAttribute("href", %s)' % css) widget.view.load(QUrl(url)) # self.widget=widget # widget.setLayout(QVBoxLayout()) self.setMainWidget(widget) self.sideBar = WinterSideBar(self) # widget.view.loadFinished.connect(self.start) self.core.start()
def startGame(self): widget = QTabWidget(self) widget.setLayout(QVBoxLayout()) self.inv = InventoryPanel(self, self.core.hero) self.doll = DollPanel(self, self.core.hero) tables = QWidget() tables.setLayout(QGridLayout()) widget.layout().addWidget(tables) hi = QWidget() hi.setLayout(QHBoxLayout()) tables.layout().addWidget(hi) tables.layout().addWidget(self.inv, 0, 1) self.stats = StatsPanel(self, self.core.hero) hi.layout().addWidget(self.stats) hi.layout().addWidget(self.doll) self.log = GameLog(self) self.status = EffectsBar(self) # widget.layout().addWidget(self.status) self.log.setTitleBarWidget(self.status) # panel = QStackedWidget() # tables.layout().addWidget(panel,1,1) self.setMainWidget(widget) self.sideBar = WinterSideBar(self) self.addDockWidget(Qt.BottomDockWidgetArea, self.log) icon = QIcon(self.api.icons[self.api.config.options.app.inv_icon]) widget.addTab(tables, icon, 'Inventory') icon = QIcon(self.api.icons[self.api.config.options.app.vault_icon]) vt = QWidget() vt.setLayout(QVBoxLayout()) self.vault = ContainerPanel(self, self.core.vault) vt.layout().addWidget(self.vault) reroll = QPushButton('ReRoll') reroll.clicked.connect(self.core.reroll) vt.layout().addWidget(reroll) # widget.addTab(vt, icon, 'Vault') self.core.start() self.createSBAction('Icons/inv_misc_bag_10', 'Vault', vt, toolbar=True, keyseq='F5')
def showRavenor(ui): sys.path.append('../Ravenor') import raven from winterstone.base import WinterConfig from config import ConfigMerger raven.API().CWD += '../Ravenor/' ravenconfig = WinterConfig(file(raven.API().CWD + 'config/main.cfg')) darniconfig = WinterConfig(file(CWD + 'config/main.cfg')) merger = ConfigMerger(resolve) merger.merge(darniconfig.options.app, ravenconfig.options.app) API().config = darniconfig from etherstone.base import EtherIntegration wi = EtherIntegration(ui, UI=False) ravenor = raven.Panel(ui) ravenor.tree = raven.Tree(ravenor, ravenor.api.CWD) newpanel = raven.NewForm(ravenor) ui.sideBar = WinterSideBar(ui) ui.createSBAction('squares', 'Content', ravenor.tree.getWidget(), toolbar=True, keyseq=darniconfig.options.app.tree_shortcut) ui.createSBAction('newPage', 'New', newpanel, toolbar=True, keyseq=darniconfig.options.app.new_shortcut) ui.createSBAction('newPage', 'Edit', newpanel, toolbar=False, keyseq=darniconfig.options.app.new_shortcut) cmd = raven.CommandLine(ravenor) lay = QWidget() lay.setLayout(QVBoxLayout()) lay.layout().addWidget(cmd) lay.layout().addWidget(ravenor) ui.mainWidget.addTab(lay, QIcon(raven.API().CWD + 'icons/app.png'), 'Ravenor')
def __init__(self, app): QMainWindow.__init__(self) self.setObjectName('MainWindow') try: for font in os.listdir(CWD + 'fonts'): try: QFontDatabase.addApplicationFont(CWD + 'fonts/' + font) except Exception as e: print(e) except OSError: pass self.centralwidget = QWidget(self) self.horizontalLayout_2 = QHBoxLayout(self.centralwidget) self.setCentralWidget(self.centralwidget) self.statusBar = QStatusBar(self) self.setStatusBar(self.statusBar) self.toolBar = QToolBar(self) self.toolBar.setObjectName('toolBar') self._afterMWInit() WinterApp.__init__(self) self.api.toolBar = self.toolBar self.api.statusBar = self.statusBar self.api.dialog = self.dialog self.api.notify = self.notify if os.path.isfile(VAULT + 'themes/%s/style.css' % self.config.options.ui.theme): self.setStyleSheet(open(VAULT + 'themes/%s/style.css' % self.config.options.ui.theme, 'r').read()) if os.path.isfile(CWD + 'themes/%s/style.css' % self.config.options.ui.theme): self.setStyleSheet(open(CWD + 'themes/%s/style.css' % self.config.options.ui.theme, 'r').read()) theme_variants = ['system'] if os.path.isdir(CWD + 'themes/'): for d in os.listdir(CWD + 'themes/'): theme_variants.append(d) if os.path.isdir(VAULT + 'themes/'): for d in os.listdir(VAULT + 'themes/'): theme_variants.append(d) self.config.options.ui.theme_variants = list(set(theme_variants)) self.sideBar = WinterSideBar(self) self.statusBar.addPermanentWidget(QWidget().setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) self._afterAppInit() if self.config.options.debug: self.debugger = WinterQtDebug(self) self.api.debugger = self.debugger self.createAction('warning', self.tr('Debugger'), 'toggleDebug', keyseq=QKeySequence(self.debugger.config.options.debug_shortcut), toolbar=True) self.flag = WinterFlag() self.flag.setIcon(self.api.icons['green'], self.tr('Toggle debug panel: %s' % self.debugger.config.options.debug_shortcut)) self.connect(self.flag, SIGNAL('clicked()'), self.toggleDebug) self.statusBar.addPermanentWidget(self.flag) self.api.setFlag = self.flag.setIcon screen = QDesktopWidget().screenGeometry() QMainWindow.setGeometry(self, 0, 0, screen.width(), screen.height()) self.setWindowTitle(self.config.info['title']) self.setWindowIcon(QIcon(self.api.icons['app'])) if hasattr(WinterEditor, 'objects'): for we in WinterEditor.objects.all(): if isinstance(we, WinterEditor): # temp fix we._afterAppInit() # self.statusBar.showMessage('Done. Switch modes: F4') if self.config.options.plugins: self.pm.activateAll() self.api.info(self.tr('Plugins initialised')) self.sm = SettingsManager(self) self.createAction('configure', self.tr('Settings'), self.sm.show, keyseq=QKeySequence('Ctrl+P'), toolbar=True) self.smflag = WinterFlag() self.smflag.setIcon(self.api.icons['configure'], self.tr('Options: Ctrl+P')) self.connect(self.smflag, SIGNAL('clicked()'), self.sm.show) self.statusBar.addPermanentWidget(self.smflag) self.api.info('Application initialised') self.createAction('about', self.tr('About'), 'about', keyseq=QKeySequence.HelpContents, toolbar=True) self.addToolBar(Qt.TopToolBarArea, self.toolBar) if not self.config.options.ui.tb_show: self.toolBar.hide() self.qs = QSettings('Winterstone', self.config.info.title) # self.restoreGeometry(self.qs.value("geometry").toByteArray()) #todo: fix # self.restoreState(self.qs.value("windowState").toByteArray()) self.signalMapper = QSignalMapper(self) self.toolBar.setIconSize( QSize(self.config.options.ui.tbicon_size, self.config.options.ui.tbicon_size)) self.toolBar.setMovable(self.config.options.ui.tb_movable) self.resize(self.config.options.ui.width, self.config.options.ui.height) self.api.sm = self.sm self.config.add(self) scriptfiles = ['init.ws', 'hotkeys.ws'] for fname in scriptfiles: path = self.api.CWD + 'scripts/' + fname if os.path.isfile(path): self.script.executeFile(path)
class WinterQtApp(QMainWindow, WinterApp, QObject): __apiclass__ = API def __init__(self, app): QMainWindow.__init__(self) self.setObjectName('MainWindow') try: for font in os.listdir(CWD + 'fonts'): try: QFontDatabase.addApplicationFont(CWD + 'fonts/' + font) except Exception as e: print(e) except OSError: pass self.centralwidget = QWidget(self) self.horizontalLayout_2 = QHBoxLayout(self.centralwidget) self.setCentralWidget(self.centralwidget) self.statusBar = QStatusBar(self) self.setStatusBar(self.statusBar) self.toolBar = QToolBar(self) self.toolBar.setObjectName('toolBar') self._afterMWInit() WinterApp.__init__(self) self.api.toolBar = self.toolBar self.api.statusBar = self.statusBar self.api.dialog = self.dialog self.api.notify = self.notify if os.path.isfile(VAULT + 'themes/%s/style.css' % self.config.options.ui.theme): self.setStyleSheet(open(VAULT + 'themes/%s/style.css' % self.config.options.ui.theme, 'r').read()) if os.path.isfile(CWD + 'themes/%s/style.css' % self.config.options.ui.theme): self.setStyleSheet(open(CWD + 'themes/%s/style.css' % self.config.options.ui.theme, 'r').read()) theme_variants = ['system'] if os.path.isdir(CWD + 'themes/'): for d in os.listdir(CWD + 'themes/'): theme_variants.append(d) if os.path.isdir(VAULT + 'themes/'): for d in os.listdir(VAULT + 'themes/'): theme_variants.append(d) self.config.options.ui.theme_variants = list(set(theme_variants)) self.sideBar = WinterSideBar(self) self.statusBar.addPermanentWidget(QWidget().setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) self._afterAppInit() if self.config.options.debug: self.debugger = WinterQtDebug(self) self.api.debugger = self.debugger self.createAction('warning', self.tr('Debugger'), 'toggleDebug', keyseq=QKeySequence(self.debugger.config.options.debug_shortcut), toolbar=True) self.flag = WinterFlag() self.flag.setIcon(self.api.icons['green'], self.tr('Toggle debug panel: %s' % self.debugger.config.options.debug_shortcut)) self.connect(self.flag, SIGNAL('clicked()'), self.toggleDebug) self.statusBar.addPermanentWidget(self.flag) self.api.setFlag = self.flag.setIcon screen = QDesktopWidget().screenGeometry() QMainWindow.setGeometry(self, 0, 0, screen.width(), screen.height()) self.setWindowTitle(self.config.info['title']) self.setWindowIcon(QIcon(self.api.icons['app'])) if hasattr(WinterEditor, 'objects'): for we in WinterEditor.objects.all(): if isinstance(we, WinterEditor): # temp fix we._afterAppInit() # self.statusBar.showMessage('Done. Switch modes: F4') if self.config.options.plugins: self.pm.activateAll() self.api.info(self.tr('Plugins initialised')) self.sm = SettingsManager(self) self.createAction('configure', self.tr('Settings'), self.sm.show, keyseq=QKeySequence('Ctrl+P'), toolbar=True) self.smflag = WinterFlag() self.smflag.setIcon(self.api.icons['configure'], self.tr('Options: Ctrl+P')) self.connect(self.smflag, SIGNAL('clicked()'), self.sm.show) self.statusBar.addPermanentWidget(self.smflag) self.api.info('Application initialised') self.createAction('about', self.tr('About'), 'about', keyseq=QKeySequence.HelpContents, toolbar=True) self.addToolBar(Qt.TopToolBarArea, self.toolBar) if not self.config.options.ui.tb_show: self.toolBar.hide() self.qs = QSettings('Winterstone', self.config.info.title) # self.restoreGeometry(self.qs.value("geometry").toByteArray()) #todo: fix # self.restoreState(self.qs.value("windowState").toByteArray()) self.signalMapper = QSignalMapper(self) self.toolBar.setIconSize( QSize(self.config.options.ui.tbicon_size, self.config.options.ui.tbicon_size)) self.toolBar.setMovable(self.config.options.ui.tb_movable) self.resize(self.config.options.ui.width, self.config.options.ui.height) self.api.sm = self.sm self.config.add(self) scriptfiles = ['init.ws', 'hotkeys.ws'] for fname in scriptfiles: path = self.api.CWD + 'scripts/' + fname if os.path.isfile(path): self.script.executeFile(path) def on_tb_show(self, value): if value: self.toolBar.show() else: self.toolBar.hide() def on_tbicon_size(self, value): self.toolBar.setIconSize(QSize(value, value)) def on_tb_movable(self, value): self.toolBar.setMovable(value) def on_sbicon_size(self, value): self.sideBar.setIconSize(QSize(value, value)) def on_sb_movable(self, value): self.sideBar.setMovable(value) def on_height(self, value): self.resize(self.config.options.ui.width, value) def on_width(self, value): self.resize(value, self.config.options.ui.height) def setMainWidget(self, widget): # print '!!!!!!!!!!!!!!' if hasattr(self, 'mainWidget'): self.mainWidget.hide() del self.mainWidget self.mainWidget = widget self.mainWidget.api = self.api self.api.mainWidget = self.mainWidget # self.setLayout(QHBoxLayout()) self.layout().addWidget(self.mainWidget) self.horizontalLayout_2.addWidget(self.mainWidget) self.horizontalLayout_2.setStretch(0, 3) def createSBAction(self, icon, name, widget, keyseq='', toolbar=False): if type(icon).__name__ != 'QIcon': icon = QIcon.fromTheme(icon, QIcon(self.api.icons[icon])) action = SBAction(self.sideBar.dock, icon, name, self) action.widget = widget self.sideBar.stack.addWidget(widget) action.triggered.connect(functools.partial(action.showWidget)) if keyseq: action.setShortcut(keyseq) if toolbar: self.sideBar.addAction(action) self.addAction(action) return action def showSideBar(self, widget): print(widget) def createAction(self, icon, name, method, module='main', keyseq='', toolbar=False): if not isinstance(icon, QIcon) and icon: icon = QIcon.fromTheme(icon, QIcon(self.api.icons[icon])) elif not icon: icon = QIcon() action = WinterAction(icon, name, self) if keyseq: action.setShortcut(keyseq) if isinstance(method, str): method = self.getMethod(method, module) self.connect(action, SIGNAL('triggered()'), method) if toolbar: self.toolBar.addAction(action) self.addAction(action) return action def about(self): self.dialog('about', 'About %s (%s)' % (self.config.info.title, self.config.info.version), getFileContent(CWD + 'ABOUT')) def input(self, title='Input dialog', text='Please input'): inputline = '' inputline = QInputDialog.getText(self, title, text) self['debug']('input value: %s' % inputline[0]) return inputline[0] def dialog(self, type='info', title='Dialog', text='oops!!'): if type == 'info': QMessageBox.information(self, title, text) elif type == 'warning': QMessageBox.warning(self, title, text) elif type == 'critical': QMessageBox.critical(self, title, text) elif type == 'about': QMessageBox.about(self, title, text) def toggleDebug(self): if self.debugger.isHidden(): self.debugger.show() else: self.debugger.hide() def _afterMWInit(self): pass def _afterAppInit(self): pass def info(self, *args, **kwargs): self.api.info(*args, **kwargs) def error(self, *args, **kwargs): self.api.error(*args, **kwargs) def debug(self, *args, **kwargs): self.api.debug(*args, **kwargs) def echo(self, *args, **kwargs): self.dialog(title='Echo', text=args[0]) # @try_this(API()) def getMethod(self, key, module='main'): return WinterApp.getMethod(self, key, module) def closeEvent(self, event): self.qs.setValue("geometry", self.saveGeometry()) self.qs.setValue("windowState", self.saveState()) event.accept() def notify(self, title, body): if DBUS_SUPPORT and self.config.options.notification: knotify = dbus.SessionBus().get_object("org.kde.knotify", "/Notify") knotify.event('warning', 'inkmoth', [], title, body, [], [], 0, 0, dbus_interface="org.kde.KNotify") def setTitle(self, msg): self.setWindowTitle('%s [%s]' % (self.config.info.title, msg)) def exit(self): exit() def beforeCore(self): self.script = WinterScript(self) self.api.script = self.script
def __init__(self, app): QMainWindow.__init__(self) self.setObjectName('MainWindow') try: for font in os.listdir(CWD + 'fonts'): try: QFontDatabase.addApplicationFont(CWD + 'fonts/' + font) except Exception as e: print(e) except OSError: pass self.centralwidget = QWidget(self) self.horizontalLayout_2 = QHBoxLayout(self.centralwidget) self.setCentralWidget(self.centralwidget) self.statusBar = QStatusBar(self) self.setStatusBar(self.statusBar) self.toolBar = QToolBar(self) self.toolBar.setObjectName('toolBar') self._afterMWInit() WinterApp.__init__(self) self.api.toolBar = self.toolBar self.api.statusBar = self.statusBar self.api.dialog = self.dialog self.api.notify = self.notify if os.path.isfile(VAULT + 'themes/%s/style.css' % self.config.options.ui.theme): self.setStyleSheet( open( VAULT + 'themes/%s/style.css' % self.config.options.ui.theme, 'r').read()) if os.path.isfile(CWD + 'themes/%s/style.css' % self.config.options.ui.theme): self.setStyleSheet( open( CWD + 'themes/%s/style.css' % self.config.options.ui.theme, 'r').read()) theme_variants = ['system'] if os.path.isdir(CWD + 'themes/'): for d in os.listdir(CWD + 'themes/'): theme_variants.append(d) if os.path.isdir(VAULT + 'themes/'): for d in os.listdir(VAULT + 'themes/'): theme_variants.append(d) self.config.options.ui.theme_variants = list(set(theme_variants)) self.sideBar = WinterSideBar(self) self.statusBar.addPermanentWidget(QWidget().setSizePolicy( QSizePolicy.Expanding, QSizePolicy.Expanding)) self._afterAppInit() if self.config.options.debug: self.debugger = WinterQtDebug(self) self.api.debugger = self.debugger self.createAction('warning', self.tr('Debugger'), 'toggleDebug', keyseq=QKeySequence( self.debugger.config.options.debug_shortcut), toolbar=True) self.flag = WinterFlag() self.flag.setIcon( self.api.icons['green'], self.tr('Toggle debug panel: %s' % self.debugger.config.options.debug_shortcut)) self.connect(self.flag, SIGNAL('clicked()'), self.toggleDebug) self.statusBar.addPermanentWidget(self.flag) self.api.setFlag = self.flag.setIcon screen = QDesktopWidget().screenGeometry() QMainWindow.setGeometry(self, 0, 0, screen.width(), screen.height()) self.setWindowTitle(self.config.info['title']) self.setWindowIcon(QIcon(self.api.icons['app'])) if hasattr(WinterEditor, 'objects'): for we in WinterEditor.objects.all(): if isinstance(we, WinterEditor): # temp fix we._afterAppInit() # self.statusBar.showMessage('Done. Switch modes: F4') if self.config.options.plugins: self.pm.activateAll() self.api.info(self.tr('Plugins initialised')) self.sm = SettingsManager(self) self.createAction('configure', self.tr('Settings'), self.sm.show, keyseq=QKeySequence('Ctrl+P'), toolbar=True) self.smflag = WinterFlag() self.smflag.setIcon(self.api.icons['configure'], self.tr('Options: Ctrl+P')) self.connect(self.smflag, SIGNAL('clicked()'), self.sm.show) self.statusBar.addPermanentWidget(self.smflag) self.api.info('Application initialised') self.createAction('about', self.tr('About'), 'about', keyseq=QKeySequence.HelpContents, toolbar=True) self.addToolBar(Qt.TopToolBarArea, self.toolBar) if not self.config.options.ui.tb_show: self.toolBar.hide() self.qs = QSettings('Winterstone', self.config.info.title) # self.restoreGeometry(self.qs.value("geometry").toByteArray()) #todo: fix # self.restoreState(self.qs.value("windowState").toByteArray()) self.signalMapper = QSignalMapper(self) self.toolBar.setIconSize( QSize(self.config.options.ui.tbicon_size, self.config.options.ui.tbicon_size)) self.toolBar.setMovable(self.config.options.ui.tb_movable) self.resize(self.config.options.ui.width, self.config.options.ui.height) self.api.sm = self.sm self.config.add(self) scriptfiles = ['init.ws', 'hotkeys.ws'] for fname in scriptfiles: path = self.api.CWD + 'scripts/' + fname if os.path.isfile(path): self.script.executeFile(path)
class WinterQtApp(QMainWindow, WinterApp, QObject): __apiclass__ = API def __init__(self, app): QMainWindow.__init__(self) self.setObjectName('MainWindow') try: for font in os.listdir(CWD + 'fonts'): try: QFontDatabase.addApplicationFont(CWD + 'fonts/' + font) except Exception as e: print(e) except OSError: pass self.centralwidget = QWidget(self) self.horizontalLayout_2 = QHBoxLayout(self.centralwidget) self.setCentralWidget(self.centralwidget) self.statusBar = QStatusBar(self) self.setStatusBar(self.statusBar) self.toolBar = QToolBar(self) self.toolBar.setObjectName('toolBar') self._afterMWInit() WinterApp.__init__(self) self.api.toolBar = self.toolBar self.api.statusBar = self.statusBar self.api.dialog = self.dialog self.api.notify = self.notify if os.path.isfile(VAULT + 'themes/%s/style.css' % self.config.options.ui.theme): self.setStyleSheet( open( VAULT + 'themes/%s/style.css' % self.config.options.ui.theme, 'r').read()) if os.path.isfile(CWD + 'themes/%s/style.css' % self.config.options.ui.theme): self.setStyleSheet( open( CWD + 'themes/%s/style.css' % self.config.options.ui.theme, 'r').read()) theme_variants = ['system'] if os.path.isdir(CWD + 'themes/'): for d in os.listdir(CWD + 'themes/'): theme_variants.append(d) if os.path.isdir(VAULT + 'themes/'): for d in os.listdir(VAULT + 'themes/'): theme_variants.append(d) self.config.options.ui.theme_variants = list(set(theme_variants)) self.sideBar = WinterSideBar(self) self.statusBar.addPermanentWidget(QWidget().setSizePolicy( QSizePolicy.Expanding, QSizePolicy.Expanding)) self._afterAppInit() if self.config.options.debug: self.debugger = WinterQtDebug(self) self.api.debugger = self.debugger self.createAction('warning', self.tr('Debugger'), 'toggleDebug', keyseq=QKeySequence( self.debugger.config.options.debug_shortcut), toolbar=True) self.flag = WinterFlag() self.flag.setIcon( self.api.icons['green'], self.tr('Toggle debug panel: %s' % self.debugger.config.options.debug_shortcut)) self.connect(self.flag, SIGNAL('clicked()'), self.toggleDebug) self.statusBar.addPermanentWidget(self.flag) self.api.setFlag = self.flag.setIcon screen = QDesktopWidget().screenGeometry() QMainWindow.setGeometry(self, 0, 0, screen.width(), screen.height()) self.setWindowTitle(self.config.info['title']) self.setWindowIcon(QIcon(self.api.icons['app'])) if hasattr(WinterEditor, 'objects'): for we in WinterEditor.objects.all(): if isinstance(we, WinterEditor): # temp fix we._afterAppInit() # self.statusBar.showMessage('Done. Switch modes: F4') if self.config.options.plugins: self.pm.activateAll() self.api.info(self.tr('Plugins initialised')) self.sm = SettingsManager(self) self.createAction('configure', self.tr('Settings'), self.sm.show, keyseq=QKeySequence('Ctrl+P'), toolbar=True) self.smflag = WinterFlag() self.smflag.setIcon(self.api.icons['configure'], self.tr('Options: Ctrl+P')) self.connect(self.smflag, SIGNAL('clicked()'), self.sm.show) self.statusBar.addPermanentWidget(self.smflag) self.api.info('Application initialised') self.createAction('about', self.tr('About'), 'about', keyseq=QKeySequence.HelpContents, toolbar=True) self.addToolBar(Qt.TopToolBarArea, self.toolBar) if not self.config.options.ui.tb_show: self.toolBar.hide() self.qs = QSettings('Winterstone', self.config.info.title) # self.restoreGeometry(self.qs.value("geometry").toByteArray()) #todo: fix # self.restoreState(self.qs.value("windowState").toByteArray()) self.signalMapper = QSignalMapper(self) self.toolBar.setIconSize( QSize(self.config.options.ui.tbicon_size, self.config.options.ui.tbicon_size)) self.toolBar.setMovable(self.config.options.ui.tb_movable) self.resize(self.config.options.ui.width, self.config.options.ui.height) self.api.sm = self.sm self.config.add(self) scriptfiles = ['init.ws', 'hotkeys.ws'] for fname in scriptfiles: path = self.api.CWD + 'scripts/' + fname if os.path.isfile(path): self.script.executeFile(path) def on_tb_show(self, value): if value: self.toolBar.show() else: self.toolBar.hide() def on_tbicon_size(self, value): self.toolBar.setIconSize(QSize(value, value)) def on_tb_movable(self, value): self.toolBar.setMovable(value) def on_sbicon_size(self, value): self.sideBar.setIconSize(QSize(value, value)) def on_sb_movable(self, value): self.sideBar.setMovable(value) def on_height(self, value): self.resize(self.config.options.ui.width, value) def on_width(self, value): self.resize(value, self.config.options.ui.height) def setMainWidget(self, widget): # print '!!!!!!!!!!!!!!' if hasattr(self, 'mainWidget'): self.mainWidget.hide() del self.mainWidget self.mainWidget = widget self.mainWidget.api = self.api self.api.mainWidget = self.mainWidget # self.setLayout(QHBoxLayout()) self.layout().addWidget(self.mainWidget) self.horizontalLayout_2.addWidget(self.mainWidget) self.horizontalLayout_2.setStretch(0, 3) def createSBAction(self, icon, name, widget, keyseq='', toolbar=False): if type(icon).__name__ != 'QIcon': icon = QIcon.fromTheme(icon, QIcon(self.api.icons[icon])) action = SBAction(self.sideBar.dock, icon, name, self) action.widget = widget self.sideBar.stack.addWidget(widget) action.triggered.connect(functools.partial(action.showWidget)) if keyseq: action.setShortcut(keyseq) if toolbar: self.sideBar.addAction(action) self.addAction(action) return action def showSideBar(self, widget): print(widget) def createAction(self, icon, name, method, module='main', keyseq='', toolbar=False): if not isinstance(icon, QIcon) and icon: icon = QIcon.fromTheme(icon, QIcon(self.api.icons[icon])) elif not icon: icon = QIcon() action = WinterAction(icon, name, self) if keyseq: action.setShortcut(keyseq) if isinstance(method, str): method = self.getMethod(method, module) self.connect(action, SIGNAL('triggered()'), method) if toolbar: self.toolBar.addAction(action) self.addAction(action) return action def about(self): self.dialog( 'about', 'About %s (%s)' % (self.config.info.title, self.config.info.version), getFileContent(CWD + 'ABOUT')) def input(self, title='Input dialog', text='Please input'): inputline = '' inputline = QInputDialog.getText(self, title, text) self['debug']('input value: %s' % inputline[0]) return inputline[0] def dialog(self, type='info', title='Dialog', text='oops!!'): if type == 'info': QMessageBox.information(self, title, text) elif type == 'warning': QMessageBox.warning(self, title, text) elif type == 'critical': QMessageBox.critical(self, title, text) elif type == 'about': QMessageBox.about(self, title, text) def toggleDebug(self): if self.debugger.isHidden(): self.debugger.show() else: self.debugger.hide() def _afterMWInit(self): pass def _afterAppInit(self): pass def info(self, *args, **kwargs): self.api.info(*args, **kwargs) def error(self, *args, **kwargs): self.api.error(*args, **kwargs) def debug(self, *args, **kwargs): self.api.debug(*args, **kwargs) def echo(self, *args, **kwargs): self.dialog(title='Echo', text=args[0]) # @try_this(API()) def getMethod(self, key, module='main'): return WinterApp.getMethod(self, key, module) def closeEvent(self, event): self.qs.setValue("geometry", self.saveGeometry()) self.qs.setValue("windowState", self.saveState()) event.accept() def notify(self, title, body): if DBUS_SUPPORT and self.config.options.notification: knotify = dbus.SessionBus().get_object("org.kde.knotify", "/Notify") knotify.event('warning', 'inkmoth', [], title, body, [], [], 0, 0, dbus_interface="org.kde.KNotify") def setTitle(self, msg): self.setWindowTitle('%s [%s]' % (self.config.info.title, msg)) def exit(self): exit() def beforeCore(self): self.script = WinterScript(self) self.api.script = self.script
class UI(WinterQtApp): """ Main class """ def __init__(self, app): """ Create your own mymainwidget inherits QWidget and set it through self.setMainWidget. For future access use self.mainWidget property """ WinterQtApp.__init__(self, app) def _afterMWInit(self): """ Fired after MainWindow initialisation """ pass def _afterAppInit(self): """ Fired after WinterApp initialisation """ wi = EtherIntegration(self, UI=False) mymainwidget = wi.getWebView(toolbar=True) def nfilter(name, root): if not os.path.isdir(os.path.join(root, name)): file = open(os.path.join(root, name)) title = re.findall('<TITLE>([^<]*)</TITLE>', file.read()) if title: title = title[0].replace('Improved ADOM Guidebook - ', 'GB - ') title = title.replace('ADOM Manual - ', 'Manual - ') else: title = name file.close() return title else: return name def ffilter(path): if not os.path.isdir(path): if path.endswith('.html'): return True return False global app app = mymainwidget def onEmptyFind(reverse=False): if not hasattr(self, 'cpos'): self.cpos = 0 self.q = app.view.q else: self.cpos += 1 self.nf = False if self.q != app.view.q: del self.cpos app.view.onEmptyFind() else: items = app.dirtree.WFind(app.view.q, True, True) if items and len(items) == self.cpos + 1: del self.cpos else: try: url = items[self.cpos].url app.view.show(url) self.nf = True self.api.showMessage('File num: %d' % (self.cpos + 1)) app.view.WFind(app.view.q) except Exception, e: try: del self.cpos except: pass def retryFind(): if hasattr(self, 'q') and self.nf: app.view.WFind(self.q) mymainwidget.view.onEmptyFind = onEmptyFind mymainwidget.api = API() mymainwidget.dirtree = WinterDirTree(mymainwidget, CWD + 'adomgb/', 'Guide book', mymainwidget.view, ffilter, nfilter) mymainwidget.view.setHomePage(CWD + 'adomgb/adomgb-toc.html') mymainwidget.view.loadHomePage() mymainwidget.view.loadFinished.connect(retryFind) self.sideBar = WinterSideBar(self) self.createSBAction('list', 'Content', mymainwidget.dirtree.getWidget(True, True), toolbar=True, keyseq='ALT+1') self.setMainWidget(mymainwidget)
def _afterAppInit(self): ''' Fired after WinterApp initialisation ''' wi = EtherIntegration(self, UI=False) widget = QWidget(self) widget.setLayout(QVBoxLayout()) mmw = Panel(self) mmw.api = self.api mmw.tree = Tree(mmw, self.api.CWD) mmw.tree.setDragDropMode(QAbstractItemView.InternalMove) self.setMainWidget(widget) self.sideBar = WinterSideBar(self) newpanel = NewForm(mmw) css = CssPanel(self, mmw) mmw.toggle({True: 1, False: 0}[self.config.options.app.start_editor]) self.createSBAction('squares', 'Content', mmw.tree.getWidget(), toolbar=True, keyseq=self.config.options.app.tree_shortcut) self.createSBAction('newPage', 'New', newpanel, toolbar=True, keyseq=self.config.options.app.new_shortcut) self.createSBAction('css', 'Style', css, toolbar=True, keyseq=self.config.options.app.css_shortcut) self.createSBAction('edit', 'Edit', EditForm(mmw), toolbar=False, keyseq='F5') doctree = DocTree(mmw) self.createSBAction('squares', 'gDocs', doctree, toolbar=False, keyseq='Ctrl+D') cmd = CommandLine(mmw) self.cmd = cmd self.createAction('', 'Focus cmd', self.cmd.setFocus, keyseq='F3') self.createAction('list', 'Focus tree', mmw.tree.setFocus, keyseq='F2') self.createAction('cross', 'Del current', mmw.tree.delPage, keyseq='F8') self.createAction('', 'Action Editor', lambda: mmw.setCurrentIndex(2), keyseq='F7') self.createAction('', 'New page short', lambda: self.cmd.shortcut(':new '), keyseq='CTRL+N') self.createAction('', 'View page short', lambda: self.cmd.shortcut(':view '), keyseq='CTRL+E') widget.layout().addWidget(cmd) widget.layout().addWidget(mmw) self.mmw = mmw ae = QWidget() gird = QGridLayout() x = 0 y = 0 sbactions = SBAction.objects.all() actions = WinterAction.objects.all() for a in actions: sbactions.append(a) for action in sbactions: label = QLabel('%s\n%s' % (action.text(), action.shortcut().toString())) icon = QLabel('') pixmap = action.icon().pixmap(QSize(48, 48)) if pixmap.isNull(): pixmap = QPixmap(self.api.icons['newPage']).scaled( QSize(48, 48)) icon.setPixmap(pixmap) widget = QWidget() widget.setLayout(QHBoxLayout()) widget.layout().addWidget(icon) widget.layout().addWidget(label) widget.layout().setAlignment(Qt.AlignLeft) gird.addWidget(widget, y, x) x += 1 if x > 3: x = 0 y += 1 gird.setAlignment(Qt.AlignTop) ae.setLayout(gird) self.mmw.insertWidget(2, ae) mmw.setFocus()
def _afterAppInit(self): """ Fired after WinterApp initialisation """ self.setWindowTitle(u'Нагрузочное тестирование БД') table=Table(self) # table.setEditTriggers(QAbstractItemView.NoEditTriggers) self.table=table forms=QWidget() forms.setLayout(QGridLayout()) userform=QWidget() userform.setLayout(QFormLayout()) userform.setLayout(QVBoxLayout()) userform.layout().addWidget(QLabel(u'Список пользователей настраивается в файле main.cfg. <br>Пользователи циклично распределяются по потокам.')) dbform=QWidget() dbform.setLayout(QFormLayout()) self.user=QLineEdit() self.user.setText(self.config.options.app.db_user) self.password=QLineEdit() self.password.setText(self.config.options.app.db_password) self.host=QLineEdit() self.host.setText(self.config.options.app.db_host) self.base=QLineEdit() self.base.setText(self.config.options.app.db_base) self.domain=QLineEdit() self.domain.setText(self.config.options.app.domain) dbform.layout().addRow(u'Пользователь',self.user) dbform.layout().addRow(u'Пароль',self.password) dbform.layout().addRow(u'Сервер',self.host) dbform.layout().addRow(u'Имя базы',self.base) dbform.layout().addRow(u'Имя домена',self.domain) threadform=QWidget() threadform.setLayout(QGridLayout()) self.num=QSpinBox() self.num.setMaximum(999) self.num.setMinimum(1) self.num.setValue(self.config.options.app.threads_num) self.num.setToolTip(u'Значительно влияет на время выполнения и загрузку компьютера') threadform.layout().addWidget(QLabel(u'Количество потоков'),1,0) threadform.layout().addWidget(self.num,1,1) self.sepconnects=Switch(u'Создавать отдельные подключения на каждый запрос') threadform.layout().addWidget(self.sepconnects,3,0) self.skiperrors=Switch(u'Пропускать ошибки') threadform.layout().addWidget(self.skiperrors,4,0) self.fullc=Switch(u'Полный цикл') self.fullc.setChecked(True) self.fullc.stateChanged.connect(self.togglefull) threadform.layout().addWidget(self.fullc,5,0) self.minthreads=QSpinBox() self.minthreads.setValue(1) self.minthreads.setMaximum(999) self.minthreads.setMinimum(1) threadform.layout().addWidget(QLabel(u'Начально потоков'),6,0) threadform.layout().addWidget(self.minthreads,6,1) self.step=QSpinBox() self.step.setValue(1) self.step.setMaximum(999) self.step.setMinimum(1) threadform.layout().addWidget(QLabel(u'Шаг'),7,0) threadform.layout().addWidget(self.step,7,1) self.mc=QSpinBox() self.mc.setValue(0) self.mc.setMaximum(99999) self.mc.setMinimum(0) threadform.layout().addWidget(QLabel(u'Максимум запросов (0 = весь файл)'),2,0) threadform.layout().addWidget(self.mc,2,1) # options=QTabWidget() # options.addTab(dbform,u'Настройки БД') graphoptions=QWidget() graphoptions.setLayout(QFormLayout()) # options.addTab(graphoptions,u'Настройки графика') self.notshowmavg=Switch(u'Не показывать среднюю по максимуму') graphoptions.layout().addRow('',self.notshowmavg) self.showlevel01=Switch(u'Всегда показывать линию уровня 0.1sec') graphoptions.layout().addRow('',self.showlevel01) self.showlevel1=Switch(u'Всегда показывать линию уровня 1sec') graphoptions.layout().addRow('',self.showlevel1) self.notshowerr=Switch(u'Не показывать ошибки') graphoptions.layout().addRow('',self.notshowerr) self.detail=Switch(u'Детальный отчет') threadform.layout().addWidget(self.detail,8,0) # graphoptions.layout().addRow('',self.detail) # forms.layout().addWidget(options,1,1) # forms.layout().addWidget(threadform,1,0) self.sideBar = WinterSideBar(self) threadform.layout().setAlignment(Qt.AlignTop) self.createSBAction('configure','MainOptions',threadform,toolbar=True) self.createSBAction('db','db settings',dbform,toolbar=True) self.createSBAction('graph','graph settings',graphoptions,toolbar=True) self.resize(1200,600) widget=QWidget() widget.setLayout(QVBoxLayout()) widget.layout().addWidget(forms) widget.layout().addWidget(QLabel(u'')) widget.layout().addWidget(table) buttons=QWidget() buttons.setLayout(QHBoxLayout()) hb=QPushButton(u'Справка') hb.clicked.connect(self.help) self.progress=QProgressBar() buttons.layout().addWidget(hb) buttons.layout().addWidget(self.progress) spacerItem=QWidget() spacerItem.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum)) buttons.layout().addWidget(spacerItem) sb=QPushButton(u'Поехали!') sb.clicked.connect(self.launch) buttons.layout().addWidget(sb) bb=QPushButton(u'Стоп') bb.clicked.connect(self.stop) buttons.layout().addWidget(bb) qb=QPushButton(u'Выход') qb.clicked.connect(self.quit) buttons.layout().addWidget(qb) self.help=QMainWindow() self.help.resize(800,600) self.help.setWindowTitle(u'Справка') hwidget=QWidget() hwidget.setLayout(QVBoxLayout()) self.help.browser=QWebView() hwidget.layout().addWidget(self.help.browser) self.help.setCentralWidget(hwidget) self.viewer=QWebView() self.viewer.setFixedWidth(950) self.viewer.hide() wrapper=QWidget() wrapper.setLayout(QHBoxLayout()) wrapper.layout().addWidget(widget) wrapper.layout().addWidget(self.viewer) widget.layout().addWidget(buttons) self.total=0 self.callsnum=0 self.errnum=0 self.data=[] self.edata=[] self.mdata=[] self.tt=0 self.tts=[] self.force_stop=False self.callsavg={} self.pdata={} self.cc={} self.args={} self.setMainWidget(wrapper) # self.sideBar = WinterSideBar(self) self.core.start()