def _ls(self, arg): p = 'ls: ' if not arg: ls = [] pad = '' d = self._stash else: ref = self.__ref_only(arg, p) ls = [ref + '.'] pad = ' ' nodes, leaf = self.__nodes_and_leaf(ref) d = self.__get_sub_dict(ref, nodes, p) if self._valid_subnode(d, leaf): d = d[leaf] else: raise ValueError('%s%s is not a sub-list.' % (p, ref)) keys = d.keys() keys.sort() for k in keys: if isinstance(d[k], dict): ls.append('%s%s. (%d)' % (pad, k, len(d[k]))) else: ls.append('%s%s %s' % (pad, k, d[k])) qmk.Message()('\n'.join(ls))
def action(self, arg): if arg is None: qmk.Message()(qmk.Clipboard.text()) elif arg in ('-c', '--clear'): qmk.Clipboard.setText('') else: qmk.Clipboard.setText(arg)
def action(self, arg): if arg is None: arg = qmk.Clipboard.text() result = str(eval(arg)) qmk.Clipboard.setText(result) qmk.Message()(arg + ' --> ' + result)
def action(self, arg): # The assumption here is that URL shorteners just have one level of # redirection to point the short URL to the long version. r = requests.get(arg, allow_redirects=False) if requests.codes.MOVED != r.status_code: raise RuntimeError('Request does not redirect: {}'.format(arg)) url = r.headers['location'] qmk.Clipboard.setText(url) qmk.Message()(url)
def action(self, arg): now = datetime.datetime.now() year, month = now.year, now.month if arg is not None: args = arg.split() if len(args) == 2: try: y, m = int(args[0]), int(args[1]) if m < 1 or m > 12: y, m = m, y year, month = y, m except: pass elif len(args) == 1: try: y = now.year m = int(args[0]) if m < 1 or m > 12: y = m m = now.month year, month = y, m except: pass cal = calendar.TextCalendar(firstweekday=calendar.MONDAY) lines = [' ' + cal.formatmonthname(year, month, 20, True)] lines.append('Wk | ' + cal.formatweekheader(2)) i = 0 ln = '' mark = '*' if year == now.year and month == now.month else ' ' a_day_in_week = 0 for d in cal.itermonthdays(year, month): if 0 == d: ln += ' ' else: ln += '%2d%s' % (d, ' ' if now.day != d else mark) if 0 == a_day_in_week: a_day_in_week = d if 6 == i % 7: lines.append('%2d | %s' % (datetime.date( year, month, a_day_in_week).isocalendar()[1], ln)) ln = '' a_day_in_week = 0 i += 1 cal_text = '\n'.join(lines) qmk.Clipboard.setText(cal_text) qmk.Message()(cal_text)
def _take_snapshot(self): o = self._opts if '' == o.filename: fn = 'screenshot-%s.png' % pu.utils.dt_str(sep='') elif not o.filename.endswith(('.PNG', '.png')): fn = '%s.png' % o.filename else: fn = o.filename if '' == os.path.dirname(fn): fn = os.path.join(self._base_dir, fn) afn = os.path.abspath(fn) if os.path.exists(fn): if os.path.isfile(fn): if not o.clobber: raise RuntimeError('%s exists and not clobbering.' % fn) else: raise RuntimeError('%s exists and is not a file.' % fn) dn = os.path.dirname(afn) if not os.path.exists(dn): raise RuntimeError('%s is not a valid directory.' % dn) R = ctypes.wintypes.RECT() hwnd = self._gfw() if not self._gwr(hwnd, ctypes.byref(R)): self._indicateError(self._gle()) if o.desktop: pm = qmk.QtGui.QPixmap.grabWindow( qmk.QtGui.QApplication.desktop().winId()) elif o.bare: pm = qmk.QtGui.QPixmap.grabWindow(hwnd) else: pm = qmk.QtGui.QPixmap.grabWindow( qmk.QtGui.QApplication.desktop().winId(), R.left, R.top, R.right - R.left, R.bottom - R.top) if pm is None: raise RuntimeError('Had trouble grabbing window.') if not pm.save(fn, 'PNG'): raise RuntimeError('Had trouble saving to %s.' % afn) qmk.Message()('Screenshot saved to %s.' % fn)
def action(self, arg): args = arg.split() if len(args) != 3: raise ValueError('Three arguments required.') val, fu, tu = float(args[0]), args[1], args[2] co = DummyConversion() if fu in self.__P.available_units(): co = self.__P elif fu in self.__T.available_units(): co = self.__T elif fu in self.__V.available_units(): co = self.__V setattr(co, fu, val) qmk.Message()('%s %s --> %f %s' % ( args[0], fu, getattr(co, tu), tu))
def action(self, arg): now = str(datetime.datetime.now()) qmk.Message()(now)
def action(self, arg): qmk.Message()(pu.utils.rotn(arg))
def _echo(self, arg): p = 'echo: ' qmk.Message()(self.__get_leaf(self.__ref_only(arg, p), p))
def action(self, arg): if arg is None: args = [] else: args = arg.split() rect = ctypes.wintypes.RECT() hwnd = qmk.InputFilter().foregroundWindowId() if not self._gwr(hwnd, ctypes.byref(rect)): self.indicateError(self._gle()) if 0 == len(args): p = [0, 0, rect.right - rect.left, rect.bottom - rect.top, 1] elif 1 == len(args) and args[0] in ('info', 'desktop-info'): a0 = args[0] if 'info' == a0: qmk.Message()(' Left-top: (%d, %d)\n' ' Right-bottom: (%d, %d)\n' 'Width, height: %d, %d' % (rect.left, rect.top, rect.right, rect.bottom, rect.right - rect.left, rect.bottom - rect.top)) return elif 'desktop-info' == a0: qad = qmk.QtGui.QApplication.desktop() sc = qad.screenCount() shift = ' ' * 8 msg = ' %sScreen count: %d\n%sPrimary screen: %d' % ( shift, sc, shift, qad.primaryScreen()) for i in xrange(sc): sg = qad.screenGeometry(i) msg += '\n%2d: Screen Geometry: %d, %d' % ( i, sg.width(), sg.height()) ag = qad.availableGeometry(i) msg += '\n Available geometry: %d, %d' % (ag.width(), ag.height()) qmk.Message()(msg) return elif pu.utils.contains_any(arg, 'xywh'): p = [ rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 1 ] n = dict(x=0, y=1, w=2, h=3) for a in args: for c in 'xywh': if a.startswith(c): p[n[c]] = adjust(p[n[c]], a[1:]) break else: p = [ rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 1 ] for i in xrange(len(args)): p[i] = int(args[i]) check(p) if not self._mw(hwnd, *p): self.indicateError(self._gle())
QListView { background-color: #004b00; color: #00ff00; border-width: 2px; border-style: solid; border-color: #00ff00; border-radius: 5px; font-size: 18px; font-family: "Ubuntu Mono"; } ''') # }}} qmk.CommandManager().registerCommands([QuitCommand(), RestartCommand()]) qmk.CommandInput().updateCompletions() qmk.InputFilter().setQMKKeyboardCallback(qmk.Engine.QMKCallback) qmk.InputFilter().enableQMKKeyboardCallback() qmk.InputFilter().setKeyboardCallback(qmk.Engine.hideMessageCallback) qmk.InputFilter().setMouseCallback(qmk.Engine.hideMessageCallback) qmk.InputFilter().setKeyboardWindowId(int(qmk.CommandInput().winId())) os.chdir(qmk.base_dir()) qmk.Message()('QMK has started...') # Instantiate ErrorMessage in case it's eventually called from another thread # to avoid parental confusion. qmk.ErrorMessage() sys.exit(app.exec_())
def action(self, arg): qmk.Message()('' if arg is None else arg)
def action(self, arg): la = list(arg) la.sort() res = ''.join(la) qmk.Clipboard.setText(res) qmk.Message()('"%s" ==> "%s"' % (arg, res))