示例#1
0
 def __async_rpc_cb_load_campaigns(self, results):
     if self.destroyed:
         return
     store = self._tv_model
     style_context = self.dialog.get_style_context()
     bg_color = gui_utilities.gtk_style_context_get_color(
         style_context, 'theme_color_tv_bg', default=ColorHexCode.WHITE)
     fg_color = gui_utilities.gtk_style_context_get_color(
         style_context, 'theme_color_tv_fg', default=ColorHexCode.BLACK)
     hlbg_color = gui_utilities.gtk_style_context_get_color(
         style_context,
         'theme_color_tv_hlbg',
         default=ColorHexCode.LIGHT_YELLOW)
     hlfg_color = gui_utilities.gtk_style_context_get_color(
         style_context, 'theme_color_tv_hlfg', default=ColorHexCode.BLACK)
     now = datetime.datetime.now()
     campaigns = results['db']['campaigns']
     for campaign in campaigns['edges']:
         campaign = campaign['node']
         created_ts = utilities.datetime_utc_to_local(campaign['created'])
         expiration_ts = campaign['expiration']
         is_expired = False
         if expiration_ts is not None:
             expiration_ts = utilities.datetime_utc_to_local(expiration_ts)
             is_expired = expiration_ts < now
         store.append(
             _ModelNamedRow(
                 id=str(campaign['id']),
                 description=(html.escape(campaign['description'],
                                          quote=True)
                              if campaign['description'] else None),
                 bg_color=(hlbg_color if is_expired else bg_color),
                 fg_color=(hlfg_color if is_expired else fg_color),
                 name=campaign['name'],
                 company=(campaign['company']['name']
                          if campaign['company'] is not None else None),
                 type=(campaign['campaignType']['name']
                       if campaign['campaignType'] is not None else None),
                 messages=campaign['messages']['total'],
                 user=campaign['user']['name'],
                 created=created_ts,
                 expiration=expiration_ts,
             ))
     self.gobjects['label_campaign_info'].set_text(
         "Showing {0} of {1:,} Campaign{2}".format(
             len(self._tv_model_filter), len(self._tv_model),
             ('' if len(self._tv_model) == 1 else 's')))
     if campaigns['total']:
         progress = len(self._tv_model) / campaigns['total']
     else:
         progress = 1.0
     self.gobjects['progressbar_loading'].set_text(
         "Loaded {:,} of {:,} campaigns ({:.1f}%)".format(
             len(self._tv_model), campaigns['total'], progress * 100))
     self.gobjects['progressbar_loading'].set_fraction(progress)
     if campaigns['pageInfo']['hasNextPage']:
         self.load_campaigns(cursor=campaigns['pageInfo']['endCursor'])
     else:
         self.gobjects['revealer_loading'].set_reveal_child(False)
         self.gobjects['progressbar_loading'].set_fraction(1.0)
