-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissue_box.py
94 lines (84 loc) · 3.31 KB
/
issue_box.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import urllib
import webbrowser
from kivymd.uix.label import MDLabel
from kivymd.uix.card import MDCard
from kivymd.app import MDApp
from kivy.utils import get_color_from_hex
# Define your text colors for dark and light themes
LIGHT_TEXT_COLOR = get_color_from_hex('ffffff') # White text for dark backgrounds
DARK_TEXT_COLOR = get_color_from_hex('000000') # Black text for light backgrounds
class IssueBox(MDCard):
def __init__(self, title, jql_query, jira_base_url, **kwargs):
super().__init__(**kwargs)
self.title = title
self.jql_query = jql_query
self.jira_base_url = jira_base_url
self.focus_behavior = True
self.ripple_behavior = True
self.elevation = True
self.jql_label = None
self.title_label = None
self.issue_label = None
self.setup_ui()
def setup_ui(self):
"""Initializes the user interface for the issue box."""
self.size_hint = (0.5, None) # Use half the width of the parent
self.height = "140dp" # Set a height that allows for padding and readability
self.padding = "8dp" # Add some padding inside the card
self.orientation = "vertical"
self.create_labels()
def create_labels(self):
"""Creates and adds labels to the issue box."""
self.title_label = MDLabel(
text=self.title,
font_style="Subtitle1",
halign="center",
theme_text_color="Primary",
size_hint_y=None,
height="48dp",
)
self.issue_label = MDLabel(
text="Fetching data...",
font_style="H6",
halign="center",
theme_text_color="Secondary",
size_hint_y=None,
height="48dp",
)
# Adjust label height dynamically based on query length
query_lines = self.jql_query.count('\n') + 1
label_height = max(24, query_lines * 24) # Adjust 24dp per line
self.jql_label = MDLabel(
text=self.jql_query,
font_style="Caption",
halign="center",
theme_text_color="Hint",
size_hint_y=None,
height=f"{label_height}dp",
)
self.jql_label.bind(on_touch_down=self.on_jql_label_click)
self.add_widget(self.title_label)
self.add_widget(self.issue_label)
self.add_widget(self.jql_label)
def on_jql_label_click(self, instance, touch):
"""Handles click events on the JQL label."""
if self.collide_point(*touch.pos):
jira_url = f"{self.jira_base_url}?jql={urllib.parse.quote(self.jql_query)}"
webbrowser.open(jira_url)
print("User Clicked:", jira_url)
def update_label(self, count):
"""Updates the issue count label."""
self.issue_label.text = str(count)
# Inside IssueBox class
def update_ui_colors(self, theme_style):
app = MDApp.get_running_app()
if theme_style == 'Dark':
self.md_bg_color = app.theme_cls.bg_dark
text_color = LIGHT_TEXT_COLOR
else:
self.md_bg_color = app.theme_cls.bg_light
text_color = DARK_TEXT_COLOR
# Update the text color of all the labels
self.issue_label.color = text_color
self.title_label.color = text_color
self.jql_label.color = text_color