def send_favorites_list(bot, update, to_edit=None): uid = util.uid_from_update(update) user = User.from_update(update) t = threading.Thread(target=_too_many_favorites_handler, args=(bot, update, user)) t.start() favorites = Favorite.select_all(user) buttons = [ [ InlineKeyboardButton(captions.ADD_FAVORITE, callback_data=util.callback_for_action(CallbackActions.ADD_FAVORITE)), InlineKeyboardButton(captions.REMOVE_FAVORITE, callback_data=util.callback_for_action(CallbackActions.REMOVE_FAVORITE_MENU)) ], [ InlineKeyboardButton('Layout: ' + Layouts.get_caption(user.favorites_layout), callback_data=util.callback_for_action( CallbackActions.TOGGLE_FAVORITES_LAYOUT, {'v': Layouts.get_next(user.favorites_layout)})), ], [ InlineKeyboardButton(captions.SHARE, switch_inline_query=DeepLinkingActions.FAVORITES), ] ] reply_markup = InlineKeyboardMarkup(buttons) if to_edit is None: to_edit = util.mid_from_update(update) if len(favorites) == 0: text = "You have no favorites yet." else: text = _favorites_categories_md(favorites, user.favorites_layout) bot.formatter.send_or_edit(uid, text, to_edit=to_edit, reply_markup=reply_markup)
def _makeOne(self): from layouts import Layouts inst = Layouts() return inst
class User(BaseModel): id = PrimaryKeyField() chat_id = IntegerField() username = CharField(null=True) first_name = CharField(null=True) last_name = CharField(null=True) photo = CharField(null=True) banned = BooleanField(default=False) favorites_layout = CharField(choices=Layouts.choices(), default=Layouts.default()) @staticmethod def from_telegram_object(user: TelegramUser): try: u = User.get(User.chat_id == user.id) u.first_name = user.first_name u.last_name = user.last_name u.username = user.username except User.DoesNotExist: u = User(chat_id=user.id, username=user.username, first_name=user.first_name, last_name=user.last_name) u.save() return u @staticmethod def from_update(update): user = update.effective_user try: u = User.get(User.chat_id == user.id) except User.DoesNotExist: u = User(chat_id=user.id, username=user.username, first_name=user.first_name, last_name=user.last_name) u.save() return u @property def has_favorites(self): from models import Favorite return Favorite.select().where(Favorite.user == self).count() > 0 @property def num_contributions(self): from models import Bot return Bot.select().where(Bot.submitted_by == self).count() @property def contributions_ordinal(self): p = inflect.engine() return p.ordinal(self.num_contributions) def __str__(self): text = '👤 ' # emoji full_name = ' '.join([ self.first_name if self.first_name else '', self.last_name if self.last_name else '' ]) if self.username: text += '[{}](https://t.me/{})'.format(full_name, self.username) else: text += full_name return text.encode('utf-8').decode('utf-8') @property def markdown_short(self): displayname = '' if self.first_name: displayname = util.escape_markdown(self.first_name) if self.username: text = '[👤 {}](https://t.me/{})'.format(displayname, util.escape_markdown(self.username)) else: text = displayname return text.encode('utf-8').decode('utf-8') @property def plaintext(self): text = '👤 ' # emoji text += ' '.join([ self.first_name if self.first_name else '', self.last_name if self.last_name else '' ]) return text.encode('utf-8').decode('utf-8') @staticmethod def by_username(username: str): if username[0] == '@': username = username[1:] result = User.select().where( (fn.lower(User.username) == username.lower()) ) if len(result) > 0: return result[0] else: raise User.DoesNotExist() @classmethod def botlist_user_instance(cls): if not hasattr(cls, '_botlist_user'): bl_user, created = User.get_or_create(id=100000, defaults={ 'chat_id' : settings.SELF_BOT_ID, 'username' : 'BotListBot', 'first_name' : 'BotListBot', }) cls._botlist_user = bl_user return cls._botlist_user
def init_groups(self): layout = Layouts() if Function.screen_count() > 1: return [ Group("", layouts=[ layout.monadTall(), layout.monadWide(), layout.tabbed() ], screen_affinity=0, spawn="alacritty -e tmux"), Group("", layouts=[ layout.monadTall(), layout.monadWide(), ], screen_affinity=0, matches=[Match(wm_class=[ "emacs", ])]), Group("", layouts=[ layout.max(), layout.monadTall(), ], screen_affinity=2, matches=[Match(wm_class=[ "firefox", ])], spawn="firefox"), Group("", layouts=[ layout.max(), layout.monadTall(), ], screen_affinity=2, matches=[Match(wm_class=[ "chromium", ])]), Group("", layouts=[ layout.monadTall(), layout.monadWide(), ], screen_affinity=1), Group("", layouts=[ layout.monadTall(), layout.monadWide(), ], screen_affinity=1), ] else: return [ Group("", layouts=[layout.monadTall(), layout.tabbed()], screen_affinity=0, spawn="alacritty -e tmux"), Group("", layouts=[ layout.max(), layout.monadTall(), ], screen_affinity=0, matches=[Match(wm_class=[ "firefox", ])], spawn="firefox"), Group("", layouts=[ layout.monadTall(), layout.monadWide(), ], screen_affinity=0), Group("", layouts=[ layout.monadTall(), layout.monadWide(), ], screen_affinity=0), Group("", layouts=[ layout.max(), layout.monadTall(), ], screen_affinity=0, matches=[Match(wm_class=[ "chromium", ])]), ]
def init_groups(self): layout = Layouts() return [ Group("SYS", layouts=[ layout.max(), layout.two_stackWide(), layout.two_stackTall() ]), Group("CLI", layouts=[ layout.two_stackTall(), layout.monadTall(), layout.ten_monadWide() ], matches=[Match(title=["Irssi", "Mpsyt"])]), Group("TYP", layouts=[ layout.five_monadTall(), layout.two_stackTall(), layout.two_stackWide() ], matches=[Match(wm_class=["Subl3", "Howl", "Geany"])]), Group("VRT", layouts=[layout.floating()], matches=[ Match(wm_class=[ "Xephyr", "Virt-manager", re.compile("VirtualBox") ]) ]), Group("MNG", layouts=[layout.max()], matches=[Match(wm_class=["Nemo"])]), Group("AUX", layouts=[layout.max(), layout.ten_monadWide()]), Group("DOC", layouts=[ layout.two_stackTall(), layout.max(), layout.two_stackWide(), ], matches=[Match(wm_class=["Zathura", "Evince"])]), Group( "OFC", layouts=[layout.max(), layout.two_stackWide()], matches=[ Match( wm_class=["calibre", re.compile("NetBeans")]), Match(title=[re.compile("LibreOffice")]) ]), Group("GPX", layouts=[layout.max(), layout.two_stackWide()], matches=[ Match(wm_class=[ "Glade", "Inkscape", "mpv", re.compile("Gimp") ]) ]), Group("TCM", layouts=[layout.max(), layout.two_stackTall()], matches=[ Match(wm_class=[ "Tor Browser", "firefox", "qutebrowser", "Chromium", "Links" ]), Match(title=["Links"]) ]), Group("", layouts=[layout.floating()]) ]
from widgets import MyWidgets from layouts import Layouts from groups import CreateGroups from icons import group_icons ###### MAIN ###### if __name__ in ["config", "__main__"]: # Initializes objects # Initializes keybindings obj_keys = Keybindings() # Mouse obj_mouse = Mouse() obj_widgets = MyWidgets() obj_layouts = Layouts() obj_groups = CreateGroups() # Initializes qtile variables keys = obj_keys.init_keys() mouse = obj_mouse.init_mouse() layouts = obj_layouts.init_layouts() groups = obj_groups.init_groups() # Append group keys for groups keys += obj_keys.init_keys_groups(group_icons) ### DISPLAYS WIDGETS IN THE SCREEN #### screens = obj_widgets.init_screen() main_widgets_list = obj_widgets.init_widgets_list()
# Key bindings obj_keys = Keys() keys = obj_keys.init_keys(my_term, script_path, mod) # Mouse bindings and options obj_mouse = Mouses() mouse = obj_mouse.init_mouse() # group key bindings keys = Groups.add_group_key_bindings(groups, keys, mod) obj_rules = Rules() dgroups_app_rules = obj_rules.init_rules() dgroups_key_binder = None # Layouts obj_layouts = Layouts() layouts = obj_layouts.init_layouts(my_gaps) floating_layout = layout.Floating() # Widgets whichPrimary = { 'bifrost': [True, False, False], 'walhall': [False, True, False] } my_widgets1 = Widgets(hostname, primaryMonitor = whichPrimary[hostname][0]) my_widgets2 = Widgets(hostname, primaryMonitor = whichPrimary[hostname][1]) #my_widgets3 = Widgets(hostname, primaryMonitor = whichPrimary[hostname][2]) # Screens with Widgets screens = [ Screen(top=bar.Bar(widgets = my_widgets1.init_widgets(),