示例#2
0
 def load_campaigns(self):
     """Load campaigns from the remote server and populate the :py:class:`Gtk.TreeView`."""
     store = self._tv_model
     store.clear()
     style_context = self.dialog.get_style_context()
     bg_color = gui_utilities.gtk_style_context_get_color(
         style_context, 'theme_color_tv_bg', default=ColorHexCode.WHITE)
     fg_color = gui_utilities.gtk_style_context_get_color(
         style_context, 'theme_color_tv_fg', default=ColorHexCode.BLACK)
     hlbg_color = gui_utilities.gtk_style_context_get_color(
         style_context,
         'theme_color_tv_hlbg',
         default=ColorHexCode.LIGHT_YELLOW)
     hlfg_color = gui_utilities.gtk_style_context_get_color(
         style_context, 'theme_color_tv_hlfg', default=ColorHexCode.BLACK)
     now = datetime.datetime.now()
     campaigns = self.application.rpc.graphql_find_file(
         'get_campaigns.graphql')
     for campaign in campaigns['db']['campaigns']['edges']:
         campaign = campaign['node']
         created_ts = utilities.datetime_utc_to_local(campaign['created'])
         expiration_ts = campaign['expiration']
         is_expired = False
         if expiration_ts is not None:
             expiration_ts = utilities.datetime_utc_to_local(expiration_ts)
             is_expired = expiration_ts < now
         store.append(
             _ModelNamedRow(
                 id=str(campaign['id']),
                 description=(html.escape(campaign['description'],
                                          quote=True)
                              if campaign['description'] else None),
                 bg_color=(hlbg_color if is_expired else bg_color),
                 fg_color=(hlfg_color if is_expired else fg_color),
                 name=campaign['name'],
                 company=(campaign['company']['name']
                          if campaign['company'] is not None else None),
                 type=(campaign['campaignType']['name']
                       if campaign['campaignType'] is not None else None),
                 messages=campaign['messages']['total'],
                 user=campaign['user']['name'],
                 created=created_ts,
                 expiration=expiration_ts,
             ))
     self.gobjects['label_campaign_info'].set_text(
         "Showing {0} of {1:,} Campaign{2}".format(
             len(self._tv_model_filter), len(self._tv_model),
             ('' if len(self._tv_model) == 1 else 's')))
	def signal_drawingarea_draw(self, drawingarea, context):
		width, height = drawingarea.get_size_request()
		context.rectangle(0, 0, width, height)
		context.stroke_preserve()
		style_context = self.dialog.get_style_context()
		hlbg_color = gui_utilities.gtk_style_context_get_color(style_context, 'theme_color_tv_hlbg', default=ColorHexCode.LIGHT_YELLOW)
		context.set_source_rgb(hlbg_color.red, hlbg_color.green, hlbg_color.blue)
		context.fill()
示例#4
0
	def signal_drawingarea_draw(self, drawingarea, context):
		width, height = drawingarea.get_size_request()
		context.rectangle(0, 0, width, height)
		context.stroke_preserve()
		style_context = self.dialog.get_style_context()
		hlbg_color = gui_utilities.gtk_style_context_get_color(style_context, 'theme_color_tv_hlbg', default=ColorHexCode.LIGHT_YELLOW)
		context.set_source_rgb(hlbg_color.red, hlbg_color.green, hlbg_color.blue)
		context.fill()
 def load_campaigns(self):
     """Load campaigns from the remote server and populate the :py:class:`Gtk.TreeView`."""
     store = self._tv_model
     store.clear()
     style_context = self.dialog.get_style_context()
     bg_color = gui_utilities.gtk_style_context_get_color(
         style_context, 'theme_color_tv_bg', default=ColorHexCode.WHITE)
     fg_color = gui_utilities.gtk_style_context_get_color(
         style_context, 'theme_color_tv_fg', default=ColorHexCode.BLACK)
     hlbg_color = gui_utilities.gtk_style_context_get_color(
         style_context,
         'theme_color_tv_hlbg',
         default=ColorHexCode.LIGHT_YELLOW)
     hlfg_color = gui_utilities.gtk_style_context_get_color(
         style_context, 'theme_color_tv_hlfg', default=ColorHexCode.BLACK)
     now = datetime.datetime.now()
     for campaign in self.application.rpc.remote_table('campaigns'):
         company = campaign.company
         if company:
             company = company.name
         created_ts = utilities.datetime_utc_to_local(campaign.created)
         created_ts = utilities.format_datetime(created_ts)
         campaign_type = campaign.campaign_type
         if campaign_type:
             campaign_type = campaign_type.name
         expiration_ts = campaign.expiration
         is_expired = False
         if expiration_ts is not None:
             expiration_ts = utilities.datetime_utc_to_local(
                 campaign.expiration)
             if expiration_ts < now:
                 is_expired = True
             expiration_ts = utilities.format_datetime(expiration_ts)
         store.append(
             (str(campaign.id), campaign.name, company, campaign_type,
              campaign.user_id, created_ts, expiration_ts,
              (hlbg_color if is_expired else bg_color),
              (hlfg_color if is_expired else fg_color),
              (html.escape(campaign.description, quote=True)
               if campaign.description else None)))
     self.gobjects['label_campaign_info'].set_text(
         "Showing {0} of {1:,} Campaign{2}".format(
             len(self._tv_model_filter), len(self._tv_model),
             ('' if len(self._tv_model) == 1 else 's')))
	def load_campaigns(self):
		"""Load campaigns from the remote server and populate the :py:class:`Gtk.TreeView`."""
		store = self._tv_model
		store.clear()
		style_context = self.dialog.get_style_context()
		bg_color = gui_utilities.gtk_style_context_get_color(style_context, 'theme_color_tv_bg', default=ColorHexCode.WHITE)
		fg_color = gui_utilities.gtk_style_context_get_color(style_context, 'theme_color_tv_fg', default=ColorHexCode.BLACK)
		hlbg_color = gui_utilities.gtk_style_context_get_color(style_context, 'theme_color_tv_hlbg', default=ColorHexCode.LIGHT_YELLOW)
		hlfg_color = gui_utilities.gtk_style_context_get_color(style_context, 'theme_color_tv_hlfg', default=ColorHexCode.BLACK)
		now = datetime.datetime.now()
		for campaign in self.application.rpc.remote_table('campaigns'):
			company = campaign.company
			if company:
				company = company.name
			created_ts = utilities.datetime_utc_to_local(campaign.created)
			created_ts = utilities.format_datetime(created_ts)
			campaign_type = campaign.campaign_type
			if campaign_type:
				campaign_type = campaign_type.name
			expiration_ts = campaign.expiration
			is_expired = False
			if expiration_ts is not None:
				expiration_ts = utilities.datetime_utc_to_local(campaign.expiration)
				if expiration_ts < now:
					is_expired = True
				expiration_ts = utilities.format_datetime(expiration_ts)
			store.append((
				str(campaign.id),
				campaign.name,
				company,
				campaign_type,
				campaign.user_id,
				created_ts,
				expiration_ts,
				(hlbg_color if is_expired else bg_color),
				(hlfg_color if is_expired else fg_color),
				(html.escape(campaign.description, quote=True) if campaign.description else None)
			))
		self.gobjects['label_campaign_info'].set_text("Showing {0} of {1:,} Campaign{2}".format(
			len(self._tv_model_filter),
			len(self._tv_model),
			('' if len(self._tv_model) == 1 else 's')
		))
	def load_campaigns(self):
		"""Load campaigns from the remote server and populate the :py:class:`Gtk.TreeView`."""
		store = self._tv_model
		store.clear()
		style_context = self.dialog.get_style_context()
		bg_color = gui_utilities.gtk_style_context_get_color(style_context, 'theme_color_tv_bg', default=ColorHexCode.WHITE)
		fg_color = gui_utilities.gtk_style_context_get_color(style_context, 'theme_color_tv_fg', default=ColorHexCode.BLACK)
		hlbg_color = gui_utilities.gtk_style_context_get_color(style_context, 'theme_color_tv_hlbg', default=ColorHexCode.LIGHT_YELLOW)
		hlfg_color = gui_utilities.gtk_style_context_get_color(style_context, 'theme_color_tv_hlfg', default=ColorHexCode.BLACK)
		now = datetime.datetime.now()
		campaigns = self.application.rpc.graphql_find_file('get_campaigns.graphql')
		for campaign in campaigns['db']['campaigns']['edges']:
			campaign = campaign['node']
			created_ts = utilities.datetime_utc_to_local(campaign['created'])
			created_ts = utilities.format_datetime(created_ts)
			expiration_ts = campaign['expiration']
			is_expired = False
			if expiration_ts is not None:
				expiration_ts = utilities.datetime_utc_to_local(expiration_ts)
				if expiration_ts < now:
					is_expired = True
				expiration_ts = utilities.format_datetime(expiration_ts)
			store.append((
				str(campaign['id']),
				campaign['name'],
				(campaign['company']['name'] if campaign['company'] is not None else None),
				(campaign['campaignType']['name'] if campaign['campaignType'] is not None else None),
				"{0:,}".format(campaign['messages']['total']),
				campaign['user']['name'],
				created_ts,
				expiration_ts,
				(hlbg_color if is_expired else bg_color),
				(hlfg_color if is_expired else fg_color),
				(html.escape(campaign['description'], quote=True) if campaign['description'] else None)
			))
		self.gobjects['label_campaign_info'].set_text("Showing {0} of {1:,} Campaign{2}".format(
			len(self._tv_model_filter),
			len(self._tv_model),
			('' if len(self._tv_model) == 1 else 's')
		))
示例#8
0
	def get_color(self, color_name, default):
		"""
		Get a color by its style name such as 'fg' for foreground. If the
		specified color does not exist, default will be returned. The underlying
		logic for this function is provided by
		:py:func:`~.gui_utilities.gtk_style_context_get_color`.

		:param str color_name: The style name of the color.
		:param default: The default color to return if the specified one was not found.
		:return: The desired color if it was found.
		:rtype: tuple
		"""
		color_name = 'theme_color_graph_' + color_name
		sc_color = gui_utilities.gtk_style_context_get_color(self.style_context, color_name, default)
		return (sc_color.red, sc_color.green, sc_color.blue)
示例#9
0
	def get_color(self, color_name, default):
		"""
		Get a color by its style name such as 'fg' for foreground. If the
		specified color does not exist, default will be returned. The underlying
		logic for this function is provided by
		:py:func:`~.gui_utilities.gtk_style_context_get_color`.

		:param str color_name: The style name of the color.
		:param default: The default color to return if the specified one was not found.
		:return: The desired color if it was found.
		:rtype: tuple
		"""
		color_name = 'theme_color_graph_' + color_name
		sc_color = gui_utilities.gtk_style_context_get_color(self.style_context, color_name, default)
		return (sc_color.red, sc_color.green, sc_color.blue)
示例#10
0
    def load_campaigns(self):
        """Load campaigns from the remote server and populate the :py:class:`Gtk.TreeView`."""
        store = self._tv_model
        store.clear()
        style_context = self.dialog.get_style_context()
        bg_color = gui_utilities.gtk_style_context_get_color(
            style_context, 'theme_color_tv_bg', default=ColorHexCode.WHITE)
        fg_color = gui_utilities.gtk_style_context_get_color(
            style_context, 'theme_color_tv_fg', default=ColorHexCode.BLACK)
        hlbg_color = gui_utilities.gtk_style_context_get_color(
            style_context,
            'theme_color_tv_hlbg',
            default=ColorHexCode.LIGHT_YELLOW)
        hlfg_color = gui_utilities.gtk_style_context_get_color(
            style_context, 'theme_color_tv_hlfg', default=ColorHexCode.BLACK)
        now = datetime.datetime.now()
        campaigns_query = """\
		{
			db {
				campaigns {
					edges {
						node {
							id,
							name,
							description,
							company {
								name
							},
							campaignType {
								name
							},
							messages {
								total
							},
							user {
								id
							},
							created,
							expiration
						}
					}
				}
			}
		}
		"""
        campaigns = self.application.rpc.graphql(campaigns_query)
        for campaign in campaigns['db']['campaigns']['edges']:
            campaign = campaign['node']
            created_ts = utilities.datetime_utc_to_local(campaign['created'])
            created_ts = utilities.format_datetime(created_ts)
            expiration_ts = campaign['expiration']
            is_expired = False
            if expiration_ts is not None:
                expiration_ts = utilities.datetime_utc_to_local(expiration_ts)
                if expiration_ts < now:
                    is_expired = True
                expiration_ts = utilities.format_datetime(expiration_ts)
            store.append((str(campaign['id']), campaign['name'],
                          (campaign['company']['name']
                           if campaign['company'] is not None else None),
                          (campaign['campaignType']['name']
                           if campaign['campaignType'] is not None else None),
                          "{0:,}".format(campaign['messages']['total']),
                          campaign['user']['id'], created_ts, expiration_ts,
                          (hlbg_color if is_expired else bg_color),
                          (hlfg_color if is_expired else fg_color),
                          (html.escape(campaign['description'], quote=True)
                           if campaign['description'] else None)))
        self.gobjects['label_campaign_info'].set_text(
            "Showing {0} of {1:,} Campaign{2}".format(
                len(self._tv_model_filter), len(self._tv_model),
                ('' if len(self._tv_model) == 1 else 's')))